-
Notifications
You must be signed in to change notification settings - Fork 285
/
CMakeLists.txt
153 lines (137 loc) · 5.53 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#
# Copyright (c) 2011-2024, The DART development contributors
# All rights reserved.
#
# The list of contributors can be found at:
# https://github.com/dartsim/dart/blob/main/LICENSE
#
# This file is provided under the following "BSD-style" License:
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Set up GoogleTest
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest
GIT_TAG v1.14.0
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
set(gtest_disable_pthreads ON CACHE BOOL "" FORCE)
set(BUILD_GMOCK ON CACHE BOOL "" FORCE)
set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
#===============================================================================
# This function uses following global properties:
# - DART_UNITTESTS
# - DART_${test_type}_TESTS
#
# Usage:
# dart_add_test("unit" test_UnitTestA) # assumed source is test_UnitTestA.cpp
# dart_add_test("unit" test_UnitTestB test_SourceB1.cpp)
# dart_add_test("unit" test_UnitTestA test_SourceC1.cpp test_SourceC2.cpp)
#===============================================================================
function(dart_add_test test_type target_name) # ARGN for source files
dart_property_add(DART_${test_type}_TESTS ${target_name})
if(${ARGC} GREATER 2)
set(sources ${ARGN})
else()
set(sources "${target_name}.cpp")
endif()
add_executable(${target_name} ${sources})
add_test(${target_name} ${target_name})
target_link_libraries(${target_name} dart gtest gtest_main)
dart_format_add(${sources})
endfunction()
#===============================================================================
# Usage:
# dart_get_tests("integration" compreshensive_tests)
# foreach(test ${compreshensive_tests})
# message(STATUS "Test: ${test})
# endforeach()
#===============================================================================
function(dart_get_tests output_var test_type)
get_property(var GLOBAL PROPERTY DART_${test_type}_TESTS)
set(${output_var} ${var} PARENT_SCOPE)
endfunction()
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
# We categorize tests as:
# - "integration": high level tests to verify the combination of several
# components are correctly performs together
# - "regression": issue wise tests to verify that the GitHub issues are still
# fixed even after further changes are made
# - "unit": low level tests for one or few classes and functions to verify that
# they performs correctly as expected
add_subdirectory(integration)
add_subdirectory(regression)
add_subdirectory(unit)
# Print tests
dart_get_tests(integration_tests "integration")
dart_get_tests(regression_tests "regression")
dart_get_tests(unit_tests "unit")
if(DART_VERBOSE)
message(STATUS "")
message(STATUS "[ Tests ]")
foreach(test ${integration_tests})
message(STATUS "Adding test: integration/${test}")
endforeach()
foreach(test ${regression_tests})
message(STATUS "Adding test: regression/${test}")
endforeach()
foreach(test ${unit_tests})
message(STATUS "Adding test: unit/${test}")
endforeach()
else()
list(LENGTH integration_tests integration_tests_len)
list(LENGTH regression_tests regression_tests_len)
list(LENGTH unit_tests unit_tests_len)
math(
EXPR tests_len
"${integration_tests_len} + ${regression_tests_len} + ${unit_tests_len}"
)
message(STATUS "Adding ${tests_len} tests ("
"integration: ${integration_tests_len}, "
"regression: ${regression_tests_len}, "
"unit: ${unit_tests_len}"
")"
)
endif()
# Add custom target to build all the tests as a single target
add_custom_target(
tests
DEPENDS ${integration_tests} ${regression_tests} ${unit_tests}
)
# Add custom target to build all the tests and run the tests
if(MSVC)
add_custom_target(tests_and_run
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C ${CMAKE_BUILD_TYPE}
DEPENDS ${integration_tests} ${regression_tests} ${unit_tests}
)
else()
add_custom_target(tests_and_run
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
DEPENDS ${integration_tests} ${regression_tests} ${unit_tests}
)
endif()
dart_format_add(GTestUtils.hpp)
add_subdirectory(benchmark)