CMakeLists.txt 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. #
  2. # Check: a unit test framework for C
  3. #
  4. # Copyright (C) 2011 Mateusz Loskot
  5. # Copyright (C) 2001, 2002 Arien Malec
  6. # Copyright (C) 2020 Mikko Koivunalho
  7. #
  8. # This library is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU Lesser General Public
  10. # License as published by the Free Software Foundation; either
  11. # version 2.1 of the License, or (at your option) any later version.
  12. #
  13. # This library is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. # Lesser General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Lesser General Public
  19. # License along with this library; if not, write to the
  20. # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  21. # Boston, MA 02111-1307, USA.
  22. #
  23. cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
  24. include(CheckCCompilerFlag)
  25. # Detect if Check is being used in another build as a subproject
  26. # probably with command FetchContent*().
  27. set(THIS_IS_SUBPROJECT FALSE)
  28. if(DEFINED PROJECT_NAME)
  29. set(THIS_IS_SUBPROJECT TRUE)
  30. message(STATUS "Turned off installing because Check is a subproject.")
  31. message(STATUS "Turned off building tests because Check is a subproject.")
  32. endif()
  33. if(POLICY CMP0090)
  34. # export(PACKAGE) does not populate package registry by default. (NEW)
  35. cmake_policy(SET CMP0090 NEW)
  36. endif()
  37. if(POLICY CMP0076)
  38. # target_sources() leaves relative source file paths unmodified. (OLD)
  39. cmake_policy(SET CMP0076 OLD)
  40. endif()
  41. project(Check
  42. DESCRIPTION "Unit Testing Framework for C"
  43. LANGUAGES C)
  44. list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
  45. ###############################################################################
  46. # Set build features
  47. # Set CMAKE_BUILD_TYPE to Debug if source directory is a Git repository
  48. # or user does not override on the command line
  49. include(BuildType)
  50. ###############################################################################
  51. # Configure a project for testing with CTest/CDash
  52. include(CTest)
  53. macro(extract_version file setting_name)
  54. file(STRINGS ${file} VERSION_NUMBER REGEX "^${setting_name}")
  55. string(REPLACE "=" ";" VERSION_NUMBER_LIST ${VERSION_NUMBER})
  56. list(GET VERSION_NUMBER_LIST 1 ${setting_name})
  57. endmacro(extract_version)
  58. extract_version(configure.ac CHECK_MAJOR_VERSION)
  59. extract_version(configure.ac CHECK_MINOR_VERSION)
  60. extract_version(configure.ac CHECK_MICRO_VERSION)
  61. set(PROJECT_VERSION_MAJOR ${CHECK_MAJOR_VERSION})
  62. set(PROJECT_VERSION_MINOR ${CHECK_MINOR_VERSION})
  63. set(PROJECT_VERSION_PATCH ${CHECK_MICRO_VERSION})
  64. set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
  65. ###############################################################################
  66. # Provides install directory variables as defined by the GNU Coding Standards.
  67. include(GNUInstallDirs)
  68. ###############################################################################
  69. # Follow ISO C99 standard
  70. set(CMAKE_C_STANDARD 99)
  71. set(CMAKE_C_STANDARD_REQUIRED ON)
  72. set(CMAKE_C_EXTENSIONS ON) # Use GNU extensions and POSIX standard
  73. ###############################################################################
  74. # Option
  75. option(CHECK_ENABLE_TESTS
  76. "Deprecated: Enable the compilation and running of Check's unit tests" ON)
  77. if(NOT CHECK_ENABLE_TESTS)
  78. message(DEPRECATION "The option CHECK_ENABLE_TESTS is deprecated. Use option BUILD_TESTING.")
  79. # TODO Remove this option by Check 0.15.0!
  80. endif(NOT CHECK_ENABLE_TESTS)
  81. option(CHECK_ENABLE_GCOV
  82. "Turn on test coverage" OFF)
  83. if (CHECK_ENABLE_GCOV AND NOT ${CMAKE_C_COMPILER_ID} MATCHES "GNU")
  84. message(FATAL_ERROR "Code Coverage (gcov) only works if GNU compiler is used!")
  85. endif (CHECK_ENABLE_GCOV AND NOT ${CMAKE_C_COMPILER_ID} MATCHES "GNU")
  86. option(ENABLE_MEMORY_LEAKING_TESTS
  87. "Enable certain memory leaking tests only if valgrind is not used in testing" ON)
  88. option(CHECK_ENABLE_TIMEOUT_TESTS
  89. "Enable Check's timeout related unit tests" ON)
  90. if(CHECK_ENABLE_TIMEOUT_TESTS)
  91. add_definitions(-DTIMEOUT_TESTS_ENABLED=1)
  92. else(CHECK_ENABLE_TIMEOUT_TESTS)
  93. add_definitions(-DTIMEOUT_TESTS_ENABLED=0)
  94. endif(CHECK_ENABLE_TIMEOUT_TESTS)
  95. ###############################################################################
  96. # Check system and architecture
  97. if(WIN32)
  98. if(MSVC60)
  99. set(WINVER 0x0400)
  100. else()
  101. set(WINVER 0x0600)
  102. endif()
  103. set(_WIN32_WINNT ${WINVER})
  104. endif(WIN32)
  105. if(MSVC)
  106. add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
  107. add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  108. add_definitions(-D_CRT_NONSTDC_NO_WARNINGS)
  109. endif(MSVC)
  110. ###############################################################################
  111. include(CheckCSourceCompiles)
  112. include(CheckCSourceRuns)
  113. include(CheckFunctionExists)
  114. include(CheckIncludeFile)
  115. include(CheckIncludeFiles)
  116. include(CheckLibraryExists)
  117. include(CheckStructMember)
  118. include(CheckSymbolExists)
  119. include(CheckTypeExists)
  120. include(CheckTypeSize)
  121. ###############################################################################
  122. # Check headers
  123. set(INCLUDES "")
  124. macro(ck_check_include_file header var)
  125. check_include_files("${INCLUDES};${header}" ${var})
  126. if(${var})
  127. set(INCLUDES ${INCLUDES} ${header})
  128. endif(${var})
  129. endmacro(ck_check_include_file)
  130. # Some FreeBSD headers assume sys/types.h was already included.
  131. ck_check_include_file("sys/types.h" HAVE_SYS_TYPES_H)
  132. # Alphabetize the rest unless there's a compelling reason
  133. ck_check_include_file("errno.h" HAVE_ERRNO_H)
  134. ck_check_include_file("inttypes.h" HAVE_INTTYPES_H)
  135. ck_check_include_file("limits.h" HAVE_LIMITS_H)
  136. ck_check_include_file("regex.h" HAVE_REGEX_H)
  137. ck_check_include_file("signal.h" HAVE_SIGNAL_H)
  138. ck_check_include_file("stdarg.h" HAVE_STDARG_H)
  139. ck_check_include_file("stdint.h" HAVE_STDINT_H)
  140. ck_check_include_file("stdlib.h" HAVE_STDLIB_H)
  141. ck_check_include_file("string.h" HAVE_STRING_H)
  142. ck_check_include_file("strings.h" HAVE_STRINGS_H)
  143. ck_check_include_file("sys/time.h" HAVE_SYS_TIME_H)
  144. ck_check_include_file("time.h" HAVE_TIME_H)
  145. ck_check_include_file("unistd.h" HAVE_UNISTD_H)
  146. ck_check_include_file("pthread.h" HAVE_PTHREAD)
  147. # check if we have windows.h on native windows environments
  148. ck_check_include_file("windows.h" HAVE_WINDOWS_H)
  149. ###############################################################################
  150. # Check functions
  151. check_function_exists(fork HAVE_FORK)
  152. check_function_exists(getline HAVE_GETLINE)
  153. check_function_exists(getpid HAVE_GETPID)
  154. check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
  155. check_function_exists(localtime_r HAVE_DECL_LOCALTIME_R)
  156. check_function_exists(malloc HAVE_MALLOC)
  157. check_function_exists(mkstemp HAVE_MKSTEMP)
  158. check_function_exists(realloc HAVE_REALLOC)
  159. check_function_exists(setenv HAVE_DECL_SETENV)
  160. check_function_exists(sigaction HAVE_SIGACTION)
  161. check_function_exists(strdup HAVE_DECL_STRDUP)
  162. check_function_exists(strsignal HAVE_DECL_STRSIGNAL)
  163. check_function_exists(_getpid HAVE__GETPID)
  164. check_function_exists(_strdup HAVE__STRDUP)
  165. check_function_exists(alarm HAVE_DECL_ALARM)
  166. if (HAVE_WINDOWS_H)
  167. check_function_exists(InitOnceBeginInitialize HAVE_INIT_ONCE_BEGIN_INITIALIZE)
  168. check_function_exists(InitOnceComplete HAVE_INIT_ONCE_COMPLETE)
  169. endif()
  170. if (HAVE_REGEX_H)
  171. check_function_exists(regcomp HAVE_REGCOMP)
  172. check_function_exists(regexec HAVE_REGEXEC)
  173. endif()
  174. # printf related checks
  175. check_function_exists(snprintf HAVE_SNPRINTF_FUNCTION)
  176. check_function_exists(vsnprintf HAVE_VSNPRINTF_FUNCTION)
  177. check_symbol_exists(snprintf stdio.h HAVE_SNPRINTF_SYMBOL)
  178. check_symbol_exists(vsnprintf stdio.h HAVE_VSNPRINTF_SYMBOL)
  179. if(NOT HAVE_SNPRINTF_FUNCTION AND NOT HAVE_SNPRINTF_SYMBOL)
  180. add_definitions(-Dsnprintf=rpl_snprintf)
  181. set(snprintf rpl_snprintf)
  182. add_definitions(-Dvsnprintf=rpl_vsnprintf)
  183. set(vsnprintf rpl_vsnprintf)
  184. else(NOT HAVE_SNPRINTF_FUNCTION AND NOT HAVE_SNPRINTF_SYMBOL)
  185. set(HAVE_SNPRINTF 1)
  186. add_definitions(-DHAVE_SNPRINTF=1)
  187. set(HAVE_VSNPRINTF 1)
  188. add_definitions(-DHAVE_VSNPRINTF=1)
  189. endif(NOT HAVE_SNPRINTF_FUNCTION AND NOT HAVE_SNPRINTF_SYMBOL)
  190. if(HAVE_FORK)
  191. add_definitions(-DHAVE_FORK=1)
  192. set(HAVE_FORK 1)
  193. else(HAVE_FORK)
  194. add_definitions(-DHAVE_FORK=0)
  195. set(HAVE_FORK 0)
  196. endif(HAVE_FORK)
  197. if(HAVE_MKSTEMP)
  198. add_definitions(-DHAVE_MKSTEMP=1)
  199. set(HAVE_MKSTEMP 1)
  200. else(HAVE_MKSTEMP)
  201. add_definitions(-DHAVE_MKSTEMP=0)
  202. set(HAVE_MKSTEMP 0)
  203. endif(HAVE_MKSTEMP)
  204. if(HAVE_DECL_ALARM)
  205. add_definitions(-DHAVE_DECL_ALARM=1)
  206. set(HAVE_DECL_ALARM 1)
  207. else(HAVE_DECL_ALARM)
  208. add_definitions(-DHAVE_DECL_ALARM=0)
  209. set(HAVE_DECL_ALARM 0)
  210. endif(HAVE_DECL_ALARM)
  211. if(HAVE_REGEX_H AND HAVE_REGCOMP AND HAVE_REGEXEC)
  212. add_definitions(-DHAVE_REGEX=1)
  213. set(HAVE_REGEX 1)
  214. add_definitions(-DENABLE_REGEX=1)
  215. set(ENABLE_REGEX 1)
  216. endif()
  217. if (HAVE_PTHREAD)
  218. check_c_compiler_flag("-pthread" HAVE_PTHREADS_FLAG)
  219. if (HAVE_PTHREADS_FLAG)
  220. add_definitions("-pthread")
  221. add_link_options("-pthread")
  222. endif()
  223. endif()
  224. ###############################################################################
  225. # Check defines
  226. set(headers "limits.h")
  227. if(HAVE_STDINT_H)
  228. list(APPEND headers "stdint.h")
  229. endif(HAVE_STDINT_H)
  230. if(HAVE_INTTYPES_H)
  231. list(APPEND headers "inttypes.h")
  232. endif(HAVE_INTTYPES_H)
  233. check_symbol_exists(INT64_MAX "${headers}" HAVE_INT64_MAX)
  234. check_symbol_exists(INT64_MIN "${headers}" HAVE_INT64_MIN)
  235. check_symbol_exists(UINT32_MAX "${headers}" HAVE_UINT32_MAX)
  236. check_symbol_exists(UINT64_MAX "${headers}" HAVE_UINT64_MAX)
  237. check_symbol_exists(SIZE_MAX "${headers}" HAVE_SIZE_MAX)
  238. check_symbol_exists(SSIZE_MAX "limits.h" HAVE_SSIZE_MAX)
  239. ###############################################################################
  240. # Check struct members
  241. # Check for tv_sec in struct timeval
  242. if(NOT HAVE_SYS_TIME_H)
  243. if(MSVC)
  244. check_struct_member("struct timeval" tv_sec "Winsock2.h" HAVE_STRUCT_TIMEVAL_TV_SEC)
  245. check_struct_member("struct timeval" tv_usec "Winsock2.h" HAVE_STRUCT_TIMEVAL_TV_USEC)
  246. check_struct_member("struct timespec" tv_sec "Winsock2.h" HAVE_WINSOCK2_H_STRUCT_TIMESPEC_TV_SEC)
  247. check_struct_member("struct timespec" tv_sec "time.h" HAVE_TIME_H_STRUCT_TIMESPEC_TV_SEC)
  248. check_struct_member("struct itimerspec" it_value "Winsock2.h" HAVE_STRUCT_ITIMERSPEC_IT_VALUE)
  249. if(NOT HAVE_WINSOCK2_H_STRUCT_TIMESPEC_TV_SEC AND NOT HAVE_TIME_H_STRUCT_TIMESPEC_TV_SEC)
  250. add_definitions(-DSTRUCT_TIMESPEC_DEFINITION_MISSING=1)
  251. set(STRUCT_TIMESPEC_DEFINITION_MISSING 1)
  252. endif(NOT HAVE_WINSOCK2_H_STRUCT_TIMESPEC_TV_SEC AND NOT HAVE_TIME_H_STRUCT_TIMESPEC_TV_SEC)
  253. if(NOT HAVE_STRUCT_ITIMERSPEC_IT_VALUE)
  254. add_definitions(-DSTRUCT_ITIMERSPEC_DEFINITION_MISSING=1)
  255. set(STRUCT_ITIMERSPEC_DEFINITION_MISSING 1)
  256. endif(NOT HAVE_STRUCT_ITIMERSPEC_IT_VALUE)
  257. endif(MSVC)
  258. endif(NOT HAVE_SYS_TIME_H)
  259. # OSX has sys/time.h, but it still lacks itimerspec
  260. if(HAVE_SYS_TIME_H)
  261. check_struct_member("struct itimerspec" it_value "sys/time.h" HAVE_STRUCT_ITIMERSPEC_IT_VALUE)
  262. if(NOT HAVE_STRUCT_ITIMERSPEC_IT_VALUE)
  263. add_definitions(-DSTRUCT_ITIMERSPEC_DEFINITION_MISSING=1)
  264. set(STRUCT_ITIMERSPEC_DEFINITION_MISSING 1)
  265. endif(NOT HAVE_STRUCT_ITIMERSPEC_IT_VALUE)
  266. endif(HAVE_SYS_TIME_H)
  267. ###############################################################################
  268. # Check for integer types
  269. check_type_size("short" SIZE_OF_SHORT)
  270. check_type_size("int" SIZE_OF_INT)
  271. check_type_size("long" SIZE_OF_LONG)
  272. check_type_size("long long" SIZE_OF_LONG_LONG)
  273. check_type_size("unsigned short" SIZE_OF_UNSIGNED_SHORT)
  274. check_type_size("unsigned" SIZE_OF_UNSIGNED)
  275. check_type_size("unsigned long" SIZE_OF_UNSIGNED_LONG)
  276. check_type_size("unsigned long long" SIZE_OF_UNSIGNED_LONG_LONG)
  277. check_type_size("__int64" __INT64)
  278. check_type_size("unsigned __int64" UNSIGNED___INT64)
  279. check_type_size(int16_t INT16_T)
  280. check_type_size(int32_t INT32_T)
  281. check_type_size(int64_t INT64_T)
  282. check_type_size(intmax_t INTMAX_T)
  283. check_type_size(uint8_t UINT8_T)
  284. check_type_size(uint16_t UINT16_T)
  285. check_type_size(uint32_t UINT32_T)
  286. check_type_size(uint64_t UINT64_T)
  287. check_type_size(uintmax_t UINTMAX_T)
  288. #
  289. set(CMAKE_EXTRA_INCLUDE_FILES time.h)
  290. check_type_size(clock_t CLOCK_T)
  291. if(NOT HAVE_CLOCK_T)
  292. set(clock_t int)
  293. endif(NOT HAVE_CLOCK_T)
  294. unset(CMAKE_EXTRA_INCLUDE_FILES)
  295. #
  296. set(CMAKE_EXTRA_INCLUDE_FILES time.h)
  297. check_type_size(clockid_t CLOCKID_T)
  298. if(NOT HAVE_CLOCKID_T)
  299. set(clockid_t int)
  300. endif(NOT HAVE_CLOCKID_T)
  301. unset(CMAKE_EXTRA_INCLUDE_FILES)
  302. #
  303. check_type_size(size_t SIZE_T)
  304. if(NOT HAVE_SIZE_T)
  305. if("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
  306. set(size_t "uint64_t")
  307. else("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
  308. set(size_t "uint32_t")
  309. endif("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
  310. endif(NOT HAVE_SIZE_T)
  311. #
  312. check_type_size(ssize_t SSIZE_T)
  313. if(NOT HAVE_SSIZE_T)
  314. if("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
  315. set(ssize_t "int64_t")
  316. else("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
  317. set(ssize_t "long")
  318. endif("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
  319. endif(NOT HAVE_SSIZE_T)
  320. #
  321. check_type_size(pid_t PID_T)
  322. if(NOT HAVE_PID_T)
  323. if(WIN32)
  324. set(pid_t "int")
  325. else(WIN32)
  326. MESSAGE(FATAL_ERROR "pid_t doesn't exist on this platform?")
  327. endif(WIN32)
  328. endif(NOT HAVE_PID_T)
  329. #
  330. set(CMAKE_EXTRA_INCLUDE_FILES time.h)
  331. check_type_size(timer_t TIMER_T)
  332. if(NOT HAVE_TIMER_T)
  333. set(timer_t int)
  334. endif(NOT HAVE_TIMER_T)
  335. unset(CMAKE_EXTRA_INCLUDE_FILES)
  336. ###############################################################################
  337. # Check libraries
  338. check_library_exists(m floor "" HAVE_LIBM)
  339. if (HAVE_LIBM)
  340. set (LIBM "m")
  341. endif (HAVE_LIBM)
  342. check_library_exists(rt clock_gettime "" HAVE_LIBRT)
  343. if (HAVE_LIBRT)
  344. set(LIBRT "rt")
  345. ADD_DEFINITIONS(-DHAVE_LIBRT=1)
  346. endif (HAVE_LIBRT)
  347. check_library_exists(subunit subunit_test_start "" HAVE_SUBUNIT)
  348. if (HAVE_SUBUNIT)
  349. set(SUBUNIT "subunit")
  350. set(ENABLE_SUBUNIT 1)
  351. add_definitions(-DENABLE_SUBUNIT=1)
  352. else(HAVE_SUBUNIT)
  353. set(ENABLE_SUBUNIT 0)
  354. add_definitions(-DENABLE_SUBUNIT=0)
  355. endif (HAVE_SUBUNIT)
  356. ###############################################################################
  357. # Generate "config.h" from "cmake/config.h.in"
  358. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.h.in
  359. ${CMAKE_CURRENT_BINARY_DIR}/config.h)
  360. # Param @ONLY not used on purpose!
  361. include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
  362. add_definitions(-DHAVE_CONFIG_H)
  363. set(CONFIG_HEADER ${CMAKE_CURRENT_BINARY_DIR}/config.h)
  364. ###############################################################################
  365. # Generate "check_stdint.h" from "cmake/check_stdint.h.in"
  366. #
  367. # The corresponding GNU Autotools build of this project
  368. # has m4 macro `m4/ax_create_stdint_h.m4` to create
  369. # the file `check_stdint.h` from scratch.
  370. # Include file `stdint.h` was introduced in C99 ANSI standard but
  371. # many compilers were lacking behind or still are and
  372. # have not implemented C99 or their `stdint.h` is not compatible.
  373. # Therefore the m4 macro was needed to create the required datatypes.
  374. #
  375. # When converting to CMake we also want to abandon the m4 macros.
  376. #
  377. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/check_stdint.h.in
  378. ${CMAKE_CURRENT_BINARY_DIR}/check_stdint.h @ONLY)
  379. if(NOT THIS_IS_SUBPROJECT)
  380. install(
  381. FILES ${CMAKE_CURRENT_BINARY_DIR}/check_stdint.h
  382. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
  383. endif()
  384. ###############################################################################
  385. # Generate "check.pc", the package config (pkgconfig) file for libtool
  386. if(NOT THIS_IS_SUBPROJECT)
  387. set(prefix_save "${PREFIX}")
  388. set(prefix "${CMAKE_INSTALL_PREFIX}")
  389. set(exec_prefix "\${prefix}")
  390. set(libdir ${CMAKE_INSTALL_FULL_LIBDIR})
  391. set(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})
  392. set(VERSION "${PROJECT_VERSION}")
  393. if (HAVE_SUBUNIT)
  394. set(LIBSUBUNIT_PC "libsubunit")
  395. else (HAVE_SUBINIT)
  396. set(LIBSUBUNIT_PC "")
  397. endif (HAVE_SUBUNIT)
  398. if (CHECK_ENABLE_GCOV)
  399. set(GCOV_LIBS "-lgcov")
  400. else (CHECK_ENABLE_GCOV)
  401. set(GCOV_LIBS "")
  402. endif (CHECK_ENABLE_GCOV)
  403. set(PTHREAD_LIBS "-pthread")
  404. set(LIBS "")
  405. if (HAVE_LIBM)
  406. set(LIBS "${LIBS} -lm")
  407. endif (HAVE_LIBM)
  408. if (HAVE_LIBRT)
  409. set(LIBS "${LIBS} -lrt")
  410. endif (HAVE_LIBRT)
  411. set(PTHREAD_CFLAGS "-pthread")
  412. configure_file(check.pc.in check.pc @ONLY)
  413. unset(PTHREAD_CFLAGS)
  414. unset(LIBS)
  415. unset(PTHREAD_LIBS)
  416. unset(GCOV_LIBS)
  417. unset(LIBSUBUNIT_PC)
  418. unset(VERSION)
  419. unset(includedir)
  420. unset(libdir)
  421. unset(exec_prefix)
  422. set(PREFIX "${prefix_save}")
  423. install(
  424. FILES ${CMAKE_CURRENT_BINARY_DIR}/check.pc
  425. DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
  426. )
  427. endif()
  428. ###############################################################################
  429. # Subdirectories
  430. add_subdirectory(doc)
  431. add_subdirectory(lib)
  432. add_subdirectory(src)
  433. add_subdirectory(checkmk)
  434. ###############################################################################
  435. # Unit tests
  436. if(BUILD_TESTING AND NOT THIS_IS_SUBPROJECT)
  437. add_subdirectory(tests)
  438. add_test(NAME check_check COMMAND check_check)
  439. add_test(NAME check_check_export COMMAND check_check_export)
  440. # Only offer to run shell scripts if we may have a working interpreter
  441. if(UNIX OR MINGW OR MSYS)
  442. add_test(NAME test_output.sh
  443. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests
  444. COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_output.sh)
  445. add_test(NAME test_log_output.sh
  446. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests
  447. COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_log_output.sh)
  448. add_test(NAME test_xml_output.sh
  449. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests
  450. COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_xml_output.sh)
  451. add_test(NAME test_tap_output.sh
  452. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests
  453. COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_tap_output.sh)
  454. add_test(NAME test_check_nofork.sh
  455. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests
  456. COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_check_nofork.sh)
  457. add_test(NAME test_check_nofork_teardown.sh
  458. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests
  459. COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_check_nofork_teardown.sh)
  460. add_test(NAME test_set_max_msg_size.sh
  461. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests
  462. COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_set_max_msg_size.sh)
  463. endif(UNIX OR MINGW OR MSYS)
  464. endif()
  465. ###############################################################################
  466. # Export project, prepare a config and config-version files
  467. if(NOT THIS_IS_SUBPROJECT)
  468. string(TOLOWER ${PROJECT_NAME} EXPORT_NAME)
  469. include(CMakePackageConfigHelpers)
  470. configure_package_config_file(
  471. ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${EXPORT_NAME}-config.cmake.in
  472. ${CMAKE_CURRENT_BINARY_DIR}/cmake/${EXPORT_NAME}-config.cmake
  473. INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/${EXPORT_NAME}/cmake
  474. )
  475. write_basic_package_version_file(
  476. ${CMAKE_CURRENT_BINARY_DIR}/cmake/${EXPORT_NAME}-config-version.cmake
  477. VERSION ${PROJECT_VERSION}
  478. COMPATIBILITY AnyNewerVersion
  479. )
  480. export(EXPORT check-targets
  481. FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/${EXPORT_NAME}-targets.cmake"
  482. NAMESPACE "${PROJECT_NAME}::"
  483. )
  484. install(EXPORT check-targets
  485. NAMESPACE "${PROJECT_NAME}::"
  486. FILE "${EXPORT_NAME}-targets.cmake"
  487. DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${EXPORT_NAME}
  488. )
  489. install(
  490. FILES
  491. "${CMAKE_CURRENT_BINARY_DIR}/cmake/${EXPORT_NAME}-config.cmake"
  492. "${CMAKE_CURRENT_BINARY_DIR}/cmake/${EXPORT_NAME}-config-version.cmake"
  493. DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${EXPORT_NAME}
  494. )
  495. endif()
  496. # Store the current build directory in the CMake user package registry.
  497. # This helps dependent projects use a package from the current
  498. # project’s build tree, i.e. without installing it.
  499. # In CMake 3.14 and below the export(PACKAGE) command populated
  500. # the user package registry by default and users needed to set
  501. # the CMAKE_EXPORT_NO_PACKAGE_REGISTRY to disable it,
  502. # e.g. in automated build and packaging environments. Since
  503. # the user package registry is stored outside the build tree,
  504. # this side effect should not be enabled by default.
  505. # Therefore CMake 3.15 and above prefer that export(PACKAGE) does nothing
  506. # unless an explicit CMAKE_EXPORT_PACKAGE_REGISTRY variable is set.
  507. if(NOT THIS_IS_SUBPROJECT)
  508. export(PACKAGE "${PROJECT_NAME}")
  509. endif()
  510. # vim: shiftwidth=2:softtabstop=2:tabstop=2:expandtab:autoindent