diff --git a/CMakeLists.txt b/CMakeLists.txt index f4b94d25..78a591bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -148,6 +148,7 @@ endif(BUILD_CUDA_LIB) find_package(PkgConfig REQUIRED) pkg_check_modules(LZ4 REQUIRED liblz4) +include_directories(${LZ4_INCLUDE_DIRS}) #set the C/C++ include path to the "include" directory include_directories(BEFORE ${PROJECT_SOURCE_DIR}/src/cpp) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 3f4655a2..ef5fb27b 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,9 +1,13 @@ add_custom_target(examples ALL) +# Only use GNU-specific linker commands for the GNU compiler +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(CMAKE_LINK_WHAT_YOU_USE TRUE) +endif() if (BUILD_C_BINDINGS) add_executable(flann_example_c flann_example.c) - target_link_libraries(flann_example_c -Wl,--push-state,--no-as-needed ${LZ4_LIBRARIES} -Wl,--pop-state) + target_link_libraries(flann_example_c ${LZ4_LINK_LIBRARIES}) target_link_libraries(flann_example_c flann) set_target_properties(flann_example_c PROPERTIES COMPILE_FLAGS -std=c99) @@ -15,7 +19,7 @@ if (HDF5_FOUND) include_directories(${HDF5_INCLUDE_DIR}) add_executable(flann_example_cpp flann_example.cpp) - target_link_libraries(flann_example_cpp -Wl,--push-state,--no-as-needed ${LZ4_LIBRARIES} -Wl,--pop-state) + target_link_libraries(flann_example_cpp ${LZ4_LINK_LIBRARIES}) target_link_libraries(flann_example_cpp ${HDF5_LIBRARIES} flann_cpp) if (HDF5_IS_PARALLEL) target_link_libraries(flann_example_cpp ${MPI_LIBRARIES}) @@ -27,7 +31,7 @@ if (HDF5_FOUND) if (USE_MPI AND HDF5_IS_PARALLEL) add_executable(flann_example_mpi flann_example_mpi.cpp) - target_link_libraries(flann_example_mpi -Wl,--push-state,--no-as-needed ${LZ4_LIBRARIES} -Wl,--pop-state) + target_link_libraries(flann_example_mpi ${LZ4_LINK_LIBRARIES}) target_link_libraries(flann_example_mpi flann_cpp ${HDF5_LIBRARIES} ${MPI_LIBRARIES} ${Boost_LIBRARIES}) add_dependencies(examples flann_example_mpi) diff --git a/src/cpp/CMakeLists.txt b/src/cpp/CMakeLists.txt index b421abb0..4703c6f1 100644 --- a/src/cpp/CMakeLists.txt +++ b/src/cpp/CMakeLists.txt @@ -9,12 +9,17 @@ file(GLOB_RECURSE CPP_SOURCES flann_cpp.cpp) file(GLOB_RECURSE CU_SOURCES *.cu) add_library(flann_cpp_s STATIC ${CPP_SOURCES}) -target_link_libraries(flann_cpp_s ${LZ4_LIBRARIES}) +target_link_libraries(flann_cpp_s ${LZ4_LINK_LIBRARIES}) if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG) set_target_properties(flann_cpp_s PROPERTIES COMPILE_FLAGS -fPIC) endif() set_property(TARGET flann_cpp_s PROPERTY COMPILE_DEFINITIONS FLANN_STATIC FLANN_USE_CUDA) +# Only use GNU-specific linker commands for the GNU compiler +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(CMAKE_LINK_WHAT_YOU_USE TRUE) +endif() + if (BUILD_CUDA_LIB) SET(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS};-DFLANN_USE_CUDA") if(CMAKE_COMPILER_IS_GNUCC) @@ -43,7 +48,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_COMPILER_IS_GNUCC) endif() else() add_library(flann_cpp SHARED ${CPP_SOURCES}) - target_link_libraries(flann_cpp -Wl,--push-state,--no-as-needed ${LZ4_LIBRARIES} -Wl,--pop-state) + target_link_libraries(flann_cpp ${LZ4_LINK_LIBRARIES} ) # export lz4 headers, so that MSVC to creates flann_cpp.lib set_target_properties(flann_cpp PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS YES) if (BUILD_CUDA_LIB) @@ -81,7 +86,7 @@ endif() if (BUILD_C_BINDINGS) add_library(flann_s STATIC ${C_SOURCES}) - target_link_libraries(flann_s -Wl,--push-state,--no-as-needed ${LZ4_LIBRARIES} -Wl,--pop-state) + target_link_libraries(flann_s ${LZ4_LINK_LIBRARIES}) if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG) set_target_properties(flann_s PROPERTIES COMPILE_FLAGS -fPIC) endif() @@ -93,7 +98,7 @@ if (BUILD_C_BINDINGS) target_link_libraries(flann -Wl,-whole-archive flann_s -Wl,-no-whole-archive) else() add_library(flann SHARED ${C_SOURCES}) - target_link_libraries(flann -Wl,--push-state,--no-as-needed ${LZ4_LIBRARIES} -Wl,--pop-state) + target_link_libraries(flann ${LZ4_LINK_LIBRARIES}) if(MINGW AND OPENMP_FOUND) target_link_libraries(flann gomp)