forked from ashvardanian/SimSIMD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
113 lines (93 loc) · 3.9 KB
/
CMakeLists.txt
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
101
102
103
104
105
106
107
108
109
110
111
112
113
# SimSIMD library CMakeLists.txt
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
project(
simsimd
VERSION 5.4.2
LANGUAGES C CXX
DESCRIPTION "Fastest SIMD-Accelerated Vector Similarity Functions for x86 and Arm"
HOMEPAGE_URL "https://github.com/ashvardanian/simsimd"
)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED YES)
set(CMAKE_C_EXTENSIONS NO)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)
# Determine if StringZilla is built as a subproject (using `add_subdirectory`) or if it is the main project
set(SIMSIMD_IS_MAIN_PROJECT OFF)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(SIMSIMD_IS_MAIN_PROJECT ON)
endif ()
option(SIMSIMD_BUILD_SHARED "Compile a dynamic library" ${SIMSIMD_IS_MAIN_PROJECT})
option(SIMSIMD_BUILD_TESTS "Small compilation tests compile-time and run-time dispatch" OFF)
option(SIMSIMD_BUILD_BENCHMARKS "Compile micro-benchmarks for current ISA" OFF)
option(SIMSIMD_BUILD_BENCHMARKS_WITH_CBLAS "Include BLAS in micro-kernel benchmarks" OFF)
# Default to Release build type if not set
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif ()
# Global compiler flags for debug and release
set(CMAKE_CXX_FLAGS_DEBUG "-g -fsanitize=address")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_C_FLAGS_DEBUG "-g -fsanitize=address")
set(CMAKE_C_FLAGS_RELEASE "-O3")
# Compiler-specific flags
if (CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang$")
if (NOT APPLE)
add_compile_options(-march=native)
endif ()
add_compile_options(-pedantic -ferror-limit=1)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(-march=native -pedantic -fmax-errors=1 -Wno-tautological-constant-compare)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")
add_compile_options(-w -ferror-limit=1)
endif ()
# Define the header-only library
file(GLOB SIMSIMD_SOURCES include/simsimd/*.h)
add_library(simsimd INTERFACE)
target_sources(simsimd INTERFACE ${SIMSIMD_SOURCES})
target_include_directories(simsimd INTERFACE "${PROJECT_SOURCE_DIR}/include")
# Build benchmarks if required
if (SIMSIMD_BUILD_BENCHMARKS)
# Fetch external dependencies
include(FetchContent)
# Suppress building tests of Google Benchmark
set(BENCHMARK_ENABLE_TESTING OFF)
set(BENCHMARK_ENABLE_INSTALL OFF)
set(BENCHMARK_ENABLE_DOXYGEN OFF)
set(BENCHMARK_INSTALL_DOCS OFF)
set(BENCHMARK_DOWNLOAD_DEPENDENCIES ON)
set(BENCHMARK_ENABLE_GTEST_TESTS OFF)
set(BENCHMARK_USE_BUNDLED_GTEST ON)
FetchContent_Declare(
benchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG v1.7.0
)
FetchContent_MakeAvailable(benchmark)
# Remove the google benchmark built in debug warning
if (CMAKE_BUILD_TYPE STREQUAL "Release")
target_compile_definitions(benchmark PRIVATE NDEBUG)
endif ()
find_package(Threads REQUIRED)
add_executable(simsimd_bench cpp/bench.cxx)
target_link_libraries(simsimd_bench simsimd Threads::Threads benchmark)
find_package(BLAS)
if (BLAS_FOUND AND SIMSIMD_BUILD_BENCHMARKS_WITH_CBLAS)
target_compile_definitions(simsimd_bench PRIVATE SIMSIMD_BUILD_BENCHMARKS_WITH_CBLAS=1)
target_link_libraries(simsimd_bench ${BLAS_LIBRARIES})
endif ()
endif ()
if (SIMSIMD_BUILD_TESTS)
add_executable(simsimd_test_compile_time cpp/test.c)
target_link_libraries(simsimd_test_compile_time simsimd m)
add_executable(simsimd_test_run_time cpp/test.c c/lib.c)
target_compile_definitions(simsimd_test_run_time PRIVATE SIMSIMD_DYNAMIC_DISPATCH=1)
target_link_libraries(simsimd_test_run_time simsimd m)
endif ()
if (SIMSIMD_BUILD_SHARED)
set(SIMSIMD_SOURCES ${SIMSIMD_SOURCES} c/lib.c)
add_library(simsimd_shared SHARED ${SIMSIMD_SOURCES})
target_include_directories(simsimd_shared PUBLIC "${PROJECT_SOURCE_DIR}/include")
set_target_properties(simsimd_shared PROPERTIES OUTPUT_NAME simsimd)
endif ()