Skip to content

Commit

Permalink
Add unify linking (#46)
Browse files Browse the repository at this point in the history
* Always link the same

* Fix typo

* Always install all dependency headers

Signed-off-by: Alexander Vieth <vieth.alexander@gmx.net>

* Revert: keep the 1.2.8 version

* More flexible

* check lz4 for static as well

* Update CMakeLists.txt

---------

Signed-off-by: Alexander Vieth <vieth.alexander@gmx.net>
  • Loading branch information
alxvth authored Sep 27, 2024
1 parent bfe2184 commit fdbaf46
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 34 deletions.
12 changes: 10 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,18 @@ message(STATUS "CMAKE_GENERATOR: ${CMAKE_GENERATOR}")
# -----------------------------------------------------------------------------
# Dependencies
# -----------------------------------------------------------------------------
find_package(lz4 REQUIRED)
find_package(flann REQUIRED)
find_package(lz4 CONFIG REQUIRED)
find_package(flann CONFIG REQUIRED)
find_package(OpenMP)

if(${flann_FOUND})
message (STATUS "Found flann version ${flann_VERSION}")
endif()

if(${lz4_FOUND})
message (STATUS "Found lz4 version ${lz4_VERSION}")
endif()

if(OpenMP_CXX_FOUND)
message (STATUS "OpenMP found")
elseif(CMAKE_GENERATOR STREQUAL Xcode)
Expand Down
65 changes: 33 additions & 32 deletions hdi/dimensionality_reduction/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,40 @@ get_filename_component(ANNOY_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../exte
target_include_directories(${PROJECT} PRIVATE ${ANNOY_INCLUDE_DIR})
message (STATUS "Annoy: " ${ANNOY_INCLUDE_DIR})

if(${IN_CONAN_BUILD})
message (STATUS "Flann include: " ${flann_ROOT})
message (STATUS "lz4 include: " ${lz4_ROOT})
target_link_libraries(${PROJECT} PRIVATE flann::flann_cpp lz4::lz4)
else()
message (STATUS "Flann path: " ${flann_DIR})
# Need lz4 include because of the flann serialization dependency
target_include_directories(${PROJECT} PRIVATE ${lz4_INCLUDE_DIR})

# prefer static linking
if(NOT FLANN_TARGET)
if(TARGET flann::flann_cpp_s)
set(FLANN_TARGET flann::flann_cpp_s)
elseif(TARGET flann::flann_cpp)
set(FLANN_TARGET flann::flann_cpp)
elseif(TARGET flann::flann_s)
set(FLANN_TARGET flann::flann_s)
elseif(TARGET flann::flann)
set(FLANN_TARGET flann::flann)
else()
message(FATAL_ERROR "No Flann target found.")
endif()

message (STATUS "Flann link library: " ${FLANN_TARGET})
target_link_libraries(${PROJECT} PRIVATE ${FLANN_TARGET})
endif()

if(NOT LZ4_TARGET)
if(TARGET LZ4::lz4_static)
set(LZ4_TARGET LZ4::lz4_static)
elseif(TARGET LZ4::lz4_shared)
set(LZ4_TARGET LZ4::lz4_shared)
elseif(TARGET lz4::lz4)
set(LZ4_TARGET lz4::lz4)
elseif(TARGET LZ4::lz4) # intentionally UPPERCASE::LOWERCASE
set(LZ4_TARGET LZ4::lz4)
else()
message(FATAL_ERROR "No LZ4 target found.")
endif()
endif()

message (STATUS "Flann link library: " ${FLANN_TARGET})
target_link_libraries(${PROJECT} PRIVATE ${FLANN_TARGET})
message (STATUS "Linking lz4 library " ${LZ4_TARGET})
target_link_libraries(${PROJECT} PRIVATE ${LZ4_TARGET})

if(OpenMP_CXX_FOUND)
target_link_libraries(${PROJECT} PRIVATE OpenMP::OpenMP_CXX)
endif()
Expand Down Expand Up @@ -83,26 +98,12 @@ if(${HDILib_INSTALL})
)

# Install dependency headers
if(NOT DEFINED IN_CONAN_BUILD)
if(DEFINED flann_INCLUDE_DIR)
install(DIRECTORY "${flann_INCLUDE_DIR}/" DESTINATION "${CMAKE_INSTALL_PREFIX}/include" COMPONENT FLANN_HEADERS)
endif()

if(DEFINED lz4_INCLUDE_DIR)
install(DIRECTORY "${lz4_INCLUDE_DIR}/" DESTINATION "${CMAKE_INSTALL_PREFIX}/include" COMPONENT LZ4_HEADERS)
endif()

if(DEFINED VCPKG_INSTALLED_DIR)
install(DIRECTORY "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include/flann/" DESTINATION "${CMAKE_INSTALL_PREFIX}/include/flann/" COMPONENT FLANN_HEADERS)
install(CODE "foreach(LZ4_HEADER lz4.h lz4file.h lz4frame.h lz4frame_static.h lz4hc.h)
execute_process(
COMMAND \"${CMAKE_COMMAND}\" -E copy_if_different
\"${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include/\${LZ4_HEADER}\"
\"${CMAKE_INSTALL_PREFIX}/include/\${LZ4_HEADER}\"
)
endforeach()"
COMPONENT ANNOY_HEADERS
)
if(DEFINED flann_INCLUDE_DIR)
install(DIRECTORY "${flann_INCLUDE_DIR}/" DESTINATION "${CMAKE_INSTALL_PREFIX}/include" COMPONENT FLANN_HEADERS)
else()
get_target_property(FLANN_INCLUDE_DIR ${FLANN_TARGET} INTERFACE_INCLUDE_DIRECTORIES)
if(FLANN_INCLUDE_DIR)
install(DIRECTORY "${FLANN_INCLUDE_DIR}/" DESTINATION "${CMAKE_INSTALL_PREFIX}/include" COMPONENT FLANN_HEADERS)
endif()
endif()

Expand Down

0 comments on commit fdbaf46

Please sign in to comment.