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