|
| 1 | +# Copyright (c) Facebook, Inc. and its affiliates. |
| 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 | +include_guard(GLOBAL) |
| 15 | + |
| 16 | +set(VELOX_FAISS_BUILD_VERSION 1.11.0) |
| 17 | +set(VELOX_FAISS_BUILD_SHA256_CHECKSUM |
| 18 | + c5d517da6deb6a6d74290d7145331fc7474426025e2d826fa4a6d40670f4493c) |
| 19 | +set(VELOX_FAISS_SOURCE_URL |
| 20 | + "https://github.com/facebookresearch/faiss/archive/refs/tags/v${VELOX_FAISS_BUILD_VERSION}.tar.gz" |
| 21 | +) |
| 22 | + |
| 23 | +velox_resolve_dependency_url(FAISS) |
| 24 | + |
| 25 | +# We need these hints for macos to build. |
| 26 | +if(CMAKE_SYSTEM_NAME MATCHES "Darwin") |
| 27 | + message(STATUS "Detected Apple platform") |
| 28 | + execute_process( |
| 29 | + COMMAND brew --prefix libomp |
| 30 | + RESULT_VARIABLE BREW_LIBOMP_RESULT |
| 31 | + OUTPUT_VARIABLE BREW_LIBOMP_PREFIX |
| 32 | + OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 33 | + if(BREW_LIBOMP_RESULT EQUAL 0 AND EXISTS "${BREW_LIBOMP_PREFIX}") |
| 34 | + list(APPEND CMAKE_PREFIX_PATH "${BREW_LIBOMP_PREFIX}") |
| 35 | + endif() |
| 36 | + |
| 37 | + execute_process( |
| 38 | + COMMAND brew --prefix openblas |
| 39 | + RESULT_VARIABLE BREW_OPENBLAS_RESULT |
| 40 | + OUTPUT_VARIABLE BREW_OPENBLAS_PREFIX |
| 41 | + OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 42 | + if(BREW_OPENBLAS_RESULT EQUAL 0 AND EXISTS "${BREW_OPENBLAS_PREFIX}") |
| 43 | + list(APPEND CMAKE_PREFIX_PATH "${BREW_OPENBLAS_PREFIX}") |
| 44 | + endif() |
| 45 | +endif() |
| 46 | + |
| 47 | +FetchContent_Declare( |
| 48 | + faiss |
| 49 | + URL ${VELOX_FAISS_SOURCE_URL} |
| 50 | + URL_HASH ${VELOX_FAISS_BUILD_SHA256_CHECKSUM} |
| 51 | + SYSTEM # Once there are targets depending on FAISS we can add |
| 52 | + # `EXCLUDE_FROM_ALL` back in |
| 53 | +) |
| 54 | + |
| 55 | +# Set build options |
| 56 | +block() |
| 57 | +set(BUILD_SHARED_LIBS OFF) |
| 58 | +set(CMAKE_BUILD_TYPE Release) |
| 59 | +set(FAISS_ENABLE_GPU OFF) |
| 60 | +set(FAISS_ENABLE_PYTHON OFF) |
| 61 | +set(FAISS_ENABLE_GPU_TESTS OFF) |
| 62 | +# Make FAISS available |
| 63 | +FetchContent_MakeAvailable(faiss) |
| 64 | +add_library(FAISS::faiss ALIAS faiss) |
| 65 | +endblock() |
0 commit comments