-
Notifications
You must be signed in to change notification settings - Fork 36
/
CMakeLists.txt
316 lines (251 loc) · 9.64 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# Copyright (C) 2019-2024 Zilliz. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License
cmake_minimum_required(VERSION 3.20)
project(milvus-lite)
option(ENABLE_UNIT_TESTS "Enable unit tests" ON)
message(STATUS "Enable testing: ${ENABLE_UNIT_TESTS}")
list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR}/)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(COMPILER_SUPPORTS_CXX17 True)
if(APPLE)
set(CMAKE_OSX_DEPLOYMENT_TARGET 11.0)
endif()
set(CMAKE_VERBOSE_MAKEFILE ON)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_CXX_FLAGS "-g -Wall -fPIC ${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "-O3 -Wall -fPIC ${CMAKE_CXX_FLAGS}")
endif()
if(CMAKE_LITE_BUILD_TYPE STREQUAL "SHARED")
set(LITE_BUILD_TYPE "SHARED")
else()
set(LITE_BUILD_TYPE "STATIC")
endif()
if(APPLE)
if(DEFINED ENV{HOMEBREW_PREFIX})
message(STATUS "Homebrew prefix from environment: $ENV{HOMEBREW_PREFIX}")
set(OMP_INCLUDE $ENV{HOMEBREW_PREFIX}/opt/libomp/include)
include_directories($ENV{HOMEBREW_PREFIX}/opt/libomp/include)
link_directories($ENV{HOMEBREW_PREFIX}/opt/libomp/lib)
else()
message(STATUS "Homebrew prefix from environment not found, use default")
set(OMP_INCLUDE /opt/homebrew/opt/libomp/include)
include_directories(/opt/homebrew/opt/libomp/include)
link_directories(/opt/homebrew/opt/libomp/lib)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lomp")
set(OpenMP_C "${CMAKE_C_COMPILER}")
set(OpenMP_C_FLAGS "-Xclang -fopenmp -I${OMP_INCLUDE}")
set(OpenMP_C_LIB_NAMES "libomp")
set(OpenMP_libomp_LIBRARY "omp")
set(OpenMP_CXX "${CMAKE_CXX_COMPILER}")
set(OpenMP_CXX_FLAGS "-Xclang -fopenmp -I${OMP_INCLUDE}")
set(OpenMP_CXX_LIB_NAMES "libomp")
set(OpenMP_libomp_LIBRARY "omp")
endif()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(MILVUS_LITE True)
include(FetchContent)
set(CONAN_LIBS "${CONAN_LIBS};marisa::marisa;")
find_package(SQLiteCpp REQUIRED)
include_directories(${SQLiteCpp_INCLUDE_DIRS})
find_package(antlr4-runtime REQUIRED)
include_directories(${antlr4-cppruntime_INCLUDES})
find_package(Protobuf REQUIRED)
include_directories(${protobuf_INCLUDE_DIRS})
find_package(gRPC REQUIRED)
include_directories(${gRPC_INCLUDE_DIRS})
find_package(TBB REQUIRED)
include_directories(${TBB_tbb_INCLUDE_DIRS})
find_package(nlohmann_json REQUIRED)
include_directories(${nlohmann_json_INCLUDE_DIRS})
find_package(Boost REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
find_package(folly REQUIRED)
include_directories(${Folly_INCLUDE_DIRS})
find_package(fmt REQUIRED)
include_directories(${fmt_INCLUDE_DIRS})
find_package(glog REQUIRED)
include_directories(${glog_INCLUDE_DIRS})
find_package(gflags REQUIRED)
include_directories(${gflags_INCLUDE_DIRS})
find_package(Arrow REQUIRED)
include_directories(${arrow_INCLUDE_DIRS})
find_package(re2 REQUIRED)
include_directories(${re2_INCLUDE_DIRS})
link_directories(${re2_LIB_DIRS})
find_package(double-conversion REQUIRED)
include_directories(${double-conversion_INCLUDE_DIRS})
find_package(prometheus-cpp REQUIRED)
include_directories(${prometheus-cpp_INCLUDE_DIRS})
find_package(marisa REQUIRED)
include_directories(${marisa_INCLUDE_DIRS})
find_package(yaml-cpp REQUIRED)
include_directories(${yaml-cpp_INCLUDE_DIRS})
add_definitions(-DANTLR4CPP_STATIC)
add_definitions(-DHAVE_CPP_STDLIB)
add_definitions(-DMILVUS_LITE)
if(APPLE)
add_definitions("-D_GNU_SOURCE")
endif()
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/pb)
execute_process(
COMMAND git diff --quiet
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/thirdparty/milvus
RESULT_VARIABLE CHECK_RESULT)
if(${CHECK_RESULT} EQUAL 0)
message("Apply milvus patch...")
execute_process(
COMMAND git apply ${CMAKE_SOURCE_DIR}/thirdparty/milvus.patch
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/thirdparty/milvus
OUTPUT_VARIABLE result)
else()
message("Milvus not need applying patch...")
endif()
add_library(
milvus_proto STATIC
"${CMAKE_SOURCE_DIR}/src/proto/plan.proto"
"${CMAKE_SOURCE_DIR}/src/proto/schema.proto"
"${CMAKE_SOURCE_DIR}/src/proto/common.proto"
"${CMAKE_SOURCE_DIR}/src/proto/segcore.proto"
"${CMAKE_SOURCE_DIR}/src/proto/milvus.proto"
"${CMAKE_SOURCE_DIR}/src/proto/msg.proto"
"${CMAKE_SOURCE_DIR}/src/proto/feder.proto"
"${CMAKE_SOURCE_DIR}/src/proto/rg.proto")
set(PROTO_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/pb")
protobuf_generate(
TARGET milvus_proto IMPORT_DIRS "${CMAKE_SOURCE_DIR}/src/proto"
PROTOC_OUT_DIR "${PROTO_BINARY_DIR}")
add_library(milvus_grpc_service STATIC
"${CMAKE_SOURCE_DIR}/src/proto/milvus.proto")
target_link_libraries(milvus_grpc_service gRPC::grpc++ milvus_proto)
protobuf_generate(
TARGET
milvus_grpc_service
# OUT_VAR PROTO_GENERATED_FILES
LANGUAGE
grpc
GENERATE_EXTENSIONS
.grpc.pb.h
.grpc.pb.cc
PLUGIN
"protoc-gen-grpc=\$<TARGET_FILE:gRPC::grpc_cpp_plugin>"
IMPORT_DIRS
"${CMAKE_SOURCE_DIR}/src/proto"
PROTOC_OUT_DIR
"${PROTO_BINARY_DIR}")
include_directories("${CMAKE_SOURCE_DIR}/src/parser/")
include_directories("${CMAKE_SOURCE_DIR}/src/parser/antlr/")
include_directories("${CMAKE_BINARY_DIR}/pb")
include_directories("${CMAKE_BINARY_DIR}")
add_library(
parser STATIC
"${CMAKE_SOURCE_DIR}/src/parser/parser.cc"
"${CMAKE_SOURCE_DIR}/src/parser/antlr/PlanBaseVisitor.cpp"
"${CMAKE_SOURCE_DIR}/src/parser/antlr/PlanLexer.cpp"
"${CMAKE_SOURCE_DIR}/src/parser/antlr/PlanParser.cpp"
"${CMAKE_SOURCE_DIR}/src/parser/antlr/PlanVisitor.cpp")
target_link_libraries(parser milvus_proto ${antlr4-cppruntime_LIBRARIES})
add_subdirectory(thirdparty/milvus/internal/core/thirdparty/knowhere)
include_directories(
"${CMAKE_SOURCE_DIR}/thirdparty/milvus/internal/core/thirdparty/")
include_directories(
"${CMAKE_SOURCE_DIR}/thirdparty/milvus/internal/core/thirdparty/tantivy/tantivy-binding/include/"
)
include_directories(
"${CMAKE_SOURCE_DIR}/thirdparty/milvus/internal/core/thirdparty/tantivy/")
include_directories("${knowhere_SOURCE_DIR}/include")
function(MILVUS_ADD_PKG_CONFIG MODULE)
configure_file(${MODULE}.pc.in "${CMAKE_CURRENT_BINARY_DIR}/${MODULE}.pc"
@ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${MODULE}.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/")
endfunction()
include(cmake/milvus-storage.cmake)
include_directories("${CMAKE_SOURCE_DIR}/thirdparty/milvus/internal/core/src/")
add_library(
boost_bitset_ext
thirdparty/milvus/internal/core/thirdparty/boost_ext/dynamic_bitset_ext.cpp)
FetchContent_Declare(
simdjson
GIT_REPOSITORY https://github.com/simdjson/simdjson.git
GIT_TAG v3.1.7)
FetchContent_MakeAvailable(simdjson)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CARGO_CMD cargo build)
else()
set(CARGO_CMD cargo build --release)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Android" AND CMAKE_SYSTEM_PROCESSOR STREQUAL
"aarch64")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CARGO_CMD cargo build --target aarch64-linux-android)
else()
set(CARGO_CMD cargo build --target aarch64-linux-android --release)
endif()
endif()
set(HOME_VAR $ENV{HOME})
add_custom_command(
OUTPUT ls_cargo
COMMENT "ls cargo"
COMMAND ls ${HOME_VAR}/.cargo/bin/)
add_custom_target(ls_cargo_target DEPENDS ls_cargo)
add_custom_command(
OUTPUT compile_tantivy
COMMENT "Compiling tantivy binding"
COMMAND CARGO_TARGET_DIR=${CMAKE_CURRENT_BINARY_DIR}
MACOSX_DEPLOYMENT_TARGET=11.0 ${CARGO_CMD}
WORKING_DIRECTORY
${CMAKE_SOURCE_DIR}/thirdparty/milvus/internal/core/thirdparty/tantivy/tantivy-binding
DEPENDS ls_cargo_target)
add_custom_target(tantivy_binding_target DEPENDS compile_tantivy)
add_library(tantivy_binding STATIC IMPORTED)
set(IMPORT_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/release/libtantivy_binding.a")
if(CMAKE_SYSTEM_NAME STREQUAL "Android" AND CMAKE_SYSTEM_PROCESSOR STREQUAL
"aarch64")
set(IMPORT_LOCATION
"${CMAKE_CURRENT_BINARY_DIR}/aarch64-linux-android/release/libtantivy_binding.a"
)
endif()
set_target_properties(
tantivy_binding
PROPERTIES
IMPORTED_GLOBAL TRUE
IMPORTED_LOCATION "${IMPORT_LOCATION}"
INTERFACE_INCLUDE_DIRECTORIES
"${CMAKE_SOURCE_DIR}/thirdparty/milvus/internal/core/thirdparty/tantivy/tantivy-binding/include/"
)
add_dependencies(tantivy_binding tantivy_binding_target)
set(MILVUS_ENGINE_SRC "${CMAKE_SOURCE_DIR}/thirdparty/milvus/internal/core/src")
add_subdirectory(thirdparty/milvus/internal/core/src/log)
add_subdirectory(thirdparty/milvus/internal/core/src/config)
add_subdirectory(thirdparty/milvus/internal/core/src/common)
add_subdirectory(thirdparty/milvus/internal/core/src/storage)
add_subdirectory(thirdparty/milvus/internal/core/src/query)
add_subdirectory(thirdparty/milvus/internal/core/src/exec)
add_subdirectory(thirdparty/milvus/internal/core/src/index)
add_subdirectory(thirdparty/milvus/internal/core/src/segcore)
add_subdirectory(thirdparty/milvus/internal/core/src/bitset)
if(ENABLE_UNIT_TESTS)
include(CTest)
enable_testing()
endif()
add_subdirectory(src)
find_program(MEMORYCHECK_COMMAND NAMES valgrind)
set(MEMORYCHECK_COMMAND_OPTIONS
"--trace-children=yes --track-origins=yes --leak-check=full --show-leak-kinds=all"
)