-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
438 lines (367 loc) · 16.6 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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
# Build piac
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
project(piac C CXX)
include(ExternalProject)
# Set cmake modules directory
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# Disallow in-source builds
include(DisallowInSourceBuilds)
# Set CMAKE_BUILD_TYPE
include(BuildType)
# Detect operating system type and version
include(DetectOS)
# Set BUILD_SHARED_LIBS
include(BuildShared)
# Sets CMAKE_INSTALL_{BIN,LIB}DIR needed for multilib support
include(GNUInstallDirs)
# Detect compiler version
include(DetectCompilerVersion)
# Get compiler flags
include(get_compiler_flags)
# Query target architecture
include(TargetArch)
# Set compiler id
string(TOLOWER "${CMAKE_CXX_COMPILER_ID}" COMP)
# Set compiler var (will be exported to the source)
set(COMPILER "${CMAKE_CXX_COMPILER}")
# set version
set(VERSION_MAJOR "0")
set(VERSION_MINOR "1")
set(VERSION_PATCH "0")
set(PROJECT_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
# Set the requirement for the C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
message(STATUS "Required language standard: C++${CMAKE_CXX_STANDARD}")
# Set build type (will be exported to the source)
set(BUILD_TYPE ${CMAKE_BUILD_TYPE})
string(TOLOWER "${BUILD_TYPE}" BUILD_TYPE)
# Echo install prefix
message(STATUS "CMAKE_INSTALL_PREFIX: " ${CMAKE_INSTALL_PREFIX})
# Echo number of PEs found
include(ProcessorCount)
ProcessorCount(PROCESSOR_COUNT)
if(PROCESSOR_COUNT EQUAL 0) # if ncpus could not be determined, assign 1
set(PROCESSOR_COUNT "1")
endif()
message(STATUS "Found ${PROCESSOR_COUNT} PEs")
set(PIAC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
macro (add_compiler_flag flag)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
endmacro (add_compiler_flag)
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
add_compiler_flag("-fcolor-diagnostics")
add_compiler_flag("-Weverything")
add_compiler_flag("-Wno-c++98-compat")
add_compiler_flag("-Wno-exit-time-destructors")
add_compiler_flag("-Wno-global-constructors")
add_compiler_flag("-Wno-ctad-maybe-unsupported")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compiler_flag("-fdiagnostics-color")
add_compiler_flag("-Wall")
add_compiler_flag("-Wextra")
endif()
# Echo compiler flags
message(STATUS "C compiler flags: '${CMAKE_C_FLAGS}'")
message(STATUS "C++ compiler flags: '${CMAKE_CXX_FLAGS}'")
message(STATUS "Executable linker flags: '${CMAKE_EXE_LINKER_FLAGS}'")
#### piac external libraries
# Set external libraries install directory
if (NOT TPL_DIR)
set(REL_TPL_DIR ${PROJECT_SOURCE_DIR}/external/install/${COMP}-${ARCH})
get_filename_component(ABS_TPL_DIR ${REL_TPL_DIR} ABSOLUTE)
set(TPL_DIR ${ABS_TPL_DIR} CACHE
STRING "Third-party (external) libraries install directory.")
endif()
message(STATUS "Third-party (external) libraries install directory: " ${TPL_DIR})
# Add our TPL_DIR to modules directory
set(CMAKE_PREFIX_PATH ${TPL_DIR} ${CMAKE_PREFIX_PATH})
# Find monero
find_library(MONEROCPP_LIBRARIES libmonero-cpp.so ${TPL_DIR}/lib)
# Find threads
find_package(Threads REQUIRED)
# Find readline
find_package(Readline REQUIRED)
# Find zmqpp
set(zmqpp_dir ${TPL_DIR})
find_package(ZMQPP REQUIRED)
# Find Xapian
find_package(Xapian REQUIRED)
# Find Boost
find_package(Boost REQUIRED COMPONENTS filesystem serialization)
# Use monero's easylogging++
set(EASYLOGGINGPP_LIBRARIES ${TPL_DIR}/lib/libeasylogging.a
${TPL_DIR}/lib/libepee.a
${Boost_FILESYSTEM_LIBRARY})
# Find RapidJSON
find_package(RapidJSON REQUIRED)
# Find Crypto++
find_package(cryptopp REQUIRED)
# Find OpenSSL
find_package(OpenSSL REQUIRED)
# Find mtxclient
find_package(coeurl REQUIRED)
find_package(spdlog 1.0.0 CONFIG REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(libcurl REQUIRED IMPORTED_TARGET libcurl)
pkg_check_modules(libevent_core REQUIRED IMPORTED_TARGET libevent_core)
pkg_check_modules(libevent_pthreads REQUIRED IMPORTED_TARGET libevent_pthreads)
find_package(Olm 3.2.7 REQUIRED)
find_package(nlohmann_json 3.2.0 REQUIRED)
find_package(MatrixClient REQUIRED)
# Find Python: required for code coverage (fastcov) and doc (m.css)
find_package(PythonInterp 3.6)
# Attempt to find tools required for code coverage analysis
include(DetectCodeCoverage)
# Set compiler flags to perform code coverage analysis
if(CODE_COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage ")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
endif()
#### piac
set(EXECUTABLES)
add_library(db ${PIAC_SOURCE_DIR}/db.cpp)
target_include_directories(db PUBLIC ${PIAC_SOURCE_DIR}
${TPL_DIR}/include
${RAPIDJSON_INCLUDE_DIRS}
${cryptopp_INCLUDE_DIRS})
set_target_properties(db PROPERTIES LIBRARY_OUTPUT_NAME piac_db)
install(TARGETS db
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Runtime
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Development)
add_library(document ${PIAC_SOURCE_DIR}/document.cpp
${PIAC_SOURCE_DIR}/jsonbase.cpp)
target_include_directories(document PUBLIC ${PIAC_SOURCE_DIR}
${TPL_DIR}/include
${RAPIDJSON_INCLUDE_DIRS}
${cryptopp_INCLUDE_DIRS})
set_target_properties(document PROPERTIES LIBRARY_OUTPUT_NAME piac_document)
install(TARGETS document
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Runtime
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Development)
add_library(logging_util ${PIAC_SOURCE_DIR}/logging_util.cpp)
target_include_directories(logging_util PUBLIC ${PIAC_SOURCE_DIR}
${TPL_DIR}/include)
set_target_properties(logging_util
PROPERTIES LIBRARY_OUTPUT_NAME piac_logging_util)
install(TARGETS logging_util
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Runtime
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Development)
add_library(crypto_util ${PIAC_SOURCE_DIR}/crypto_util.cpp)
target_include_directories(crypto_util PUBLIC ${PIAC_SOURCE_DIR}
${cryptopp_INCLUDE_DIRS})
set_target_properties(crypto_util
PROPERTIES LIBRARY_OUTPUT_NAME piac_crypto_util)
install(TARGETS crypto_util
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Runtime
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Development)
add_library(string_util ${PIAC_SOURCE_DIR}/string_util.cpp)
target_include_directories(string_util PUBLIC ${PIAC_SOURCE_DIR})
set_target_properties(string_util
PROPERTIES LIBRARY_OUTPUT_NAME piac_string_util)
install(TARGETS string_util
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Runtime
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Development)
add_library(zmq_util ${PIAC_SOURCE_DIR}/zmq_util.cpp)
target_include_directories(zmq_util PUBLIC
${PIAC_SOURCE_DIR}
${ZMQPP_INCLUDE_DIRS})
set_target_properties(zmq_util
PROPERTIES LIBRARY_OUTPUT_NAME piac_zmq_util)
install(TARGETS zmq_util
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Runtime
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Development)
add_library(monero_util ${PIAC_SOURCE_DIR}/monero_util.cpp)
target_include_directories(monero_util PUBLIC
${PIAC_SOURCE_DIR}
${TPL_DIR}/include
${TPL_DIR}/include/common
${TPL_DIR}/include/crypto
${TPL_DIR}/include/utils
${TPL_DIR}/include/storages)
set_target_properties(monero_util
PROPERTIES LIBRARY_OUTPUT_NAME piac_monero_util)
install(TARGETS monero_util
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Runtime
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Development)
add_library(daemon_p2p_thread ${PIAC_SOURCE_DIR}/daemon_p2p_thread.cpp)
target_include_directories(daemon_p2p_thread PUBLIC
${PIAC_SOURCE_DIR}
${ZMQPP_INCLUDE_DIRS})
set_target_properties(daemon_p2p_thread PROPERTIES
LIBRARY_OUTPUT_NAME piac_daemon_p2p_thread)
install(TARGETS daemon_p2p_thread
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Runtime
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Development)
add_library(daemon_db_thread ${PIAC_SOURCE_DIR}/daemon_db_thread.cpp)
target_include_directories(daemon_db_thread PUBLIC
${PIAC_SOURCE_DIR}
${ZMQPP_INCLUDE_DIRS})
set_target_properties(daemon_db_thread PROPERTIES
LIBRARY_OUTPUT_NAME piac_daemon_db_thread)
install(TARGETS daemon_db_thread
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Runtime
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Development)
add_library(cli_matrix_thread ${PIAC_SOURCE_DIR}/cli_matrix_thread.cpp)
target_include_directories(cli_matrix_thread PUBLIC
${PIAC_SOURCE_DIR}
${TPL_DIR}/include)
set_target_properties(cli_matrix_thread PROPERTIES LIBRARY_OUTPUT_NAME
piac_cli_matrix_thread)
install(TARGETS cli_matrix_thread
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Runtime
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Development)
add_library(cli_message_thread ${PIAC_SOURCE_DIR}/cli_message_thread.cpp)
target_include_directories(cli_message_thread PUBLIC
${PIAC_SOURCE_DIR}
${TPL_DIR}/include)
set_target_properties(cli_message_thread PROPERTIES LIBRARY_OUTPUT_NAME
piac_cli_message_thread)
install(TARGETS cli_message_thread
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Runtime
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Development)
# configure piac daemon executable
set(DAEMON_EXECUTABLE "piac-daemon")
add_executable(${DAEMON_EXECUTABLE}
${CMAKE_BINARY_DIR}/project_config.cpp
${PIAC_SOURCE_DIR}/daemon.cpp)
target_include_directories(${DAEMON_EXECUTABLE} PUBLIC
${PIAC_SOURCE_DIR}
${TPL_DIR}/include
${ZMQPP_INCLUDE_DIRS}
${PROJECT_BINARY_DIR})
target_link_libraries(${DAEMON_EXECUTABLE}
daemon_db_thread
daemon_p2p_thread
db
document
logging_util
string_util
crypto_util
zmq_util
${XAPIAN_LIBRARIES}
${ZMQPP_LIBRARIES}
${EASYLOGGINGPP_LIBRARIES}
Threads::Threads
cryptopp::cryptopp)
install(TARGETS ${DAEMON_EXECUTABLE}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Runtime
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Development)
message(STATUS "Target ${DAEMON_EXECUTABLE} configured")
list(APPEND EXECUTABLES ${DAEMON_EXECUTABLE})
# configure piac cli executable
set(CLI_EXECUTABLE "piac-cli")
add_executable(${CLI_EXECUTABLE}
${CMAKE_BINARY_DIR}/project_config.cpp
${PIAC_SOURCE_DIR}/cli.cpp)
target_include_directories(${CLI_EXECUTABLE} PUBLIC
${PIAC_SOURCE_DIR}
${PROJECT_BINARY_DIR})
target_link_libraries(${CLI_EXECUTABLE} PRIVATE
cli_matrix_thread
cli_message_thread
logging_util
string_util
monero_util
crypto_util
zmq_util
${ZMQPP_LIBRARIES}
${Readline_LIBRARY}
${Boost_SERIALIZATION_LIBRARY}
${OPENSSL_CRYPTO_LIBRARIES}
${EASYLOGGINGPP_LIBRARIES}
${MONEROCPP_LIBRARIES}
MatrixClient::MatrixClient
cryptopp::cryptopp
Threads::Threads)
install(TARGETS ${CLI_EXECUTABLE}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Runtime
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Development)
message(STATUS "Target ${CLI_EXECUTABLE} configured")
list(APPEND EXECUTABLES ${CLI_EXECUTABLE})
#### Testing
option(ENABLE_TESTS "Enable tests" ON)
if (NOT ENABLE_TESTS)
message(STATUS "Tests disabled")
else()
enable_testing()
add_subdirectory(${PROJECT_SOURCE_DIR}/test)
list(APPEND EXECUTABLES kill_daemon rnd_json_entry pirate_server)
endif()
# Grab current date to stick into the executables
execute_process(COMMAND "date" "--utc" OUTPUT_VARIABLE BUILD_DATE)
string(REGEX REPLACE "[\r\n]" "" BUILD_DATE "${BUILD_DATE}")
execute_process(COMMAND "date" "+%A, %b %d, %Y"
OUTPUT_VARIABLE BUILD_DATE_SIMPLE)
string(REGEX REPLACE "[\r\n]" "" BUILD_DATE_SIMPLE "${BUILD_DATE_SIMPLE}")
# Configure cmake variables to pass to the build
configure_file( "${PIAC_SOURCE_DIR}/project_config.hpp.in"
"${PROJECT_BINARY_DIR}/project_config.hpp" )
configure_file( "${PIAC_SOURCE_DIR}/project_config.cpp.in"
"${PROJECT_BINARY_DIR}/project_config.cpp" )
# configure zmq curve certificate generator executable
add_executable(curve_keygen ${PIAC_SOURCE_DIR}/curve_keygen.cpp)
list(APPEND EXECUTABLES curve_keygen)
target_include_directories(curve_keygen PUBLIC ${ZMQPP_INCLUDE_DIRS})
target_link_libraries(curve_keygen PRIVATE ${ZMQPP_LIBRARIES})
# Configure building documentation and web page
find_package(Doxygen 1.8.15)
find_package(MCSS)
if (DOXYGEN_FOUND AND MCSS_FOUND AND PYTHONINTERP_FOUND AND PYGMENTS_FOUND AND
JINJA2_FOUND)
find_program( PERL perl )
find_program( AWK awk )
find_program( XARGS xargs )
find_program( HEAD head )
if (PERL AND AWK AND XARGS AND HEAD)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/piac.doxy
${CMAKE_CURRENT_BINARY_DIR}/doc/piac.doxy @ONLY)
file(GLOB doc_pages CONFIGURE_DEPENDS
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "doc/pages/*.dox")
foreach(page ${doc_pages})
configure_file(${page} ${CMAKE_CURRENT_BINARY_DIR}/${page} @ONLY)
endforeach()
file(COPY doc/images DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/doc/html)
add_custom_command(OUTPUT xml
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/doc/piac.doxy
COMMAND ${DOXYGEN_EXECUTABLE} piac.doxy
COMMAND ${MCSS_DOX2HTML5} --no-doxygen piac.doxy
VERBATIM USES_TERMINAL)
add_custom_target(doc DEPENDS xml
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc
COMMENT "Documentation")
message(STATUS "Add target 'doc' to generate documentation to ./doc/html/index.html")
endif()
endif()
# Setup code coverage targets
if(CODE_COVERAGE)
# Determine number of CPUs available
if (DEFINED ENV{SLURM_NPROCS})
set(PROCESSOR_COUNT $ENV{SLURM_NPROCS})
else()
include(ProcessorCount)
ProcessorCount(PROCESSOR_COUNT)
if(PROCESSOR_COUNT EQUAL 0) # if ncpus could not be determined, assign 1
set(PROCESSOR_COUNT "1")
endif()
endif()
message(STATUS "Found ${PROCESSOR_COUNT} PEs")
include(CppCheck)
include(CodeCoverage)
setup_target_for_coverage(doc/html/${CMAKE_BUILD_TYPE} test_coverage
DEPENDS ${EXECUTABLES})
endif()