From cc770c5894ed0663db2581232a7719c95a0595b1 Mon Sep 17 00:00:00 2001 From: Alexander Vieth Date: Fri, 4 Oct 2024 17:12:37 +0200 Subject: [PATCH] Backwards compatible dependencies (#48) * Remain compatible with older lz4 and flann versions * install flann headers to subfolder * Update README.md --- CMakeLists.txt | 31 ++++++++++++++++----- README.md | 4 +-- hdi/dimensionality_reduction/CMakeLists.txt | 16 +++++++---- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ad0444c..b01bafa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,17 +73,34 @@ message(STATUS "CMAKE_GENERATOR: ${CMAKE_GENERATOR}") # ----------------------------------------------------------------------------- # Dependencies # ----------------------------------------------------------------------------- -find_package(lz4 CONFIG REQUIRED) -find_package(flann CONFIG REQUIRED) -find_package(OpenMP) +find_package(lz4 CONFIG) +if(NOT ${lz4_FOUND}) + find_package(PkgConfig REQUIRED) + + pkg_check_modules(lz4 REQUIRED IMPORTED_TARGET liblz4) + set(LZ4_TARGET PkgConfig::lz4) +endif() + +if(NOT ${lz4_FOUND}) + message (FATAL_ERROR "lz4 NOT found") +endif() +message (STATUS "Found lz4 version ${lz4_VERSION}") + +find_package(flann CONFIG) +if(NOT ${flann_FOUND}) + find_package(PkgConfig REQUIRED) -if(${flann_FOUND}) - message (STATUS "Found flann version ${flann_VERSION}") + pkg_check_modules(flann REQUIRED flann) + set(FLANN_TARGET flann_cpp) + set(flann_INCLUDE_DIR "${flann_INCLUDE_DIRS}/flann") endif() -if(${lz4_FOUND}) - message (STATUS "Found lz4 version ${lz4_VERSION}") +if(NOT ${flann_FOUND}) + message (FATAL_ERROR "flann NOT found") endif() +message (STATUS "Found flann version ${flann_VERSION}") + +find_package(OpenMP) if(OpenMP_CXX_FOUND) message (STATUS "OpenMP found") diff --git a/README.md b/README.md index 83ce263..6f39069 100644 --- a/README.md +++ b/README.md @@ -64,11 +64,11 @@ When configuring cmake make sure to setup vcpkg with CMAKE_TOOLCHAIN_FILE (`PATH You may also use system-specific package managers, e.g. on Linux with ```bash -sudo apt-get -y install libflann-dev liblz4-dev +sudo apt-get -y install libflann-dev liblz4-dev pkg-config ``` and Mac OS with ``` -brew install flann lz4 +brew install flann lz4 pkg-config ``` ### Generate the build files diff --git a/hdi/dimensionality_reduction/CMakeLists.txt b/hdi/dimensionality_reduction/CMakeLists.txt index c85e3f7..e936f07 100644 --- a/hdi/dimensionality_reduction/CMakeLists.txt +++ b/hdi/dimensionality_reduction/CMakeLists.txt @@ -97,13 +97,17 @@ if(${HDILib_INSTALL}) ) # Install dependency 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) + if(NOT flann_INCLUDE_DIR) + get_target_property(flann_INCLUDE_DIR ${FLANN_TARGET} INTERFACE_INCLUDE_DIRECTORIES) + endif() + + if(flann_INCLUDE_DIR) + if(NOT flann_INCLUDE_DIR MATCHES "flann$") + set(flann_INCLUDE_DIR "${flann_INCLUDE_DIR}/flann") endif() + + message(STATUS "Using flann includes at: ${flann_INCLUDE_DIR}") + install(DIRECTORY "${flann_INCLUDE_DIR}/" DESTINATION "${CMAKE_INSTALL_PREFIX}/include/flann" COMPONENT FLANN_HEADERS) endif() install(DIRECTORY "${HNSWLIB_INCLUDE_DIR}/hnswlib/" DESTINATION "${CMAKE_INSTALL_PREFIX}/include/hnswlib" COMPONENT HNSW_HEADERS)