[hnswlib] backport CMake targets (#31305)

* [hnswlib] backport CMake targets

* download cmake changes as patch

* add patch file
This commit is contained in:
moritz-h 2023-05-10 21:36:01 +02:00 committed by GitHub
parent 281cfd338c
commit d163f9d5f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 78 additions and 10 deletions

44
ports/hnswlib/cmake.patch Normal file
View File

@ -0,0 +1,44 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7cebe60..b2aecc8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,11 +1,36 @@
-cmake_minimum_required (VERSION 2.6)
-project(hnsw_lib
+cmake_minimum_required(VERSION 3.0...3.26)
+
+project(hnswlib
LANGUAGES CXX)
+include(GNUInstallDirs)
+
add_library(hnswlib INTERFACE)
-target_include_directories(hnswlib INTERFACE .)
+add_library(hnswlib::hnswlib ALIAS hnswlib)
+
+target_include_directories(hnswlib INTERFACE
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
+
+# Install
+install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/hnswlib
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+install(TARGETS hnswlib
+ EXPORT hnswlibTargets)
+
+install(EXPORT hnswlibTargets
+ FILE hnswlibConfig.cmake
+ NAMESPACE hnswlib::
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/hnswlib)
+
+# Examples and tests
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
+ option(HNSWLIB_EXAMPLES "Build examples and tests." ON)
+else()
+ option(HNSWLIB_EXAMPLES "Build examples and tests." OFF)
+endif()
+if(HNSWLIB_EXAMPLES)
set(CMAKE_CXX_STANDARD 11)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")

View File

@ -1,12 +1,24 @@
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO nmslib/hnswlib
REF 359b2ba87358224963986f709e593d799064ace6 # v0.7.0
SHA512 59a0c02bbe8f7389a2ecad9188a76eb3847b719a213d306093753c04e4eeb11d95e8e310aa03888364be475a2f2e6e7976bd81117517eef81eff2983379ac743
REF "v${VERSION}"
SHA512 fd74c23040598973d7e0b5a6af73eb884ee2d30703187d1702fdd48eaf8f7f96d8fbb125d3763f90111d9fb7c5ab3434ebdb818da8717d35c5571e99083c812b
HEAD_REF master
PATCHES
cmake.patch # Backport CMake targets from nmslib/hnswlib #446 to 0.7.0 release.
)
file(COPY "${SOURCE_PATH}/hnswlib" DESTINATION "${CURRENT_PACKAGES_DIR}/include")
set(VCPKG_BUILD_TYPE "release") # header-only port
vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
-DHNSWLIB_EXAMPLES=OFF
)
vcpkg_cmake_install()
vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/hnswlib)
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/lib")
file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")

View File

@ -1,4 +0,0 @@
hnswlib is header-only and can be used from CMake via:
find_path(HNSWLIB_INCLUDE_DIRS "hnswlib/hnswlib.h")
target_include_directories(main PRIVATE ${HNSWLIB_INCLUDE_DIRS})

View File

@ -1,7 +1,18 @@
{
"name": "hnswlib",
"version": "0.7.0",
"port-version": 1,
"description": "Header-only library for fast approximate nearest neighbors",
"homepage": "https://github.com/nmslib/hnswlib",
"license": "Apache-2.0"
"license": "Apache-2.0",
"dependencies": [
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
}
]
}

View File

@ -3130,7 +3130,7 @@
},
"hnswlib": {
"baseline": "0.7.0",
"port-version": 0
"port-version": 1
},
"hps": {
"baseline": "2022-01-18",

View File

@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "497030f03d37d63ff86c9e99d24d9e8f048ea067",
"version": "0.7.0",
"port-version": 1
},
{
"git-tree": "7053d263445d46410589894d921fa6c85fbf107c",
"version": "0.7.0",