-
-
Notifications
You must be signed in to change notification settings - Fork 211
/
Copy pathCMakeLists.txt
113 lines (104 loc) · 4.42 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
# ##############################################################################
# Set up the compiler suite.
# ##############################################################################
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# ##############################################################################
# Build CuTest.
# ##############################################################################
add_library(cutest STATIC "cutest/CuTest.c")
target_include_directories(cutest PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/cutest")
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
# Disable warnings regarding sprintf.
target_compile_definitions(cutest PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()
# ##############################################################################
# Build testutils.
# ##############################################################################
add_library(testutils STATIC "testutils.c")
target_include_directories(testutils PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(testutils PUBLIC cutest tinyspline)
# ##############################################################################
# Check if code coverage is available. Coverage is measured and visualized using
# gcov, lcov, and genthml. If one of these tools is missing, code coverage
# cannot be generated.
#
# TINYSPLINE_COVERAGE_AVAILABLE TRUE if the tools that are required to generate
# code coverage are available. FALSE otherwise.
#
# TINYSPLINE_GCOV gcov executable.
#
# TINYSPLINE_LCOV lcov executable.
#
# TINYSPLINE_GENHTML genhtml executable.
#
# TINYSPLINE_COVERAGE_OUTPUT_DIRECTORY Root directory of genhtml output. Each
# target that generates code coverage should store its results in a separate
# subdirectory.
#
# TINYSPLINE_COVERAGE_C_FLAGS C flags for coverage executables.
#
# TINYSPLINE_COVERAGE_C_LIBRARIES C libraries for coverage executables.
#
# TINYSPLINE_COVERAGE_CXX_FLAGS C++ flags for coverage executables.
#
# TINYSPLINE_COVERAGE_CXX_LIBRARIES C++ libraries for coverage executables.
# ##############################################################################
# TINYSPLINE_COVERAGE_AVAILABLE
set(TINYSPLINE_COVERAGE_AVAILABLE FALSE)
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "GNU")
message(STATUS "Code coverage needs GCC")
else()
find_program(TINYSPLINE_GCOV gcov)
find_program(TINYSPLINE_LCOV lcov)
find_program(TINYSPLINE_GENHTML genhtml)
if(NOT TINYSPLINE_GCOV
OR NOT TINYSPLINE_LCOV
OR NOT TINYSPLINE_GENHTML
)
message(STATUS "Code coverage requires gcov, lcov, and genhtml")
else()
set(TINYSPLINE_COVERAGE_AVAILABLE TRUE)
endif()
endif()
# TINYSPLINE_COVERAGE_OUTPUT_DIRECTORY
set(TINYSPLINE_COVERAGE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/coverage)
set_directory_properties(
PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
"${TINYSPLINE_COVERAGE_OUTPUT_DIRECTORY}"
)
# TINYSPLINE_COVERAGE_C_FLAGS TINYSPLINE_COVERAGE_CXX_FLAGS
set(TINYSPLINE_COVERAGE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
set(TINYSPLINE_COVERAGE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
# TINYSPLINE_COVERAGE_C_LIBRARIES TINYSPLINE_COVERAGE_CXX_LIBRARIES
set(TINYSPLINE_COVERAGE_C_LIBRARIES "-lgcov")
set(TINYSPLINE_COVERAGE_CXX_LIBRARIES "-lgcov")
# ##############################################################################
# Add subdirectories containing unit tests.
# ##############################################################################
add_subdirectory(c)
add_subdirectory(cxx)
# ##############################################################################
# Subsume unit tests and code coverage via custom targets.
# ##############################################################################
add_custom_target(
tests
DEPENDS tinyspline_tests tinysplinecxx_tests
COMMAND tinyspline_tests
COMMAND tinysplinecxx_tests
)
add_custom_target(coverage DEPENDS tinyspline_coverage tinysplinecxx_coverage)
# ##############################################################################
# Add a custom target for checking memory issues with CTest.
# ##############################################################################
add_custom_target(
memcheck
DEPENDS tests
COMMAND ${CMAKE_CTEST_COMMAND} -T memcheck
COMMAND ${CMAKE_COMMAND} -E cat
"${CMAKE_BINARY_DIR}/Testing/Temporary/MemoryChecker.1.log"
COMMAND ${CMAKE_COMMAND} -E cat
"${CMAKE_BINARY_DIR}/Testing/Temporary/MemoryChecker.2.log"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
)