From 3968e4a00cfdaa9cff555321b16c73032e5f359a Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Fri, 18 Oct 2019 19:22:52 +1100 Subject: [PATCH 1/2] Use common test targets module --- c/CMakeLists.txt | 1 + c/cmake/common | 2 +- c/test/CMakeLists.txt | 33 +++++++++++++++++---------------- 3 files changed, 19 insertions(+), 17 deletions(-) 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..9d4ce3e2e3 100644 --- a/c/test/CMakeLists.txt +++ b/c/test/CMakeLists.txt @@ -6,20 +6,14 @@ 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) if(MSVC) - target_include_directories(test_libsbp PRIVATE ${PROJECT_SOURCE_DIR}/include/libsbp/) + set(TEST_INCLUDES ${PROJECT_SOURCE_DIR}/include/libsbp/) else() - target_include_directories(test_libsbp PRIVATE ${PROJECT_SOURCE_DIR}/include/libsbp/) + set(TEST_INCLUDES ${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) + set(test_libsbp /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 @@ -27,13 +21,20 @@ else() # 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") + set(TEST_INCLUDES "-L/usr/local/lib") endif() 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} + ) + From 22f430e4f641fd79e049483b51ef0a52b789eb0b Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Thu, 24 Oct 2019 07:34:32 +1100 Subject: [PATCH 2/2] Code review comments --- c/test/CMakeLists.txt | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/c/test/CMakeLists.txt b/c/test/CMakeLists.txt index 9d4ce3e2e3..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") @@ -7,22 +8,19 @@ endif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") FILE(GLOB generated_c_sources auto*.c) -if(MSVC) - set(TEST_INCLUDES ${PROJECT_SOURCE_DIR}/include/libsbp/) -else() - set(TEST_INCLUDES ${PROJECT_SOURCE_DIR}/include/libsbp/) - if(APPLE) - # Some libraries are available in non-standard places on apple. - set(test_libsbp /usr/local/include) +set(TEST_INCLUDES ${PROJECT_SOURCE_DIR}/include/libsbp) - # 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. - set(TEST_INCLUDES "-L/usr/local/lib") - endif() +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. + list(APPEND TEST_INCLUDES "-L/usr/local/lib") endif() swift_add_test(test-libsbp