# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#
-project(check C)
+cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
+project(check
+ DESCRIPTION "Unit Testing Framework for C"
+ LANGUAGES C)
+
+###############################################################################
+# Configure a project for testing with CTest/CDash
+include(CTest)
-cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
macro(extract_version file setting_name)
extract_version(configure.ac CHECK_MINOR_VERSION)
extract_version(configure.ac CHECK_MICRO_VERSION)
+set(PROJECT_VERSION_MAJOR ${CHECK_MAJOR_VERSION})
+set(PROJECT_VERSION_MINOR ${CHECK_MINOR_VERSION})
+set(PROJECT_VERSION_PATCH ${CHECK_MICRO_VERSION})
+set(PROJECT_VERSION_TWEAK 0)
+set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.${PROJECT_VERSION_TWEAK}")
+
set(check_VERSION
"${CHECK_MAJOR_VERSION}.${CHECK_MINOR_VERSION}.${CHECK_MICRO_VERSION}")
###############################################################################
# Option
option(CHECK_ENABLE_TESTS
- "Enable the compilation and running of Check's unit tests" ON)
+ "Deprecated: Enable the compilation and running of Check's unit tests" ON)
+if(NOT CHECK_ENABLE_TESTS)
+ message(DEPRECATION "The option CHECK_ENABLE_TESTS is deprecated. Use option BUILD_TESTING.")
+ # TODO Remove this option by Check 0.15.0!
+endif(NOT CHECK_ENABLE_TESTS)
+option(CHECK_ENABLE_GCOV
+ "Turn on test coverage" OFF)
+if (CHECK_ENABLE_GCOV AND NOT ${CMAKE_C_COMPILER_ID} MATCHES "GNU")
+ message(FATAL_ERROR "Code Coverage (gcov) only works if GNU compiler is used!")
+endif (CHECK_ENABLE_GCOV AND NOT ${CMAKE_C_COMPILER_ID} MATCHES "GNU")
###############################################################################
# Check system and architecture
if(WIN32)
if(MSVC60)
- set(WINVER 0x0400)
+ set(WINVER 0x0400)
else()
- set(WINVER 0x0500)
+ set(WINVER 0x0500)
endif()
set(_WIN32_WINNT ${WINVER})
endif(WIN32)
ck_check_include_file("strings.h" HAVE_STRINGS_H)
ck_check_include_file("sys/time.h" HAVE_SYS_TIME_H)
ck_check_include_file("time.h" HAVE_TIME_H)
+ck_check_include_file("unistd.h" HAVE_UNISTD_H)
###############################################################################
# Check functions
check_function_exists(strsignal HAVE_DECL_STRSIGNAL)
check_function_exists(_getpid HAVE__GETPID)
check_function_exists(_strdup HAVE__STRDUP)
+check_function_exists(alarm HAVE_DECL_ALARM)
if (HAVE_REGEX_H)
check_function_exists(regcomp HAVE_REGCOMP)
check_function_exists(regexec HAVE_REGEXEC)
check_symbol_exists(vsnprintf stdio.h HAVE_VSNPRINTF_SYMBOL)
if(NOT HAVE_SNPRINTF_FUNCTION AND NOT HAVE_SNPRINTF_SYMBOL)
- add_definitions(-Dsnprintf=rpl_snprintf)
- set(snprintf rpl_snprintf)
- add_definitions(-Dvsnprintf=rpl_vsnprintf)
- set(vsnprintf rpl_vsnprintf)
+ add_definitions(-Dsnprintf=rpl_snprintf)
+ set(snprintf rpl_snprintf)
+ add_definitions(-Dvsnprintf=rpl_vsnprintf)
+ set(vsnprintf rpl_vsnprintf)
else(NOT HAVE_SNPRINTF_FUNCTION AND NOT HAVE_SNPRINTF_SYMBOL)
- set(HAVE_SNPRINTF 1)
- add_definitions(-DHAVE_SNPRINTF=1)
- set(HAVE_VSNPRINTF 1)
- add_definitions(-DHAVE_VSNPRINTF=1)
+ set(HAVE_SNPRINTF 1)
+ add_definitions(-DHAVE_SNPRINTF=1)
+ set(HAVE_VSNPRINTF 1)
+ add_definitions(-DHAVE_VSNPRINTF=1)
endif(NOT HAVE_SNPRINTF_FUNCTION AND NOT HAVE_SNPRINTF_SYMBOL)
if(HAVE_FORK)
- add_definitions(-DHAVE_FORK=1)
- set(HAVE_FORK 1)
+ add_definitions(-DHAVE_FORK=1)
+ set(HAVE_FORK 1)
else(HAVE_FORK)
- add_definitions(-DHAVE_FORK=0)
- set(HAVE_FORK 0)
+ add_definitions(-DHAVE_FORK=0)
+ set(HAVE_FORK 0)
endif(HAVE_FORK)
if(HAVE_MKSTEMP)
- add_definitions(-DHAVE_MKSTEMP=1)
- set(HAVE_MKSTEMP 1)
+ add_definitions(-DHAVE_MKSTEMP=1)
+ set(HAVE_MKSTEMP 1)
else(HAVE_MKSTEMP)
- add_definitions(-DHAVE_MKSTEMP=0)
- set(HAVE_MKSTEMP 0)
+ add_definitions(-DHAVE_MKSTEMP=0)
+ set(HAVE_MKSTEMP 0)
endif(HAVE_MKSTEMP)
+if(HAVE_DECL_ALARM)
+ add_definitions(-DHAVE_DECL_ALARM=1)
+ set(HAVE_DECL_ALARM 1)
+else(HAVE_DECL_ALARM)
+ add_definitions(-DHAVE_DECL_ALARM=0)
+ set(HAVE_DECL_ALARM 0)
+endif(HAVE_DECL_ALARM)
+
if(HAVE_REGEX_H AND HAVE_REGCOMP AND HAVE_REGEXEC)
- add_definitions(-DHAVE_REGEX=1)
- set(HAVE_REGEX 1)
- add_definitions(-DENABLE_REGEX=1)
- set(ENABLE_REGEX 1)
+ add_definitions(-DHAVE_REGEX=1)
+ set(HAVE_REGEX 1)
+ add_definitions(-DENABLE_REGEX=1)
+ set(ENABLE_REGEX 1)
endif()
check_symbol_exists(UINT32_MAX "${headers}" HAVE_UINT32_MAX)
check_symbol_exists(UINT64_MAX "${headers}" HAVE_UINT64_MAX)
check_symbol_exists(SIZE_MAX "${headers}" HAVE_SIZE_MAX)
-check_symbol_exists(SSIZE_MAX "limits.h" HAVE_SSIZE_MAX)
+check_symbol_exists(SSIZE_MAX "limits.h" HAVE_SSIZE_MAX)
###############################################################################
# Check struct members
# Check for tv_sec in struct timeval
if(NOT HAVE_SYS_TIME_H)
- if(MSVC)
- check_struct_member("struct timeval" tv_sec "Winsock2.h" HAVE_STRUCT_TIMEVAL_TV_SEC)
- check_struct_member("struct timeval" tv_usec "Winsock2.h" HAVE_STRUCT_TIMEVAL_TV_USEC)
- check_struct_member("struct timespec" tv_sec "Winsock2.h" HAVE_WINSOCK2_H_STRUCT_TIMESPEC_TV_SEC)
- check_struct_member("struct timespec" tv_sec "time.h" HAVE_TIME_H_STRUCT_TIMESPEC_TV_SEC)
- check_struct_member("struct itimerspec" it_value "Winsock2.h" HAVE_STRUCT_ITIMERSPEC_IT_VALUE)
-
- if(NOT HAVE_WINSOCK2_H_STRUCT_TIMESPEC_TV_SEC AND NOT HAVE_TIME_H_STRUCT_TIMESPEC_TV_SEC)
- add_definitions(-DSTRUCT_TIMESPEC_DEFINITION_MISSING=1)
- set(STRUCT_TIMESPEC_DEFINITION_MISSING 1)
- endif(NOT HAVE_WINSOCK2_H_STRUCT_TIMESPEC_TV_SEC AND NOT HAVE_TIME_H_STRUCT_TIMESPEC_TV_SEC)
-
- if(NOT HAVE_STRUCT_ITIMERSPEC_IT_VALUE)
- add_definitions(-DSTRUCT_ITIMERSPEC_DEFINITION_MISSING=1)
- set(STRUCT_ITIMERSPEC_DEFINITION_MISSING 1)
- endif(NOT HAVE_STRUCT_ITIMERSPEC_IT_VALUE)
- endif(MSVC)
+ if(MSVC)
+ check_struct_member("struct timeval" tv_sec "Winsock2.h" HAVE_STRUCT_TIMEVAL_TV_SEC)
+ check_struct_member("struct timeval" tv_usec "Winsock2.h" HAVE_STRUCT_TIMEVAL_TV_USEC)
+ check_struct_member("struct timespec" tv_sec "Winsock2.h" HAVE_WINSOCK2_H_STRUCT_TIMESPEC_TV_SEC)
+ check_struct_member("struct timespec" tv_sec "time.h" HAVE_TIME_H_STRUCT_TIMESPEC_TV_SEC)
+ check_struct_member("struct itimerspec" it_value "Winsock2.h" HAVE_STRUCT_ITIMERSPEC_IT_VALUE)
+
+ if(NOT HAVE_WINSOCK2_H_STRUCT_TIMESPEC_TV_SEC AND NOT HAVE_TIME_H_STRUCT_TIMESPEC_TV_SEC)
+ add_definitions(-DSTRUCT_TIMESPEC_DEFINITION_MISSING=1)
+ set(STRUCT_TIMESPEC_DEFINITION_MISSING 1)
+ endif(NOT HAVE_WINSOCK2_H_STRUCT_TIMESPEC_TV_SEC AND NOT HAVE_TIME_H_STRUCT_TIMESPEC_TV_SEC)
+
+ if(NOT HAVE_STRUCT_ITIMERSPEC_IT_VALUE)
+ add_definitions(-DSTRUCT_ITIMERSPEC_DEFINITION_MISSING=1)
+ set(STRUCT_ITIMERSPEC_DEFINITION_MISSING 1)
+ endif(NOT HAVE_STRUCT_ITIMERSPEC_IT_VALUE)
+ endif(MSVC)
endif(NOT HAVE_SYS_TIME_H)
# OSX has sys/time.h, but it still lacks itimerspec
if(HAVE_SYS_TIME_H)
- check_struct_member("struct itimerspec" it_value "sys/time.h" HAVE_STRUCT_ITIMERSPEC_IT_VALUE)
- if(NOT HAVE_STRUCT_ITIMERSPEC_IT_VALUE)
- add_definitions(-DSTRUCT_ITIMERSPEC_DEFINITION_MISSING=1)
- set(STRUCT_ITIMERSPEC_DEFINITION_MISSING 1)
- endif(NOT HAVE_STRUCT_ITIMERSPEC_IT_VALUE)
+ check_struct_member("struct itimerspec" it_value "sys/time.h" HAVE_STRUCT_ITIMERSPEC_IT_VALUE)
+ if(NOT HAVE_STRUCT_ITIMERSPEC_IT_VALUE)
+ add_definitions(-DSTRUCT_ITIMERSPEC_DEFINITION_MISSING=1)
+ set(STRUCT_ITIMERSPEC_DEFINITION_MISSING 1)
+ endif(NOT HAVE_STRUCT_ITIMERSPEC_IT_VALUE)
endif(HAVE_SYS_TIME_H)
###############################################################################
check_library_exists(m floor "" HAVE_LIBM)
if (HAVE_LIBM)
- set (LIBM "m")
+ set (LIBM "m")
endif (HAVE_LIBM)
check_library_exists(rt clock_gettime "" HAVE_LIBRT)
if (HAVE_LIBRT)
- set(LIBRT "rt")
- ADD_DEFINITIONS(-DHAVE_LIBRT=1)
+ set(LIBRT "rt")
+ ADD_DEFINITIONS(-DHAVE_LIBRT=1)
endif (HAVE_LIBRT)
check_library_exists(subunit subunit_test_start "" HAVE_SUBUNIT)
if (HAVE_SUBUNIT)
- set(SUBUNIT "subunit")
- set(ENABLE_SUBUNIT 1)
- add_definitions(-DENABLE_SUBUNIT=1)
+ set(SUBUNIT "subunit")
+ set(ENABLE_SUBUNIT 1)
+ add_definitions(-DENABLE_SUBUNIT=1)
else(HAVE_SUBUNIT)
- set(ENABLE_SUBUNIT 0)
- add_definitions(-DENABLE_SUBUNIT=0)
+ set(ENABLE_SUBUNIT 0)
+ add_definitions(-DENABLE_SUBUNIT=0)
endif (HAVE_SUBUNIT)
###############################################################################
# Generate "config.h" from "cmake/config.h.in"
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.h.in
${CMAKE_CURRENT_BINARY_DIR}/config.h)
+ # Param @ONLY not used on purpose!
include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
add_definitions(-DHAVE_CONFIG_H)
set(CONFIG_HEADER ${CMAKE_CURRENT_BINARY_DIR}/config.h)
+
+###############################################################################
+# Generate "check_stdint.h" from "cmake/check_stdint.h.in"
+#
+# The corresponding GNU Autotools build of this project
+# has m4 macro `m4/ax_create_stdint_h.m4` to create
+# the file `check_stdint.h` from scratch.
+# Include file `stdint.h` was introduced in C99 ANSI standard but
+# many compilers were lacking behind or still are and
+# have not implemented C99 or their `stdint.h` is not compatible.
+# Therefore the m4 macro was needed to create the required datatypes.
+#
+# When converting to CMake we also want to abandon the m4 macros.
+#
+set(PROJECT_VERSION "${check_VERSION}")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/check_stdint.h.in
- ${CMAKE_CURRENT_BINARY_DIR}/check_stdint.h)
+ ${CMAKE_CURRENT_BINARY_DIR}/check_stdint.h @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/check_stdint.h DESTINATION include)
+###############################################################################
+# Generate "check.pc", the package config (pkgconfig) file for libtool
+set(prefix_save "${PREFIX}")
+set(prefix "${CMAKE_INSTALL_PREFIX}")
+set(exec_prefix "\${prefix}")
+set(libdir "\${exec_prefix}/lib")
+set(includedir "\${prefix}/include")
+
+if (HAVE_SUBUNIT)
+ set(LIBSUBUNIT_PC "libsubunit")
+else (HAVE_SUBINIT)
+ set(LIBSUBUNIT_PC "")
+endif (HAVE_SUBUNIT)
+
+if (CHECK_ENABLE_GCOV)
+ set(GCOV_LIBS "-lgcov")
+else (CHECK_ENABLE_GCOV)
+ set(GCOV_LIBS "")
+endif (CHECK_ENABLE_GCOV)
+
+set(PTHREAD_LIBS "")
+set(LIBS "")
+
+if (HAVE_LIBM)
+ set(LIBS "${LIBS} -lm")
+endif (HAVE_LIBM)
+
+if (HAVE_LIBRT)
+ set(LIBS "${LIBS} -lrt")
+endif (HAVE_LIBRT)
+
+set(PTHREAD_CFLAGS "-pthread")
+
+configure_file(check.pc.in check.pc @ONLY)
+
+unset(PTHREAD_CFLAGS)
+unset(LIBS)
+unset(PTHREAD_LIBS)
+unset(GCOV_LIBS)
+unset(LIBSUBUNIT_PC)
+unset(includedir)
+unset(libdir)
+unset(exec_prefix)
+set(PREFIX "${prefix_save}")
+
+install(
+ FILES ${CMAKE_CURRENT_BINARY_DIR}/check.pc
+ DESTINATION lib/pkgconfig
+)
+
###############################################################################
# Subdirectories
add_subdirectory(lib)
###############################################################################
# Unit tests
-if (CHECK_ENABLE_TESTS)
+if (BUILD_TESTING)
add_subdirectory(tests)
- enable_testing()
add_test(NAME check_check COMMAND check_check)
add_test(NAME check_check_export COMMAND check_check_export)
# Only offer to run shell scripts if we may have a working interpreter
if(UNIX OR MINGW OR MSYS)
- add_test(NAME test_output.sh
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests
- COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_output.sh)
- add_test(NAME test_log_output.sh
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests
- COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_log_output.sh)
- add_test(NAME test_xml_output.sh
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests
- COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_xml_output.sh)
- add_test(NAME test_tap_output.sh
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests
- COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_tap_output.sh)
- add_test(NAME test_check_nofork.sh
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests
- COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_check_nofork.sh)
- add_test(NAME test_check_nofork_teardown.sh
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests
- COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_check_nofork_teardown.sh)
- add_test(NAME test_set_max_msg_size.sh
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests
- COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_set_max_msg_size.sh)
+ add_test(NAME test_output.sh
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests
+ COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_output.sh)
+ add_test(NAME test_log_output.sh
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests
+ COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_log_output.sh)
+ add_test(NAME test_xml_output.sh
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests
+ COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_xml_output.sh)
+ add_test(NAME test_tap_output.sh
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests
+ COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_tap_output.sh)
+ add_test(NAME test_check_nofork.sh
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests
+ COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_check_nofork.sh)
+ add_test(NAME test_check_nofork_teardown.sh
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests
+ COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_check_nofork_teardown.sh)
+ add_test(NAME test_set_max_msg_size.sh
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests
+ COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_set_max_msg_size.sh)
endif(UNIX OR MINGW OR MSYS)
-endif()
+endif (BUILD_TESTING)
###############################################################################
# Export project, prepare a config and config-version files
set(EXPORT_NAME ${PROJECT_NAME})
include(CMakePackageConfigHelpers)
configure_package_config_file(
- ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${EXPORT_NAME}-config.cmake.in
- ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_NAME}-config.cmake
- INSTALL_DESTINATION ${LIB_INSTALL_DIR}/${EXPORT_NAME}/cmake
+ ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${EXPORT_NAME}-config.cmake.in
+ ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_NAME}-config.cmake
+ INSTALL_DESTINATION ${LIB_INSTALL_DIR}/${EXPORT_NAME}/cmake
)
write_basic_package_version_file(
- ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_NAME}-config-version.cmake
- VERSION ${check_VERSION}
- COMPATIBILITY AnyNewerVersion
+ ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_NAME}-config-version.cmake
+ VERSION ${check_VERSION}
+ COMPATIBILITY AnyNewerVersion
)
export(EXPORT check-targets
- FILE "${CMAKE_CURRENT_BINARY_DIR}/check-targets.cmake"
- NAMESPACE Check::
+ FILE "${CMAKE_CURRENT_BINARY_DIR}/check-targets.cmake"
+ NAMESPACE Check::
)
install(EXPORT check-targets
- NAMESPACE Check::
- FILE check-targets.cmake
- DESTINATION lib/cmake/${EXPORT_NAME}
+ NAMESPACE Check::
+ FILE check-targets.cmake
+ DESTINATION lib/cmake/${EXPORT_NAME}
)
install(
- FILES
- "${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_NAME}-config.cmake"
- "${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_NAME}-config-version.cmake"
- DESTINATION lib/cmake/${EXPORT_NAME}
+ FILES
+ "${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_NAME}-config.cmake"
+ "${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_NAME}-config-version.cmake"
+ DESTINATION lib/cmake/${EXPORT_NAME}
)