-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
248 lines (209 loc) · 7.51 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
cmake_minimum_required(VERSION 2.8.10)
project(neu_blockchain)
option(LINK_SO "Whether examples are linked dynamically" ON)
option(LINK_TCMALLOC "Link tcmalloc if possible" ON)
set(CMAKE_PREFIX_PATH ${OUTPUT_PATH})
INCLUDE_DIRECTORIES(include)
include(FindThreads)
include(FindProtobuf)
if (NOT PROTOBUF_PROTOC_EXECUTABLE)
get_filename_component(PROTO_LIB_DIR ${PROTOBUF_LIBRARY} DIRECTORY)
set(PROTOBUF_PROTOC_EXECUTABLE "${PROTO_LIB_DIR}/../bin/protoc")
endif ()
PROTOBUF_GENERATE_CPP(PROTO_SRC PROTO_HEADER
./include/proto/transaction.proto
./include/proto/chaincode.proto
./include/proto/common.proto
./include/proto/kv_rwset.proto
./include/proto/comm.proto
./include/proto/tpc-c.proto
./include/proto/db_test_chaincode.proto
./include/proto/block.proto
./include/proto/chain.proto
)
# include PROTO_HEADER
include_directories(${CMAKE_CURRENT_BINARY_DIR})
find_path(BRPC_INCLUDE_PATH NAMES brpc/server.h)
if (LINK_SO)
find_library(BRPC_LIB NAMES brpc)
find_library(BRAFT_LIB NAMES braft)
else ()
find_library(BRPC_LIB NAMES libbrpc.a brpc)
find_library(BRAFT_LIB NAMES libbraft.a braft)
endif ()
#3. yaml
FIND_PACKAGE(yaml-cpp REQUIRED)
FIND_PATH(YAML_INCLUDE_PATH NAMES yaml-cpp/yaml.h)
FIND_LIBRARY(YAML_LIB NAMES yaml-cpp)
if ((NOT YAML_INCLUDE_PATH) OR (NOT YAML_LIB))
MESSAGE(FATAL_ERROR "Fail to find yaml-cpp")
endif ()
INCLUDE_DIRECTORIES(${YAML_INCLUDE_DIRS})
# 1. zmq
FIND_PACKAGE(cppzmq)
FIND_PATH(ZMQ_INCLUDE_PATH zmq.hpp)
FIND_LIBRARY(ZMQ_LIB NAMES libzmq.a zmq)
if ((NOT ZMQ_INCLUDE_PATH) OR (NOT ZMQ_LIB))
MESSAGE(FATAL_ERROR "Fail to find zmq")
endif ()
INCLUDE_DIRECTORIES(${ZMQ_INCLUDE_PATH})
# brpc
if ((NOT BRPC_INCLUDE_PATH) OR (NOT BRPC_LIB))
message(FATAL_ERROR "Fail to find brpc")
endif ()
include_directories(${BRPC_INCLUDE_PATH})
# braft
find_path(BRAFT_INCLUDE_PATH NAMES braft/raft.h)
if ((NOT BRAFT_INCLUDE_PATH) OR (NOT BRAFT_LIB))
message(FATAL_ERROR "Fail to find braft")
endif ()
include_directories(${BRAFT_INCLUDE_PATH})
# we do not link gflag library, it has already included in protobuf
find_path(GFLAGS_INCLUDE_PATH gflags/gflags.h)
find_library(GFLAGS_LIBRARY NAMES gflags libgflags)
if ((NOT GFLAGS_INCLUDE_PATH) OR (NOT GFLAGS_LIBRARY))
message(FATAL_ERROR "Fail to find gflags")
endif ()
include_directories(${GFLAGS_INCLUDE_PATH})
# glog
find_package(glog REQUIRED)
if (NOT LINK_SO)
execute_process(
COMMAND bash -c "grep \"namespace [_A-Za-z0-9]\\+ {\" ${GFLAGS_INCLUDE_PATH}/gflags/gflags_declare.h | head -1 | awk '{print $2}' | tr -d '\n'"
OUTPUT_VARIABLE GFLAGS_NS
)
if (${GFLAGS_NS} STREQUAL "GFLAGS_NAMESPACE")
execute_process(
COMMAND bash -c "grep \"#define GFLAGS_NAMESPACE [_A-Za-z0-9]\\+\" ${GFLAGS_INCLUDE_PATH}/gflags/gflags_declare.h | head -1 | awk '{print $3}' | tr -d '\n'"
OUTPUT_VARIABLE GFLAGS_NS
)
endif ()
set(CMAKE_CPP_FLAGS "-DGFLAGS_NS=${GFLAGS_NS}")
SET(LIBRARY_DEPENDENCIES
${LIBRARY_DEPENDENCIES}
${GFLAGS_LIBRARY}
libgflags.a
)
endif ()
if (LINK_TCMALLOC)
find_path(GPERFTOOLS_INCLUDE_DIR NAMES gperftools/heap-profiler.h)
find_library(GPERFTOOLS_LIBRARIES NAMES tcmalloc_and_profiler)
if (GPERFTOOLS_INCLUDE_DIR AND GPERFTOOLS_LIBRARIES)
set(CMAKE_CXX_FLAGS "-DBRPC_ENABLE_CPU_PROFILER")
include_directories(${GPERFTOOLS_INCLUDE_DIR})
else ()
set(GPERFTOOLS_LIBRARIES "")
endif ()
endif ()
SET(CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG} \
${CMAKE_CXX_FLAGS_COMMON} \
-g -O0 -fprofile-arcs -ftest-coverage")
SET(CMAKE_CXX_FLAGS_RELEASE
"${CMAKE_CXX_FLAGS_RELEASE} \
${CMAKE_CXX_FLAGS_COMMON} \
-O3")
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} ${CMAKE_CXX_FLAGS} -D__const__=__unused__ -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer")
# release version
# set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} ${CMAKE_CXX_FLAGS} -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer")
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# require at least gcc 4.8
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
message(FATAL_ERROR "GCC is too old, please install a newer version supporting C++11")
endif ()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# require at least clang 3.3
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.3)
message(FATAL_ERROR "Clang is too old, please install a newer version supporting C++11")
endif ()
else ()
message(WARNING "You are using an unsupported compiler! Compilation has only been tested with Clang and GCC.")
endif ()
if (CMAKE_VERSION VERSION_LESS "3.1.3")
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
endif ()
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
endif ()
else ()
SET(CMAKE_CXX_STANDARD 17)
SET(CMAKE_CXX_STANDARD_REQUIRED on)
endif ()
# leveldb
find_path(LEVELDB_INCLUDE_PATH NAMES leveldb/db.h)
find_library(LEVELDB_LIB NAMES leveldb)
if ((NOT LEVELDB_INCLUDE_PATH) OR (NOT LEVELDB_LIB))
message(FATAL_ERROR "Fail to find leveldb")
endif ()
include_directories(${LEVELDB_INCLUDE_PATH})
ADD_LIBRARY(aria_protobuf ${PROTO_HEADER} ${PROTO_SRC} include/block_server/coordinator/net_topology_manager.h)
# common file
FILE(GLOB SRC_COMMON_DATA_STRUCTURE
"src/common/*.cpp"
"src/common/*.c")
FILE(GLOB SRC_COMMON_MERKLE_TREE
"src/common/merkle_tree/*.c")
FILE(GLOB SRC_COMMON_MSP
"src/common/msp/*.cpp")
FILE(GLOB SRC_COMMON_TX_PAYLOAD
${SRC_COMMON_DATA_STRUCTURE}
"src/common/payload/*.cpp"
"src/block_server/transaction/mock/mock_transaction.cpp")
FILE(GLOB SRC_COMMON_ZMQ
"src/common/zmq/*.cpp")
# client proxy
FILE(GLOB SRC_CLIENT_PROXY
"src/block_server/comm/client_proxy/*.cpp")
FILE(GLOB SRC_CLIENT_PROXY_MOCK
"src/block_server/comm/mock/*.cpp")
# query interface
FILE(GLOB SRC_QUERY
"src/block_server/comm/query/*.cpp")
# block server
FILE(GLOB SRC_BLOCK_SERVER_COORDINATOR
"src/block_server/coordinator/*.cpp")
FILE(GLOB SRC_BLOCK_SERVER_WORKER
"src/block_server/worker/*.cpp"
"src/block_server/worker/impl/*.cpp"
"src/block_server/worker/chaincode/*.cpp")
FILE(GLOB SRC_BLOCK_SERVER_DATABASE
"src/block_server/database/*.cpp"
"src/block_server/database/impl/*.cpp"
"src/block_server/database/orm/*.cpp"
"src/block_server/database/orm/impl/*.cpp")
FILE(GLOB SRC_BLOCK_SERVER_TRANSACTION
"src/block_server/transaction/impl/*.cpp")
FILE(GLOB SRC_BLOCK_SERVER_TRANSACTION_MOCK
"src/block_server/transaction/mock/*.cpp")
FILE(GLOB SRC_BLOCK_SERVER_RESERVE_TABLE
"src/block_server/reserve_table/*.cpp"
"src/block_server/reserve_table/mock/*.cpp")
FILE(GLOB SRC_BLOCK_BENCH
"src/user/block_bench/*.cpp")
SET(LIBRARY_DEPENDENCIES
${LIBRARY_DEPENDENCIES}
${CMAKE_THREAD_LIBS_INIT}
${GLOG_LIBRARY}
${PROTOBUF_LIBRARY}
${GPERFTOOLS_LIBRARIES}
${LEVELDB_LIB}
${BRAFT_LIB}
${BRPC_LIB}
${YAML_LIB}
${ZMQ_LIB}
glog::glog
aria_protobuf
crypto
pqxx.a
pq.so
ssl
dl
rt
z
)
# runnable src
ADD_SUBDIRECTORY(src/block_server)
ADD_SUBDIRECTORY(src/epoch_server)
ADD_SUBDIRECTORY(src/user)
ADD_SUBDIRECTORY(tests)