Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ swift_create_project_options(
TEST_PACKAGES "Check"
)
include(CodeCoverage)
include(TestTargets)
add_code_coverage_all_targets()

##########################################################
Expand Down
53 changes: 26 additions & 27 deletions c/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
set(TEST_LIBS ${TEST_LIBS} ${CHECK_LIBRARIES} pthread sbp m)
find_package(Threads)
set(TEST_LIBS ${TEST_LIBS} ${CHECK_LIBRARIES} Threads::Threads sbp m)

# Check needs to be linked against Librt on Linux
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(TEST_LIBS ${TEST_LIBS} rt)
endif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")

FILE(GLOB generated_c_sources auto*.c)
add_executable(test_libsbp check_main.c check_edc.c check_sbp.c ${generated_c_sources})

target_link_libraries(test_libsbp PRIVATE ${TEST_LIBS})
set_target_properties(test_libsbp PROPERTIES
C_STANDARD 99
C_STANDARD_REQUIRED ON)
set(TEST_INCLUDES ${PROJECT_SOURCE_DIR}/include/libsbp)

if(MSVC)
target_include_directories(test_libsbp PRIVATE ${PROJECT_SOURCE_DIR}/include/libsbp/)
else()
target_include_directories(test_libsbp PRIVATE ${PROJECT_SOURCE_DIR}/include/libsbp/)
if(APPLE)
# Some libraries are available in non-standard places on apple.
target_include_directories(test_libsbp PRIVATE /usr/local/include)
if(APPLE)
# Some libraries are available in non-standard places on apple.
list(APPEND TEST_INCLUDES /usr/local/include)

# This is not a great way of doing this, but the proper cmake function
# target_link_directories() was introduced in version 3.13 and we need to support
# older versions for the moment. We can use target_link_libraries to pass arbitrary
# linker flags, making sure that this instance is well protected and only applies
# to a single platform. Don't use the extant link_directories() function since
# that leaks the path to other targets.
target_link_libraries(test_libsbp PRIVATE "-L/usr/local/lib")
endif()
# This is not a great way of doing this, but the proper cmake function
# target_link_directories() was introduced in version 3.13 and we need to support
# older versions for the moment. We can use target_link_libraries to pass arbitrary
# linker flags, making sure that this instance is well protected and only applies
# to a single platform. Don't use the extant link_directories() function since
# that leaks the path to other targets.
list(APPEND TEST_INCLUDES "-L/usr/local/lib")
endif()
target_code_coverage(test_libsbp AUTO ALL)

add_custom_command(
TARGET test_libsbp POST_BUILD
COMMENT "Running unit tests"
COMMAND test_libsbp
)
swift_add_test(test-libsbp
POST_BUILD
SRCS
check_main.c
check_edc.c
check_sbp.c
${generated_c_sources}
INCLUDE
${TEST_INCLUDES}
LINK
${TEST_LIBS}
)