- Use Development.Module instead of Development component - Find Python in main Faiss CMakeLists.txt before python subdirectory - Add debug output to trace Python variable passing - Set Python_FIND_VIRTUALENV=ONLY for Faiss
91 lines
3.8 KiB
CMake
91 lines
3.8 KiB
CMake
cmake_minimum_required(VERSION 3.24)
|
|
project(leann_backend_hnsw_wrapper)
|
|
set(CMAKE_C_COMPILER_WORKS 1)
|
|
set(CMAKE_CXX_COMPILER_WORKS 1)
|
|
|
|
# Set OpenMP path for macOS
|
|
if(APPLE)
|
|
set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp -I/opt/homebrew/opt/libomp/include")
|
|
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I/opt/homebrew/opt/libomp/include")
|
|
set(OpenMP_C_LIB_NAMES "omp")
|
|
set(OpenMP_CXX_LIB_NAMES "omp")
|
|
set(OpenMP_omp_LIBRARY "/opt/homebrew/opt/libomp/lib/libomp.dylib")
|
|
endif()
|
|
|
|
# Use system ZeroMQ instead of building from source
|
|
find_package(PkgConfig REQUIRED)
|
|
pkg_check_modules(ZMQ REQUIRED libzmq)
|
|
|
|
# Add cppzmq headers
|
|
include_directories(third_party/cppzmq)
|
|
|
|
# Configure msgpack-c - disable boost dependency
|
|
set(MSGPACK_USE_BOOST OFF CACHE BOOL "" FORCE)
|
|
add_compile_definitions(MSGPACK_NO_BOOST)
|
|
include_directories(third_party/msgpack-c/include)
|
|
|
|
# Find Python for our own use (not for Faiss)
|
|
if(DEFINED SKBUILD)
|
|
message(STATUS "Building with scikit-build")
|
|
# scikit-build-core provides Python information
|
|
endif()
|
|
|
|
# Find Python - scikit-build-core should provide this
|
|
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module NumPy)
|
|
|
|
# Print Python information for debugging
|
|
message(STATUS "Python_FOUND: ${Python_FOUND}")
|
|
message(STATUS "Python_VERSION: ${Python_VERSION}")
|
|
message(STATUS "Python_EXECUTABLE: ${Python_EXECUTABLE}")
|
|
message(STATUS "Python_INCLUDE_DIRS: ${Python_INCLUDE_DIRS}")
|
|
message(STATUS "Python_NumPy_INCLUDE_DIRS: ${Python_NumPy_INCLUDE_DIRS}")
|
|
|
|
# Pass Python information to faiss through cache variables
|
|
set(Python_EXECUTABLE ${Python_EXECUTABLE} CACHE FILEPATH "Python executable" FORCE)
|
|
set(Python_INCLUDE_DIRS ${Python_INCLUDE_DIRS} CACHE PATH "Python include dirs" FORCE)
|
|
set(Python_NumPy_INCLUDE_DIRS ${Python_NumPy_INCLUDE_DIRS} CACHE PATH "NumPy include dirs" FORCE)
|
|
set(Python_VERSION ${Python_VERSION} CACHE STRING "Python version" FORCE)
|
|
set(Python_FOUND ${Python_FOUND} CACHE BOOL "Python found" FORCE)
|
|
|
|
# Also set Python3 variables for compatibility
|
|
set(Python3_EXECUTABLE ${Python_EXECUTABLE} CACHE FILEPATH "Python3 executable" FORCE)
|
|
set(Python3_INCLUDE_DIRS ${Python_INCLUDE_DIRS} CACHE PATH "Python3 include dirs" FORCE)
|
|
set(Python3_NumPy_INCLUDE_DIRS ${Python_NumPy_INCLUDE_DIRS} CACHE PATH "NumPy include dirs" FORCE)
|
|
set(Python3_VERSION ${Python_VERSION} CACHE STRING "Python3 version" FORCE)
|
|
set(Python3_FOUND ${Python_FOUND} CACHE BOOL "Python3 found" FORCE)
|
|
set(Python3_Development_FOUND TRUE CACHE BOOL "Python3 development found" FORCE)
|
|
set(Python3_NumPy_FOUND TRUE CACHE BOOL "Python3 NumPy found" FORCE)
|
|
|
|
# Faiss configuration - streamlined build
|
|
set(FAISS_ENABLE_PYTHON ON CACHE BOOL "" FORCE)
|
|
set(FAISS_ENABLE_GPU OFF CACHE BOOL "" FORCE)
|
|
set(FAISS_ENABLE_EXTRAS OFF CACHE BOOL "" FORCE)
|
|
set(BUILD_TESTING OFF CACHE BOOL "" FORCE)
|
|
set(FAISS_ENABLE_C_API OFF CACHE BOOL "" FORCE)
|
|
set(FAISS_OPT_LEVEL "generic" CACHE STRING "" FORCE)
|
|
|
|
# Disable additional SIMD versions to speed up compilation
|
|
set(FAISS_ENABLE_AVX2 OFF CACHE BOOL "" FORCE)
|
|
set(FAISS_ENABLE_AVX512 OFF CACHE BOOL "" FORCE)
|
|
|
|
# Additional optimization options from INSTALL.md
|
|
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
|
|
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) # Static library is faster to build
|
|
|
|
# Avoid building demos and benchmarks
|
|
set(BUILD_DEMOS OFF CACHE BOOL "" FORCE)
|
|
set(BUILD_BENCHS OFF CACHE BOOL "" FORCE)
|
|
|
|
# NEW: Tell Faiss to only build the generic version
|
|
set(FAISS_BUILD_GENERIC ON CACHE BOOL "" FORCE)
|
|
set(FAISS_BUILD_AVX2 OFF CACHE BOOL "" FORCE)
|
|
set(FAISS_BUILD_AVX512 OFF CACHE BOOL "" FORCE)
|
|
|
|
# IMPORTANT: Disable building AVX versions to speed up compilation
|
|
set(FAISS_BUILD_AVX_VERSIONS OFF CACHE BOOL "" FORCE)
|
|
|
|
# Force Faiss to use our Python settings
|
|
set(Python_FIND_VIRTUALENV ONLY CACHE STRING "" FORCE)
|
|
set(Python3_FIND_VIRTUALENV ONLY CACHE STRING "" FORCE)
|
|
|
|
add_subdirectory(third_party/faiss) |