-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathCMakeLists.txt
342 lines (283 loc) · 12.4 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
###############################################################################
# Copyright (c) 2014-2023 libbitcoin-network developers (see COPYING).
#
# GENERATED SOURCE CODE, DO NOT EDIT EXCEPT EXPERIMENTALLY
#
###############################################################################
# libbitcoin-network project configuration.
#------------------------------------------------------------------------------
cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
project(libbitcoin-network LANGUAGES C CXX)
enable_testing()
list( APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/modules" )
include(CheckIncludeFiles)
include(CheckSymbolExists)
include(CheckCXXCompilerFlag)
include(CheckCXXSourceCompiles)
include(CheckLinkerFlag)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
if (MSVC)
set( CANONICAL_LIB_NAME libbitcoin-network )
else ()
set( CANONICAL_LIB_NAME bitcoin-network )
find_package( PkgConfig REQUIRED )
set( prefix "${CMAKE_PREFIX_PATH}" )
set( exec_prefix "\${prefix}" )
set( libdir "\${exec_prefix}/lib" )
set( includedir "\${exec_prefix}/include" )
set( PACKAGE_VERSION "3.8.0" )
set( VERSION "${PACKAGE_VERSION}" )
endif ()
set( CMAKE_CXX_STANDARD 11 )
set( CMAKE_CXX_STANDARD_REQUIRED ON )
# Add compiler options
#------------------------------------------------------------------------------
# Warn on all stuff.
check_cxx_compiler_flag( "-Wall" HAS_FLAG_WALL )
if ( HAS_FLAG_WALL )
add_compile_options( $<$<COMPILE_LANGUAGE:CXX>:-Wall> )
else()
message( FATAL_ERROR "Compiler does not support -Wall" )
endif()
# Warn on extra stuff.
check_cxx_compiler_flag( "-Wextra" HAS_FLAG_WEXTRA )
if ( HAS_FLAG_WEXTRA )
add_compile_options( $<$<COMPILE_LANGUAGE:CXX>:-Wextra> )
else()
message( FATAL_ERROR "Compiler does not support -Wextra" )
endif()
# Be really annoying.
check_cxx_compiler_flag( "-Wpedantic" HAS_FLAG_WPEDANTIC )
if ( HAS_FLAG_WPEDANTIC )
add_compile_options( $<$<COMPILE_LANGUAGE:CXX>:-Wpedantic> )
else()
message( FATAL_ERROR "Compiler does not support -Wpedantic" )
endif()
# Disallow warning on style order of declarations.
check_cxx_compiler_flag( "-Wno-reorder" HAS_FLAG_WNO-REORDER )
if ( HAS_FLAG_WNO-REORDER )
add_compile_options( $<$<COMPILE_LANGUAGE:CXX>:-Wno-reorder> )
else()
message( FATAL_ERROR "Compiler does not support -Wno-reorder" )
endif()
# Suppress warning for incomplete field initialization.
check_cxx_compiler_flag( "-Wno-missing-field-initializers" HAS_FLAG_WNO-MISSING-FIELD-INITIALIZERS )
if ( HAS_FLAG_WNO-MISSING-FIELD-INITIALIZERS )
add_compile_options( $<$<COMPILE_LANGUAGE:CXX>:-Wno-missing-field-initializers> )
else()
message( FATAL_ERROR "Compiler does not support -Wno-missing-field-initializers" )
endif()
# Conform to style.
check_cxx_compiler_flag( "-Wno-missing-braces" HAS_FLAG_WNO-MISSING-BRACES )
if ( HAS_FLAG_WNO-MISSING-BRACES )
add_compile_options( $<$<COMPILE_LANGUAGE:CXX>:-Wno-missing-braces> )
else()
message( FATAL_ERROR "Compiler does not support -Wno-missing-braces" )
endif()
# Ignore comments within comments or commenting of backslash extended lines.
check_cxx_compiler_flag( "-Wno-comment" HAS_FLAG_WNO-COMMENT )
if ( HAS_FLAG_WNO-COMMENT )
add_compile_options( $<$<COMPILE_LANGUAGE:CXX>:-Wno-comment> )
else()
message( FATAL_ERROR "Compiler does not support -Wno-comment" )
endif()
# Suppress warning for copy of implicitly generated copy constructor.
check_cxx_compiler_flag( "-Wno-deprecated-copy" HAS_FLAG_WNO-DEPRECATED-COPY )
if ( HAS_FLAG_WNO-DEPRECATED-COPY )
add_compile_options( $<$<COMPILE_LANGUAGE:CXX>:-Wno-deprecated-copy> )
else()
message( FATAL_ERROR "Compiler does not support -Wno-deprecated-copy" )
endif()
# Conflict in stdlib under clang.
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
check_cxx_compiler_flag( "-Wno-mismatched-tags" HAS_FLAG_WNO-MISMATCHED-TAGS )
if ( HAS_FLAG_WNO-MISMATCHED-TAGS )
add_compile_options( $<$<COMPILE_LANGUAGE:CXX>:-Wno-mismatched-tags> )
else()
message( FATAL_ERROR "Compiler does not support -Wno-mismatched-tags" )
endif()
endif()
# Implement -Dpkgconfigdir and output ${pkgconfigdir}.
#------------------------------------------------------------------------------
set( pkgconfigdir "${libdir}/pkgconfig" CACHE PATH "Path to pkgconfig directory." )
# Implement -Dwith-tests and declare with-tests.
#------------------------------------------------------------------------------
set( with-tests "yes" CACHE BOOL "Compile with unit tests." )
# Implement -Denable-ndebug and define NDEBUG.
#------------------------------------------------------------------------------
set( enable-ndebug "yes" CACHE BOOL "Compile without debug assertions." )
if (enable-ndebug)
add_definitions( -DNDEBUG )
endif()
# Inherit -Denable-shared and define BOOST_ALL_DYN_LINK.
#------------------------------------------------------------------------------
if (BUILD_SHARED_LIBS)
add_definitions( -DBOOST_ALL_DYN_LINK )
endif()
if (BUILD_SHARED_LIBS)
set( Boost_USE_STATIC_LIBS "off" )
else()
set( Boost_USE_STATIC_LIBS "on" )
endif()
# Find boost
#------------------------------------------------------------------------------
find_package( Boost 1.73.0 REQUIRED COMPONENTS
unit_test_framework )
set( boost_unit_test_framework_LIBS "-lboost_unit_test_framework" )
set( Boost_LIBRARY_DIR $<IF:$<BOOL:${enable-ndebug}>,"${Boost_LIBRARY_DIR_RELEASE}","${Boost_LIBRARY_DIR_DEBUG}">)
set( boost_CPPFLAGS "-I${Boost_INCLUDE_DIR}" )
set( boost_LDFLAGS "-L${Boost_LIBRARY_DIR}" )
# Find bitcoin-system
#------------------------------------------------------------------------------
find_package( Bitcoin-System 3.8.0 REQUIRED )
# Define project common includes for build.
#------------------------------------------------------------------------------
if (BUILD_SHARED_LIBS)
set( bitcoin_system_FOR_BUILD_INCLUDE_DIRS ${bitcoin_system_INCLUDE_DIRS} CACHE STRING "Placeholder" )
else()
set( bitcoin_system_FOR_BUILD_INCLUDE_DIRS ${bitcoin_system_STATIC_INCLUDE_DIRS} CACHE STRING "Placeholder" )
endif()
# Define project common includes directories
#------------------------------------------------------------------------------
include_directories( SYSTEM
${bitcoin_system_FOR_BUILD_INCLUDE_DIRS} )
# Define project common library directories for build.
#------------------------------------------------------------------------------
if (BUILD_SHARED_LIBS)
set( bitcoin_system_FOR_BUILD_LIBRARY_DIRS ${bitcoin_system_LIBRARY_DIRS} CACHE STRING "Placeholder" )
else()
set( bitcoin_system_FOR_BUILD_LIBRARY_DIRS ${bitcoin_system_STATIC_LIBRARY_DIRS} CACHE STRING "Placeholder" )
endif()
# Define project common library directories
#------------------------------------------------------------------------------
link_directories(
${bitcoin_system_FOR_BUILD_LIBRARY_DIRS} )
# Define project common linker flags.
#------------------------------------------------------------------------------
check_linker_flag(CXX "-no_fixup_chains" "no_fixup_chains_FOUND")
if (no_fixup_chains_FOUND)
add_link_options("-no_fixup_chains")
endif()
check_linker_flag(CXX "-fstack-protector" "fstack_protector_FOUND")
if (fstack_protector_FOUND)
add_link_options("-fstack-protector")
endif()
check_linker_flag(CXX "-fstack-protector-all" "fstack_protector_all_FOUND")
if (fstack_protector_all_FOUND)
add_link_options("-fstack-protector-all")
endif()
# Define common library usage for build.
#------------------------------------------------------------------------------
if (BUILD_SHARED_LIBS)
set( bitcoin_system_FOR_BUILD_LIBRARIES ${bitcoin_system_LIBRARIES} CACHE STRING "Placeholder" )
else()
set( bitcoin_system_FOR_BUILD_LIBRARIES ${bitcoin_system_STATIC_LIBRARIES} CACHE STRING "Placeholder" )
endif()
# Define project common libraries.
#------------------------------------------------------------------------------
link_libraries(
${bitcoin_system_FOR_BUILD_LIBRARIES} )
# Define ${CANONICAL_LIB_NAME} project.
#------------------------------------------------------------------------------
add_library( ${CANONICAL_LIB_NAME}
"../../src/acceptor.cpp"
"../../src/channel.cpp"
"../../src/connector.cpp"
"../../src/hosts.cpp"
"../../src/message_subscriber.cpp"
"../../src/p2p.cpp"
"../../src/proxy.cpp"
"../../src/settings.cpp"
"../../src/protocols/protocol.cpp"
"../../src/protocols/protocol_address_31402.cpp"
"../../src/protocols/protocol_events.cpp"
"../../src/protocols/protocol_ping_31402.cpp"
"../../src/protocols/protocol_ping_60001.cpp"
"../../src/protocols/protocol_reject_70002.cpp"
"../../src/protocols/protocol_seed_31402.cpp"
"../../src/protocols/protocol_timer.cpp"
"../../src/protocols/protocol_version_31402.cpp"
"../../src/protocols/protocol_version_70002.cpp"
"../../src/sessions/session.cpp"
"../../src/sessions/session_batch.cpp"
"../../src/sessions/session_inbound.cpp"
"../../src/sessions/session_manual.cpp"
"../../src/sessions/session_outbound.cpp"
"../../src/sessions/session_seed.cpp" )
# ${CANONICAL_LIB_NAME} project specific include directory normalization for build.
#------------------------------------------------------------------------------
if (BUILD_SHARED_LIBS)
set( bitcoin_system_FOR_BUILD_INCLUDE_DIRS ${bitcoin_system_INCLUDE_DIRS} CACHE STRING "Placeholder" )
else()
set( bitcoin_system_FOR_BUILD_INCLUDE_DIRS ${bitcoin_system_STATIC_INCLUDE_DIRS} CACHE STRING "Placeholder" )
endif()
# ${CANONICAL_LIB_NAME} project specific include directories.
#------------------------------------------------------------------------------
target_include_directories( ${CANONICAL_LIB_NAME} PRIVATE
"../../include"
${bitcoin_system_FOR_BUILD_INCLUDE_DIRS} )
target_include_directories( ${CANONICAL_LIB_NAME} PUBLIC
"../../include" )
# ${CANONICAL_LIB_NAME} project specific libraries noramalization for build.
#------------------------------------------------------------------------------
if (BUILD_SHARED_LIBS)
set( bitcoin_system_FOR_BUILD_LIBRARIES ${bitcoin_system_LIBRARIES} CACHE STRING "Placeholder" )
else()
set( bitcoin_system_FOR_BUILD_LIBRARIES ${bitcoin_system_STATIC_LIBRARIES} CACHE STRING "Placeholder" )
endif()
# ${CANONICAL_LIB_NAME} project specific libraries/linker flags.
#------------------------------------------------------------------------------
target_link_libraries( ${CANONICAL_LIB_NAME}
${bitcoin_system_FOR_BUILD_LIBRARIES} )
# Define libbitcoin-network-test project.
#------------------------------------------------------------------------------
if (with-tests)
add_executable( libbitcoin-network-test
"../../test/main.cpp"
"../../test/p2p.cpp" )
add_test( NAME libbitcoin-network-test COMMAND libbitcoin-network-test
--run_test=empty_tests
--log_level=warning
--show_progress=no
--detect_memory_leak=0
--report_level=no
--build_info=yes )
# libbitcoin-network-test project specific include directories.
#------------------------------------------------------------------------------
target_include_directories( libbitcoin-network-test PRIVATE
"../../include" )
# libbitcoin-network-test project specific libraries/linker flags.
#------------------------------------------------------------------------------
target_link_libraries( libbitcoin-network-test
${CANONICAL_LIB_NAME}
${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} )
endif()
# Manage pkgconfig installation.
#------------------------------------------------------------------------------
configure_file(
"../../libbitcoin-network.pc.in"
"libbitcoin-network.pc" @ONLY )
install( FILES
"${CMAKE_CURRENT_BINARY_DIR}/libbitcoin-network.pc"
DESTINATION "${pkgconfigdir}" )
# Manage installation of docs.
#------------------------------------------------------------------------------
install( FILES
"../../AUTHORS"
"../../COPYING"
"../../ChangeLog"
"../../INSTALL"
"../../NEWS"
"../../README"
DESTINATION share/doc/libbitcoin-network )
# Manage ${CANONICAL_LIB_NAME} installation.
#------------------------------------------------------------------------------
install( TARGETS ${CANONICAL_LIB_NAME}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
PUBLIC_HEADER DESTINATION include )
# Manage include installation.
#------------------------------------------------------------------------------
install( DIRECTORY "../../include/bitcoin"
DESTINATION include )