Skip to content

Commit

Permalink
Add libcompat code directly to libcheck
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mikkoi committed Sep 8, 2019
1 parent 4e2bd6b commit 224b6d1
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 87 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -440,7 +444,6 @@ install(

###############################################################################
# Subdirectories
add_subdirectory(lib)
add_subdirectory(src)
add_subdirectory(checkmk)

Expand Down
78 changes: 0 additions & 78 deletions lib/CMakeLists.txt

This file was deleted.

64 changes: 62 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
Expand Down
12 changes: 6 additions & 6 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

0 comments on commit 224b6d1

Please sign in to comment.