-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
130 lines (116 loc) · 4.79 KB
/
CMakeLists.txt
File metadata and controls
130 lines (116 loc) · 4.79 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
cmake_minimum_required(VERSION 3.5...3.31)
project(ngt)
if(CMAKE_VERSION VERSION_GREATER "3.8")
# Enable Link Time Optimization (LTO)
cmake_policy(SET CMP0069 NEW)
include(CheckIPOSupported)
check_ipo_supported(RESULT LTO_SUPPORTED OUTPUT LTO_ERROR)
endif()
if(LTO_SUPPORTED)
message(STATUS "LTO enabled")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(STATUS "LTO not supported: ${LTO_ERROR}")
endif()
file(STRINGS "VERSION" ngt_VERSION)
message(STATUS "VERSION: ngt ${ngt_VERSION}")
string(REGEX MATCH "^[0-9]+" ngt_VERSION_MAJOR ${ngt_VERSION})
set(ngt_VERSION ${ngt_VERSION})
set(ngt_SOVERSION ${ngt_VERSION_MAJOR})
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif(NOT CMAKE_BUILD_TYPE)
string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_LOWER)
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
message(STATUS "CMAKE_BUILD_TYPE_LOWER: ${CMAKE_BUILD_TYPE_LOWER}")
if(${NGT_SHARED_MEMORY_ALLOCATOR})
set(NGT_QBG_DISABLED TRUE)
endif(${NGT_SHARED_MEMORY_ALLOCATOR})
if(${UNIX})
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
if(CMAKE_VERSION VERSION_LESS 3.1)
set(BASE_OPTIONS "-Wall -std=gnu++0x -lrt")
set(NGT_FOREST OFF)
message(STATUS "NGT_FOREST is disabled (requires CMake >= 3.1 and C++17)")
if(${NGT_AVX_DISABLED})
message(STATUS "AVX will not be used to compute distances.")
endif()
if(${NGT_OPENMP_DISABLED})
message(STATUS "OpenMP is disabled.")
else()
set(BASE_OPTIONS "${BASE_OPTIONS} -fopenmp")
endif()
if(${NGT_ASSERT_DISABLED})
message(STATUS "assert() is disabled.")
set(BASE_OPTIONS "${BASE_OPTIONS} -DNDEBUG")
endif()
set(CMAKE_CXX_FLAGS_DEBUG "-g ${BASE_OPTIONS}")
if(${NGT_MARCH_NATIVE_DISABLED})
message(STATUS "Compile option -march=native is disabled.")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 ${BASE_OPTIONS}")
else()
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -march=native ${BASE_OPTIONS}")
endif()
else()
set(NGT_FOREST ON)
if (CMAKE_BUILD_TYPE_LOWER STREQUAL "release")
set(CMAKE_CXX_FLAGS_RELEASE "")
if(${NGT_MARCH_NATIVE_DISABLED})
message(STATUS "Compile option -march=native is disabled.")
add_compile_options(-O2 -DNDEBUG)
elseif(${NGT_AVX2})
add_compile_options(-Ofast -march=haswell -DNDEBUG)
elseif(NGT_AVX_DISABLED OR NGT_SIMD_DISABLED)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64|i.86)$")
message(STATUS "AVX will not be used to compute distances.")
add_compile_options(-Ofast -march=x86-64 -DNDEBUG)
else()
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR
CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
message(STATUS "ARM64 detected: NEON is mandatory, disable SIMD logically")
add_compile_options(-O3 -ffast-math -DNDEBUG)
else()
message(STATUS "NEON will not be used to compute distances.")
add_compile_options(-O3 -ffast-math -mno-neon -DNDEBUG)
endif()
endif()
else()
if(${NGT_SANITIZE})
add_compile_options(-Ofast -march=native -fsanitize=address -g -O1)
add_link_options(-fsanitize=address)
else()
add_compile_options(-Ofast -march=native -DNDEBUG)
endif()
endif()
endif()
add_compile_options(-Wall)
add_compile_options(-Wno-deprecated-literal-operator)
if(${NGT_OPENMP_DISABLED})
message(STATUS "OpenMP is disabled.")
else()
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.1.0")
message(FATAL_ERROR "Insufficient AppleClang version")
endif()
cmake_minimum_required(VERSION 3.16)
endif()
find_package(OpenMP REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()
set(CMAKE_CXX_STANDARD 17) # for forest
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Threads REQUIRED)
if(${NGT_QBG_DISABLED})
message(STATUS "QBG is disabled.")
else()
find_package(BLAS REQUIRED)
find_package(LAPACK REQUIRED)
endif()
endif()
if(${NGT_BFLOAT_DISABLED})
message(STATUS "bfloat is disabled.")
endif()
add_subdirectory("${PROJECT_SOURCE_DIR}/lib")
add_subdirectory("${PROJECT_SOURCE_DIR}/bin")
add_subdirectory("${PROJECT_SOURCE_DIR}/samples")
endif(${UNIX})