From 692f7a7c03ce3c26a447ce7755893a5272db0121 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Wed, 12 Jun 2019 10:54:37 +1000 Subject: [PATCH 1/2] Don't use hardcoded include/link paths --- c/CMakeLists.txt | 1 - c/test/CMakeLists.txt | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/c/CMakeLists.txt b/c/CMakeLists.txt index 0ba59c46cf..3e4f3499fd 100644 --- a/c/CMakeLists.txt +++ b/c/CMakeLists.txt @@ -22,7 +22,6 @@ if(MSVC) set(LIBSBP_CFLAGS "/Wall" CACHE STRING "Compile flags for libsbp.") else() set(LIBSBP_CFLAGS "-Wall -Werror" CACHE STRING "Compile flags for libsbp.") - link_directories("/usr/local/lib") endif() add_subdirectory(src) diff --git a/c/test/CMakeLists.txt b/c/test/CMakeLists.txt index a0cccf94f5..b0db3db3eb 100644 --- a/c/test/CMakeLists.txt +++ b/c/test/CMakeLists.txt @@ -16,7 +16,7 @@ set_target_properties(test_libsbp PROPERTIES 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/ /usr/local/include/) + target_include_directories(test_libsbp PRIVATE ${PROJECT_SOURCE_DIR}/include/libsbp/) endif() add_custom_command( From 672c5a5c28d2ac062196301129977310cdf5fd44 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Thu, 13 Jun 2019 09:46:14 +1000 Subject: [PATCH 2/2] Re-add /usr/local/ paths for apple platform --- c/test/CMakeLists.txt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/c/test/CMakeLists.txt b/c/test/CMakeLists.txt index b0db3db3eb..71300d8d33 100644 --- a/c/test/CMakeLists.txt +++ b/c/test/CMakeLists.txt @@ -8,7 +8,7 @@ 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 ${TEST_LIBS}) +target_link_libraries(test_libsbp PRIVATE ${TEST_LIBS}) set_target_properties(test_libsbp PROPERTIES C_STANDARD 99 C_STANDARD_REQUIRED ON) @@ -17,6 +17,18 @@ 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) + + # 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() endif() add_custom_command(