Skip to content

Commit

Permalink
Backwards compatible dependencies (#48)
Browse files Browse the repository at this point in the history
* Remain compatible with older lz4 and flann versions

* install flann headers to subfolder

* Update README.md
  • Loading branch information
alxvth authored Oct 4, 2024
1 parent 649ef49 commit cc770c5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
31 changes: 24 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 10 additions & 6 deletions hdi/dimensionality_reduction/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit cc770c5

Please sign in to comment.