-
Notifications
You must be signed in to change notification settings - Fork 46
/
CMakeLists.txt
1009 lines (903 loc) · 33.3 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
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
cmake_minimum_required(VERSION 3.2.0)
project(Neblio)
option(NEBLIO_CMAKE "Enable buildig with cmake (to ensure this is for development)" OFF)
if(NOT NEBLIO_CMAKE)
if(NOT DEFINED ENV{NEBLIO_CMAKE})
message(FATAL_ERROR "This cmake file is only for development. Please use qmake to build the project.")
endif()
endif()
cmake_host_system_information(RESULT hostname QUERY HOSTNAME)
message("Building on machine: " ${hostname})
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-variable -Wno-unused-function -Wno-unused-private-field -Wno-class-memaccess -Wno-stringop-truncation")
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-psabi") # some ABI compatbility warnings... irrelevant: https://gcc.gnu.org/legacy-ml/gcc/2017-05/msg00073.html
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow") # pragma to disable warnings doesn't work with arm gcc
endif()
if(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wa,-mbig-obj")
endif()
include(CMakePushCheckState)
include(CheckCXXSourceCompiles)
option(COMPILE_GUI "Enable compiling neblio-qt" ON)
option(COMPILE_DAEMON "Enable compiling nebliod" ON)
option(COMPILE_CURL "Download and compile libcurl (and OpenSSL) automatically (Not for Windows)" OFF)
option(COMPILE_TESTS "Build tests" ON)
option(USE_QRCODE "Enable QRCode" ON)
option(USE_UPNP "Enable Miniupnpc" OFF)
option(USE_DBUS "Enable Dbus" ON)
option(USE_CUSTOM_WARNINGS "Enable custom warnings" OFF)
option(DISABLE_ASSERTS "Disables asserts" OFF)
option(CONFIGURE_SYSTEM_TESTS "Configure system tests" ON)
option(DISABLE_ATTRUBTES_WARNINGS "Set the flag -Wno-attributes to disable attributes warnings (for CI)" OFF)
option(ASSEMBLY_OPTIMIZED_SCRYPT "Enable optimized scrypt and xor_salsa8 for better performance" ON)
if(DISABLE_ATTRUBTES_WARNINGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-attributes")
endif()
if(ASSEMBLY_OPTIMIZED_SCRYPT)
add_definitions(-DOPTIMIZED_SALSA)
endif()
if(NOT DISABLE_ASSERTS)
# this removes the definition NDEBUG from release mode and release mode with debug info
# for both gcc/clang and Visual Studio
string( REPLACE "/DNDEBUG" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
string( REPLACE "/DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
string( REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
string( REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
endif()
option(SANITIZE_THREAD "Enable clang thread-sanitizer (only for clang-compiler)" OFF)
if(SANITIZE_THREAD)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=thread")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=thread")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize-blacklist=${CMAKE_SOURCE_DIR}/sanitizer-blacklist.txt")
endif()
option(SANITIZE_UNDEFINED "Enable clang undefined-behavior-sanitizer (only for clang-compiler)" OFF)
if(SANITIZE_UNDEFINED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=undefined")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=undefined")
endif()
option(SANITIZE_ADDRESS "Enable clang address-sanitizer (only for clang-compiler)" OFF)
if(SANITIZE_ADDRESS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=address")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
endif()
option(SANITIZE_LEAK "Enable clang leak-sanitizer (only for clang-compiler)" OFF)
if(SANITIZE_LEAK)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=leak")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=leak")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=leak")
endif()
option(SANITIZE_MEMORY "Enable clang memory-sanitizer (only for clang-compiler)" OFF)
if(SANITIZE_MEMORY)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=memory")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=memory")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=memory")
endif()
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
add_definitions(-DBOOST_BIND_GLOBAL_PLACEHOLDERS)
list(INSERT CMAKE_MODULE_PATH 0
"${CMAKE_SOURCE_DIR}/cmake")
add_definitions("-DQT_STATICPLUGIN")
foreach(plugin ${Qt5Widgets_PLUGINS})
get_target_property(_loc ${plugin} LOCATION)
message("Plugin ${plugin} is at location ${_loc}")
endforeach()
set(Boost_USE_STATIC_LIBS 1)
if(WIN32)
set(Boost_USE_STATIC_RUNTIME 1)
endif()
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Core REQUIRED)
find_package(Qt5LinguistTools REQUIRED)
find_package(BerkeleyDB REQUIRED)
find_package(PkgConfig REQUIRED)
find_package(Boost 1.65 COMPONENTS system random filesystem thread regex program_options iostreams atomic REQUIRED)
find_package(Threads REQUIRED)
find_package(sodium REQUIRED)
set(ATOMIC32_TEST_CODE "
#include <atomic>
#include <stdint.h>
int main() {
std::atomic<int32_t> x;
x.store(1);
x--;
return x.load();
}")
set(ATOMIC64_TEST_CODE "
#include <atomic>
#include <stdint.h>
int main() {
std::atomic<int64_t> x;
x.store(1);
x--;
return x.load();
}")
macro(ATOMIC_CHECK)
# test whether atomic works
check_cxx_source_compiles("${ATOMIC32_TEST_CODE}" atomic32_test)
check_cxx_source_compiles("${ATOMIC64_TEST_CODE}" atomic64_test)
# if doesn't work, attempt to find the atomic library, link with it and try again
if(NOT atomic32_test OR NOT atomic64_test)
find_library(ATOMIC NAMES libatomic.so.1
HINTS
$ENV{HOME}/local/lib64
$ENV{HOME}/local/lib
/usr/local/lib64
/usr/local/lib
/opt/local/lib64
/opt/local/lib
/usr/lib64
/usr/lib
/lib64
/lib
/usr/lib/arm-linux-gnueabihf
)
if(ATOMIC)
set(LIBATOMIC ${ATOMIC})
message(STATUS "Found libatomic: ${LIBATOMIC}")
message(STATUS "Attempting to test atomic with atomic library linked")
get_filename_component(atomic_lib_dir ${LIBATOMIC} DIRECTORY)
# Before setting CMAKE_REQUIRED_FLAGS, we preserve the current state
cmake_push_check_state()
set(CMAKE_REQUIRED_LIBRARIES "-L${atomic_lib_dir}" "-latomic")
check_cxx_source_compiles("${ATOMIC32_TEST_CODE}" atomic32_test_with_atomic_linking)
check_cxx_source_compiles("${ATOMIC64_TEST_CODE}" atomic64_test_with_atomic_linking)
cmake_pop_check_state()
if(NOT atomic32_test_with_atomic_linking)
message(FATAL_ERROR "Even after linking with the atomic library, atomic 32-bit compilation failed.")
endif()
if(NOT atomic64_test_with_atomic_linking)
message(FATAL_ERROR "Even after linking with the atomic library, atomic 64-bit compilation failed.")
endif()
set(ATOMIC_LINKER_LIBS "-L${atomic_lib_dir} -latomic")
else()
message(FATAL_ERROR "Failed to find libatomic even though it seems to be required")
endif()
endif()
endmacro()
ATOMIC_CHECK()
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64") # 32-bit and 64-bit arm
elseif(CMAKE_SIZEOF_VOID_P EQUAL "4") # 32-bit compiler + x86
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2")
endif()
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
find_package(ZLIB REQUIRED)
if(COMPILE_CURL AND NOT WIN32)
include(FindPythonInterp)
if( !PYTHONINTERP_FOUND )
message( FATAL_ERROR "Could not find a Python interpreter. A python interpreter is requirered to compile curl." )
endif()
if(IS_SYMLINK "${CMAKE_BINARY_DIR}/openssl_build" OR EXISTS "${CMAKE_BINARY_DIR}/openssl_build")
else()
message("Compiling OpenSSL...")
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/build_scripts/CompileOpenSSL-Linux.py"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
OUTPUT_VARIABLE COMPILE_OPENSSL_OUTPUT
ERROR_VARIABLE COMPILE_OPENSSL_OUTPUT
RESULT_VARIABLE COMPILE_OPENSSL_RETURN_VALUE
)
if (NOT COMPILE_OPENSSL_RETURN_VALUE EQUAL 0)
message(FATAL_ERROR "Failed to compile OpenSSL: ${COMPILE_OPENSSL_OUTPUT}")
endif()
message("Done compiling OpenSSL.")
endif()
if(IS_SYMLINK "${CMAKE_BINARY_DIR}/curl_build" OR EXISTS "${CMAKE_BINARY_DIR}/curl_build")
else()
message("Compiling libcurl...")
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/build_scripts/CompileCurl-Linux.py"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
OUTPUT_VARIABLE COMPILE_CURL_OUTPUT
ERROR_VARIABLE COMPILE_CURL_OUTPUT
RESULT_VARIABLE COMPILE_CURL_RETURN_VALUE
)
if (NOT COMPILE_CURL_RETURN_VALUE EQUAL 0)
message(FATAL_ERROR "Failed to compile OpenSSL: ${COMPILE_CURL_OUTPUT}")
endif()
message("Done compiling libcurl.")
endif()
SET(ENV{PKG_CONFIG_PATH} "${CMAKE_BINARY_DIR}/curl_build/lib/pkgconfig/:$ENV{PKG_CONFIG_PATH}")
SET(ENV{PKG_CONFIG_PATH} ":${CMAKE_BINARY_DIR}/openssl_build/lib/pkgconfig/:$ENV{PKG_CONFIG_PATH}")
endif()
############################## CURL and OpenSSL PkgConfig
execute_process(
COMMAND "${PKG_CONFIG_EXECUTABLE}" "libcurl" "--libs"
OUTPUT_VARIABLE CURL_LIBS
ERROR_VARIABLE CURL_LIBS
RESULT_VARIABLE CURL_LIBS_RETURN_VALUE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (NOT CURL_LIBS_RETURN_VALUE EQUAL 0)
message(FATAL_ERROR "Failed to retrieve libs for libcurl with pkg-config: ${CURL_LIBS} ")
endif()
execute_process(
COMMAND "${PKG_CONFIG_EXECUTABLE}" "libcurl" "--cflags"
OUTPUT_VARIABLE CURL_INCLUDES
ERROR_VARIABLE CURL_INCLUDES
RESULT_VARIABLE CURL_INCLUDES_RETURN_VALUE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (NOT CURL_INCLUDES_RETURN_VALUE EQUAL 0)
message(FATAL_ERROR "Failed to retrieve libs for libcurl with pkg-config: ${CURL_INCLUDES}")
endif()
execute_process(
COMMAND ${PKG_CONFIG_EXECUTABLE} openssl --libs
OUTPUT_VARIABLE OPENSSL_LIBS
ERROR_VARIABLE OPENSSL_LIBS
RESULT_VARIABLE OPENSSL_LIBS_RETURN_VALUE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (NOT OPENSSL_LIBS_RETURN_VALUE EQUAL 0)
message(FATAL_ERROR "Failed to retrieve libs for openssl with pkg-config: ${OPENSSL_LIBS}")
endif()
execute_process(
COMMAND ${PKG_CONFIG_EXECUTABLE} openssl --cflags
OUTPUT_VARIABLE OPENSSL_INCLUDES
ERROR_VARIABLE OPENSSL_INCLUDES
RESULT_VARIABLE OPENSSL_INCLUDES_RETURN_VALUE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (NOT OPENSSL_INCLUDES_RETURN_VALUE EQUAL 0)
message(FATAL_ERROR "Failed to retrieve libs for openssl with pkg-config: ${OPENSSL_INCLUDES}")
endif()
add_definitions(-DCURL_STATICLIB)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPENSSL_INCLUDES} ${CURL_INCLUDES}")
################################################
if(USE_DBUS)
execute_process(
COMMAND ${PKG_CONFIG_EXECUTABLE} dbus-1 --libs
OUTPUT_VARIABLE DBUS_LIBRARY_DIRS
ERROR_VARIABLE DBUS_LIBRARY_DIRS
RESULT_VARIABLE DBUS_LIBS_RETURN_VALUE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (NOT DBUS_LIBS_RETURN_VALUE EQUAL 0)
message(FATAL_ERROR "Failed to retrieve libs for dbus with pkg-config: ${DBUS_LIBRARY_DIRS}")
endif()
execute_process(
COMMAND ${PKG_CONFIG_EXECUTABLE} dbus-1 --cflags
OUTPUT_VARIABLE DBUS_INCLUDE_DIRS
ERROR_VARIABLE DBUS_INCLUDE_DIRS
RESULT_VARIABLE DBUS_INCLUDES_RETURN_VALUE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (NOT DBUS_INCLUDES_RETURN_VALUE EQUAL 0)
message(FATAL_ERROR "Failed to retrieve libs for dbus with pkg-config: ${DBUS_INCLUDE_DIRS}")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-command-line-argument")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DBUS_LIBRARY_DIRS}")
endif()
# copy "res", the resources dir to build dir
file(COPY "${CMAKE_SOURCE_DIR}/wallet/qt/res" DESTINATION "${CMAKE_BINARY_DIR}")
# read, modify then write the qrc file, remove "locale/" directory as it's not necessary when translation files are generated in build dir
file(READ ${CMAKE_SOURCE_DIR}/wallet/qt/bitcoin.qrc resources_file_data)
STRING(REGEX REPLACE "locale\/(bitcoin[a-zA-Z_]+\.qm)" "\\1" resources_file_data_mod "${resources_file_data}" )
FILE(WRITE ${CMAKE_BINARY_DIR}/bitcoin.qrc "${resources_file_data_mod}")
set(RESOURCE ${CMAKE_BINARY_DIR}/bitcoin.qrc)
qt5_add_resources(RESOURCE_ADDED ${RESOURCE})
add_subdirectory(test)
add_definitions(-DBOOST_SPIRIT_THREADSAFE)
if(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.12 -arch x86_64 -Wno-nullability-completeness -Wno-unused-command-line-argument")
add_library(mac_libs
qt/macdockiconhandler.h
qt/macnotificationhandler.h
qt/macdockiconhandler.mm
qt/macnotificationhandler.mm
)
target_link_libraries(mac_libs
-framework Foundation -framework ApplicationServices -framework AppKit
)
add_definitions(-DMAC_OSX MSG_NOSIGNAL=0)
# NOTE: Don't include the path in MACOSX_BUNDLE_ICON_FILE -- this is
# the property added to Info.plist
set(MACOSX_BUNDLE_ICON_FILE qt/res/icons/bitcoin.icns)
# And this part tells CMake where to find and install the file itself
set(myApp_ICON ${CMAKE_CURRENT_SOURCE_DIR}/images/myAppImage.icns)
set_source_files_properties(${myApp_ICON} PROPERTIES
MACOSX_PACKAGE_LOCATION "Resources")
endif()
if(UNIX AND NOT APPLE)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-Bstatic")
add_definitions(-DLINUX)
endif()
if(NOT WIN32)
# for extra security against potential buffer overflows: enable GCCs Stack Smashing Protection
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-all -Wstack-protector")
# We need to exclude this for Windows cross compile with MinGW 4.2.x, as it will result in a non-working executable!
# This can be enabled for Windows, when we switch to MinGW >= 4.4.x.
endif()
# for extra security (see: https://wiki.debian.org/Hardening)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FORTIFY_SOURCE=2")
if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND NOT WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-z,relro -Wl,-z,now")
endif()
if(WIN32)
# for extra security on Windows: enable ASLR and DEP via GCC linker flags
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -Wl,--dynamicbase -Wl,--nxcompat")
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -Wl,--large-address-aware -static")
add_definitions(-DWIN32)
add_definitions(-D_MT -DBOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN)
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -lmingwthrd -mthreads")
set(CMAKE_CXX_FLAGS "-Wno-unused-variable")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-Bstatic")
endif()
# TODO
#contains(BITCOIN_NEED_QT_PLUGINS, 1) {
# DEFINES += BITCOIN_NEED_QT_PLUGINS
# QTPLUGIN += qcncodecs qjpcodecs qtwcodecs qkrcodecs qtaccessiblewidgets
#}
#############################################################
# lmdb
# Check whether we're on a 32-bit or 64-bit system
if(CMAKE_SIZEOF_VOID_P EQUAL "8")
set(DEFAULT_LMDB64 ON)
else()
set(DEFAULT_LMDB64 OFF)
endif()
option(USE_LMDB64 "Build LMDB for 64-bit? 'OFF' builds for 32-bit." ${DEFAULT_LMDB64})
add_subdirectory(wallet/liblmdb)
include_directories(${LMDB_INCLUDE})
#############################################################
###################
# generate build.h
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/build")
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/build/build.h
COMMAND /bin/sh ${CMAKE_SOURCE_DIR}/share/genbuild.sh ${CMAKE_BINARY_DIR}/build/build.h
)
set_property(SOURCE ${CMAKE_BINARY_DIR}/build/build.h PROPERTY SKIP_AUTOMOC ON)
###################
if(USE_CUSTOM_WARNINGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-show-option -Wall -Wextra -Wno-ignored-qualifiers -Wformat -Wformat-security -Wno-unused-parameter -Wstack-protector")
endif()
# TODO: from qmake. Is this necessary?
# CODECFORTR = UTF-8
qt5_add_translation(QM_FILES
wallet/qt/locale/bitcoin_af_ZA.ts
wallet/qt/locale/bitcoin_ar.ts
wallet/qt/locale/bitcoin_be_BY.ts
wallet/qt/locale/bitcoin_bg.ts
wallet/qt/locale/bitcoin_bs.ts
wallet/qt/locale/bitcoin_ca.ts
wallet/qt/locale/[email protected]
wallet/qt/locale/bitcoin_ca_ES.ts
wallet/qt/locale/bitcoin_cs.ts
wallet/qt/locale/bitcoin_cy.ts
wallet/qt/locale/bitcoin_da.ts
wallet/qt/locale/bitcoin_de.ts
wallet/qt/locale/bitcoin_el_GR.ts
wallet/qt/locale/bitcoin_en.ts
wallet/qt/locale/bitcoin_eo.ts
wallet/qt/locale/bitcoin_es.ts
wallet/qt/locale/bitcoin_es_CL.ts
wallet/qt/locale/bitcoin_es_DO.ts
wallet/qt/locale/bitcoin_es_MX.ts
wallet/qt/locale/bitcoin_es_UY.ts
wallet/qt/locale/bitcoin_et.ts
wallet/qt/locale/bitcoin_eu_ES.ts
wallet/qt/locale/bitcoin_fa.ts
wallet/qt/locale/bitcoin_fa_IR.ts
wallet/qt/locale/bitcoin_fi.ts
wallet/qt/locale/bitcoin_fr.ts
wallet/qt/locale/bitcoin_fr_CA.ts
wallet/qt/locale/bitcoin_gl.ts
wallet/qt/locale/bitcoin_he.ts
wallet/qt/locale/bitcoin_hi_IN.ts
wallet/qt/locale/bitcoin_hr.ts
wallet/qt/locale/bitcoin_hu.ts
wallet/qt/locale/bitcoin_id_ID.ts
wallet/qt/locale/bitcoin_it.ts
wallet/qt/locale/bitcoin_ja.ts
wallet/qt/locale/bitcoin_ka.ts
wallet/qt/locale/bitcoin_kk_KZ.ts
wallet/qt/locale/bitcoin_ko_KR.ts
wallet/qt/locale/bitcoin_ky.ts
wallet/qt/locale/bitcoin_la.ts
wallet/qt/locale/bitcoin_lt.ts
wallet/qt/locale/bitcoin_lv_LV.ts
wallet/qt/locale/bitcoin_ms_MY.ts
wallet/qt/locale/bitcoin_nb.ts
wallet/qt/locale/bitcoin_nl.ts
wallet/qt/locale/bitcoin_pam.ts
wallet/qt/locale/bitcoin_pl.ts
wallet/qt/locale/bitcoin_pt_BR.ts
wallet/qt/locale/bitcoin_pt_PT.ts
wallet/qt/locale/bitcoin_ro_RO.ts
wallet/qt/locale/bitcoin_ru.ts
wallet/qt/locale/bitcoin_sah.ts
wallet/qt/locale/bitcoin_sk.ts
wallet/qt/locale/bitcoin_sl_SI.ts
wallet/qt/locale/bitcoin_sq.ts
wallet/qt/locale/bitcoin_sr.ts
wallet/qt/locale/bitcoin_sv.ts
wallet/qt/locale/bitcoin_th_TH.ts
wallet/qt/locale/bitcoin_tr.ts
wallet/qt/locale/bitcoin_uk.ts
wallet/qt/locale/bitcoin_ur_PK.ts
wallet/qt/locale/bitcoin_vi.ts
wallet/qt/locale/bitcoin_vi_VN.ts
wallet/qt/locale/bitcoin_zh_CN.ts
wallet/qt/locale/bitcoin_zh_TW.ts
)
if(USE_QRCODE AND COMPILE_GUI)
include(FindPythonInterp)
if( !PYTHONINTERP_FOUND )
message( FATAL_ERROR "Could not find a Python interpreter. A python interpreter is requirered to compile qrencode." )
endif()
if(NOT WIN32)
if(IS_SYMLINK "${CMAKE_BINARY_DIR}/qrencode_build" OR EXISTS "${CMAKE_BINARY_DIR}/qrencode_build")
else()
message("Compiling qrencode...")
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/build_scripts/CompileQREncode-Linux.py"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
OUTPUT_VARIABLE COMPILE_QRENCODE_OUTPUT
ERROR_VARIABLE COMPILE_QRENCODE_OUTPUT
RESULT_VARIABLE COMPILE_QRENCODE_RETURN_VALUE
)
if (NOT COMPILE_QRENCODE_RETURN_VALUE EQUAL 0)
message(FATAL_ERROR "Failed to compile OpenSSL: ${COMPILE_QRENCODE_OUTPUT}")
endif()
message("Done compiling qrencode.")
endif()
endif()
SET(ENV{PKG_CONFIG_PATH} "${CMAKE_BINARY_DIR}/qrencode_build/lib/pkgconfig/:$ENV{PKG_CONFIG_PATH}")
execute_process(
COMMAND "${PKG_CONFIG_EXECUTABLE}" "libqrencode" "--libs"
OUTPUT_VARIABLE QRENCODE_LIBS
ERROR_VARIABLE QRENCODE_LIBS
RESULT_VARIABLE QRENCODE_LIBS_RETURN_VALUE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (NOT QRENCODE_LIBS_RETURN_VALUE EQUAL 0)
message(FATAL_ERROR "Failed to retrieve libs for libqrencode with pkg-config: ${QRENCODE_LIBS} ")
endif()
execute_process(
COMMAND "${PKG_CONFIG_EXECUTABLE}" "libqrencode" "--cflags"
OUTPUT_VARIABLE QRENCODE_INCLUDES
ERROR_VARIABLE QRENCODE_INCLUDES
RESULT_VARIABLE QRENCODE_INCLUDES_RETURN_VALUE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(QRCODE_SOURCES "wallet/qt/qrcodedialog.cpp" "wallet/qt/ui_qrcodedialog.h")
add_definitions(-DUSE_QRCODE)
endif()
add_library(logging_lib STATIC
wallet/logging/defaultlogger.cpp
wallet/logging/logger.cpp
)
add_library(gui_lib STATIC
wallet/qt/bitcoingui.cpp
wallet/qt/transactiontablemodel.cpp
wallet/qt/addresstablemodel.cpp
wallet/qt/optionsdialog.cpp
wallet/qt/sendcoinsdialog.cpp
wallet/qt/coincontroldialog.cpp
wallet/qt/coincontroltreewidget.cpp
wallet/qt/addressbookpage.cpp
wallet/qt/signverifymessagedialog.cpp
wallet/qt/aboutdialog.cpp
wallet/qt/editaddressdialog.cpp
wallet/qt/bitcoinaddressvalidator.cpp
wallet/qt/clientmodel.cpp
wallet/qt/guiutil.cpp
wallet/qt/transactionrecord.cpp
wallet/qt/optionsmodel.cpp
wallet/qt/monitoreddatamapper.cpp
wallet/qt/transactiondesc.cpp
wallet/qt/transactiondescdialog.cpp
wallet/qt/bitcoinstrings.cpp
wallet/qt/bitcoinamountfield.cpp
wallet/qt/transactionfilterproxy.cpp
wallet/qt/transactionview.cpp
wallet/qt/walletmodel.cpp
wallet/qt/overviewpage.cpp
wallet/qt/csvmodelwriter.cpp
wallet/qt/sendcoinsentry.cpp
wallet/qt/qvalidatedlineedit.cpp
wallet/qt/bitcoinunits.cpp
wallet/qt/qvaluecombobox.cpp
wallet/qt/askpassphrasedialog.cpp
wallet/qt/notificator.cpp
wallet/qt/qtipcserver.cpp
wallet/qt/rpcconsole.cpp
wallet/qt/ClickableLabel.cpp
wallet/qt/neblioupdatedialog.cpp
wallet/qt/messageboxwithtimer.cpp
wallet/qt/coldstakingpage.cpp
wallet/qt/coldstakingmodel.cpp
wallet/qt/coldstakinglistitemdelegate.cpp
wallet/qt/coldstakinglistfilterproxy.cpp
wallet/qt/newstakedelegationdialog.cpp
wallet/qt/sociallinks.cpp
wallet/qt/nebliosplash.cpp
wallet/qt/votesdialog.cpp
wallet/qt/votesdatamodel.cpp
wallet/qt/votesdataview.cpp
wallet/qt/votestablecelldelegate.cpp
${QRCODE_SOURCES}
)
if(USE_QRCODE)
target_compile_options(gui_lib PRIVATE ${QRENCODE_INCLUDES})
endif()
target_link_libraries(gui_lib
Qt5::Core
Qt5::Widgets
${QRENCODE_LIBS}
ui_lib
)
add_library(ui_lib STATIC
wallet/qt/ui_aboutdialog.h
wallet/qt/ui_addressbookpage.h
wallet/qt/ui_askpassphrasedialog.h
wallet/qt/ui_coincontroldialog.h
wallet/qt/ui_editaddressdialog.h
wallet/qt/ui_coldstakingpage.h
wallet/qt/ui_ntp1summary.h
wallet/qt/ui_optionsdialog.h
wallet/qt/ui_overviewpage.h
wallet/qt/ui_qrcodedialog.h
wallet/qt/ui_rpcconsole.h
wallet/qt/ui_sendcoinsdialog.h
wallet/qt/ui_sendcoinsentry.h
wallet/qt/ui_signverifymessagedialog.h
wallet/qt/ui_transactiondescdialog.h
)
target_link_libraries(ui_lib
Qt5::Core
Qt5::Widgets
)
add_library(ntp1_gui_lib STATIC
wallet/qt/ntp1summary.cpp
wallet/qt/ntp1/ntp1tokenlistmodel.cpp
wallet/qt/ntp1/ntp1tokenlistfilterproxy.cpp
wallet/qt/ntp1/ntp1tokenlistitemdelegate.cpp
wallet/qt/ntp1/ntp1createmetadatadialog.cpp
wallet/qt/ntp1/ntp1metadatapairwidget.cpp
wallet/qt/ntp1/ntp1custommetadatawidget.cpp
wallet/qt/ntp1/ntp1metadatapairswidget.cpp
wallet/qt/ntp1sendtokensfeewidget.cpp
wallet/qt/json/AbstractTreeNode.cpp
wallet/qt/json/JsonNewNodeDialog.cpp
wallet/qt/json/JsonTreeModel.cpp
wallet/qt/json/JsonTreeNode.cpp
wallet/qt/json/JsonTreeView.cpp
wallet/qt/json/NTP1MetadataViewer.cpp
wallet/qt/ntp1/issuenewntp1tokendialog.cpp
)
target_link_libraries(ntp1_gui_lib
Qt5::Core
Qt5::Widgets
ui_lib
)
add_library(utils_lib STATIC
wallet/stringmanip.cpp
)
set_source_files_properties(wallet/scrypt-arm.S PROPERTIES LANGUAGE CXX)
set_source_files_properties(wallet/scrypt-x86.S PROPERTIES LANGUAGE CXX)
set_source_files_properties(wallet/scrypt-x86_64.S PROPERTIES LANGUAGE CXX)
add_library(core_lib STATIC
${CMAKE_BINARY_DIR}/build/build.h
wallet/version.cpp
wallet/sync.cpp
wallet/util.cpp
wallet/hash.cpp
wallet/netbase.cpp
wallet/key.cpp
wallet/script.cpp
wallet/script_error.cpp
wallet/main.cpp
wallet/miner.cpp
wallet/net.cpp
wallet/bloom.cpp
wallet/checkpoints.cpp
wallet/addrman.cpp
wallet/db.cpp
wallet/walletdb.cpp
wallet/keystore.cpp
wallet/bitcoinrpc.cpp
wallet/rpcdump.cpp
wallet/rpcnet.cpp
wallet/rpcmining.cpp
wallet/rpcwallet.cpp
wallet/rpcblockchain.cpp
wallet/rpcrawtransaction.cpp
wallet/crypter.cpp
wallet/protocol.cpp
wallet/noui.cpp
wallet/kernel.cpp
wallet/scrypt-arm.S
wallet/scrypt-x86.S
wallet/scrypt-x86_64.S
wallet/scrypt.cpp
wallet/pbkdf2.cpp
wallet/neblioupdater.cpp
wallet/neblioversion.cpp
wallet/neblioreleaseinfo.cpp
wallet/ThreadSafeMap.cpp
wallet/ThreadSafeHashMap.cpp
wallet/NetworkForks.cpp
wallet/blockindexcatalog.cpp
wallet/blockindex.cpp
wallet/outpoint.cpp
wallet/inpoint.cpp
wallet/block.cpp
wallet/transaction.cpp
wallet/globals.cpp
wallet/disktxpos.cpp
wallet/txindex.cpp
wallet/txin.cpp
wallet/txout.cpp
wallet/txmempool.cpp
wallet/merkletx.cpp
wallet/blocklocator.cpp
wallet/crypto_highlevel.cpp
wallet/chainparamsbase.cpp
wallet/chainparams.cpp
wallet/consensus_params.cpp
wallet/amount.h
wallet/CustomTypes.cpp
wallet/merkle.cpp
wallet/wallet_ismine.cpp
wallet/stakemaker.cpp
wallet/work.cpp
wallet/addressbook.cpp
wallet/validation.cpp
wallet/itxdb.h
wallet/coldstakedelegation.cpp
wallet/udaddress.cpp
wallet/blockreject.cpp
wallet/blockmetadata.cpp
wallet/blockindexlrucache.cpp
wallet/proposal.cpp
)
target_link_libraries(core_lib
logging_lib
ntp1_lib
curltools_lib
sodium
db_lib
utils_lib
${ATOMIC_LINKER_LIBS}
)
add_library(curltools_lib STATIC
wallet/curltools.cpp
)
if(USE_UPNP)
find_package(Miniupnpc REQUIRED)
message(Building without UPNP support)
target_link_libraries(core_lib -lminiupnpc)
target_compile_definitions(core_lib PRIVATE -DUSE_UPNP=1)
endif()
add_library(ntp1_lib STATIC
wallet/ntp1/ntp1sendtokensonerecipientdata.cpp
wallet/ntp1/ntp1script_burn.cpp
wallet/ntp1/ntp1tokenminimalmetadata.cpp
wallet/ntp1/ntp1sendtxdata.cpp
wallet/ntp1/ntp1tokenmetadata.cpp
wallet/ntp1/intp1wallet.h
wallet/ntp1/ntp1wallet.cpp
wallet/ntp1/ntp1tools.cpp
wallet/ntp1/ntp1inpoint.cpp
wallet/ntp1/ntp1outpoint.cpp
wallet/ntp1/ntp1transaction.cpp
wallet/ntp1/ntp1txin.cpp
wallet/ntp1/ntp1txout.cpp
wallet/ntp1/ntp1tokentxdata.cpp
wallet/ntp1/ntp1apicalls.cpp
wallet/ntp1/ntp1script.cpp
wallet/ntp1/ntp1script_issuance.cpp
wallet/ntp1/ntp1script_transfer.cpp
wallet/ntp1/ntp1v1_issuance_static_data.cpp
)
target_link_libraries(ntp1_lib
curltools_lib
)
add_library(json_spirit_lib STATIC
wallet/json/json_spirit_value.cpp
wallet/json/json_spirit_reader.cpp
wallet/json/json_spirit_writer.cpp
)
if(WIN32)
# this solves a problem of big string tables on Windows when building in debug mode
set_property(TARGET json_spirit_lib PROPERTY COMPILE_FLAGS "-O2")
endif()
add_library(db_lib STATIC
wallet/db/idb.h
wallet/db/lmdb/lmdb.cpp
wallet/db/lmdb/lmdbtransaction.cpp
)
add_library(txdb_lib STATIC
wallet/txdb-lmdb.cpp
wallet/SerializationTester.cpp
wallet/db/lmdb/lmdbtransaction.cpp
)
target_link_libraries(db_lib
lmdb
)
target_link_libraries(txdb_lib
db_lib
utils_lib
)
target_link_libraries(curltools_lib
${CURL_LIBS}
${OPENSSL_LIBS}
)
include_directories(wallet)
include_directories(wallet/spdlog/include)
include_directories(wallet/json)
target_include_directories(gui_lib PRIVATE wallet/qt)
target_include_directories(ntp1_gui_lib PRIVATE wallet/qt)
include_directories(${ZLIB_INCLUDE_DIRS})
include_directories(${sodium_INCLUDE_DIR})
# the following from here https://github.com/owncloud/client/blob/master/src/gui/CMakeLists.txt
target_compile_definitions(gui_lib PRIVATE "QT_DISABLE_DEPRECATED_BEFORE=0")
if(COMPILE_TESTS)
# GTEST ##############
set(GTEST_PATH ${CMAKE_SOURCE_DIR}/wallet/test/googletest/googletest)
include_directories(${GTEST_PATH}/include)
include_directories(${GTEST_PATH}/)
add_library(gtest ${GTEST_PATH}/src/gtest-all.cc)
target_link_libraries(gtest Threads::Threads)
set_property(TARGET gtest PROPERTY COMPILE_FLAGS "-w")
######################
# GMOCK ##############
set(GMOCK_PATH ${CMAKE_SOURCE_DIR}/wallet/test/googletest/googlemock)
include_directories(${GMOCK_PATH}/include)
include_directories(${GMOCK_PATH}/)
add_library(gmock ${GMOCK_PATH}/src/gmock-all.cc)
target_link_libraries(gtest Threads::Threads)
set_property(TARGET gmock PROPERTY COMPILE_FLAGS "-w")
######################
enable_testing()
add_subdirectory(wallet/test)
endif()
if(WIN32)
if(COMPILE_GUI)
add_executable(
neblio-qt
${RESOURCE_ADDED}
${QM_FILES}
# sources that depend on target as they have defs inside them
wallet/qt/bitcoin.cpp
wallet/wallet.cpp
wallet/init.cpp
)
target_link_libraries(neblio-qt
gui_lib
ui_lib
ntp1_gui_lib
curltools_lib
ntp1_lib
core_lib
json_spirit_lib
txdb_lib
Threads::Threads
### win32 libs
-lws2_32 -lshlwapi -lmswsock -lole32 -loleaut32 -luuid -lgdi32
##############
Boost::system
Boost::filesystem
Boost::thread
Boost::regex
Boost::program_options
Boost::iostreams
Boost::atomic
${BERKELEY_DB_LIBRARIES}
${CURL_LIBS}
${OPENSSL_LIBS}
${ZLIB_LIBRARIES}
)
target_compile_definitions(neblio-qt PRIVATE
QT_GUI
)
target_link_libraries(neblio-qt Qt5::QWindowsIntegrationPlugin)
endif()
if(COMPILE_DAEMON)
add_executable(
# sources that depend on target as they have defs inside them
nebliod
wallet/wallet.cpp
wallet/init.cpp
)
target_link_libraries(nebliod
core_lib
ntp1_lib
curltools_lib
json_spirit_lib
txdb_lib
Threads::Threads
### win32 libs
-lws2_32 -lshlwapi -lmswsock -lole32 -loleaut32 -luuid -lgdi32
##############
Boost::system
Boost::filesystem
Boost::thread
Boost::regex
Boost::program_options
${BERKELEY_DB_LIBRARIES}
${CURL_LIBS}
${OPENSSL_LIBS}
)
endif()
elseif(APPLE)
add_executable(
neblio-qt
MACOSX_BUNDLE ${myApp_ICON}
)
else()
if(COMPILE_GUI)
add_executable(
neblio-qt
${RESOURCE_ADDED}
${QM_FILES}
# sources that depend on target as they have defs inside them
wallet/qt/bitcoin.cpp
wallet/wallet.cpp
wallet/init.cpp
)
target_link_libraries(neblio-qt
gui_lib
ui_lib
ntp1_gui_lib
curltools_lib
ntp1_lib
core_lib
json_spirit_lib
txdb_lib
Threads::Threads
-lrt
-ldl
Boost::system
Boost::filesystem
Boost::thread
Boost::regex
Boost::program_options
Boost::iostreams
${BERKELEY_DB_LIBRARIES}
${CURL_LIBS}
${OPENSSL_LIBS}
${ZLIB_LIBRARIES}
)
target_compile_definitions(neblio-qt PRIVATE
QT_GUI
)
endif()
if(COMPILE_DAEMON)
add_executable(
nebliod
# sources that depend on target as they have defs inside them
wallet/wallet.cpp
wallet/init.cpp
)
target_link_libraries(nebliod
core_lib
ntp1_lib
curltools_lib
json_spirit_lib
txdb_lib
Threads::Threads
-lrt
-ldl
Boost::system
Boost::filesystem
Boost::thread
Boost::regex
Boost::program_options