-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathCMakeLists.txt
127 lines (108 loc) · 3.44 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
# handle configuration for generation of coverage information as library
add_library(coverage INTERFACE)
if(OVERLAP_WITH_COVERAGE)
if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
if(NOT CMAKE_BUILD_TYPE MATCHES "(Debug|RelWithDebInfo)")
message(
FATAL_ERROR
"Generation of coverage information requires debug information, set "
"CMAKE_BUILD_TYPE=Debug or CMAKE_BUILD_TYPE=RelWithDebInfo."
)
endif()
message(STATUS "Enabling generation of coverage reports for C++ unit tests")
set(_coverage_compile_flags "--coverage")
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-fprofile-abs-path" have_fprofile_abs_path)
if(have_fprofile_abs_path)
list(APPEND _coverage_compile_flags "-fprofile-abs-path")
endif()
target_compile_options(coverage INTERFACE ${_coverage_compile_flags})
target_link_options(coverage INTERFACE "--coverage")
else()
message(FATAL_ERROR "Generation of coverage information not supported for "
${CMAKE_CXX_COMPILER_ID} " compiler"
)
endif()
endif()
if(NOT TARGET doctest::doctest)
add_subdirectory(
"${PROJECT_SOURCE_DIR}/third_party/doctest" "third_party/doctest"
EXCLUDE_FROM_ALL
)
list(APPEND CMAKE_MODULE_PATH
"${PROJECT_SOURCE_DIR}/third_party/doctest/scripts/cmake"
)
endif()
include(CTest)
include(doctest)
# helper function to add an individual test
function(overlap_add_test test_name test_source)
add_executable(${test_name} ${test_source})
target_compile_features(${test_name} PRIVATE cxx_std_17)
target_link_libraries(${test_name} PRIVATE doctest::doctest coverage)
set_target_properties(${test_name} PROPERTIES FOLDER tests)
target_compile_definitions(
${test_name} PRIVATE DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
)
doctest_discover_tests(
${test_name}
REPORTER
junit
OUTPUT_DIR
${CMAKE_BINARY_DIR}/
OUTPUT_PREFIX
doctest_testing_
OUTPUT_SUFFIX
.xml
)
endfunction()
# list of unit tests
set(unit_tests
clamp
contains
decompose_elements
normal_newell
polygon
polyhedron
regularized_wedge
regularized_wedge_area
sphere
sphere_element_area_edgecases
sphere_element_overlap
sphere_element_overlap_edgecases
sphere_hex_area
sphere_tet_area
sphere_tet_overlap_edgecases
)
list(TRANSFORM unit_tests PREPEND "test_")
# check for feenableexcept
include(CheckIncludeFile)
include(CheckSymbolExists)
include(CMakePushCheckState)
cmake_push_check_state(RESET)
check_include_file("fenv.h" _have_fenv_h)
if(_have_fenv_h)
set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
if(UNIX)
set(CMAKE_REQUIRED_LIBRARIES m)
endif()
check_symbol_exists(feenableexcept "fenv.h" OVERLAP_HAVE_FEENABLEEXCEPT)
set(CMAKE_REQUIRED_LIBRARIES)
endif()
cmake_reset_check_state()
# activate additional compiler warnings and keep frame pointers
if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)" AND CMAKE_BUILD_TYPE MATCHES
"(Debug|RelWithDebInfo)"
)
string(APPEND CMAKE_CXX_FLAGS "-Wall -Werror -Wextra -fno-omit-frame-pointer")
endif()
# register the individual unit tests
foreach(unit_test ${unit_tests})
overlap_add_test(${unit_test} "${unit_test}.cpp")
target_link_libraries(${unit_test} PRIVATE overlap::headers Eigen3::Eigen)
if(OVERLAP_HAVE_FEENABLEEXCEPT)
target_compile_definitions(
${unit_test} PRIVATE -DOVERLAP_HAVE_FEENABLEEXCEPT
)
endif()
endforeach()