diff --git a/c/CMakeLists.txt b/c/CMakeLists.txt index dbfaa74752..b7a1c7a957 100644 --- a/c/CMakeLists.txt +++ b/c/CMakeLists.txt @@ -12,6 +12,7 @@ swift_create_project_options( TEST_PACKAGES "Check" ) include(CodeCoverage) +include(TestTargets) add_code_coverage_all_targets() ########################################################## diff --git a/c/cmake/common b/c/cmake/common index 0616a352eb..c4920a9afd 160000 --- a/c/cmake/common +++ b/c/cmake/common @@ -1 +1 @@ -Subproject commit 0616a352eb7b3141393efb65614fdae90f4d7e6a +Subproject commit c4920a9afd05d5091be8cda1a0858e00aa967360 diff --git a/c/test/CMakeLists.txt b/c/test/CMakeLists.txt index 4dcd99f225..916bd27b69 100644 --- a/c/test/CMakeLists.txt +++ b/c/test/CMakeLists.txt @@ -1,4 +1,5 @@ -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") @@ -6,34 +7,32 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") 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} + ) +