From d0d20008b7f5c847491e60d9776163370e1eccce Mon Sep 17 00:00:00 2001 From: Mikko Johannes Koivunalho Date: Sun, 8 Sep 2019 20:58:30 +0200 Subject: [PATCH] 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)