forked from nanocurrency/nano-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
959 lines (859 loc) · 27.9 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
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
cmake_minimum_required(VERSION 3.14)
if(CMAKE_VERSION VERSION_GREATER 3.12 OR CMAKE_VERSION VERSION_EQUAL 3.12)
# find_package uses <PACKAGENAME>_ROOT variables
cmake_policy(SET CMP0074 NEW)
endif()
if(CMAKE_VERSION VERSION_GREATER 3.13 OR CMAKE_VERSION VERSION_EQUAL 3.13)
# option honors normal variables
cmake_policy(SET CMP0077 NEW)
endif()
# OSX compatibility needs to be set before project is declared
set(CMAKE_OSX_DEPLOYMENT_TARGET
13.3
CACHE STRING "")
project(nano-node)
# Get the latest abbreviated commit hash of the working branch
execute_process(
COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE)
option(CI_VERSION_PRE_RELEASE false)
set(COVERAGE
OFF
CACHE BOOL "Code Coverage Targets")
if(COVERAGE)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules")
include(CoverageTest)
endif()
if(MSVC)
add_definitions(/MP)
endif()
set(CPACK_PACKAGE_VENDOR "Nano Currency")
set(CPACK_PACKAGE_VERSION_MAJOR "28")
set(CPACK_PACKAGE_VERSION_MINOR "0")
set(CPACK_PACKAGE_VERSION_PATCH "0")
if(CI_VERSION_PRE_RELEASE)
set(CPACK_PACKAGE_VERSION_PRE_RELEASE "${CI_VERSION_PRE_RELEASE}")
else()
set(CPACK_PACKAGE_VERSION_PRE_RELEASE "99")
endif()
if(CI_TAG)
set(TAG_VERSION_STRING "${CI_TAG}")
else()
set(TAG_VERSION_STRING
"V${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")
endif()
if(APPLE)
set(CMAKE_INSTALL_RPATH "@executable_path/../Frameworks")
else()
set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib")
endif()
# Create all libraries and executables in the root binary dir
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR})
set(NANO_GUI
OFF
CACHE BOOL "")
set(NANO_TEST
OFF
CACHE BOOL "")
set(NANO_SECURE_RPC
OFF
CACHE BOOL "")
set(NANO_WARN_TO_ERR
OFF
CACHE BOOL "")
set(NANO_TIMED_LOCKS
0
CACHE STRING "")
set(NANO_TIMED_LOCKS_IGNORE_BLOCKED
OFF
CACHE BOOL "")
set(NANO_TIMED_LOCKS_FILTER
""
CACHE
STRING
"Selects which mutex should be the only one to have stacktraces generated, empty string means report on all"
)
set_property(
CACHE NANO_TIMED_LOCKS_FILTER
PROPERTY STRINGS
active
block_arrival
block_processor
block_uniquer
dropped_elections,
election_winner_details
gap_cache
network_filter
observer_set
request_aggregator
state_block_signature_verification
telemetry
vote_generator
vote_processor
vote_uniquer
votes_cache
work_pool)
set(NANO_FUZZER_TEST
OFF
CACHE BOOL "")
set(NANO_ASIO_HANDLER_TRACKING
0
CACHE STRING "")
set(NANO_ROCKSDB_TOOLS
OFF
CACHE BOOL "")
option(NANO_STACKTRACE_BACKTRACE
"Use BOOST_STACKTRACE_USE_BACKTRACE in stacktraces, for POSIX" OFF)
if(NANO_STACKTRACE_BACKTRACE)
add_definitions(-DNANO_STACKTRACE_BACKTRACE)
add_definitions(-DBOOST_STACKTRACE_USE_BACKTRACE)
if(NANO_BACKTRACE_INCLUDE)
add_definitions(
-DBOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE=${NANO_BACKTRACE_INCLUDE})
endif()
endif()
# Enable NANO_TRACING by default in Debug builds
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
option(NANO_TRACING "Enable trace logging" ON)
else()
option(NANO_TRACING "Enable trace logging" OFF)
endif()
if(NANO_TRACING)
message(STATUS "Using trace logging")
add_compile_definitions(NANO_TRACING)
endif()
if(${NANO_TIMED_LOCKS} GREATER 0)
add_definitions(-DNANO_TIMED_LOCKS=${NANO_TIMED_LOCKS})
add_definitions(-DNANO_TIMED_LOCKS_FILTER=${NANO_TIMED_LOCKS_FILTER})
if(NANO_TIMED_LOCKS_IGNORE_BLOCKED)
add_definitions(-DNANO_TIMED_LOCKS_IGNORE_BLOCKED)
endif()
endif()
if(${NANO_ASIO_HANDLER_TRACKING} GREATER 0)
add_definitions(-DNANO_ASIO_HANDLER_TRACKING=${NANO_ASIO_HANDLER_TRACKING}
-DBOOST_ASIO_ENABLE_HANDLER_TRACKING)
endif()
option(NANO_SIMD_OPTIMIZATIONS
"Enable CPU-specific SIMD optimizations (SSE/AVX or NEON, e.g.)" OFF)
option(
ENABLE_AES
"Enable AES optimizations (enabled by default with NANO_SIMD_OPTIMIZATIONS, set OFF to disable"
ON)
option(ENABLE_AVX2 "Enable AVX2 optimizations" OFF)
set(ACTIVE_NETWORK
nano_live_network
CACHE STRING "Selects which network parameters are used")
set_property(
CACHE ACTIVE_NETWORK PROPERTY STRINGS nano_dev_network nano_beta_network
nano_live_network nano_test_network)
set(CPACK_PACKAGE_NAME
"nano-node"
CACHE STRING "" FORCE)
set(CPACK_NSIS_PACKAGE_NAME
"Nano"
CACHE STRING "" FORCE)
set(CPACK_PACKAGE_INSTALL_DIRECTORY
"nanocurrency"
CACHE STRING "" FORCE)
set(NANO_SERVICE "nanocurrency.service")
set(NANO_PREFIX "")
if("${ACTIVE_NETWORK}" MATCHES "nano_beta_network")
project("nano-node-beta")
set(CPACK_PACKAGE_NAME
"nano-node-beta"
CACHE STRING "" FORCE)
set(CPACK_NSIS_PACKAGE_NAME
"Nano-Beta"
CACHE STRING "" FORCE)
set(CPACK_PACKAGE_INSTALL_DIRECTORY
"nanocurrency-beta"
CACHE STRING "" FORCE)
set(NANO_SERVICE "nanocurrency-beta.service")
set(NANO_PREFIX "Beta")
elseif("${ACTIVE_NETWORK}" MATCHES "nano_test_network")
project("nano-node-test")
set(CPACK_PACKAGE_NAME
"nano-node-test"
CACHE STRING "" FORCE)
set(CPACK_NSIS_PACKAGE_NAME
"Nano-Test"
CACHE STRING "" FORCE)
set(CPACK_PACKAGE_INSTALL_DIRECTORY
"nanocurrency-test"
CACHE STRING "" FORCE)
set(NANO_SERVICE "nanocurrency-test.service")
set(NANO_PREFIX "Test")
endif()
set(NANO_OSX_PACKAGE_NAME
${CPACK_NSIS_PACKAGE_NAME}
CACHE STRING "" FORCE)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE
"Release"
CACHE
STRING
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
FORCE)
endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
find_package(Threads)
# Sanitizers
option(NANO_ASAN "Enable ASan" OFF)
if(NANO_ASAN)
if(MSVC)
message(FATAL_ERROR "ASan is not supported on MSVC")
endif()
message(STATUS "Using Asan")
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(
"-fsanitize-ignorelist=${PROJECT_SOURCE_DIR}/sanitize_ignorelist_asan")
add_link_options(
"-fsanitize-ignorelist=${PROJECT_SOURCE_DIR}/sanitize_ignorelist_asan")
endif()
add_definitions(-DED25519_NO_INLINE_ASM)
endif()
option(NANO_ASAN_INT "Enable ASan+Integer overflow" OFF)
if(NANO_ASAN_INT)
if(MSVC)
message(FATAL_ERROR "ASan+Integer overflow is not supported on MSVC")
endif()
message(STATUS "Using ASan+Integer overflow")
add_compile_options(-fsanitize=address,integer)
add_link_options(-fsanitize=address,integer)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(
"-fsanitize-ignorelist=${PROJECT_SOURCE_DIR}/sanitize_ignorelist_asan")
add_link_options(
"-fsanitize-ignorelist=${PROJECT_SOURCE_DIR}/sanitize_ignorelist_asan")
endif()
add_definitions(-DED25519_NO_INLINE_ASM)
endif()
option(NANO_UBSAN "Enable UBSan" OFF)
if(NANO_UBSAN)
if(MSVC)
message(FATAL_ERROR "UBSan is not supported on MSVC")
endif()
message(STATUS "Using UBSan")
add_compile_options(-fsanitize=undefined)
add_link_options(-fsanitize=undefined)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(
"-fsanitize-ignorelist=${PROJECT_SOURCE_DIR}/sanitize_ignorelist_ubsan")
add_link_options(
"-fsanitize-ignorelist=${PROJECT_SOURCE_DIR}/sanitize_ignorelist_ubsan")
endif()
add_definitions(-DED25519_NO_INLINE_ASM)
add_definitions(-DROCKSDB_UBSAN_RUN)
endif()
option(NANO_TSAN "Enable TSan" OFF)
if(NANO_TSAN)
if(MSVC)
message(FATAL_ERROR "TSan is not supported on MSVC")
endif()
message(STATUS "Using TSan")
add_compile_options(-fsanitize=thread)
add_link_options(-fsanitize=thread)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(
"-fsanitize-ignorelist=${PROJECT_SOURCE_DIR}/sanitize_ignorelist_tsan")
add_link_options(
"-fsanitize-ignorelist=${PROJECT_SOURCE_DIR}/sanitize_ignorelist_tsan")
endif()
add_definitions(-DED25519_NO_INLINE_ASM)
endif()
if(NANO_WARN_TO_ERR)
add_compile_options(-Werror -Wno-deprecated-declarations)
endif()
if(WIN32)
find_library(PSAPI Psapi)
add_definitions(-D_WIN32_WINNT=0x0600 -DWINVER=0x0600 -DMINIUPNP_STATICLIB
-D_CRT_SECURE_NO_WARNINGS -DNOGDI /EHsc)
else()
if(NANO_FUZZER_TEST)
add_compile_options(-fsanitize=fuzzer-no-link -fno-omit-frame-pointer)
add_definitions(-DNANO_FUZZER_TEST)
endif()
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(i.86|x86(_64)?)$")
if(NANO_SIMD_OPTIMIZATIONS
OR RAIBLOCKS_SIMD_OPTIMIZATIONS
OR ENABLE_AVX2)
add_compile_options(-msse4)
if(ENABLE_AES)
add_compile_options(-maes)
else()
add_definitions(-DCRYPTOPP_DISABLE_AESNI)
endif()
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
add_compile_options(-msse2)
add_definitions(-DCRYPTOPP_DISABLE_SSSE3 -DCRYPTOPP_DISABLE_AESNI)
endif()
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
if(NANO_SIMD_OPTIMIZATIONS OR RAIBLOCKS_SIMD_OPTIMIZATIONS)
add_compile_options(-march=armv8-a+crc+crypto)
else()
add_compile_options(-march=armv8-a)
add_definitions(-DCRYPTOPP_DISABLE_ASM)
endif()
endif()
endif()
if(ENABLE_AVX2)
if(WIN32)
add_definitions(/arch:AVX2)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(i.86|x86(_64)?)$")
add_compile_options(-mavx2 -mbmi -mbmi2 -maes)
endif()
if(PERMUTE_WITH_GATHER)
add_definitions(-DPERMUTE_WITH_GATHER)
elseif(PERMUTE_WITH_SHUFFLES)
add_definitions(-DPERMUTE_WITH_SHUFFLES)
endif()
endif()
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
# set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# set(CMAKE_CXX_EXTENSIONS OFF)
if(WIN32)
set(PLATFORM_LINK_FLAGS "")
add_definitions(/bigobj)
else()
if(APPLE)
set(PLATFORM_LINK_FLAGS "-framework Foundation -framework OpenCL")
else()
set(PLATFORM_LINK_FLAGS "-static-libgcc -static-libstdc++")
endif()
if(NANO_FUZZER_TEST)
set(PLATFORM_LINK_FLAGS "${PLATFORM_LINK_FLAGS} -fsanitize=fuzzer-no-link")
endif()
endif()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PLATFORM_LINK_FLAGS}")
if(NANO_SECURE_RPC OR RAIBLOCKS_SECURE_RPC)
find_package(OpenSSL 1.0 REQUIRED)
include_directories(${OPENSSL_INCLUDE_DIR})
add_definitions(-DNANO_SECURE_RPC)
message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}")
message("OpenSSL libraries: ${OPENSSL_LIBRARIES}")
message("OpenSSL lib: ${OPENSSL_SSL_LIBRARY}")
message("Crypto lib: ${OPENSSL_CRYPTO_LIBRARY}")
else()
set(OPENSSL_LIBRARIES "")
endif()
include_directories(${CMAKE_SOURCE_DIR})
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules")
set(Boost_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/submodules/boost/libs/config/include)
set(BOOST_MODULE_LIBS
algorithm
align
any
array
asio
assert
atomic
beast
bind
chrono
circular_buffer
concept_check
config
container
container_hash
context
conversion
core
coroutine
date_time
describe
detail
dll
dynamic_bitset
endian
exception
filesystem
foreach
format
function
function_types
functional
fusion
integer
interprocess
intrusive
io
iostreams
iterator
lexical_cast
property_tree
lambda
log
logic
math
move
mp11
mpl
multi_index
multiprecision
numeric/conversion
optional
parameter
phoenix
pool
predef
preprocessor
process
program_options
proto
random
range
ratio
rational
regex
scope
scope_exit
serialization
smart_ptr
spirit
stacktrace
static_assert
static_string
system
test
thread
throw_exception
tokenizer
tuple
type_index
type_traits
typeof
unordered
utility
variant
variant2
winapi)
add_definitions(-DBOOST_ALL_NO_LIB) # Disable automatic boost linking
foreach(lib IN LISTS BOOST_MODULE_LIBS)
add_subdirectory(submodules/boost/libs/${lib} EXCLUDE_FROM_ALL)
endforeach()
include_directories(${BOOST_LIBRARY_INCLUDES})
add_library(Boost::stacktrace ALIAS boost_stacktrace_basic)
add_definitions(-DBOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED)
# Workaround for missing reference errata in the boost property_tree module
target_link_libraries(boost_property_tree INTERFACE Boost::any)
target_link_libraries(boost_property_tree INTERFACE Boost::format)
target_link_libraries(boost_property_tree INTERFACE Boost::multi_index)
# RocksDB
include_directories(submodules/rocksdb/include)
set(USE_RTTI
ON
CACHE BOOL "")
set(WITH_GFLAGS
OFF
CACHE BOOL "")
set(WITH_TESTS
OFF
CACHE BOOL "")
set(WITH_BENCHMARK_TOOLS
OFF
CACHE BOOL "")
set(ROCKSDB_BUILD_SHARED
OFF
CACHE BOOL "")
set(WITH_CORE_TOOLS
${NANO_ROCKSDB_TOOLS}
CACHE BOOL "" FORCE)
set(WITH_TOOLS
${NANO_ROCKSDB_TOOLS}
CACHE BOOL "" FORCE)
if(ENABLE_AVX2)
set(PORTABLE
0
CACHE BOOL "" FORCE)
else()
set(PORTABLE
1
CACHE BOOL "" FORCE)
endif()
add_subdirectory(submodules/rocksdb EXCLUDE_FROM_ALL)
# cpptoml
include_directories(submodules/cpptoml/include)
# magic_enum
include_directories(submodules/magic_enum/include/magic_enum)
add_subdirectory(crypto/ed25519-donna)
add_subdirectory(nano/ipc_flatbuffers_lib)
add_subdirectory(nano/ipc_flatbuffers_test)
# fmt
add_subdirectory(submodules/fmt EXCLUDE_FROM_ALL)
include_directories(submodules/fmt/include)
# spdlog
add_definitions(-DSPDLOG_FMT_EXTERNAL)
add_subdirectory(submodules/spdlog EXCLUDE_FROM_ALL)
include_directories(submodules/spdlog/include)
# miniupnp
set(UPNPC_BUILD_SHARED
OFF
CACHE BOOL "")
add_subdirectory(submodules/miniupnp/miniupnpc EXCLUDE_FROM_ALL)
set(BUILD_SHARED
OFF
CACHE BOOL "")
set(BUILD_TESTING
OFF
CACHE BOOL "")
set(USE_INTERMEDIATE_OBJECTS_TARGET
OFF
CACHE BOOL "")
set(CRYPTOPP_EXTRA "")
if(WIN32)
add_definitions(-DCRYPTOPP_DISABLE_ASM -DCRYPTOPP_DISABLE_SSSE3
-DCRYPTOPP_DISABLE_AESNI)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64"
AND (NANO_SIMD_OPTIMIZATIONS OR RAIBLOCKS_SIMD_OPTIMIZATIONS))
set(CRYPTOPP_EXTRA
submodules/cryptopp/crc_simd.cpp submodules/cryptopp/gcm_simd.cpp
submodules/cryptopp/gf2n_simd.cpp submodules/cryptopp/neon_simd.cpp)
add_definitions(-DCRYPTOPP_NO_CPU_FEATURE_PROBES)
endif()
# Some Clang cannot handle mixed asm with positional arguments, where the body
# is Intel style with no prefix and the templates are AT&T style. See:
# submodules/cryptopp/config.h Also see
# https://bugs.llvm.org/show_bug.cgi?id=39895
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_definitions(-DCRYPTOPP_DISABLE_MIXED_ASM -DCRYPTOPP_DISABLE_ASM)
message(
STATUS
"CryptoPP with disabled ASM for ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}"
)
endif()
add_definitions(-DCRYPTOPP_DISABLE_SHANI)
# Fix failing builds after commit
# https://github.com/weidai11/cryptopp/commit/df9fa62205f2d341e2b1b26595a3a1b6377c60c5
add_definitions(-DCRYPTOPP_DISABLE_CLMUL)
set(CRYPTOPP_LIBRARY cryptopp)
add_library(
cryptopp
submodules/cryptopp/aes.h
submodules/cryptopp/algparam.cpp
submodules/cryptopp/allocate.cpp
submodules/cryptopp/asn.cpp
submodules/cryptopp/basecode.cpp
submodules/cryptopp/cpu.cpp
submodules/cryptopp/cryptlib.cpp
submodules/cryptopp/default.cpp
submodules/cryptopp/des.cpp
submodules/cryptopp/dessp.cpp
submodules/cryptopp/dll.cpp
submodules/cryptopp/ec2n.cpp
submodules/cryptopp/ecp.cpp
submodules/cryptopp/filters.cpp
submodules/cryptopp/fips140.cpp
submodules/cryptopp/gcm.cpp
submodules/cryptopp/gf2n.cpp
submodules/cryptopp/gfpcrypt.cpp
submodules/cryptopp/hex.cpp
submodules/cryptopp/hmac.cpp
submodules/cryptopp/hrtimer.cpp
submodules/cryptopp/integer.cpp
submodules/cryptopp/iterhash.cpp
submodules/cryptopp/misc.h
submodules/cryptopp/misc.cpp
submodules/cryptopp/modes.h
submodules/cryptopp/modes.cpp
submodules/cryptopp/mqueue.cpp
submodules/cryptopp/nbtheory.cpp
submodules/cryptopp/oaep.cpp
submodules/cryptopp/osrng.h
submodules/cryptopp/osrng.cpp
submodules/cryptopp/pubkey.cpp
submodules/cryptopp/queue.cpp
submodules/cryptopp/randpool.cpp
submodules/cryptopp/rdtables.cpp
submodules/cryptopp/rijndael.cpp
submodules/cryptopp/rijndael_simd.cpp
submodules/cryptopp/rng.cpp
submodules/cryptopp/sha.cpp
submodules/cryptopp/sha_simd.cpp
submodules/cryptopp/simple.cpp
submodules/cryptopp/sse_simd.cpp
submodules/cryptopp/seckey.h
submodules/cryptopp/siphash.h
submodules/cryptopp/words.h
${CRYPTOPP_EXTRA})
target_include_directories(cryptopp PUBLIC submodules)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(i.86|x86(_64)?)$")
set(ARGON_CORE submodules/phc-winner-argon2/src/opt.c)
else()
set(ARGON_CORE submodules/phc-winner-argon2/src/ref.c)
endif()
add_library(
argon2
submodules/phc-winner-argon2/src/argon2.c
submodules/phc-winner-argon2/include/argon2.h
submodules/phc-winner-argon2/src/core.c
submodules/phc-winner-argon2/src/thread.c
submodules/phc-winner-argon2/src/encoding.c
${ARGON_CORE})
target_include_directories(argon2 PUBLIC submodules/phc-winner-argon2/include)
target_include_directories(argon2 PUBLIC submodules/phc-winner-argon2/src)
target_include_directories(argon2 PUBLIC crypto/blake2)
add_library(
lmdb
submodules/lmdb/libraries/liblmdb/lmdb.h
submodules/lmdb/libraries/liblmdb/mdb.c
submodules/lmdb/libraries/liblmdb/midl.c)
if(WIN32)
target_link_libraries(lmdb ntdll)
endif()
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(i.86|x86(_64)?)$")
set(BLAKE2_IMPLEMENTATION "crypto/blake2/blake2b.c")
else()
set(BLAKE2_IMPLEMENTATION "crypto/blake2/blake2b-ref.c")
endif()
add_library(blake2 crypto/blake2/blake2-config.h crypto/blake2/blake2-impl.h
crypto/blake2/blake2.h ${BLAKE2_IMPLEMENTATION})
target_compile_definitions(blake2 PRIVATE -D__SSE2__)
add_subdirectory(nano/crypto_lib)
add_subdirectory(nano/secure)
add_subdirectory(nano/store)
target_include_directories(nano_store PUBLIC ${BOOST_LIBRARY_INCLUDES})
target_include_directories(nano_store PUBLIC submodules)
add_subdirectory(nano/lib)
add_subdirectory(nano/node)
add_subdirectory(nano/nano_node)
add_subdirectory(nano/rpc)
add_subdirectory(nano/nano_rpc)
add_custom_target(
executables
COMMAND echo "BATCH BUILDING node + rpc"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS nano_node nano_rpc)
if(NANO_FUZZER_TEST)
if(NOT WIN32)
add_subdirectory(nano/fuzzer_test)
else()
message(WARNING "Fuzzing is not supported on Windows")
endif()
endif()
if(NANO_TEST OR RAIBLOCKS_TEST)
if(WIN32)
if(MSVC_VERSION)
if(MSVC_VERSION GREATER_EQUAL 1910)
add_definitions(-DGTEST_LANG_CXX11=1)
add_definitions(-DGTEST_HAS_TR1_TUPLE=0)
endif()
endif()
set(gtest_force_shared_crt ON)
else()
set(gtest_force_shared_crt OFF)
endif()
add_subdirectory(nano/load_test)
# FIXME: This fixes googletest GOOGLETEST_VERSION requirement
set(GOOGLETEST_VERSION 1.11.0)
add_subdirectory(submodules/gtest/googletest)
# FIXME: This fixes gtest include directories without modifying gtest's
# CMakeLists.txt. Ideally we should use GTest::GTest and GTest::Main as
# dependencies but it requires building gtest differently
set_target_properties(
gtest PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
"${CMAKE_SOURCE_DIR}/submodules/gtest/googletest/include")
add_subdirectory(nano/test_common)
add_subdirectory(nano/core_test)
add_subdirectory(nano/rpc_test)
add_subdirectory(nano/slow_test)
add_custom_target(
all_tests
COMMAND echo "BATCH BUILDING TESTS"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS core_test load_test rpc_test slow_test nano_node nano_rpc)
endif()
if(NANO_TEST OR RAIBLOCKS_TEST)
if(NANO_GUI OR RAIBLOCKS_GUI)
add_custom_target(
quick_tests
COMMAND echo "BATCH QUICK TESTS"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS core_test rpc_test qt_test)
else()
add_custom_target(
quick_tests
COMMAND echo "BATCH QUICK TESTS -- qt_test is disabled"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS core_test rpc_test)
endif()
endif()
if(NANO_GUI OR RAIBLOCKS_GUI)
install(FILES ${PROJECT_BINARY_DIR}/config-node.toml.sample DESTINATION .)
install(FILES ${PROJECT_BINARY_DIR}/config-rpc.toml.sample DESTINATION .)
install(FILES ${PROJECT_BINARY_DIR}/config-log.toml.sample DESTINATION .)
if(WIN32)
set(PLATFORM_QT_PACKAGES WinExtras)
else()
set(PLATFORM_QT_PACKAGES)
endif()
find_package(Qt5 COMPONENTS Core Gui Widgets Test ${PLATFORM_QT_PACKAGES})
add_library(qt nano/qt/qt.cpp nano/qt/qt.hpp)
include_directories(${CMAKE_SOURCE_DIR}/submodules)
target_link_libraries(
qt
node
secure
nano_lib
libminiupnpc-static
Qt5::Gui
Qt5::Widgets)
target_compile_definitions(
qt PRIVATE -DTAG_VERSION_STRING=${TAG_VERSION_STRING}
-DGIT_COMMIT_HASH=${GIT_COMMIT_HASH})
if(WIN32)
set(PLATFORM_GUI_TARGET_PROPERTIES WIN32)
else()
set(PLATFORM_GUI_TARGET_PROPERTIES "")
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(PLATFORM_WALLET_SOURCE nano/nano_wallet/plat/default/icon.cpp)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(PLATFORM_WALLET_SOURCE nano/nano_wallet/plat/windows/icon.cpp Nano.rc)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(PLATFORM_WALLET_SOURCE nano/nano_wallet/plat/default/icon.cpp)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
set(PLATFORM_WALLET_SOURCE nano/nano_wallet/plat/default/icon.cpp)
else()
error("Unknown platform: ${CMAKE_SYSTEM_NAME}")
endif()
qt5_add_resources(RES resources.qrc)
add_executable(
nano_wallet ${PLATFORM_GUI_TARGET_PROPERTIES} ${PLATFORM_WALLET_SOURCE}
nano/nano_wallet/entry.cpp nano/nano_wallet/icon.hpp ${RES})
target_link_libraries(nano_wallet Boost::process rpc node qt)
if(WIN32)
target_link_libraries(nano_wallet Qt5::WinExtras)
# nano_wallet.com executable for Windows console
add_executable(nano_wallet_com nano/nano_wallet/entry_com.cpp)
target_link_libraries(nano_wallet_com node)
set_target_properties(
nano_wallet_com
PROPERTIES COMPILE_FLAGS "-DBOOST_ASIO_HAS_STD_ARRAY=1"
OUTPUT_NAME "nano_wallet"
SUFFIX ".com")
endif()
set_target_properties(
qt nano_wallet PROPERTIES COMPILE_FLAGS
"-DQT_NO_KEYWORDS -DBOOST_ASIO_HAS_STD_ARRAY=1")
if(NANO_TEST OR RAIBLOCKS_TEST)
add_executable(qt_test nano/qt_test/entry.cpp nano/qt_test/qt.cpp)
target_link_libraries(
qt_test
node
secure
test_common
gtest
gtest_main
qt
Qt5::Test)
set_target_properties(
qt_test PROPERTIES COMPILE_FLAGS
"-DQT_NO_KEYWORDS -DBOOST_ASIO_HAS_STD_ARRAY=1")
add_dependencies(all_tests qt_test)
endif()
if(APPLE)
set(CPACK_GENERATOR "DragNDrop")
configure_file(${CMAKE_SOURCE_DIR}/Info.plist.in
${CMAKE_SOURCE_DIR}/Info.plist @ONLY)
install(TARGETS nano_wallet
DESTINATION ${NANO_OSX_PACKAGE_NAME}.app/Contents/MacOS)
install(TARGETS nano_node
DESTINATION ${NANO_OSX_PACKAGE_NAME}.app/Contents/MacOS)
install(TARGETS nano_rpc
DESTINATION ${NANO_OSX_PACKAGE_NAME}.app/Contents/MacOS)
install(FILES Info.plist DESTINATION ${NANO_OSX_PACKAGE_NAME}.app/Contents)
install(FILES qt.conf
DESTINATION ${NANO_OSX_PACKAGE_NAME}.app/Contents/Resources)
install(DIRECTORY ${Qt5_DIR}/../../QtCore.framework
DESTINATION ${NANO_OSX_PACKAGE_NAME}.app/Contents/Frameworks)
install(DIRECTORY ${Qt5_DIR}/../../QtDBus.framework
DESTINATION ${NANO_OSX_PACKAGE_NAME}.app/Contents/Frameworks)
install(DIRECTORY ${Qt5_DIR}/../../QtGui.framework
DESTINATION ${NANO_OSX_PACKAGE_NAME}.app/Contents/Frameworks)
install(DIRECTORY ${Qt5_DIR}/../../QtPrintSupport.framework
DESTINATION ${NANO_OSX_PACKAGE_NAME}.app/Contents/Frameworks)
install(DIRECTORY ${Qt5_DIR}/../../QtTest.framework
DESTINATION ${NANO_OSX_PACKAGE_NAME}.app/Contents/Frameworks)
install(DIRECTORY ${Qt5_DIR}/../../QtWidgets.framework
DESTINATION ${NANO_OSX_PACKAGE_NAME}.app/Contents/Frameworks)
install(FILES "${Qt5_DIR}/../../../plugins/platforms/libqcocoa.dylib"
DESTINATION ${NANO_OSX_PACKAGE_NAME}.app/Contents/PlugIns/platforms)
install(FILES Nano.icns
DESTINATION ${NANO_OSX_PACKAGE_NAME}.app/Contents/Resources)
elseif(WIN32)
if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
set(WIN_REDIST vc_redist.x64.exe)
else()
set(WIN_REDIST vc_redist.x86.exe)
endif()
set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS
"ExecWait '\\\"$INSTDIR\\\\${WIN_REDIST}\\\" /quiet /norestart'
WriteRegDWORD HKLM 'SYSTEM\\\\CurrentControlSet\\\\Services\\\\EventLog\\\\Nano\\\\Nano${NANO_PREFIX}' 'TypesSupported' '0x7'
WriteRegStr HKLM 'SYSTEM\\\\CurrentControlSet\\\\Services\\\\EventLog\\\\Nano\\\\Nano${NANO_PREFIX}' 'EventMessageFile' '$INSTDIR\\\\nano_wallet.exe'"
)
set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS
"DeleteRegKey HKLM 'SYSTEM\\\\CurrentControlSet\\\\Services\\\\EventLog\\\\Nano${NANO_PREFIX}'"
)
set(CPACK_NSIS_MUI_ICON ${CMAKE_SOURCE_DIR}/Nano.ico)
set(CPACK_NSIS_DISPLAY_NAME "Nano${NANO_PREFIX}")
set(CPACK_NSIS_URL_INFO_ABOUT "https://nano.org")
set(CPACK_NSIS_CONTACT "[email protected]")
set(CPACK_NSIS_MENU_LINKS "nano_wallet.exe" "Nano Wallet"
"https://nano.org" "Nano website")
set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON)
get_target_property(Qt5WindowsPlugin Qt5::QWindowsIntegrationPlugin
LOCATION)
get_filename_component(Qt5_bin_DIR ${Qt5_DIR}/../../../bin ABSOLUTE)
install(TARGETS nano_wallet DESTINATION .)
install(TARGETS nano_wallet_com DESTINATION .)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${WIN_REDIST} DESTINATION .)
install(FILES ${Qt5_bin_DIR}/libGLESv2.dll DESTINATION .)
install(FILES ${Qt5_bin_DIR}/Qt5Core.dll DESTINATION .)
install(FILES ${Qt5_bin_DIR}/Qt5Gui.dll DESTINATION .)
install(FILES ${Qt5_bin_DIR}/Qt5Widgets.dll DESTINATION .)
install(FILES ${Qt5_bin_DIR}/Qt5WinExtras.dll DESTINATION .)
install(FILES ${Qt5WindowsPlugin} DESTINATION platforms)
else()
set(CPACK_GENERATOR "TBZ2;DEB")
set(CPACK_DEBIAN_PACKAGE_DEPENDS
"qt5-default | qtbase5-dev, qtchooser, qt5-qmake, qtbase5-dev-tools")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "[email protected]")
install(TARGETS nano_wallet RUNTIME DESTINATION ./bin)
set(DEBIAN_POSTINST postinst.in)
set(DEBIAN_POSTRM postrm.in)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/debian-control/${DEBIAN_POSTINST}
${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/postinst)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/debian-control/${DEBIAN_POSTRM}
${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/postrm)
file(
COPY ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/postinst
${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/postrm
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/debian-control/.
FILE_PERMISSIONS
OWNER_READ
OWNER_WRITE
OWNER_EXECUTE
GROUP_READ
GROUP_EXECUTE
WORLD_READ
WORLD_EXECUTE)
install(FILES etc/systemd/${NANO_SERVICE} DESTINATION ./extras/systemd/.)
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
"${CMAKE_CURRENT_BINARY_DIR}/debian-control/postinst;${CMAKE_CURRENT_BINARY_DIR}/debian-control/postrm"
)
endif()
endif()
if(COVERAGE)
add_subdirectory(coverage)
endif()
set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/LICENSE)
include(CPack)