forked from erpc-io/eRPC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
324 lines (287 loc) · 10.5 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
317
318
319
320
321
322
323
324
cmake_minimum_required(VERSION 2.8)
project(eRPC)
include(CMakeDependentOption)
# Pick a compiler
#set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_CXX_COMPILER g++)
add_definitions(-std=c++11 -march=native -g)
add_definitions(-Wall -Wextra -Werror -pedantic -Wsign-conversion -Wold-style-cast)
add_definitions(-Wno-unused-function -Wno-nested-anon-types -Wno-keyword-macro)
set(LIBRARIES ${LIBRARIES} rt numa pthread gflags)
# Unit tests
enable_testing()
find_package(GTest REQUIRED)
include_directories(${CMAKE_SOURCE_DIR}/src)
include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/third_party)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/build)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/build)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/build)
# DPDK may be needed for different reasons (e.g., the transport is DPDK, or
# if the transport is not DPDK but the application needs DPDK libraries)
set(DPDK_NEEDED "false")
# Options exposed to the user
set(TRANSPORT "dpdk" CACHE STRING "Datapath transport (infiniband/raw/dpdk)")
option(ROCE "Use RoCE if TRANSPORT is infiniband" OFF)
option(PERF "Compile for performance" ON)
set(PGO "none" CACHE STRING "Profile-guided optimization (generate/use/none)")
set(LOG_LEVEL "warn" CACHE STRING "Logging level (none/error/warn/info/reorder/trace/cc)")
# Parse the user-exposed options
if(PERF)
message(STATUS "Compilation optimized for performance.")
set(DEBUG OFF)
set(TESTING OFF)
else(PERF)
message(STATUS "Compilation not optimized for performance.")
set(DEBUG ON)
set(TESTING ON)
endif(PERF)
# Profile-guided optimization
if(PGO STREQUAL "generate")
message(STATUS "Profile-guided optimization (generate mode) is enabled. Performance will be low.")
add_definitions(-fprofile-generate)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-generate")
elseif(PGO STREQUAL "use")
message(STATUS "Profile-guided optimization (use mode) is enabled.")
add_definitions(-fprofile-use -fprofile-correction)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-use -fprofile-correction")
elseif(PGO STREQUAL "none")
message(STATUS "Profile-guided optimization is disabled.")
endif()
# Logging level
if(LOG_LEVEL STREQUAL "none")
message(STATUS "Logging level = none.")
add_definitions(-DERPC_LOG_LEVEL=0)
elseif(LOG_LEVEL STREQUAL "error")
message(STATUS "Logging level = error.")
add_definitions(-DERPC_LOG_LEVEL=1)
elseif(LOG_LEVEL STREQUAL "warn")
message(STATUS "Logging level = warn.")
add_definitions(-DERPC_LOG_LEVEL=2)
elseif(LOG_LEVEL STREQUAL "info")
message(STATUS "Logging level = info.")
add_definitions(-DERPC_LOG_LEVEL=3)
elseif(LOG_LEVEL STREQUAL "reorder")
message(STATUS "Logging level = reorder. Warning: Performance will be low.")
add_definitions(-DERPC_LOG_LEVEL=4)
elseif(LOG_LEVEL STREQUAL "trace")
message(STATUS "Logging level = trace. Warning: Performance will be low.")
add_definitions(-DERPC_LOG_LEVEL=5)
elseif(LOG_LEVEL STREQUAL "cc")
message(STATUS "Logging level = cc. Warning: Performance will be low.")
add_definitions(-DERPC_LOG_LEVEL=6)
else()
message(STATUS "No logging level specified. Using warning level.")
add_definitions(-DERPC_LOG_LEVEL=2)
endif()
# Debug mode
if(DEBUG)
message(STATUS "Debugging is enabled. Perf will be low.")
else(DEBUG)
message(STATUS "Debugging is disabled.")
add_definitions(-DNDEBUG)
add_definitions(-O2)
endif(DEBUG)
# Testing for packet loss, machine failure, etc
if(TESTING)
message(STATUS "Testing is enabled. Performance will be low.")
add_definitions(-DERPC_TESTING=true)
else(TESTING)
message(STATUS "Testing is disabled, so tests may fail.")
add_definitions(-DERPC_TESTING=false)
endif(TESTING)
set(SOURCES
src/nexus_impl/nexus.cc
src/nexus_impl/nexus_bg_thread.cc
src/nexus_impl/nexus_sm_thread.cc
src/rpc_impl/rpc.cc
src/rpc_impl/rpc_queues.cc
src/rpc_impl/rpc_rfr.cc
src/rpc_impl/rpc_cr.cc
src/rpc_impl/rpc_kick.cc
src/rpc_impl/rpc_req.cc
src/rpc_impl/rpc_resp.cc
src/rpc_impl/rpc_ev_loop.cc
src/rpc_impl/rpc_fault_inject.cc
src/rpc_impl/rpc_pkt_loss.cc
src/rpc_impl/rpc_rx.cc
src/rpc_impl/rpc_connect_handlers.cc
src/rpc_impl/rpc_disconnect_handlers.cc
src/rpc_impl/rpc_reset_handlers.cc
src/rpc_impl/rpc_sm_api.cc
src/rpc_impl/rpc_sm_helpers.cc
src/transport_impl/transport.cc
src/transport_impl/dpdk/dpdk_transport.cc
src/transport_impl/dpdk/dpdk_transport_datapath.cc
src/transport_impl/infiniband/ib_transport.cc
src/transport_impl/infiniband/ib_transport_datapath.cc
src/transport_impl/raw/raw_transport.cc
src/transport_impl/raw/raw_transport_datapath.cc
src/util/huge_alloc.cc
src/util/externs.cc
src/util/tls_registry.cc)
# Transport-specific. Mellanox OFED drivers are the best choice for raw and
# infiniband, but they do not play well with DPDK. So we compile only one
# transport. Other transports are exluded using preprocessor macros.
string(TOUPPER ${TRANSPORT} DEFINE_TRANSPORT)
add_definitions(-DERPC_${DEFINE_TRANSPORT}=true)
message(STATUS "Selected transport = ${TRANSPORT}.")
set(CONFIG_IS_ROCE false)
if(TRANSPORT STREQUAL "dpdk")
set(CONFIG_TRANSPORT "DpdkTransport")
set(CONFIG_HEADROOM 40)
set(DPDK_NEEDED "true") # We'll resolve DPDK later
else()
find_library(IBVERBS_LIB ibverbs)
if(NOT IBVERBS_LIB)
message(FATAL_ERROR "ibverbs library not found")
endif()
set(LIBRARIES ${LIBRARIES} ibverbs)
if(TRANSPORT STREQUAL "raw")
set(CONFIG_TRANSPORT "RawTransport")
set(CONFIG_HEADROOM 40)
elseif(TRANSPORT STREQUAL "infiniband")
set(CONFIG_TRANSPORT "IBTransport")
if(ROCE)
set(CONFIG_HEADROOM 40)
set(CONFIG_IS_ROCE true)
else()
set(CONFIG_HEADROOM 0)
set(CONFIG_IS_ROCE false)
endif()
endif()
endif()
configure_file(src/config.h.in src/config.h)
# MICA sources
set(MICA_SOURCES
mica/src/mica/util/cityhash/city_mod.cc
mica/src/mica/util/config.cc)
# The tests to run using ctest
set(CLIENT_TESTS
create_session_test
destroy_session_test
small_msg_test
large_msg_test
req_in_cont_func_test
req_in_req_func_test
packet_loss_test
#server_failure_test
multi_process_test)
set(PROTOCOL_TESTS
rpc_sm_test
rpc_list_test
rpc_req_test
rpc_resp_test
rpc_cr_test
rpc_rfr_test
rpc_kick_test)
if(TRANSPORT STREQUAL "raw")
set(TRANSPORT_TESTS
raw_transport_test)
endif()
# These are not run using ctest
set(UTIL_TESTS
huge_alloc_test
hugepage_caching_virt2phy_test
timing_wheel_test
heartbeat_mgr_test
rand_test
misc_test
fixed_vector_test
timely_test
numautil_test)
# Compile the library
add_library(erpc ${SOURCES})
# Compile the tests
if(TESTING)
foreach(test_name IN LISTS CLIENT_TESTS)
add_executable(${test_name} tests/client_tests/${test_name}.cc)
target_link_libraries(${test_name} erpc ${GTEST_LIBRARIES} ${LIBRARIES})
add_test(NAME ${test_name} COMMAND ${test_name})
endforeach()
foreach(test_name IN LISTS PROTOCOL_TESTS)
add_executable(${test_name} tests/protocol_tests/${test_name}.cc)
target_link_libraries(${test_name} erpc ${GTEST_LIBRARIES} ${LIBRARIES})
add_test(NAME ${test_name} COMMAND ${test_name})
endforeach()
foreach(test_name IN LISTS TRANSPORT_TESTS)
add_executable(${test_name} tests/transport_tests/${test_name}.cc)
target_link_libraries(${test_name} erpc ${GTEST_LIBRARIES} ${LIBRARIES})
add_test(NAME ${test_name} COMMAND ${test_name})
endforeach()
foreach(test_name IN LISTS UTIL_TESTS)
add_executable(${test_name} tests/util_tests/${test_name}.cc)
target_link_libraries(${test_name} erpc ${GTEST_LIBRARIES} ${LIBRARIES})
endforeach()
endif()
# The app to compile. Only one app is compiled to reduce compile time.
if(EXISTS "${CMAKE_SOURCE_DIR}/scripts/autorun_app_file")
file(STRINGS "scripts/autorun_app_file" APP)
else()
message(STATUS "No autorun_app_file found. No application will be compiled.")
return()
endif()
message(STATUS "Compiling app = " ${APP})
# Add app-specific defines now, isolating them from the library and tests
# libpmem is installable from package managers in only recent distros. If it's
# not present, don't link it in.
find_library(PMEM_LIB pmem)
if(NOT PMEM_LIB)
message(STATUS "Persistent memory library (libpmem) not found")
set(PMEM "")
else()
set(PMEM "pmem")
endif()
if(APP STREQUAL "smr")
# Raft library from willemt/raft, installed at system-level
set(LIBRARIES ${LIBRARIES} raft ${PMEM})
# MICA
include_directories(mica/src)
set(APP_ADDITIONAL_SOURCES ${MICA_SOURCES})
elseif(APP STREQUAL "masstree_analytics")
# CMake-based Masstree library from anujkaliaiitd/masstree-beta
link_directories(${CMAKE_SOURCE_DIR}/third_party/masstree-beta)
include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/third_party/masstree-beta)
add_definitions(-include ${CMAKE_SOURCE_DIR}/third_party/masstree-beta/config.h)
set(APP_ADDITIONAL_SOURCES
apps/masstree_analytics/mt_index_api.cc
mica/src/mica/util/cityhash/city_mod.cc)
set(LIBRARIES ${LIBRARIES} masstree)
include_directories(mica/src)
elseif(APP STREQUAL "mica_test")
include_directories(mica/src)
set(APP_ADDITIONAL_SOURCES ${MICA_SOURCES})
elseif(APP STREQUAL "latency")
set(LIBRARIES ${LIBRARIES} ${PMEM})
elseif(APP STREQUAL "pmem_bw")
set(LIBRARIES ${LIBRARIES} ${PMEM})
message(STATUS "DPDK is needed for pmem_bw application")
add_definitions(-fpermissive)
set(DPDK_NEEDED "true")
elseif(APP STREQUAL "persistent_kv")
set(LIBRARIES ${LIBRARIES} ${PMEM} cityhash)
elseif(APP STREQUAL "log")
set(LIBRARIES ${LIBRARIES} ${PMEM})
endif()
if(DPDK_NEEDED STREQUAL "true")
find_library(DPDK_LIB dpdk)
if(NOT DPDK_LIB)
message(FATAL_ERROR "DPDK library not found")
endif()
set(LIBRARIES ${LIBRARIES} -Wl,--whole-archive dpdk -Wl,--no-whole-archive dl)
# DPDK include directory. Locating rte_config.h does not work on some systems.
# Example: it may be kept in /usr/include/x86_64-linux-gnu/, and symlinked
# from the real DPDK include directory (/usr/include/dpdk/).
find_path(DPDK_INCLUDE_DIR NAMES rte_ethdev.h PATH_SUFFIXES dpdk)
if (DPDK_INCLUDE_DIR)
message(STATUS "DPDK include directory = ${DPDK_INCLUDE_DIR}")
else()
message(FATAL_ERROR "DPDK include directory not found")
endif()
include_directories(SYSTEM ${DPDK_INCLUDE_DIR})
endif()
# Using link-time optimization sometimes requires building with sources instead
# of liberpc. See the hello world example's Makefile for an example of
# compiling with liberpc.
add_executable(${APP} apps/${APP}/${APP}.cc ${APP_ADDITIONAL_SOURCES} ${SOURCES})
target_compile_options(${APP} PRIVATE "-flto")
target_link_libraries(${APP} ${GTEST_LIBRARIES} ${LIBRARIES})