From 34447635dbb5e71b0ee227baf85f486ab00eb7fa Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Sun, 8 Sep 2019 16:48:32 +0200 Subject: [PATCH 01/12] Start using GNUInstallDirs in every CMake install() Signed-off-by: Mikko Johannes Koivunalho --- CMakeLists.txt | 15 +++++++++++---- checkmk/CMakeLists.txt | 5 ++--- src/CMakeLists.txt | 14 +++++++------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0edfd006..46946616 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,10 @@ set(MEMORY_LEAKING_TESTS_ENABLED 1) # Set build features set(CMAKE_BUILD_TYPE Debug) +############################################################################### +# Provides install directory variables as defined by the GNU Coding Standards. +include(GNUInstallDirs) + ############################################################################### # Adhere strictly to old ANSI C89 / ISO C90 standard set(CMAKE_C_STANDARD 90) @@ -379,7 +383,10 @@ set(CONFIG_HEADER ${CMAKE_CURRENT_BINARY_DIR}/config.h) 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) +install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/check_stdint.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +) ############################################################################### # Generate "check.pc", the package config (pkgconfig) file for libtool @@ -428,7 +435,7 @@ set(PREFIX "${prefix_save}") install( FILES ${CMAKE_CURRENT_BINARY_DIR}/check.pc - DESTINATION lib/pkgconfig + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig ) ############################################################################### @@ -494,12 +501,12 @@ export(EXPORT check-targets install(EXPORT check-targets NAMESPACE Check:: FILE check-targets.cmake - DESTINATION lib/cmake/${EXPORT_NAME} + DESTINATION ${CMAKE_INSTALL_LIBDIR}/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} + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${EXPORT_NAME} ) diff --git a/checkmk/CMakeLists.txt b/checkmk/CMakeLists.txt index 1254ec2c..4634b8de 100644 --- a/checkmk/CMakeLists.txt +++ b/checkmk/CMakeLists.txt @@ -7,7 +7,6 @@ configure_file(checkmk.in checkmk @ONLY) file(COPY doc/checkmk.1 DESTINATION man/man1) option(INSTALL_CHECKMK "Install checkmk" ON) -include(GNUInstallDirs) if(INSTALL_CHECKMK) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/checkmk @@ -15,8 +14,8 @@ if(INSTALL_CHECKMK) PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) install( - DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/man/man1 - DESTINATION share/man + DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/man + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR} ) endif(INSTALL_CHECKMK) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8b126671..15a102bb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -51,7 +51,8 @@ target_link_libraries(check ${LIBM} ${LIBRT} ${SUBUNIT}) target_include_directories(check PUBLIC $ - $) + $ +) if(MSVC) add_definitions(-DCK_DLL_EXP=_declspec\(dllexport\)) @@ -59,10 +60,9 @@ endif (MSVC) install(TARGETS check EXPORT check-targets - INCLUDES DESTINATION include - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib) - -install(FILES ${CMAKE_BINARY_DIR}/src/check.h DESTINATION include) + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +) From 02783adccdf2879cb788c301066336918794267c Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Sun, 8 Sep 2019 20:58:30 +0200 Subject: [PATCH 02/12] Add libcompat code directly to libcheck We have tried to statically link the built libcompat into built libcheck in CMake without success. With autotools (libtool et.al.) this is most likely very easy but there is no support on Windows. So instead of building libcompat separately we incorporate the necessary parts of libcompat code directly into libcheck when building libcheck. Signed-off-by: Mikko Johannes Koivunalho --- CMakeLists.txt | 4 +++ lib/CMakeLists.txt | 6 ----- src/CMakeLists.txt | 64 ++++++++++++++++++++++++++++++++++++++++++-- tests/CMakeLists.txt | 12 ++++----- 4 files changed, 72 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 46946616..a3a8f0a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,10 @@ # Boston, MA 02111-1307, USA. # cmake_minimum_required(VERSION 3.9 FATAL_ERROR) +if(POLICY CMP0076) + # target_sources() leaves relative source file paths unmodified. (OLD) + cmake_policy(SET CMP0076 OLD) +endif() project(check DESCRIPTION "Unit Testing Framework for C" LANGUAGES C) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index c4813ce6..e6346dd5 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -70,9 +70,3 @@ set(HEADERS libcompat.h) add_library(compat STATIC ${SOURCES} ${HEADERS}) -install(TARGETS compat - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib) - -install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/libcompat.h DESTINATION include) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 15a102bb..3c27b5fe 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -46,8 +46,68 @@ set(HEADERS configure_file(check.h.in check.h @ONLY) add_library(check STATIC ${SOURCES} ${HEADERS}) -target_link_libraries(check ${LIBM} ${LIBRT} ${SUBUNIT}) -# Enable finding check.h +# Add parts of libcompat as required +target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/fpclassify.c) + +if (NOT HAVE_LIBRT) + target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/clock_gettime.c) + target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/timer_create.c) + target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/timer_delete.c) + target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/timer_settime.c) +endif(NOT HAVE_LIBRT) + +if(NOT HAVE_GETLINE) + target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/getline.c) +endif(NOT HAVE_GETLINE) + +if(NOT HAVE_GETTIMEOFDAY) + target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/gettimeofday.c) +endif(NOT HAVE_GETTIMEOFDAY) + +if(NOT HAVE_DECL_LOCALTIME_R) + target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/localtime_r.c) +endif(NOT HAVE_DECL_LOCALTIME_R) + +if(NOT HAVE_MALLOC) + target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/malloc.c) +endif(NOT HAVE_MALLOC) + +if(NOT HAVE_REALLOC) + target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/realloc.c) +endif(NOT HAVE_REALLOC) + +if(NOT HAVE_SNPRINTF) + target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/snprintf.c) +endif(NOT HAVE_SNPRINTF) + +if(NOT HAVE_DECL_STRDUP AND NOT HAVE__STRDUP) + target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/strdup.c) +endif(NOT HAVE_DECL_STRDUP AND NOT HAVE__STRDUP) + +if(NOT HAVE_DECL_STRSIGNAL) + target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/strsignal.c) +endif(NOT HAVE_DECL_STRSIGNAL) + +if(NOT HAVE_DECL_ALARM) + target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/alarm.c) +endif(NOT HAVE_DECL_ALARM) + +# Include libraries if available +if (HAVE_LIBM) + target_link_libraries(check PUBLIC m) +endif (HAVE_LIBM) +if (HAVE_LIBRT) + target_link_libraries(check PUBLIC rt) +endif (HAVE_LIBRT) +if (HAVE_SUBUNIT) + target_link_libraries(check PUBLIC subunit) +endif (HAVE_SUBUNIT) + +# More configuration for exporting +set_target_properties(check PROPERTIES + OUTPUT_NAME check + PUBLIC_HEADER ${CMAKE_CURRENT_BINARY_DIR}/check.h +) target_include_directories(check PUBLIC $ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 82e3b439..8a1c241e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -57,7 +57,7 @@ set(CHECK_CHECK_SOURCES check_list.c) set(CHECK_CHECK_HEADERS check_check.h) add_executable(check_check ${CHECK_CHECK_HEADERS} ${CHECK_CHECK_SOURCES}) -target_link_libraries(check_check check compat) +target_link_libraries(check_check check) set(CHECK_CHECK_EXPORT_SOURCES check_check_sub.c @@ -70,20 +70,20 @@ set(CHECK_CHECK_EXPORT_HEADERS check_check.h) add_executable(check_check_export ${CHECK_CHECK_EXPORT_HEADERS} ${CHECK_CHECK_EXPORT_SOURCES}) -target_link_libraries(check_check_export check compat) +target_link_libraries(check_check_export check) set(EX_OUTPUT_SOURCES ex_output.c) add_executable(ex_output ${EX_OUTPUT_SOURCES}) -target_link_libraries(ex_output check compat) +target_link_libraries(ex_output check) set(CHECK_NOFORK_SOURCES check_nofork.c) add_executable(check_nofork ${CHECK_NOFORK_SOURCES}) -target_link_libraries(check_nofork check compat) +target_link_libraries(check_nofork check) set(CHECK_NOFORK_TEARDOWN_SOURCES check_nofork_teardown.c) add_executable(check_nofork_teardown ${CHECK_NOFORK_TEARDOWN_SOURCES}) -target_link_libraries(check_nofork_teardown check compat) +target_link_libraries(check_nofork_teardown check) set(CHECK_SET_MAX_MSG_SIZE_SOURCES check_set_max_msg_size.c) add_executable(check_set_max_msg_size ${CHECK_SET_MAX_MSG_SIZE_SOURCES}) -target_link_libraries(check_set_max_msg_size check compat) +target_link_libraries(check_set_max_msg_size check) From e241d5cb2c831af6d99a1621b9dff31637b9b960 Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Sun, 23 Jun 2019 16:50:51 +0200 Subject: [PATCH 03/12] Change definition CK_DLL_EXP from global to target specific Signed-off-by: Mikko Johannes Koivunalho --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3c27b5fe..45024498 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -115,7 +115,7 @@ target_include_directories(check ) if(MSVC) - add_definitions(-DCK_DLL_EXP=_declspec\(dllexport\)) + target_compile_definitions(check PUBLIC CK_DLL_EXP=_declspec\(dllexport\)) endif (MSVC) install(TARGETS check From cd88edfc2e35df27d44192d1b845047f7325c9f7 Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Fri, 13 Sep 2019 22:12:48 +0200 Subject: [PATCH 04/12] Remove MSVC specific dllexport Target check is specifically a static library --- src/CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 45024498..c2a35d20 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -114,10 +114,6 @@ target_include_directories(check $ ) -if(MSVC) - target_compile_definitions(check PUBLIC CK_DLL_EXP=_declspec\(dllexport\)) -endif (MSVC) - install(TARGETS check EXPORT check-targets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} From cf07d2362d7dda7661427c24ee960e93340f5b20 Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Fri, 13 Sep 2019 22:31:04 +0200 Subject: [PATCH 05/12] Add better explanation for '#define CK_DLL_EXP' --- src/check.h.in | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/check.h.in b/src/check.h.in index ac86d9bb..0c6aa2c7 100644 --- a/src/check.h.in +++ b/src/check.h.in @@ -93,6 +93,15 @@ CK_CPPSTART * Used for MSVC to create the export attribute * CK_DLL_EXP is defined during the compilation of the library * on the command line. + * + * This definition is only used when building or linking to + * the shared library, i.e. libcheck.so. When building the library + * the value must be "_declspec(dllexport)". + * When linking with the library, the value must be "_declspec(dllimport)" + * + * This is only used with Microsoft Visual C. In other systems + * the value is empty. In MSVC the value is empty when linking with + * a static library. */ #ifndef CK_DLL_EXP #define CK_DLL_EXP From d0f1e1dcf995c4b06c0d228f52f904f1f08a5b0c Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Sun, 23 Jun 2019 10:50:22 +0200 Subject: [PATCH 06/12] Add target shared library to CMake build Signed-off-by: Mikko Johannes Koivunalho --- src/CMakeLists.txt | 60 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c2a35d20..f5e4af9e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -30,7 +30,7 @@ set(SOURCES check_run.c check_str.c) -set(HEADERS +set(HEADERS ${CONFIG_HEADER} ${CMAKE_CURRENT_BINARY_DIR}/check.h check.h.in @@ -46,66 +46,114 @@ set(HEADERS configure_file(check.h.in check.h @ONLY) add_library(check STATIC ${SOURCES} ${HEADERS}) + +# We would like to create an OBJECT library but currently they are +# too unreliable and cumbersome, +# especially with target_link_libraries and install(EXPORT... +# https://stackoverflow.com/questions/38832528/transitive-target-include-directories-on-object-libraries +# So we instead do the work twice. +add_library(checkShared SHARED ${SOURCES} ${HEADERS}) + # Add parts of libcompat as required target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/fpclassify.c) +target_sources(checkShared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/fpclassify.c) if (NOT HAVE_LIBRT) target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/clock_gettime.c) target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/timer_create.c) target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/timer_delete.c) target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/timer_settime.c) + target_sources(checkShared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/clock_gettime.c) + target_sources(checkShared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/timer_create.c) + target_sources(checkShared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/timer_delete.c) + target_sources(checkShared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/timer_settime.c) endif(NOT HAVE_LIBRT) if(NOT HAVE_GETLINE) target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/getline.c) + target_sources(checkShared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/getline.c) endif(NOT HAVE_GETLINE) if(NOT HAVE_GETTIMEOFDAY) target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/gettimeofday.c) + target_sources(checkShared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/gettimeofday.c) endif(NOT HAVE_GETTIMEOFDAY) if(NOT HAVE_DECL_LOCALTIME_R) target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/localtime_r.c) + target_sources(checkShared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/localtime_r.c) endif(NOT HAVE_DECL_LOCALTIME_R) if(NOT HAVE_MALLOC) target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/malloc.c) + target_sources(checkShared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/malloc.c) endif(NOT HAVE_MALLOC) if(NOT HAVE_REALLOC) target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/realloc.c) + target_sources(checkShared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/realloc.c) endif(NOT HAVE_REALLOC) if(NOT HAVE_SNPRINTF) target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/snprintf.c) + target_sources(checkShared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/snprintf.c) endif(NOT HAVE_SNPRINTF) if(NOT HAVE_DECL_STRDUP AND NOT HAVE__STRDUP) target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/strdup.c) + target_sources(checkShared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/snprintf.c) endif(NOT HAVE_DECL_STRDUP AND NOT HAVE__STRDUP) if(NOT HAVE_DECL_STRSIGNAL) target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/strsignal.c) + target_sources(checkShared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/strsignal.c) endif(NOT HAVE_DECL_STRSIGNAL) if(NOT HAVE_DECL_ALARM) target_sources(check PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/alarm.c) + target_sources(checkShared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/alarm.c) endif(NOT HAVE_DECL_ALARM) # Include libraries if available if (HAVE_LIBM) target_link_libraries(check PUBLIC m) + target_link_libraries(checkShared PUBLIC m) endif (HAVE_LIBM) if (HAVE_LIBRT) target_link_libraries(check PUBLIC rt) + target_link_libraries(checkShared PUBLIC rt) endif (HAVE_LIBRT) if (HAVE_SUBUNIT) target_link_libraries(check PUBLIC subunit) + target_link_libraries(checkShared PUBLIC subunit) endif (HAVE_SUBUNIT) +if(MSVC) + target_compile_definitions(checkShared + PRIVATE "CK_DLL_EXP=_declspec(dllexport)" + INTERFACE "CK_DLL_EXP=_declspec(dllimport)" + ) +endif (MSVC) + # More configuration for exporting + +set(LIBRARY_OUTPUT_NAME "check") + set_target_properties(check PROPERTIES - OUTPUT_NAME check + OUTPUT_NAME ${LIBRARY_OUTPUT_NAME} + PUBLIC_HEADER ${CMAKE_CURRENT_BINARY_DIR}/check.h +) + +if (MSVC) + # "On Windows you should probably give each library a different name, + # since there is a ".lib" file for both shared and static". + # https://stackoverflow.com/a/2152157/4716395 + set(LIBRARY_OUTPUT_NAME "checkStatic") +endif (MSVC) +set_target_properties(checkShared PROPERTIES + OUTPUT_NAME ${LIBRARY_OUTPUT_NAME} + VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_VERSION_MAJOR} PUBLIC_HEADER ${CMAKE_CURRENT_BINARY_DIR}/check.h ) target_include_directories(check @@ -113,8 +161,14 @@ target_include_directories(check $ $ ) +target_include_directories(checkShared + PUBLIC + $ + $ +) -install(TARGETS check +include(GNUInstallDirs) +install(TARGETS check checkShared EXPORT check-targets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} From 111d3728417805ddaacc42aad4dfa27d060cea92 Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Sat, 14 Sep 2019 18:15:48 +0200 Subject: [PATCH 07/12] Remove the needless resetting of PROJECT_VERSION Variable PROJECT_VERSION was not yet in use when check_stdint.h configuration was updated. Signed-off-by: Mikko Johannes Koivunalho --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a3a8f0a0..6e1453c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -384,7 +384,6 @@ set(CONFIG_HEADER ${CMAKE_CURRENT_BINARY_DIR}/config.h) # # 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( From 4e3b3f58620d93925192132379ef4a734cc8ac9a Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Sat, 14 Sep 2019 18:18:45 +0200 Subject: [PATCH 08/12] Add variable VERSION to pkgconfig/check.pc configuration File check.pc.in is shared with Autotools and CMake build. File uses variable 'VERSION'. Signed-off-by: Mikko Johannes Koivunalho --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e1453c6..dd4e925a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -398,6 +398,7 @@ set(prefix "${CMAKE_INSTALL_PREFIX}") set(exec_prefix "\${prefix}") set(libdir "\${exec_prefix}/lib") set(includedir "\${prefix}/include") +set(VERSION "${PROJECT_VERSION}") if (HAVE_SUBUNIT) set(LIBSUBUNIT_PC "libsubunit") @@ -431,6 +432,7 @@ unset(LIBS) unset(PTHREAD_LIBS) unset(GCOV_LIBS) unset(LIBSUBUNIT_PC) +unset(VERSION) unset(includedir) unset(libdir) unset(exec_prefix) From 604e6f3eb5b678a79ef8c47aa90e4464d0206814 Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Sat, 14 Sep 2019 18:59:53 +0200 Subject: [PATCH 09/12] Truncate PROJECT_VERSION to three components For compatibility with the Autotools build which only uses three parts: major, minor and patch. CMake allows four components in version numbering: major, minor, patch and tweak. Signed-off-by: Mikko Johannes Koivunalho --- CMakeLists.txt | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dd4e925a..7baa02d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,11 +47,7 @@ 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}") +set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}") set(MEMORY_LEAKING_TESTS_ENABLED 1) @@ -494,7 +490,7 @@ configure_package_config_file( ) write_basic_package_version_file( ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_NAME}-config-version.cmake - VERSION ${check_VERSION} + VERSION ${PROJECT_VERSION} COMPATIBILITY AnyNewerVersion ) From c5cc43f243ce80023afb84cd36e83f3b116cdfb5 Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Sat, 14 Sep 2019 19:31:40 +0200 Subject: [PATCH 10/12] Correct indentation Signed-off-by: Mikko Johannes Koivunalho --- CMakeLists.txt | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7baa02d0..9fc20981 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -454,27 +454,27 @@ if (BUILD_TESTING) # 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 (BUILD_TESTING) From 12d566b468f71cbaa068cabccac3728a36e11edd Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Sat, 14 Sep 2019 21:06:12 +0200 Subject: [PATCH 11/12] Add option ENABLE_MEMORY_LEAKING_TESTS Removing the set(MEMORY_LEAKING_TESTS_ENABLED) which had no effect on the build. The new CMake build option uses verb-first structure (do something on something: e.g. ENABLE/BUILD) like other build options. The definition itself is "MEMORY_LEAKING_TESTS_ENABLED" and only enabled in the tests/ subdirectory. Signed-off-by: Mikko Johannes Koivunalho --- CMakeLists.txt | 6 ++++-- tests/CMakeLists.txt | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9fc20981..12b01768 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,8 +49,6 @@ set(PROJECT_VERSION_MINOR ${CHECK_MINOR_VERSION}) set(PROJECT_VERSION_PATCH ${CHECK_MICRO_VERSION}) set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}") -set(MEMORY_LEAKING_TESTS_ENABLED 1) - ############################################################################### # Set build features set(CMAKE_BUILD_TYPE Debug) @@ -73,12 +71,16 @@ 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") +option(ENABLE_MEMORY_LEAKING_TESTS + "Enable certain memory leaking tests only if valgrind is not used in testing" ON) + ############################################################################### # Check system and architecture if(WIN32) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8a1c241e..5a925c25 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -40,6 +40,12 @@ endif(WIN32) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/test_vars.in ${CMAKE_CURRENT_BINARY_DIR}/test_vars @ONLY) +if(ENABLE_MEMORY_LEAKING_TESTS) + add_definitions(-DMEMORY_LEAKING_TESTS_ENABLED=1) +else(ENABLE_MEMORY_LEAKING_TESTS) + add_definitions(-DMEMORY_LEAKING_TESTS_ENABLED=0) +endif(ENABLE_MEMORY_LEAKING_TESTS) + set(CHECK_CHECK_SOURCES check_check_exit.c check_check_fixture.c From 517bf26abbb655562b3f22b530f11b2e0d4ae2a6 Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Sat, 14 Sep 2019 21:16:50 +0200 Subject: [PATCH 12/12] Remove unneeded include() Already included in the project root CMakeLists.txt Signed-off-by: Mikko Johannes Koivunalho --- src/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f5e4af9e..437ea2a6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -167,7 +167,6 @@ target_include_directories(checkShared $ ) -include(GNUInstallDirs) install(TARGETS check checkShared EXPORT check-targets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}