|
| 1 | +# Copyright (C) 2023 Intel Corporation |
| 2 | +# |
| 3 | +# This software and the related documents are Intel copyrighted materials, |
| 4 | +# and your use of them is governed by the express license under which they |
| 5 | +# were provided to you ("License"). Unless the License provides otherwise, |
| 6 | +# you may not use, modify, copy, publish, distribute, disclose or transmit |
| 7 | +# this software or the related documents without Intel's prior written |
| 8 | +# permission. |
| 9 | +# |
| 10 | +# This software and the related documents are provided as is, with no |
| 11 | +# express or implied warranties, other than those that are expressly stated |
| 12 | +# in the License. |
| 13 | + |
| 14 | +cmake_minimum_required(VERSION 3.21) |
| 15 | +project(svs_runtime VERSION 0.0.10 LANGUAGES CXX) |
| 16 | +set(TARGET_NAME svs_runtime) |
| 17 | + |
| 18 | +set(SVS_RUNTIME_HEADERS |
| 19 | + include/IndexSVSImplDefs.h |
| 20 | + include/IndexSVSFlatImpl.h |
| 21 | + include/IndexSVSVamanaImpl.h |
| 22 | +) |
| 23 | + |
| 24 | +set(SVS_RUNTIME_SOURCES |
| 25 | + src/IndexSVSImplUtils.h |
| 26 | + src/IndexSVSFlatImpl.cpp |
| 27 | + src/IndexSVSVamanaImpl.cpp |
| 28 | +) |
| 29 | + |
| 30 | +option(SVS_RUNTIME_ENABLE_LVQ "Enable compilation of SVS runtime with LVQ support" ON) |
| 31 | +if (SVS_RUNTIME_ENABLE_LVQ) |
| 32 | + message(STATUS "SVS runtime will be built with LVQ support") |
| 33 | + list(APPEND SVS_RUNTIME_HEADERS |
| 34 | + include/IndexSVSVamanaLVQImpl.h |
| 35 | + ) |
| 36 | + list(APPEND SVS_RUNTIME_SOURCES |
| 37 | + src/IndexSVSVamanaLVQImpl.cpp |
| 38 | + ) |
| 39 | +else() |
| 40 | + message(STATUS "SVS runtime will be built without LVQ support") |
| 41 | +endif() |
| 42 | + |
| 43 | +option(SVS_RUNTIME_ENABLE_LEANVEC "Enable compilation of SVS runtime with LeanVec support" ON) |
| 44 | +if (SVS_RUNTIME_ENABLE_LEANVEC) |
| 45 | + message(STATUS "SVS runtime will be built with LeanVec support") |
| 46 | + list(APPEND SVS_RUNTIME_HEADERS |
| 47 | + include/IndexSVSVamanaLeanVecImpl.h |
| 48 | + ) |
| 49 | + list(APPEND SVS_RUNTIME_SOURCES |
| 50 | + src/IndexSVSVamanaLeanVecImpl.cpp |
| 51 | + ) |
| 52 | +else() |
| 53 | + message(STATUS "SVS runtime will be built without LeanVec support") |
| 54 | +endif() |
| 55 | + |
| 56 | +find_package(OpenMP REQUIRED) |
| 57 | + |
| 58 | +add_library(${TARGET_NAME} SHARED |
| 59 | + ${SVS_RUNTIME_HEADERS} |
| 60 | + ${SVS_RUNTIME_SOURCES} |
| 61 | +) |
| 62 | + |
| 63 | +target_link_libraries(${TARGET_NAME} PUBLIC |
| 64 | + OpenMP::OpenMP_CXX |
| 65 | +) |
| 66 | + |
| 67 | +target_include_directories(${TARGET_NAME} PRIVATE |
| 68 | + ${CMAKE_CURRENT_SOURCE_DIR}/include |
| 69 | +) |
| 70 | + |
| 71 | +target_compile_options(${TARGET_NAME} PRIVATE |
| 72 | + -DSVS_ENABLE_OMP=1 |
| 73 | + -fvisibility=hidden |
| 74 | +) |
| 75 | + |
| 76 | +target_compile_features(${TARGET_NAME} INTERFACE cxx_std_20) |
| 77 | +set_target_properties(${TARGET_NAME} PROPERTIES PUBLIC_HEADER "${SVS_RUNTIME_HEADERS}") |
| 78 | +set_target_properties(${TARGET_NAME} PROPERTIES CXX_STANDARD 20) |
| 79 | +set_target_properties(${TARGET_NAME} PROPERTIES CXX_STANDARD_REQUIRED ON) |
| 80 | +set_target_properties(${TARGET_NAME} PROPERTIES CXX_EXTENSIONS OFF) |
| 81 | +set_target_properties(${TARGET_NAME} PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR} ) |
| 82 | + |
| 83 | +if ((SVS_RUNTIME_ENABLE_LVQ OR SVS_RUNTIME_ENABLE_LEANVEC)) |
| 84 | + if(TARGET svs::svs_static_library) |
| 85 | + target_link_libraries(${TARGET_NAME} PRIVATE |
| 86 | + svs::svs |
| 87 | + svs::svs_static_library |
| 88 | + svs_compile_options |
| 89 | + svs_x86_options_base |
| 90 | + ) |
| 91 | + else() |
| 92 | + set(SVS_URL "https://github.com/intel/ScalableVectorSearch/releases/download/v1.0.0-dev/svs-shared-library-1.0.0-NIGHTLY-20251017-faiss.tar.gz" |
| 93 | + CACHE STRING "URL to download SVS shared library") |
| 94 | + include(FetchContent) |
| 95 | + FetchContent_Declare( |
| 96 | + svs |
| 97 | + URL ${SVS_URL} |
| 98 | + ) |
| 99 | + FetchContent_MakeAvailable(svs) |
| 100 | + list(APPEND CMAKE_PREFIX_PATH "${svs_SOURCE_DIR}") |
| 101 | + find_package(svs REQUIRED) |
| 102 | + target_link_libraries(${TARGET_NAME} PRIVATE |
| 103 | + svs::svs |
| 104 | + svs::svs_compile_options |
| 105 | + svs::svs_static_library |
| 106 | + ) |
| 107 | + endif() |
| 108 | +else() |
| 109 | + # Include the SVS library directly if needed. |
| 110 | + if (NOT TARGET svs::svs) |
| 111 | + add_subdirectory("../.." "${CMAKE_CURRENT_BINARY_DIR}/svs") |
| 112 | + endif() |
| 113 | + target_link_libraries(${TARGET_NAME} PRIVATE |
| 114 | + svs::svs |
| 115 | + svs_compile_options |
| 116 | + svs_x86_options_base |
| 117 | + ) |
| 118 | +endif() |
| 119 | + |
| 120 | +# installing |
| 121 | +include(GNUInstallDirs) |
| 122 | + |
| 123 | +set(SVS_RUNTIME_EXPORT_NAME ${TARGET_NAME}) |
| 124 | +set(VERSION_CONFIG "${CMAKE_CURRENT_BINARY_DIR}/${SVS_RUNTIME_EXPORT_NAME}ConfigVersion.cmake") |
| 125 | +set(SVS_RUNTIME_CONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/svs_runtime) |
| 126 | +set(SVS_RUNTIME_COMPONENT_NAME "Runtime") |
| 127 | + |
| 128 | +install(TARGETS ${TARGET_NAME} |
| 129 | + EXPORT ${SVS_RUNTIME_EXPORT_NAME} |
| 130 | + COMPONENT ${SVS_RUNTIME_COMPONENT_NAME} |
| 131 | + LIBRARY DESTINATION lib |
| 132 | + PUBLIC_HEADER DESTINATION include/svs/runtime |
| 133 | + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} |
| 134 | +) |
| 135 | + |
| 136 | +install(DIRECTORY include/svs/runtime |
| 137 | + COMPONENT ${SVS_RUNTIME_COMPONENT_NAME} |
| 138 | + DESTINATION include/svs |
| 139 | + FILES_MATCHING PATTERN "*.h" |
| 140 | +) |
| 141 | + |
| 142 | +install(EXPORT ${SVS_RUNTIME_EXPORT_NAME} |
| 143 | + COMPONENT ${SVS_RUNTIME_COMPONENT_NAME} |
| 144 | + NAMESPACE svs:: |
| 145 | + DESTINATION ${SVS_RUNTIME_CONFIG_INSTALL_DIR} |
| 146 | +) |
| 147 | + |
| 148 | +include(CMakePackageConfigHelpers) |
| 149 | +configure_package_config_file( |
| 150 | + "${CMAKE_CURRENT_LIST_DIR}/runtimeConfig.cmake.in" |
| 151 | + "${CMAKE_CURRENT_BINARY_DIR}/${SVS_RUNTIME_EXPORT_NAME}Config.cmake" |
| 152 | + INSTALL_DESTINATION "${SVS_RUNTIME_CONFIG_INSTALL_DIR}" |
| 153 | +) |
| 154 | + |
| 155 | +# Don't make compatibility guarantees until we reach a compatibility milestone. |
| 156 | +write_basic_package_version_file( |
| 157 | + ${VERSION_CONFIG} |
| 158 | + VERSION ${PROJECT_VERSION} |
| 159 | + COMPATIBILITY ExactVersion |
| 160 | +) |
| 161 | + |
| 162 | +install(FILES |
| 163 | + "${CMAKE_CURRENT_BINARY_DIR}/${SVS_RUNTIME_EXPORT_NAME}Config.cmake" |
| 164 | + "${VERSION_CONFIG}" |
| 165 | + COMPONENT ${SVS_RUNTIME_COMPONENT_NAME} |
| 166 | + DESTINATION "${SVS_RUNTIME_CONFIG_INSTALL_DIR}" |
| 167 | +) |
| 168 | + |
0 commit comments