-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
395 lines (320 loc) · 12.1 KB
/
CMakeLists.txt
File metadata and controls
395 lines (320 loc) · 12.1 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
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# 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}")
option(USE_SYSTEM_DEPS "Build with system dependencies rather than Conan" OFF)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR}/ ${CMAKE_SOURCE_DIR}/cmake)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(COMPILER_SUPPORTS_CXX17 True)
if(LINUX)
# When building for Linux, tell the dynamic loader to load shared libraries
# from executable's directory. This also prevents CMake from leaking build
# paths into the distributed executable.
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
set(CMAKE_INSTALL_RPATH "$ORIGIN")
endif()
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})
# note: gRPC needs to be included before protobuf when using system dependencies.
find_package(gRPC REQUIRED)
include_directories(${gRPC_INCLUDE_DIRS})
find_package(Protobuf REQUIRED)
if(USE_SYSTEM_DEPS)
set(PROTOBUF_LIBRARIES protobuf::libprotobuf)
else()
set(PROTOBUF_LIBRARIES protobuf::protobuf)
include_directories(${protobuf_INCLUDE_DIRS})
endif()
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(Libevent REQUIRED)
include_directories(${libevent_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)
if(USE_SYSTEM_DEPS)
find_package(Parquet REQUIRED)
set(ARROW_LIBRARIES Arrow::arrow_shared Parquet::parquet_shared)
else()
set(ARROW_LIBRARIES arrow::arrow)
include_directories(${arrow_INCLUDE_DIRS})
endif()
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)
if(USE_SYSTEM_DEPS)
set(PROMETHEUS_CPP_TARGETS prometheus-cpp::pull)
else()
set(PROMETHEUS_CPP_TARGETS prometheus-cpp::prometheus-cpp)
include_directories(${prometheus-cpp_INCLUDE_DIRS})
endif()
if(USE_SYSTEM_DEPS)
find_package(Marisa REQUIRED)
set(MARISA_LIBRARIES Marisa::marisa)
else()
find_package(marisa REQUIRED)
set(MARISA_LIBRARIES marisa::marisa)
include_directories(${marisa_INCLUDE_DIRS})
endif()
find_package(yaml-cpp REQUIRED)
include_directories(${yaml-cpp_INCLUDE_DIRS})
find_package(RapidJSON REQUIRED)
include_directories(${RapidJSON_INCLUDE_DIRS})
find_package(roaring REQUIRED)
include_directories(${roaring_INCLUDE_DIRS})
find_package(prometheus-cpp REQUIRED)
include_directories(${prometheus-cpp_INCLUDE_DIRS})
if(NOT USE_SYSTEM_DEPS)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
endif()
FetchContent_Declare(
simdjson
GIT_REPOSITORY https://github.com/simdjson/simdjson.git
GIT_TAG v3.1.7)
FetchContent_MakeAvailable(simdjson)
include_directories(${simdjson_SOURCE_DIR}/include)
add_definitions(-DANTLR4CPP_STATIC)
add_definitions(-DHAVE_CPP_STDLIB)
add_definitions(-DMILVUS_LITE)
add_definitions(-DFMT_HEADER_ONLY)
if(APPLE)
add_definitions("-D_GNU_SOURCE")
endif()
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/pb)
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/cgo_msg.proto"
"${CMAKE_SOURCE_DIR}/src/proto/index_cgo_msg.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}")
include_directories(${PROTO_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})
include(thirdparty/milvus/internal/core/cmake/BuildUtils.cmake)
include(thirdparty/milvus/internal/core/cmake/Utils.cmake)
set(WITH_LIGHT ON CACHE BOOL "" FORCE)
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")
#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)
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)
string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_LOWER)
set(IMPORT_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE_LOWER}/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/${CMAKE_BUILD_TYPE_LOWER}/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)
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()
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)
add_subdirectory(thirdparty/milvus/internal/core/src/indexbuilder)
add_subdirectory(thirdparty/milvus/internal/core/src/futures)
add_subdirectory(thirdparty/milvus/internal/core/src/monitor)
add_library(milvus_core STATIC
$<TARGET_OBJECTS:milvus_log>
$<TARGET_OBJECTS:milvus_config>
$<TARGET_OBJECTS:milvus_common>
$<TARGET_OBJECTS:milvus_storage>
$<TARGET_OBJECTS:milvus_index>
$<TARGET_OBJECTS:milvus_query>
$<TARGET_OBJECTS:milvus_segcore>
$<TARGET_OBJECTS:milvus_indexbuilder>
$<TARGET_OBJECTS:milvus_exec>
$<TARGET_OBJECTS:milvus_bitset>
$<TARGET_OBJECTS:milvus_futures>
$<TARGET_OBJECTS:milvus_monitor>
)
target_link_libraries(
milvus_core
PUBLIC
milvus_proto
${PROMETHEUS_CPP_TARGET}
knowhere
)
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"
)