-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
100 lines (75 loc) · 3.62 KB
/
CMakeLists.txt
File metadata and controls
100 lines (75 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
cmake_minimum_required(VERSION 3.10)
cmake_policy(SET CMP0077 NEW)
set(CMAKE_CXX_STANDARD 20)
# VECSIM_BUILD_TEST_HELPERS: Enables test helper methods (fitMemory, serialization, etc.)
# in VectorSimilarity classes without building test executables.
option(VECSIM_BUILD_TEST_HELPERS "Build test helper methods (fitMemory, serialization)" OFF)
# VECSIM_BUILD_TESTS: Builds VectorSimilarity test executables (unit tests, benchmarks).
# When ON, test helpers are also built even if VECSIM_BUILD_TEST_HELPERS is OFF.
option(VECSIM_BUILD_TESTS "Build VectorSimilarity test executables" ON)
get_filename_component(root ${CMAKE_CURRENT_LIST_DIR} ABSOLUTE)
message("# VectorSimilarity root: " ${root})
get_filename_component(binroot ${CMAKE_CURRENT_BINARY_DIR} ABSOLUTE)
message("# VectorSimilarity binroot: " ${binroot})
if(USE_COVERAGE)
if(NOT CMAKE_BUILD_TYPE STREQUAL "DEBUG")
message(FATAL_ERROR "Build type must be DEBUG for coverage")
endif()
set(COV_CXX_FLAGS "-coverage")
endif()
include(cmake/san.cmake)
# ----------------------------------------------------------------------------------------------
project(VectorSimilarity)
# Only do these if this is the main project, and not if it is included through add_subdirectory
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions -fPIC ${CLANG_SAN_FLAGS} ${LLVM_CXX_FLAGS} ${COV_CXX_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} ${LLVM_LD_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} ${LLVM_LD_FLAGS}")
IF(USE_PROFILE)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer")
ENDIF()
include(cmake/svs.cmake)
include_directories(src)
# Define BUILD_TESTS macro if test helpers OR tests are requested.
# This enables test helper methods (fitMemory, serialization, etc.) in class definitions.
if(VECSIM_BUILD_TEST_HELPERS OR VECSIM_BUILD_TESTS)
ADD_DEFINITIONS(-DBUILD_TESTS)
endif()
# Build test executables only if explicitly requested (VECSIM_BUILD_TESTS=ON).
# This fetches googletest/google_benchmark and builds test targets.
if(VECSIM_BUILD_TESTS)
include(FetchContent)
enable_testing()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions -fPIC ${CLANG_SAN_FLAGS} ${LLVM_CXX_FLAGS} ${COV_CXX_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} ${LLVM_LD_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} ${LLVM_LD_FLAGS}")
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/refs/tags/v1.16.0.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
option(BENCHMARK_ENABLE_GTEST_TESTS "" OFF)
option(BENCHMARK_ENABLE_TESTING "" OFF)
FetchContent_Declare(
google_benchmark
URL https://github.com/google/benchmark/archive/refs/tags/v1.8.0.zip
)
FetchContent_MakeAvailable(google_benchmark)
add_subdirectory(tests/unit unit_tests)
add_subdirectory(tests/module module_tests)
if(NOT(USE_ASAN OR USE_MSAN))
add_subdirectory(tests/benchmark benchmark)
endif()
endif()
add_subdirectory(src/VecSim)
# Needed for build as ExternalProject (like RediSearch does)
install(TARGETS VectorSimilarity DESTINATION ${CMAKE_INSTALL_PREFIX})
install(TARGETS VectorSimilaritySpaces DESTINATION ${CMAKE_INSTALL_PREFIX})
# Print compiler flags (similar to RediSearch)
get_directory_property(COMPILE_DEFS COMPILE_DEFINITIONS)
message(STATUS "CXXFLAGS: ${CMAKE_CXX_FLAGS}")
message(STATUS "COMPILE_DEFS: ${COMPILE_DEFS}")
message(STATUS "LDFLAGS: ${CMAKE_SHARED_LINKER_FLAGS}")