|
| 1 | +# Copyright 2025 Intel Corporation |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +cmake_minimum_required(VERSION 3.21) |
| 16 | +project(svs_runtime VERSION 0.0.11 LANGUAGES CXX) |
| 17 | +set(TARGET_NAME svs_runtime) |
| 18 | + |
| 19 | +set(SVS_RUNTIME_HEADERS |
| 20 | + include/svs/runtime/version.h |
| 21 | + include/svs/runtime/api_defs.h |
| 22 | + include/svs/runtime/training.h |
| 23 | + include/svs/runtime/vamana_index.h |
| 24 | + include/svs/runtime/dynamic_vamana_index.h |
| 25 | + include/svs/runtime/flat_index.h |
| 26 | +) |
| 27 | + |
| 28 | +set(SVS_RUNTIME_SOURCES |
| 29 | + src/svs_runtime_utils.h |
| 30 | + src/dynamic_vamana_index_impl.h |
| 31 | + src/dynamic_vamana_index_leanvec_impl.h |
| 32 | + src/training_impl.h |
| 33 | + src/flat_index_impl.h |
| 34 | + src/api_defs.cpp |
| 35 | + src/training.cpp |
| 36 | + src/vamana_index.cpp |
| 37 | + src/dynamic_vamana_index.cpp |
| 38 | + src/flat_index.cpp |
| 39 | +) |
| 40 | + |
| 41 | +option(SVS_RUNTIME_ENABLE_LVQ_LEANVEC "Enable compilation of SVS runtime with LVQ and LeanVec support" ON) |
| 42 | +if (SVS_RUNTIME_ENABLE_LVQ_LEANVEC) |
| 43 | + message(STATUS "SVS runtime will be built with LVQ support") |
| 44 | +else() |
| 45 | + message(STATUS "SVS runtime will be built without LVQ or LeanVec support") |
| 46 | +endif() |
| 47 | + |
| 48 | +add_library(${TARGET_NAME} SHARED |
| 49 | + ${SVS_RUNTIME_HEADERS} |
| 50 | + ${SVS_RUNTIME_SOURCES} |
| 51 | +) |
| 52 | + |
| 53 | +target_include_directories(${TARGET_NAME} PRIVATE |
| 54 | + ${CMAKE_CURRENT_SOURCE_DIR}/include |
| 55 | +) |
| 56 | + |
| 57 | +find_package(OpenMP REQUIRED) |
| 58 | +target_link_libraries(${TARGET_NAME} PUBLIC OpenMP::OpenMP_CXX) |
| 59 | + |
| 60 | +target_compile_options(${TARGET_NAME} PRIVATE |
| 61 | + -DSVS_ENABLE_OMP=1 |
| 62 | + -fvisibility=hidden |
| 63 | +) |
| 64 | + |
| 65 | +if(UNIX AND NOT APPLE) |
| 66 | + # Don't export 3rd-party symbols from the lib |
| 67 | + target_link_options(${TARGET_NAME} PRIVATE "SHELL:-Wl,--exclude-libs,ALL") |
| 68 | +endif() |
| 69 | + |
| 70 | +target_compile_features(${TARGET_NAME} INTERFACE cxx_std_20) |
| 71 | +set_target_properties(${TARGET_NAME} PROPERTIES PUBLIC_HEADER "${SVS_RUNTIME_HEADERS}") |
| 72 | +set_target_properties(${TARGET_NAME} PROPERTIES CXX_STANDARD 20) |
| 73 | +set_target_properties(${TARGET_NAME} PROPERTIES CXX_STANDARD_REQUIRED ON) |
| 74 | +set_target_properties(${TARGET_NAME} PROPERTIES CXX_EXTENSIONS OFF) |
| 75 | +set_target_properties(${TARGET_NAME} PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR} ) |
| 76 | + |
| 77 | +if (SVS_RUNTIME_ENABLE_LVQ_LEANVEC) |
| 78 | + if(DEFINED SVS_LVQ_HEADER AND DEFINED SVS_LEANVEC_HEADER) |
| 79 | + # expected that pre-defined headers are implementation headers |
| 80 | + message(STATUS "Using pre-defined LVQ header: ${SVS_LVQ_HEADER}") |
| 81 | + message(STATUS "Using pre-defined LeanVec header: ${SVS_LEANVEC_HEADER}") |
| 82 | + else() |
| 83 | + set(SVS_LVQ_HEADER "svs/extensions/vamana/lvq.h") |
| 84 | + set(SVS_LEANVEC_HEADER "svs/extensions/vamana/leanvec.h") |
| 85 | + endif() |
| 86 | + |
| 87 | + if(RUNTIME_BINDINGS_PRIVATE_SOURCE_BUILD) |
| 88 | + message(STATUS "Building directly from private sources") |
| 89 | + target_link_libraries(${TARGET_NAME} PRIVATE |
| 90 | + svs::svs |
| 91 | + ) |
| 92 | + link_mkl_static(${TARGET_NAME}) |
| 93 | + elseif(TARGET svs::svs) |
| 94 | + message(FATAL_ERROR |
| 95 | + "Pre-built LVQ/LeanVec SVS library cannot be used in SVS main build. " |
| 96 | + "Please build SVS Runtime using bindings/cpp directory as CMake source root." |
| 97 | + ) |
| 98 | + else() |
| 99 | + # Links to LTO-enabled static library, requires GCC/G++ 11.2 |
| 100 | + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "11.2" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "11.3") |
| 101 | + set(SVS_URL "https://github.com/intel/ScalableVectorSearch/releases/download/v1.0.0-dev/svs-shared-library-1.0.0-NIGHTLY-20251119-807-lto.tar.gz" |
| 102 | + CACHE STRING "URL to download SVS shared library") |
| 103 | + else() |
| 104 | + message(WARNING |
| 105 | + "Pre-built LVQ/LeanVec SVS library requires GCC/G++ v.11.2 to apply LTO optimizations." |
| 106 | + "Current compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}" |
| 107 | + ) |
| 108 | + set(SVS_URL "https://github.com/intel/ScalableVectorSearch/releases/download/v0.0.11/svs-shared-library-0.0.11.tar.gz" |
| 109 | + CACHE STRING "URL to download SVS shared library") |
| 110 | + endif() |
| 111 | + include(FetchContent) |
| 112 | + FetchContent_Declare( |
| 113 | + svs |
| 114 | + URL ${SVS_URL} |
| 115 | + DOWNLOAD_EXTRACT_TIMESTAMP TRUE |
| 116 | + ) |
| 117 | + FetchContent_MakeAvailable(svs) |
| 118 | + list(APPEND CMAKE_PREFIX_PATH "${svs_SOURCE_DIR}") |
| 119 | + find_package(svs REQUIRED) |
| 120 | + target_link_libraries(${TARGET_NAME} PRIVATE |
| 121 | + svs::svs |
| 122 | + svs::svs_compile_options |
| 123 | + svs::svs_static_library |
| 124 | + ) |
| 125 | + endif() |
| 126 | + target_compile_definitions(${TARGET_NAME} PRIVATE |
| 127 | + PUBLIC "SVS_LVQ_HEADER=\"${SVS_LVQ_HEADER}\"" |
| 128 | + PUBLIC "SVS_LEANVEC_HEADER=\"${SVS_LEANVEC_HEADER}\"" |
| 129 | + ) |
| 130 | +else() |
| 131 | + # Include the SVS library directly if needed. |
| 132 | + if (NOT TARGET svs::svs) |
| 133 | + add_subdirectory("../.." "${CMAKE_CURRENT_BINARY_DIR}/svs") |
| 134 | + endif() |
| 135 | + target_link_libraries(${TARGET_NAME} PRIVATE |
| 136 | + svs::svs |
| 137 | + svs_compile_options |
| 138 | + svs_x86_options_base |
| 139 | + ) |
| 140 | +endif() |
| 141 | + |
| 142 | +# installing |
| 143 | +include(GNUInstallDirs) |
| 144 | + |
| 145 | +set(SVS_RUNTIME_EXPORT_NAME ${TARGET_NAME}) |
| 146 | +set(VERSION_CONFIG "${CMAKE_CURRENT_BINARY_DIR}/${SVS_RUNTIME_EXPORT_NAME}ConfigVersion.cmake") |
| 147 | +set(SVS_RUNTIME_CONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/svs_runtime) |
| 148 | +set(SVS_RUNTIME_COMPONENT_NAME "Runtime") |
| 149 | + |
| 150 | +install(TARGETS ${TARGET_NAME} |
| 151 | + EXPORT ${SVS_RUNTIME_EXPORT_NAME} |
| 152 | + COMPONENT ${SVS_RUNTIME_COMPONENT_NAME} |
| 153 | + LIBRARY DESTINATION lib |
| 154 | + PUBLIC_HEADER DESTINATION include/svs/runtime |
| 155 | + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} |
| 156 | +) |
| 157 | + |
| 158 | +install(DIRECTORY include/svs/runtime |
| 159 | + COMPONENT ${SVS_RUNTIME_COMPONENT_NAME} |
| 160 | + DESTINATION include/svs |
| 161 | + FILES_MATCHING PATTERN "*.h" |
| 162 | +) |
| 163 | + |
| 164 | +install(EXPORT ${SVS_RUNTIME_EXPORT_NAME} |
| 165 | + COMPONENT ${SVS_RUNTIME_COMPONENT_NAME} |
| 166 | + NAMESPACE svs:: |
| 167 | + DESTINATION ${SVS_RUNTIME_CONFIG_INSTALL_DIR} |
| 168 | +) |
| 169 | + |
| 170 | +include(CMakePackageConfigHelpers) |
| 171 | +configure_package_config_file( |
| 172 | + "${CMAKE_CURRENT_LIST_DIR}/runtimeConfig.cmake.in" |
| 173 | + "${CMAKE_CURRENT_BINARY_DIR}/${SVS_RUNTIME_EXPORT_NAME}Config.cmake" |
| 174 | + INSTALL_DESTINATION "${SVS_RUNTIME_CONFIG_INSTALL_DIR}" |
| 175 | +) |
| 176 | + |
| 177 | +# Don't make compatibility guarantees until we reach a compatibility milestone. |
| 178 | +write_basic_package_version_file( |
| 179 | + ${VERSION_CONFIG} |
| 180 | + VERSION ${PROJECT_VERSION} |
| 181 | + COMPATIBILITY ExactVersion |
| 182 | +) |
| 183 | + |
| 184 | +install(FILES |
| 185 | + "${CMAKE_CURRENT_BINARY_DIR}/${SVS_RUNTIME_EXPORT_NAME}Config.cmake" |
| 186 | + "${VERSION_CONFIG}" |
| 187 | + COMPONENT ${SVS_RUNTIME_COMPONENT_NAME} |
| 188 | + DESTINATION "${SVS_RUNTIME_CONFIG_INSTALL_DIR}" |
| 189 | +) |
| 190 | + |
| 191 | +# Build tests if requested |
| 192 | +if(SVS_BUILD_RUNTIME_TESTS) |
| 193 | + add_subdirectory(tests) |
| 194 | +endif() |
0 commit comments