forked from cpputest/cpputest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
284 lines (239 loc) · 9.92 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# 2.6.3 is needed for ctest support
# 3.1 is needed for target_sources
cmake_minimum_required(VERSION 3.1)
project(CppUTest)
set(CppUTest_version_major 4)
set(CppUTest_version_minor 0)
###############
# Conan support
###############
if (EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
message(STATUS "conan_basic_setup()")
conan_basic_setup()
endif()
option(STD_C "Use the standard C library" ON)
option(STD_CPP "Use the standard C++ library" ON)
option(CPPUTEST_FLAGS "Use the CFLAGS/CXXFLAGS/LDFLAGS set by CppUTest" ON)
option(MEMORY_LEAK_DETECTION "Enable memory leak detection" ON)
option(EXTENSIONS "Use the CppUTest extension library" ON)
option(LONGLONG "Support long long" OFF)
option(MAP_FILE "Enable the creation of a map file" OFF)
option(COVERAGE "Enable running with coverage" OFF)
option(C++11 "Compile with C++11 support" OFF)
option(WERROR "Compile with warnings as errors" OFF)
option(TESTS "Compile and make tests for the code?" ON)
option(TESTS_DETAILED "Run each test separately instead of grouped?" OFF)
option(TESTS_BUILD_DISCOVER "Build time test discover" ON)
option(EXAMPLES "Compile and make examples?" OFF)
option(VERBOSE_CONFIG "Print configuration to stdout during generation" ON)
option(LIBNAME_POSTFIX_BITSIZE "Add architecture bitsize (32/64) to the library name?" OFF)
option(LIBNAME_POSTFIX_DEBUG "Add indication of debug compilation to the library name?" OFF)
option(HAS_INF "Compiler has Inf value for float" ON)
option(HAS_NAN "Compiler has NaN value for float" ON)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "What kind of build this is" FORCE)
endif(NOT CMAKE_BUILD_TYPE)
# Pkg-config file
include(FindPkgConfig)
set(CppUTest_PKGCONFIG_FILE cpputest.pc)
set(CppUTestRootDirectory ${PROJECT_SOURCE_DIR})
set( CppUTestLibName "CppUTest" )
set( CppUTestExtLibName "CppUTestExt" )
if(LIBNAME_POSTFIX_BITSIZE)
if( "${CMAKE_SIZEOF_VOID_P}" STREQUAL "8" )
set( CppUTestLibName "${CppUTestLibName}64" )
set( CppUTestExtLibName "${CppUTestExtLibName}64" )
elseif( "${CMAKE_SIZEOF_VOID_P}" STREQUAL "4" )
set( CppUTestLibName "${CppUTestLibName}32" )
set( CppUTestExtLibName "${CppUTestExtLibName}32" )
endif()
endif(LIBNAME_POSTFIX_BITSIZE)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CppUTestRootDirectory}/cmake/Modules)
include("${CppUTestRootDirectory}/cmake/Modules/CppUTestConfigurationOptions.cmake")
include(CTest)
#include("${CppUTestRootDirectory}/cmake/Modules/CheckFunctionExists.cmake")
include("${CppUTestRootDirectory}/cmake/Modules/CppUTestBuildTimeDiscoverTests.cmake")
include("${CppUTestRootDirectory}/cmake/Modules/CppUTestNormalizeTestOutputLocation.cmake")
include(GNUInstallDirs)
enable_testing()
add_subdirectory(src/CppUTest)
include(CheckIncludeFileCXX)
check_include_file_cxx("fenv.h" CPPUTEST_HAVE_FENV)
# Check for functions before setting a lot of stuff
include(CheckFunctionExists)
include(CheckSymbolExists)
set (CMAKE_REQUIRED_INCLUDES "unistd.h")
check_symbol_exists(fork "unistd.h" HAVE_FORK)
if(HAVE_FORK)
target_compile_definitions(${CppUTestLibName}
PUBLIC
CPPUTEST_HAVE_FORK
)
endif(HAVE_FORK)
check_symbol_exists(waitpid "sys/wait.h" HAVE_WAITPID)
if(HAVE_WAITPID)
target_compile_definitions(${CppUTestLibName}
PUBLIC
CPPUTEST_HAVE_WAITPID
)
endif(HAVE_WAITPID)
check_symbol_exists(gettimeofday "sys/time.h" HAVE_GETTIMEOFDAY)
if(HAVE_GETTIMEOFDAY)
target_compile_definitions(${CppUTestLibName}
PUBLIC
CPPUTEST_HAVE_GETTIMEOFDAY=1
)
endif(HAVE_GETTIMEOFDAY)
check_symbol_exists(pthread_mutex_lock "pthread.h" HAVE_PTHREAD_MUTEX_LOCK)
if(HAVE_PTHREAD_MUTEX_LOCK)
target_compile_definitions(${CppUTestLibName}
PUBLIC
CPPUTEST_HAVE_PTHREAD_MUTEX_LOCK=1
)
endif(HAVE_PTHREAD_MUTEX_LOCK)
if (NOT IAR)
check_function_exists(strdup HAVE_STRDUP)
if(HAVE_STRDUP)
target_compile_definitions(${CppUTestLibName}
PUBLIC
CPPUTEST_HAVE_STRDUP=1
)
endif(HAVE_STRDUP)
endif(NOT IAR)
if (MINGW)
# Apply workaround for MinGW timespec redefinition (pthread.h / time.h)
include(CheckStructHasMember)
check_struct_has_member("struct timespec" tv_sec time.h HAVE_STRUCT_TIMESPEC)
if (HAVE_STRUCT_TIMESPEC)
target_compile_definitions(${CppUTestLibName}
PUBLIC
_TIMESPEC_DEFINED=1
)
endif()
if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# Apply workaround for static/shared libraries on MinGW C/C++ compiler
# Issue occurs with CMake >= 3.9.0, it doesn't filter out gcc,gcc_s,gcc_eh from
# the implicit library list anymore, so the C++ linker is getting passed the static
# gcc_eh library since that's what the C linker uses by default. Only solution appears
# to be to force static linkage.
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
endif()
endif()
include(CheckTypeSize)
check_type_size("long long" SIZEOF_LONGLONG)
if(HAVE_SIZEOF_LONGLONG)
set(CPPUTEST_HAVE_LONG_LONG_INT ON)
endif()
configure_file (
"${PROJECT_SOURCE_DIR}/config.h.cmake"
"${PROJECT_BINARY_DIR}/generated/CppUTestGeneratedConfig.h"
)
target_include_directories(${CppUTestLibName}
PUBLIC
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
)
target_compile_definitions(${CppUTestLibName}
PUBLIC
$<BUILD_INTERFACE:HAVE_CONFIG_H>
)
if (EXTENSIONS)
add_subdirectory(src/CppUTestExt)
endif (EXTENSIONS)
if (TESTS)
add_subdirectory(tests/CppUTest)
if (EXTENSIONS)
add_subdirectory(tests/CppUTestExt)
endif (EXTENSIONS)
endif (TESTS)
if (EXAMPLES)
add_subdirectory(examples)
endif(EXAMPLES)
set (INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
set (LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}")
set (INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
# Pkg-config file.
set (prefix "${CMAKE_INSTALL_PREFIX}")
set (exec_prefix "\${prefix}")
set (libdir "\${exec_prefix}/${LIB_INSTALL_DIR}")
set (includedir "\${prefix}/${INCLUDE_INSTALL_DIR}")
set (PACKAGE_VERSION "${CppUTest_version_major}.${CppUTest_version_minor}")
configure_file (cpputest.pc.in
${CMAKE_CURRENT_BINARY_DIR}/${CppUTest_PKGCONFIG_FILE} @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${CppUTest_PKGCONFIG_FILE}
DESTINATION ${LIB_INSTALL_DIR}/pkgconfig
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/generated/CppUTestGeneratedConfig.h"
DESTINATION "${INCLUDE_INSTALL_DIR}/CppUTest"
)
# Try to include helper module
include(CMakePackageConfigHelpers OPTIONAL
RESULT_VARIABLE PkgHelpers_AVAILABLE)
# guard against older versions of cmake which do not provide it
if(PkgHelpers_AVAILABLE)
configure_package_config_file(CppUTestConfig.cmake.install.in
${CMAKE_CURRENT_BINARY_DIR}/install/CppUTestConfig.cmake
INSTALL_DESTINATION ${LIB_INSTALL_DIR}/CppUTest/cmake
PATH_VARS INCLUDE_INSTALL_DIR LIB_INSTALL_DIR)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/install/CppUTestConfigVersion.cmake
VERSION ${CppUTest_version_major}.${CppUTest_version_minor}
COMPATIBILITY SameMajorVersion )
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/install/CppUTestConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/install/CppUTestConfigVersion.cmake
DESTINATION ${LIB_INSTALL_DIR}/CppUTest/cmake )
install(EXPORT CppUTestTargets
DESTINATION ${LIB_INSTALL_DIR}/CppUTest/cmake)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Scripts/CppUTestBuildTimeDiscoverTests.cmake
DESTINATION ${LIB_INSTALL_DIR}/CppUTest/cmake/Scripts)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/CppUTestBuildTimeDiscoverTests.cmake
DESTINATION ${LIB_INSTALL_DIR}/CppUTest/cmake/Modules)
configure_package_config_file(CppUTestConfig.cmake.build.in
${CMAKE_CURRENT_BINARY_DIR}/CppUTestConfig.cmake
INSTALL_DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
PATH_VARS INCLUDE_DIR CMAKE_CURRENT_BINARY_DIR)
if (EXTENSIONS)
export(TARGETS ${CppUTestLibName} ${CppUTestExtLibName}
FILE "${CMAKE_CURRENT_BINARY_DIR}/CppUTestTargets.cmake")
else()
export(TARGETS ${CppUTestLibName}
FILE "${CMAKE_CURRENT_BINARY_DIR}/CppUTestTargets.cmake")
endif()
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/CppUTestConfigVersion.cmake
VERSION ${CppUTest_version_major}.${CppUTest_version_minor}
COMPATIBILITY SameMajorVersion )
set(CppUTest_DIR "${CMAKE_CURRENT_BINARY_DIR}" CACHE PATH "The directory containing a CMake configuration file for CppUTest.")
else()
message("If you wish to use find_package(CppUTest) in your own project to find CppUTest library"
" please update cmake to version which provides CMakePackageConfighelpers module"
" or write generators for CppUTestConfig.cmake by yourself.")
endif()
if(VERBOSE_CONFIG)
message("
-------------------------------------------------------
CppUTest Version ${CppUTest_version_major}.${CppUTest_version_minor}
Current compiler options:
CC: ${CMAKE_C_COMPILER}
CXX: ${CMAKE_CXX_COMPILER}
CppUTest CFLAGS: ${CPPUTEST_C_FLAGS}
CppUTest CXXFLAGS: ${CPPUTEST_CXX_FLAGS}
CppUTest LDFLAGS: ${CPPUTEST_LD_FLAGS}
Features configured in CppUTest:
Memory Leak Detection: ${MEMORY_LEAK_DETECTION}
Compiling Extensions: ${EXTENSIONS}
Support Long Long: ${LONGLONG}
Use CppUTest flags: ${CPPUTEST_FLAGS}
Using Standard C library: ${STD_C}
Using Standard C++ library: ${STD_CPP}
Using C++11 library: ${C++11}
Generating map file: ${MAP_FILE}
Compiling with coverage: ${COVERAGE}
Compile and run self-tests ${TESTS}
Run self-tests separately ${TESTS_DETAILED}
Library name options:
Add architecture bitsize (32/64) ${LIBNAME_POSTFIX_BITSIZE}
Add debug compilation indicator ${LIBNAME_POSTFIX_DEBUG}
-------------------------------------------------------
")
endif()