-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
164 lines (135 loc) · 6.3 KB
/
CMakeLists.txt
File metadata and controls
164 lines (135 loc) · 6.3 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
# Copyright (C) 2019-2020 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.18 )
project(milvus_common CXX C)
option(ENABLE_UNIT_TESTS "Enable unit tests" OFF)
option(ENABLE_SYNCPOINT "Enable sync point for testing" OFF)
set( CMAKE_CXX_STANDARD 17 )
set( CMAKE_CXX_STANDARD_REQUIRED on )
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set( CMAKE_EXPORT_COMPILE_COMMANDS ON )
set(MILVUS_COMMON_WORKSPACE ${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${MILVUS_COMMON_WORKSPACE}/include)
set(CMAKE_CXX_FLAGS "-Wall -fPIC ${CMAKE_CXX_FLAGS}")
# folly's F14 hash tables require SSE4.2 CRC intrinsics on x86_64
if(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64|amd64|AMD64)")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2")
endif()
if (WITH_ASAN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer -fno-stack-protector -fno-var-tracking")
endif()
find_package(opentelemetry-cpp REQUIRED)
find_package(folly REQUIRED)
set(GFLAGS_USE_TARGET_NAMESPACE TRUE)
find_package(gflags REQUIRED)
find_package(glog REQUIRED)
find_package(fmt REQUIRED)
find_package(prometheus-cpp REQUIRED)
# OpenMP is required for thread pool OMP setter
if(APPLE)
# Apple Clang needs Homebrew libomp: brew install libomp
find_program(_BREW_CMD brew)
if(_BREW_CMD)
execute_process(COMMAND ${_BREW_CMD} --prefix libomp OUTPUT_VARIABLE LIBOMP_PREFIX OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
if(LIBOMP_PREFIX)
set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp -I${LIBOMP_PREFIX}/include")
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I${LIBOMP_PREFIX}/include")
set(OpenMP_C_LIB_NAMES "omp")
set(OpenMP_CXX_LIB_NAMES "omp")
set(OpenMP_omp_LIBRARY "${LIBOMP_PREFIX}/lib/libomp.dylib")
endif()
endif()
find_package(OpenMP REQUIRED)
if(APPLE)
# On macOS, transitive find_package calls (CURL, ZLIB, etc.) resolve to the
# SDK sysroot (e.g. .../MacOSX.sdk/usr/include). When CMake adds that path
# as -I or -isystem, it places C standard library headers ahead of libc++'s
# C++ wrapper headers (cinttypes, cstdio, etc.), breaking compilation.
# Strip SDK sysroot include dirs from all imported targets since the compiler
# already searches them by default.
execute_process(COMMAND xcrun --show-sdk-path OUTPUT_VARIABLE _SDK_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
set(_SDK_INCLUDE "${_SDK_PATH}/usr/include")
get_property(_all_targets DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY IMPORTED_TARGETS)
foreach(_tgt IN LISTS _all_targets)
foreach(_prop INTERFACE_INCLUDE_DIRECTORIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES)
get_target_property(_dirs ${_tgt} ${_prop})
if(_dirs)
list(REMOVE_ITEM _dirs "${_SDK_INCLUDE}")
# Also handle versioned SDK paths (e.g. MacOSX15.sdk)
foreach(_d IN LISTS _dirs)
if(_d MATCHES "/SDKs/MacOSX[0-9]*\\.sdk/usr/include$")
list(REMOVE_ITEM _dirs "${_d}")
endif()
endforeach()
set_target_properties(${_tgt} PROPERTIES ${_prop} "${_dirs}")
endif()
endforeach()
endforeach()
endif()
list(APPEND COMMON_LINKER_LIBS glog::glog)
list(APPEND COMMON_LINKER_LIBS prometheus-cpp::core prometheus-cpp::push)
list(APPEND COMMON_LINKER_LIBS fmt::fmt)
list(APPEND COMMON_LINKER_LIBS Folly::folly)
list(APPEND COMMON_LINKER_LIBS gflags::gflags)
list(APPEND COMMON_LINKER_LIBS opentelemetry-cpp::opentelemetry_trace)
list(APPEND COMMON_LINKER_LIBS opentelemetry-cpp::opentelemetry_exporter_ostream_span)
list(APPEND COMMON_LINKER_LIBS opentelemetry-cpp::opentelemetry_exporter_otlp_http)
if(TARGET opentelemetry-cpp::opentelemetry_exporter_otlp_grpc)
list(APPEND COMMON_LINKER_LIBS opentelemetry-cpp::opentelemetry_exporter_otlp_grpc)
set(HAVE_OTLP_GRPC_EXPORTER ON)
endif()
file(GLOB_RECURSE SRC_FILES src/*.cpp src/*.cc)
# Check for libaio library and conditionally include aio_context_pool.cc
find_library(LIBAIO_LIBRARY NAMES aio)
if(NOT LIBAIO_LIBRARY)
list(REMOVE_ITEM SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/knowhere/aio_context_pool.cc)
message(STATUS "libaio not found, excluding aio_context_pool.cc from build")
else()
message(STATUS "libaio found: ${LIBAIO_LIBRARY}, including aio_context_pool.cc in build")
list(APPEND COMMON_LINKER_LIBS ${LIBAIO_LIBRARY})
endif()
add_library(milvus-common SHARED ${SRC_FILES})
# Use std::shared_ptr etc. instead of opentelemetry::nostd:: equivalents
target_compile_definitions(milvus-common PUBLIC OPENTELEMETRY_STL_VERSION=2017)
if(APPLE)
target_compile_definitions(milvus-common PUBLIC BOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED)
endif()
if(HAVE_OTLP_GRPC_EXPORTER)
target_compile_definitions(milvus-common PUBLIC HAVE_OTLP_GRPC_EXPORTER)
endif()
if (ENABLE_SYNCPOINT)
add_definitions(-DENABLE_SYNCPOINT)
endif()
target_link_libraries(milvus-common PUBLIC
${COMMON_LINKER_LIBS}
)
target_link_libraries(milvus-common PUBLIC OpenMP::OpenMP_CXX)
# thread_pool.cc uses openblas-specific API (openblas_set_num_threads) under OPENBLAS_OS_LINUX
if(NOT APPLE)
find_library(OPENBLAS_LIBRARY NAMES openblas)
if(OPENBLAS_LIBRARY)
target_link_libraries(milvus-common PUBLIC ${OPENBLAS_LIBRARY})
else()
message(WARNING "OpenBLAS not found, openblas_set_num_threads will be unavailable")
endif()
endif()
if(WITH_COMMON_UT)
# Enable unit-test-only helpers for caching layer
target_compile_definitions(milvus-common PRIVATE MCL_ENABLE_TEST_CGROUP_OVERRIDE)
enable_testing()
find_package(GTest REQUIRED)
add_subdirectory(test)
endif()
install(TARGETS milvus-common
DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
install(DIRECTORY "${MILVUS_COMMON_WORKSPACE}/include/"
DESTINATION "${CMAKE_INSTALL_PREFIX}/include")