Skip to content

Commit

Permalink
Added pkg-config / pkgconf support...
Browse files Browse the repository at this point in the history
  • Loading branch information
kiplingw committed Nov 19, 2024
1 parent c1b9b79 commit 23f2990
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
31 changes: 31 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,37 @@ install(EXPORT hnswlibTargets
NAMESPACE hnswlib::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/hnswlib)

# pkg-config / pkgconf support
option(HNSWLIB_PKG_CONFIG "Build pkg-config manifest" ON)
if(HNSWLIB_PKG_CONFIG)

function(JOIN_PATHS joined_path first_path_segment)
set(temp_path "${first_path_segment}")
foreach(current_segment IN LISTS ARGN)
if(NOT ("${current_segment}" STREQUAL ""))
if(IS_ABSOLUTE "${current_segment}")
set(temp_path "${current_segment}")
else()
set(temp_path "${temp_path}/${current_segment}")
endif()
endif()
endforeach()
set(${joined_path} "${temp_path}" PARENT_SCOPE)
endfunction()

JOIN_PATHS(libdir_for_pc_file "\${exec_prefix}" "${CMAKE_INSTALL_LIBDIR}")
JOIN_PATHS(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")

configure_file(
"libhnswlib.pc.in"
"libhnswlib.pc"
@ONLY)

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libhnswlib.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")

endif()

# Examples and tests
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
option(HNSWLIB_EXAMPLES "Build examples and tests." ON)
Expand Down
12 changes: 12 additions & 0 deletions libhnswlib.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=@CMAKE_INSTALL_PREFIX@
libdir=@libdir_for_pc_file@
includedir=@includedir_for_pc_file@

Name: lib@CMAKE_PROJECT_NAME@
Description: Header-only C++/python library for fast approximate nearest neighbors.
Version:
URL: https://github.com/nmslib/hnswlib
Libs: -L${libdir}
Cflags: -I${includedir}

0 comments on commit 23f2990

Please sign in to comment.