-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathCMakeLists.txt
376 lines (291 loc) · 10.1 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
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
cmake_minimum_required (VERSION 2.8.12)
project (Residue)
option (production "Build for production" ON)
option (debug "Enable debug logging" OFF)
option (profiling "Turns profiling on for various scenarios" OFF)
option (enable_extensions "Enables extensions support for the build" ON)
option (use_mine "Use mine whereever possible" OFF)
option (use_boost "Use boost or standalone networking lib" OFF)
option (old_toolchain "Is old toolchain" OFF)
set (RESIDUE_MAJOR "2")
set (RESIDUE_MINOR "3")
set (RESIDUE_PATCH "6")
set (RESIDUE_VERSION "${RESIDUE_MAJOR}.${RESIDUE_MINOR}.${RESIDUE_PATCH}")
set (RESIDUE_NAME "Residue")
add_definitions (-DRESIDUE_VERSION="${RESIDUE_VERSION}")
add_definitions (-DRESIDUE_VERSION_MAJOR="${RESIDUE_MAJOR}")
add_definitions (-DRESIDUE_VERSION_MINOR="${RESIDUE_MINOR}")
add_definitions (-DRESIDUE_VERSION_PATCH="${RESIDUE_PATCH}")
add_definitions (-DRIPE_VERSION="4.1.1-static")
if (enable_extensions)
add_definitions (-DRESIDUE_HAS_EXTENSIONS)
endif(enable_extensions)
if (old_toolchain)
message ("==> USING OLD TOOLCHAIN")
add_definitions (-D_GLIBCXX_USE_NANOSLEEP)
endif(old_toolchain)
if (use_mine)
add_definitions (-DRESIDUE_USE_MINE)
endif(use_mine)
if (profiling)
message ("==> PROFILING IS ON")
add_definitions (-DRESIDUE_PROFILING)
endif(profiling)
if (debug)
message ("==> DEBUGGING IS ON")
add_definitions (-DRESIDUE_DEBUG)
endif(debug)
set (test "OFF")
if (production)
message ("==> PRODUCTION BUILD")
add_definitions (-DRESIDUE_PRODUCTION)
else(production)
message ("==> DEVELOPMENT MODE")
add_definitions (-DRESIDUE_DEV)
add_definitions (-DELPP_DEBUG_ERRORS)
add_definitions (-DELPP_DEBUG_INFO)
set (CMAKE_BUILD_TYPE "DEBUG")
set (test "ON")
endif(production)
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
include(residue-dev)
include (FindPackageHandleStandardArgs)
include (FindCURL)
check_apple()
set (cxx_standard c++11)
set (optimization_level 0)
if (production)
set (optimization_level 3)
endif (production)
set (extra_flags "")
if (APPLE)
set (extra_flags "-mmacosx-version-min=10.10")
endif()
list (APPEND CMAKE_CXX_FLAGS " -std=${cxx_standard} -O${optimization_level} ${extra_flags} -Wall -Wextra -pedantic -pedantic-errors -Wno-undefined-var-template -Wno-undef -Wno-unused-local-typedef -Wno-unused-variable -Wno-deprecated-declarations -Wno-unknown-warning-option -Wno-pessimizing-move ")
if (CMAKE_BUILD_TYPE EQUAL "DEBUG" OR CMAKE_BUILD_TYPE EQUAL "RELWITHDEBINFO")
message ("==> EXPORTING DEBUG SYMBOLS")
endif()
## Prefer static linking
# SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
find_package (CURL REQUIRED)
if (CURL_FOUND)
add_definitions (-DRESIDUE_HAS_CURL)
include_directories (${CURL_INCLUDE_DIRS})
message ("-- libcurl: " ${CURL_LIBRARIES} " version: " ${CURL_VERSION_STRING})
endif()
find_package(ZLIB REQUIRED)
if (ZLIB_FOUND)
include_directories(${ZLIB_INCLUDE_DIRS})
message ("-- libz: " ${ZLIB_LIBRARIES} " version: " ${ZLIB_VERSION_STRING})
endif(ZLIB_FOUND)
if (use_boost)
message ("==> BASED ON BOOST")
add_definitions (-DRESIDUE_BOOST)
# Boost
message ("-- Check for Boost System (static)")
set (Boost_USE_STATIC_LIBS ON)
find_package (Boost REQUIRED COMPONENTS system)
include_directories (${Boost_INCLUDE_DIR})
message ("-- libboost: " ${Boost_LIBRARIES})
set(NET_LIBRARIES ${Boost_LIBRARIES})
else()
message ("==> BASED ON STANDALONE ASIO")
add_definitions (-DASIO_STANDALONE)
endif(use_boost)
# Check for cryptopp (static)
set(CryptoPP_USE_STATIC_LIBS ON)
find_package(CryptoPP REQUIRED)
message ("-- Crypto++ binary: " ${CRYPTOPP_LIBRARY})
include_directories (${CRYPTOPP_INCLUDE_DIRS})
thread_packages_check()
include_directories (${CMAKE_SOURCE_DIR})
include_directories (${CMAKE_SOURCE_DIR}/deps)
include_directories (${CMAKE_SOURCE_DIR}/src)
if (use_mine)
set (MINE_SRC deps/mine/mine.cc)
else()
set (MINE_SRC "")
endif()
set (DEPS_SRC
${MINE_SRC}
deps/linenoise/linenoise.c
deps/easyloggingpp/easylogging++.cc
deps/ripe/Ripe.cc
deps/gason/gason.cc
)
set (SOURCE_FILES
src/setup.cc
src/connect/connection-request.cc
src/connect/connection-request-handler.cc
src/connect/connection-response.cc
src/admin/admin-request.cc
src/admin/admin-request-handler.cc
src/logging/log-request-handler.cc
src/logging/log-request.cc
src/logging/user-log-builder.cc
src/logging/user-message.cc
src/logging/logging-queue.cc
src/logging/client-queue-processor.cc
src/core/client.cc
src/core/request.cc
src/core/request-handler.cc
src/core/response.cc
src/core/configuration.cc
src/core/registry.cc
src/core/json-doc.cc
src/crypto/rsa.cc
src/crypto/aes.cc
src/crypto/base64.cc
src/crypto/base16.cc
src/crypto/zlib.cc
src/net/server.cc
src/net/session.cc
src/net/url.cc
src/net/http-client.cc
src/cli/command.cc
src/cli/command-handler.cc
src/cli/update.cc
src/cli/reset.cc
src/cli/reload-config.cc
src/cli/stats.cc
src/cli/rotate.cc
src/cli/list-logging-files.cc
src/cli/clients.cc
src/extensions/extension.cc
src/extensions/log-extension.cc
src/extensions/pre-archive-extension.cc
src/extensions/post-archive-extension.cc
src/tasks/auto-updater.cc
src/tasks/client-integrity-task.cc
src/tasks/task.cc
src/tasks/log-rotator.cc
src/utils/tar.cc
src/utils/utils.cc
)
set (SHARED_REQUIRED_LIBS
${NET_LIBRARIES}
${CURL_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
${ZLIB_LIBRARIES}
${CRYPTOPP_LIBRARIES}
)
if (enable_extensions)
set (SHARED_REQUIRED_LIBS ${SHARED_REQUIRED_LIBS} ${CMAKE_DL_LIBS})
endif(enable_extensions)
############# RESIDUE CORE LIB (STATIC) ###############
add_library (residue-core STATIC ${SOURCE_FILES})
set_target_properties (residue-core PROPERTIES
VERSION ${RESIDUE_VERSION}
)
target_link_libraries (residue-core ${SHARED_REQUIRED_LIBS})
target_compile_definitions (residue-core PUBLIC
ELPP_FORCE_USE_STD_THREAD
ELPP_THREAD_SAFE
ELPP_NO_GLOBAL_LOCK
)
# Set RPATH to library install path.
set (CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
############# RESIDUE EXTENSION LIB (STATIC) ###############
if (enable_extensions)
set (EXTENSION_FILES
src/extensions/extension.cc
src/extensions/log-extension.cc
src/extensions/dispatch-error-extension.cc
src/extensions/pre-archive-extension.cc
src/extensions/post-archive-extension.cc
src/core/json-doc.cc
deps/gason/gason.cc
)
add_library (residue-extension-st STATIC ${EXTENSION_FILES})
set_target_properties (residue-extension-st PROPERTIES
VERSION ${RESIDUE_VERSION}
)
target_compile_definitions (residue-extension-st PUBLIC
RESIDUE_EXTENSION_LIB
)
set_target_properties (residue-extension-st PROPERTIES OUTPUT_NAME "residue-extension-st")
# install (TARGETS residue-extension-st DESTINATION lib)
######### Shared lib for extension
add_library (residue-extension SHARED ${EXTENSION_FILES})
set_target_properties (residue-extension PROPERTIES
VERSION ${RESIDUE_VERSION}
)
target_link_libraries (residue-extension
residue-extension-st
)
target_compile_definitions (residue-extension PUBLIC
RESIDUE_EXTENSION_LIB
)
set_target_properties (residue-extension PROPERTIES OUTPUT_NAME "residue-extension")
install (TARGETS residue-extension DESTINATION lib)
file(GLOB EXTENSIONS_H "src/extensions/*.h")
install (FILES ${EXTENSIONS_H} DESTINATION "include/residue/extensions/")
install (FILES src/core/json-doc.h DESTINATION "include/residue/core/")
install (FILES deps/gason/gason.h DESTINATION "include/residue/gason/")
install (FILES include/extensions.h DESTINATION "include/residue/")
endif(enable_extensions)
############# CONFIG VALIDATOR TOOL ###############
if (true)
add_executable (residue-config-validator-bin
tools/config-validator/main.cc
${DEPS_SRC}
)
target_compile_definitions (residue-config-validator-bin PUBLIC
ELPP_NO_DEFAULT_LOG_FILE
ELPP_NO_LOG_TO_FILE
ELPP_STL_LOGGING
AUTO_INITIALIZE_EASYLOGGINGPP
ELPP_DEFAULT_LOGGING_FLAGS=4096
)
target_link_libraries (residue-config-validator-bin
residue-core)
set_target_properties (residue-config-validator-bin PROPERTIES
OUTPUT_NAME "residue-config-validator"
VERSION ${RESIDUE_VERSION}
)
#install (TARGETS residue-config-validator-bin DESTINATION bin)
endif()
############# RESIDUE BINARY ###############
add_executable (residue-bin
src/main.cc
${DEPS_SRC}
)
target_compile_definitions (residue-bin PUBLIC
ELPP_STL_LOGGING
ELPP_STACKTRACE
ELPP_FEATURE_CRASH_LOG
ELPP_NO_DEFAULT_LOG_FILE
)
set_target_properties (residue-bin PROPERTIES
VERSION ${RESIDUE_VERSION}
OUTPUT_NAME "residue"
)
target_link_libraries (residue-bin residue-core)
set_target_properties (residue-bin PROPERTIES OUTPUT_NAME "residue")
install (TARGETS residue-bin DESTINATION bin)
#############################################
# Reference all headers, to make certain IDEs happy.
file (GLOB_RECURSE all_headers ${CMAKE_SOURCE_DIR}/*.h)
add_custom_target (all_placeholder SOURCES ${all_headers})
############# RESIDUE TESTS ###############
if (test)
find_package (gtest REQUIRED)
include_directories (${GTEST_INCLUDE_DIRS})
enable_testing()
add_executable (residue-unit-tests
test/main.cc
${DEPS_SRC}
)
target_compile_definitions (residue-unit-tests PUBLIC
ELPP_FEATURE_ALL
ELPP_STL_LOGGING
ELPP_DEFAULT_LOG_FILE="/tmp/logs/residue_unit_tests.log"
ELPP_DEFAULT_LOGGING_FLAGS=4096
)
# Standard linking to gtest stuff.
target_link_libraries (residue-unit-tests ${GTEST_LIBRARIES})
# Extra linking for the project.
target_link_libraries (residue-unit-tests residue-core)
target_link_libraries (residue-unit-tests ${SHARED_REQUIRED_LIBS})
add_test (NAME residueUnitTests COMMAND residue-unit-tests)
endif() ## test