From 24901a43e9804674693ee532c704b8182901410f Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Sat, 8 Jun 2019 21:45:40 +0200 Subject: [PATCH 01/15] Raise minimum CMake version to 3.9 Signed-off-by: Mikko Johannes Koivunalho --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c822ea0..4a001841 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,9 +19,9 @@ # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # +cmake_minimum_required(VERSION 3.9 FATAL_ERROR) project(check C) -cmake_minimum_required(VERSION 2.8 FATAL_ERROR) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") macro(extract_version file setting_name) From 27e3eba6b54389566b1b504add96f00b2da88166 Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Sat, 8 Jun 2019 21:47:59 +0200 Subject: [PATCH 02/15] Add tags DESCRIPTION and LANGUAGES to project() Signed-off-by: Mikko Johannes Koivunalho --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a001841..a8a76a50 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,9 @@ # Boston, MA 02111-1307, USA. # cmake_minimum_required(VERSION 3.9 FATAL_ERROR) -project(check C) +project(check + DESCRIPTION "Unit Testing Framework for C" + LANGUAGES C) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") From 37bb15b6aaf1a7efb39f73210b058ae6ad153c13 Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Sun, 9 Jun 2019 20:35:06 +0200 Subject: [PATCH 03/15] Create variables PROJECT_VERSION_* Signed-off-by: Mikko Johannes Koivunalho --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index a8a76a50..1b0ef31a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,12 @@ extract_version(configure.ac CHECK_MAJOR_VERSION) 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}") From e831f563ae2d81635d0f17b424bce5502dcd40f8 Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Sat, 8 Jun 2019 21:55:05 +0200 Subject: [PATCH 04/15] Add command 'cmake --version' to appveyor builds Signed-off-by: Mikko Johannes Koivunalho --- appveyor.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index f6760bdd..ec6d03cb 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -111,6 +111,7 @@ before_build: - if %platform%==msvc call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" - if %platform%==msvc mkdir build - if %platform%==msvc chdir build + - if %platform%==msvc cmake --version - if %platform%==msvc cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=%P% -DCMAKE_BUILD_TYPE=Debug .. - if %platform%==vs ( set "makecommand=Visual Studio" @@ -158,6 +159,7 @@ before_build: ) - if %platform%==vs mkdir build - if %platform%==vs chdir build + - if %platform%==vs cmake --version - if %platform%==vs cmake -G "%makecommand%" -DCMAKE_INSTALL_PREFIX=%P% -DCMAKE_BUILD_TYPE=Debug .. - if %platform%==cygwin set PATH=C:\cygwin\bin;%PATH% - if %platform%==cygwin bash -c "autoreconf -i" @@ -165,6 +167,7 @@ before_build: - if %platform%==mingw32 set PATH=C:\MinGW\bin;%PATH% - if %platform%==mingw32 mkdir build - if %platform%==mingw32 chdir build + - if %platform%==mingw32 cmake --version - if %platform%==mingw32 cmake -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=%P% -DCMAKE_BUILD_TYPE=Debug .. - if %platform%==mingw64msys set PATH=C:\msys64\mingw64\bin;C:\msys64\usr\bin;%PATH% - if %platform%==mingw64msys bash -c "autoreconf -i" From 3c78db405230f717d1d5c6a48daaf48044b7ee77 Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Sat, 8 Jun 2019 22:00:53 +0200 Subject: [PATCH 05/15] Remove support for old CMake version Signed-off-by: Mikko Johannes Koivunalho --- src/CMakeLists.txt | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4cc3747d..6a86811c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -48,14 +48,10 @@ configure_file(check.h.in check.h) add_library(check STATIC ${SOURCES} ${HEADERS}) target_link_libraries(check ${LIBM} ${LIBRT} ${SUBUNIT}) # Enable finding check.h -if(CMAKE_VERSION VERSION_LESS 2.8.12) - include_directories(${CMAKE_CURRENT_BINARY_DIR}) -else() - target_include_directories(check - PUBLIC - $ - $) -endif() +target_include_directories(check + PUBLIC + $ + $) if(MSVC) add_definitions(-DCK_DLL_EXP=_declspec\(dllexport\)) From 749ceae73a34f1c08fda1c59b1381bb14119a9b8 Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Sat, 22 Jun 2019 18:49:37 +0200 Subject: [PATCH 06/15] Add alarm.c to the build Signed-off-by: Mikko Johannes Koivunalho --- CMakeLists.txt | 9 +++++++++ lib/CMakeLists.txt | 3 +++ 2 files changed, 12 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b0ef31a..4809eb0c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -134,6 +134,7 @@ check_function_exists(strdup HAVE_DECL_STRDUP) 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) @@ -173,6 +174,14 @@ else(HAVE_MKSTEMP) 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) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index fabfdf25..c4813ce6 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -62,6 +62,9 @@ if(NOT HAVE_DECL_STRSIGNAL) set(SOURCES ${SOURCES} strsignal.c) endif(NOT HAVE_DECL_STRSIGNAL) +if(NOT HAVE_DECL_ALARM) + set(SOURCES ${SOURCES} alarm.c) +endif(NOT HAVE_DECL_ALARM) set(HEADERS libcompat.h) From 6064051d914dd8573a5550b587c73d180ab169ca Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Sun, 23 Jun 2019 07:10:09 +0200 Subject: [PATCH 07/15] Add 'cmake --version' to Travis script Signed-off-by: Mikko Johannes Koivunalho --- travis.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/travis.sh b/travis.sh index 88fd01b8..021f5e07 100644 --- a/travis.sh +++ b/travis.sh @@ -30,6 +30,7 @@ if [ -d doc/doxygen ]; then fi if [ "${USE_CMAKE}" = 'YES' ] ; then + cmake --version cmake . || exit 1 make || exit 1 ctest -V || exit 1 @@ -82,6 +83,7 @@ if [ "${PRE_RELEASE_CHECK}" = 'YES' ]; then make prereleasecheck || exit 1 tar xf check-*.tar.gz cd check-* + cmake --version cmake . || exit 1 make || exit 1 fi From f63378cd2e2e9330860406305f8e8f2bccf489f9 Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Sat, 8 Jun 2019 15:40:14 +0200 Subject: [PATCH 08/15] Add HAVE_UNISTD_H to CMake and config.h.in Signed-off-by: Mikko Johannes Koivunalho --- CMakeLists.txt | 1 + cmake/config.h.in | 3 +++ 2 files changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4809eb0c..2f4eb333 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -117,6 +117,7 @@ ck_check_include_file("string.h" HAVE_STRING_H) 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 diff --git a/cmake/config.h.in b/cmake/config.h.in index aaa447f9..9c2d898a 100644 --- a/cmake/config.h.in +++ b/cmake/config.h.in @@ -300,6 +300,9 @@ typedef uint64_t uintmax_t; /* Define to 1 if you have the header file. */ #cmakedefine HAVE_TIME_H 1 +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_UNISTD_H 1 + /* Define to 1 if the system has the type `unsigned long long'. */ #cmakedefine HAVE_UNSIGNED_LONG_LONG 1 From b35afad200b0f03f6e8304e8f12175221fb0a563 Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Fri, 2 Aug 2019 06:15:19 +0200 Subject: [PATCH 09/15] Add missing header file when HAVE_FORK Function _exit(int) is included in unistd.h. Also fork() is here. Functions exit(int) (C89) and _Exit(int) (C99) are in stdlib.h. Signed-off-by: Mikko Johannes Koivunalho --- src/check.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/check.c b/src/check.c index c6cd22a0..d89b2a83 100644 --- a/src/check.c +++ b/src/check.c @@ -26,6 +26,10 @@ #include #include +#if defined(HAVE_FORK) && HAVE_FORK==1 +#include +#endif /* HAVE_FORK */ + #include "check.h" #include "check_error.h" #include "check_list.h" From f5c8e5f0829bb82072338b0291b023ebfa186692 Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Fri, 2 Aug 2019 07:08:25 +0200 Subject: [PATCH 10/15] Reindent CMake file to 2 chars indentation Signed-off-by: Mikko Johannes Koivunalho --- CMakeLists.txt | 190 ++++++++++++++++++++++++------------------------- 1 file changed, 95 insertions(+), 95 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f4eb333..8d131012 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,8 +21,8 @@ # cmake_minimum_required(VERSION 3.9 FATAL_ERROR) project(check - DESCRIPTION "Unit Testing Framework for C" - LANGUAGES C) + DESCRIPTION "Unit Testing Framework for C" + LANGUAGES C) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") @@ -66,9 +66,9 @@ option(CHECK_ENABLE_TESTS # 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) @@ -148,46 +148,46 @@ check_symbol_exists(snprintf stdio.h HAVE_SNPRINTF_SYMBOL) 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) + 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) + 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() @@ -208,39 +208,39 @@ check_symbol_exists(INT64_MIN "${headers}" HAVE_INT64_MIN) 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) ############################################################################### @@ -322,23 +322,23 @@ unset(CMAKE_EXTRA_INCLUDE_FILES) 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) ############################################################################### @@ -368,27 +368,27 @@ if (CHECK_ENABLE_TESTS) # 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() @@ -398,30 +398,30 @@ set(LIB_INSTALL_DIR lib CACHE FILEPATH "lib INSTALL DIR") 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} ) From d480b36e8638b903f5f492eff573f763fd046ded Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Mon, 2 Sep 2019 18:57:59 +0200 Subject: [PATCH 11/15] Add pkgconfig/check.pc file generation to CMake Signed-off-by: Mikko Johannes Koivunalho --- CMakeLists.txt | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d131012..ccb402fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,6 +61,11 @@ set(CMAKE_C_EXTENSIONS ON) # Use GNU extensions and POSIX standard # Option option(CHECK_ENABLE_TESTS "Enable the compilation and running of Check's unit tests" ON) +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 @@ -352,6 +357,56 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/check_stdint.h.in ${CMAKE_CURRENT_BINARY_DIR}/check_stdint.h) 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) From af2a3f0d2665e3a2c13b1a99e34a5fcdee982d7a Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Sun, 1 Sep 2019 20:44:42 +0200 Subject: [PATCH 12/15] Fix missing macro undefinition If we don't undefine the macro, it will enter the user's namespace. This macro is only for our internal use. Otherwise it would have the "CK_" prefix. Signed-off-by: Mikko Johannes Koivunalho --- src/check.h.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/check.h.in b/src/check.h.in index 3e12bd08..ac86d9bb 100644 --- a/src/check.h.in +++ b/src/check.h.in @@ -74,6 +74,8 @@ CK_CPPSTART #define CK_ATTRIBUTE_NORETURN #endif /* GCC 2.5 */ +#undef GCC_VERSION_AT_LEAST + #include #if defined(_MSC_VER) From 09bd2b8722dcbdddba32c10940c02b6f6229e6d2 Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Mon, 2 Sep 2019 22:34:49 +0200 Subject: [PATCH 13/15] Remove non-CMake style option CHECK_ENABLE_TESTS It is a CMake best practice to include file 'CTest' in the project main file and then use option 'BUILD_TESTING' (defined in 'CTest') to enable or disable building the tests. BUILD_TESTING is ON by default. https://cmake.org/cmake/help/v3.9/module/CTest.html?highlight=build_testing https://cmake.org/cmake/help/v3.9/command/add_test.html?highlight=build_testing Option CHECK_ENABLE_TESTS is deprecated. Because it is on by default, deprecation warning is only shown to user when user explicitly turns CHECK_ENABLE_TESTS off. Suggesting to remove the option by release 0.15.0. Signed-off-by: Mikko Johannes Koivunalho --- CMakeLists.txt | 15 +++++++++++---- tests/CMakeLists.txt | 2 -- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ccb402fa..8b93c187 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,10 @@ project(check DESCRIPTION "Unit Testing Framework for C" LANGUAGES C) +############################################################################### +# Configure a project for testing with CTest/CDash +include(CTest) + set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") macro(extract_version file setting_name) @@ -60,7 +64,11 @@ set(CMAKE_C_EXTENSIONS ON) # Use GNU extensions and POSIX standard ############################################################################### # 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") @@ -415,9 +423,8 @@ add_subdirectory(checkmk) ############################################################################### # 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) @@ -445,7 +452,7 @@ if (CHECK_ENABLE_TESTS) 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 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b3d7ab7e..7ce83890 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -40,8 +40,6 @@ endif(WIN32) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/test_vars.in ${CMAKE_CURRENT_BINARY_DIR}/test_vars) -include(CTest) - set(CHECK_CHECK_SOURCES check_check_exit.c check_check_fixture.c From 12fb004766caeb376f40fff0ee4277414d6fdfc4 Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Sun, 8 Sep 2019 11:54:31 +0200 Subject: [PATCH 14/15] Add param @ONLY to CMake configure_file() Restrict variable replacement to references of the form @VAR@. This is useful for configuring scripts that also use ${VAR} syntax. Adding @ONLY is precautionary action to prevent future bugs. Attn. cmake/config.h.in contains ${VAR} in #cmakedefine clauses! How to use CMake variable substitution. Wrong: #if @HAVE_FORK@ [..] #endif Because this will result as: #if 1 [..] #endif Better: /* Imported CMake variables created during build. */ #cmakedefine HAVE_FORK 1 #ifdef HAVE_FORK [..] #endif Because this will result as: /* Imported CMake variables created during build. */ #define HAVE_FORK 1 #ifdef HAVE_FORK [..] #endif Or: /* Imported CMake variables created during build. */ /* #undef HAVE_FORK */ [..] This is more readable. Now we know which decision actually was taken. If you need to pass the parameter to the definition, it is just as easy: /* Imported CMake variables created during build. */ #cmakedefine CORRECT_SIZE @CORRECT_SIZE@ #if CORRECT_SIZE >= 20 [..] #endif Signed-off-by: Mikko Johannes Koivunalho --- CMakeLists.txt | 3 ++- src/CMakeLists.txt | 2 +- tests/CMakeLists.txt | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b93c187..f4b958fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -358,11 +358,12 @@ 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) 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) ############################################################################### diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6a86811c..8b126671 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -43,7 +43,7 @@ set(HEADERS check_print.h check_str.h) -configure_file(check.h.in check.h) +configure_file(check.h.in check.h @ONLY) add_library(check STATIC ${SOURCES} ${HEADERS}) target_link_libraries(check ${LIBM} ${LIBRT} ${SUBUNIT}) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7ce83890..82e3b439 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -38,7 +38,7 @@ if(WIN32) endif(WIN32) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/test_vars.in - ${CMAKE_CURRENT_BINARY_DIR}/test_vars) + ${CMAKE_CURRENT_BINARY_DIR}/test_vars @ONLY) set(CHECK_CHECK_SOURCES check_check_exit.c From a77491a907dd421ca96f017eacb87394a34ff75d Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Sun, 8 Sep 2019 09:51:44 +0200 Subject: [PATCH 15/15] Improve check_stdint.h creation in CMake Will not convert m4/ax_create_stdint_h.m4 to CMake. Make the resulting check_stdint.h similar to the old one (as much as is possible). GNU Autotools build is untouched. It continues to use m4 macro and generates check_stdint.h from scratch. Signed-off-by: Mikko Johannes Koivunalho --- CMakeLists.txt | 15 +++++++++++++++ cmake/check_stdint.h.in | 39 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f4b958fa..0edfd006 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -362,6 +362,21 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.h.in 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 @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/check_stdint.h DESTINATION include) diff --git a/cmake/check_stdint.h.in b/cmake/check_stdint.h.in index ab467c1f..13f284a9 100644 --- a/cmake/check_stdint.h.in +++ b/cmake/check_stdint.h.in @@ -1,6 +1,41 @@ +/*-*- mode:C; -*- */ +/* + * Check: a unit test framework for C + * + * Copyright (C) 2013 Branden Archer + * Copyright (C) 2019 Mikko Johannes Koivunalho + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + #ifndef _CHECK_CHECK_STDINT_H #define _CHECK_CHECK_STDINT_H 1 +#ifndef _GENERATED_STDINT_H +#define _GENERATED_STDINT_H "@PROJECT_NAME@ @PROJECT_VERSION@" +/* generated using CMake @CMAKE_VERSION@ from file cmake/check_stdint.h.in */ + +/* Imported CMake variables created during build. */ +#cmakedefine HAVE_STDINT_H 1 + #ifdef HAVE_STDINT_H +#define _STDINT_HAVE_STDINT_H 1 #include -#endif -#endif +#undef HAVE_STDINT_H +#endif /* defined HAVE_STDINT_H */ + +/* Define only once */ +#endif /* _GENERATED_STDINT_H */ +#endif /* _CHECK_CHECK_STDINT_H */