forked from dingodb/dingofs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
199 lines (153 loc) · 5.94 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
# Copyright (c) 2024 dingodb.com, Inc. 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.
# if compile_commands.json is needed, please enable CMAKE_EXPORT_COMPILE_COMMANDS, of use `bear --append -- make` to do make, it's more recommended to use bear.
cmake_minimum_required(VERSION 3.25 FATAL_ERROR)
project(dingofs C CXX)
option(BUILD_UNIT_TESTS "Build unit test" OFF)
set(CMAKE_CXX_STANDARD 17)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()
message("CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
message("SYSTEM: ${CMAKE_HOST_SYSTEM_NAME} ${CMAKE_HOST_SYSTEM_PROCESSOR}")
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
message("CMAKE_FIND_LIBRARY_SUFFIXES: ${CMAKE_FIND_LIBRARY_SUFFIXES}")
# bin output dir
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
set(TEST_EXECUTABLE_OUTPUT_PATH ${EXECUTABLE_OUTPUT_PATH}/test)
# third-party install path
if(NOT THIRD_PARTY_INSTALL_PATH)
if(DEFINED ENV{THIRD_PARTY_INSTALL_PATH})
set(THIRD_PARTY_INSTALL_PATH $ENV{THIRD_PARTY_INSTALL_PATH})
else()
set(THIRD_PARTY_INSTALL_PATH "$ENV{HOME}/.local/dingo-eureka")
endif()
endif()
message("THIRD_PARTY_INSTALL_PATH:${THIRD_PARTY_INSTALL_PATH}")
set(CMAKE_PREFIX_PATH
${THIRD_PARTY_INSTALL_PATH}
${PROJECT_SOURCE_DIR}/thirdparties/etcdclient
${CMAKE_PREFIX_PATH}
)
message("CMAKE_PREFIX_PATH:${CMAKE_PREFIX_PATH}")
# link first lookup from THIRD_PARTY_INSTALL_PATH
link_directories(BEFORE ${THIRD_PARTY_INSTALL_PATH}/lib)
link_directories(BEFORE ${PROJECT_SOURCE_DIR}/thirdparties/etcdclient)
# include dir
include_directories(${THIRD_PARTY_INSTALL_PATH}/include)
include_directories(${PROJECT_SOURCE_DIR}/thirdparties/etcdclient)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
add_definitions(-DUSE_BTHREAD_MUTEX)
find_package(FUSE3 REQUIRED)
message("Using FUSE3 ${FUSE3_VERSION}, include_dir:${FUSE3_INCLUDE_DIR}")
include_directories(${FUSE3_INCLUDE_DIR})
find_package(LIBMEMCACHED REQUIRED)
message("Using LIBMEMCACHED ${LIBMEMCACHED_VERSION}, lib:${LIBMEMCACHED_LIBRARY}")
# find third-party
set(gflags_DIR ${THIRD_PARTY_INSTALL_PATH}/lib/cmake/gflags)
find_package(gflags REQUIRED)
message("Using gflags ${gflags_VERSION}, include_dir:${gflags_INCLUDE_DIR}")
# openssl
if(NOT OPENSSL_ROOT_DIR)
set(OPENSSL_ROOT_DIR ${THIRD_PARTY_INSTALL_PATH})
endif()
find_package(OpenSSL REQUIRED)
message("OpenSSL libraries: ${OPENSSL_LIBRARIES}, include dir: ${OPENSSL_INCLUDE_DIR}")
find_package(Snappy)
message("Using Snappy ${Snappy_VERSION}")
find_package(fmt REQUIRED)
message("Using fmt ${fmt_VERSION}")
set(ZLIB_USE_STATIC_LIBS "ON")
find_package(ZLIB REQUIRED)
message("Using zlib ${ZLIB_VERSION}, include_dir:${ZLIB_INCLUDE_DIR}")
find_package (glog REQUIRED)
# used for glog 0.7.0
add_compile_definitions(GLOG_USE_GLOG_EXPORT)
message("Using glog ${glog_VERSION}")
find_package(GTest CONFIG REQUIRED)
message("Using GTest ${GTest_VERSION}")
set(protobuf_MODULE_COMPATIBLE TRUE)
find_package(Protobuf CONFIG REQUIRED)
message("Using protobuf ${Protobuf_VERSION}" )
find_program(PROTOC protoc REQUIRED)
message("Using protoc ${PROTOC}")
find_package(AWSSDK COMPONENTS s3)
message("Using AWSSDK ${AWSSDK_VERSION}, lib:${AWSSDK_LIBRARIES}")
find_package(absl REQUIRED)
message("Using absl ${absl_VERSION}")
find_package(nlohmann_json REQUIRED)
message("Using nlohmann_json ${nlohmann_json_VERSION}")
find_package(opentelemetry-cpp CONFIG REQUIRED)
message("Using opentelemetry-cpp ${opentelemetry-cpp_VERSION}")
# depends by rocksdb
find_package(uring)
message("Using uring ${uring_VERSION}")
find_package(jsoncpp REQUIRED)
message("Using jsoncpp ${jsoncpp_VERSION}")
find_package(brpc REQUIRED)
find_package(braft REQUIRED)
find_package(RocksDB REQUIRED)
# ------------------------ related to source code ------------------------
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
include_directories(${CMAKE_BINARY_DIR}/protos)
set(PROTO_OUTPUT_DIR ${CMAKE_BINARY_DIR}/protos/proto)
add_custom_target(create_proto_output_dir ALL
COMMAND ${CMAKE_COMMAND} -E make_directory ${PROTO_OUTPUT_DIR}
)
message("PROTO_OUTPUT_DIR:${PROTO_OUTPUT_DIR}")
set(PROTOS_DIR ${PROJECT_SOURCE_DIR}/proto)
message("PROTOS_DIR:${PROTOS_DIR}")
file(GLOB_RECURSE MSG_PROTOS ${PROTOS_DIR}/*.proto)
set(PROTO_SRCS "")
set(PROTO_HDRS "")
foreach(msg ${MSG_PROTOS})
get_filename_component(FIL_WE ${msg} NAME_WE)
message(STATUS "proto file: ${msg}")
set(FILE_PREFIX_NAME "${PROTO_OUTPUT_DIR}/${FIL_WE}")
message(STATUS "FILE_PREFIX_NAME: ${FILE_PREFIX_NAME}")
list(APPEND PROTO_SRCS "${FILE_PREFIX_NAME}.pb.cc")
list(APPEND PROTO_HDRS "${FILE_PREFIX_NAME}.pb.h")
add_custom_command(
OUTPUT "${FILE_PREFIX_NAME}.pb.cc"
"${FILE_PREFIX_NAME}.pb.h"
COMMAND ${PROTOC}
ARGS --cpp_out ${PROTO_OUTPUT_DIR}
ARGS --proto_path=${PROTOS_DIR}
${msg}
DEPENDS ${msg}
COMMENT "Running C++ protocol buffer compiler on ${msg}"
VERBATIM
)
endforeach()
set_source_files_properties(
${PROTO_SRCS}
${PROTO_HDRS}
PROPERTIES GENERATED TRUE)
set(PROTO_OBJS_SRC
${PROTO_SRCS}
${PROTO_HDRS}
)
add_library(PROTO_OBJS OBJECT
${PROTO_OBJS_SRC}
)
set_target_properties(PROTO_OBJS
PROPERTIES
POSITION_INDEPENDENT_CODE ON
)
add_subdirectory(src)
if(BUILD_UNIT_TESTS)
message(STATUS "Build unit test")
add_subdirectory(test)
endif()