forked from BeamMW/beam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
336 lines (275 loc) · 10.8 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
cmake_minimum_required(VERSION 3.1)
set(VERSION_MAJOR 1)
set(VERSION_MINOR 0)
set(VERSION_REVISION 0)
set(GIT_COMMIT_HASH "unknown")
find_package(Git)
if(Git_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} status
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
ERROR_VARIABLE RESULT_STRING
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(LENGTH "${RESULT_STRING}" LENGTH_RESULT_STRING)
if(${LENGTH_RESULT_STRING} EQUAL 0)
execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --format=%H
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-list HEAD --count
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE VERSION_REVISION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(APPVEYOR_REPO_BRANCH_EXISTS $ENV{APPVEYOR_REPO_BRANCH})
set(TRAVIS_BRANCH_EXISTS $ENV{TRAVIS_BRANCH})
if(NOT DEFINED BRANCH_NAME)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE BRANCH_NAME
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
endif()
else()
set(BRANCH_NAME "")
endif()
message("BRANCH_NAME: ${BRANCH_NAME}")
project(beam VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION})
message("BEAM_VERSION: ${PROJECT_VERSION}")
if(UNIX AND NOT APPLE AND NOT ANDROID)
set(LINUX TRUE)
endif()
enable_testing()
function(add_test_snippet EXE_NAME LIB_NAME)
add_executable(${EXE_NAME} ${EXE_NAME}.cpp)
add_dependencies(${EXE_NAME} ${LIB_NAME})
target_link_libraries(${EXE_NAME} ${LIB_NAME})
add_test(NAME ${EXE_NAME} COMMAND $<TARGET_FILE:${EXE_NAME}>)
endfunction()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(BEAM_USE_AVX FALSE)
if (BEAM_CPU_ARCH MATCHES "avx")
set(BEAM_USE_AVX TRUE)
endif()
if(BEAM_USE_GPU)
add_definitions(-DBEAM_USE_GPU)
set(BEAM_USE_AVX TRUE)
endif()
if(BEAM_USE_AVX)
add_definitions(-DBEAM_USE_AVX)
endif()
set(BEAM_QT_UI_WALLET TRUE)
if (BEAM_NO_QT_UI_WALLET)
set(BEAM_QT_UI_WALLET FALSE)
endif()
set(BEAM_USE_STATIC FALSE)
if(BEAM_LINK_TYPE MATCHES "Static")
set(BEAM_USE_STATIC TRUE)
endif()
if(BEAM_USE_STATIC)
add_definitions(-DBEAM_USE_STATIC)
endif()
#it's enabled by default for testnet
#if(DEBUG_MESSAGES_IN_RELEASE_MODE)
add_definitions(-DDEBUG_MESSAGES_IN_RELEASE_MODE)
#endif()
#it's enabled by default for testnet
#add_definitions(-DLOG_VERBOSE_ENABLED=1)
if(SHOW_CODE_LOCATION)
add_definitions(-DSHOW_CODE_LOCATION=1)
endif()
if(BRANCH_NAME MATCHES "testnet")
add_definitions(-DBEAM_TESTNET)
endif()
if(BEAM_TESTNET)
add_definitions(-DBEAM_TESTNET)
endif()
if(MSVC)
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4 /WX" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /WX")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4100") # unreferenced formal parameter
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4324") # '__blake2b_state': structure was padded due to alignment specifier
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /O2")
SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /OPT:REF /INCREMENTAL:NO")
SET(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /OPT:REF /INCREMENTAL:NO")
SET(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL} /OPT:REF /INCREMENTAL:NO")
if(BEAM_USE_STATIC)
# use static runtime
foreach(flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
flag_var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
if(${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif(${flag_var} MATCHES "/MD")
endforeach(flag_var)
endif()
else()
if(NOT ANDROID)
if(ARCH_NATIVE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=core2")
endif()
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -pthread")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -ggdb3")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
# disable some warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-overloaded-virtual") # appears alot in our macro expansions
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-const-variable") # so what?
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-function") # mostly in 3rd-party libs
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-value") # proto.h
endif()
if(UNIX OR WIN32)
set(UV_INTERNAL ON)
add_definitions(-DUV_INTERNAL)
endif()
include_directories($ENV{BOOST_ROOT}/include)
link_directories($ENV{BOOST_ROOT}/lib)
if(ANDROID)
message("ANDROID_ABI: ${ANDROID_ABI}")
add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY)
include_directories($ENV{BOOST_ROOT_ANDROID}/${ANDROID_ABI}/include/boost-1_68)
if(ANDROID_ABI STREQUAL "armeabi-v7a")
set(OPENSSL_ROOT_DIR_ANDROID $ENV{OPENSSL_ROOT_DIR_ANDROID}/armv7-shared)
elseif(ANDROID_ABI STREQUAL "x86")
set(OPENSSL_ROOT_DIR_ANDROID $ENV{OPENSSL_ROOT_DIR_ANDROID}/x86-shared)
else()
message(FATAL_ERROR "error, ANDROID_ABI not defined.")
endif()
else()
if(BEAM_USE_STATIC)
include(FindBoost)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC_RUNTIME ON)
else()
if (WIN32)
add_definitions( -DBOOST_ALL_DYN_LINK )
endif()
endif()
endif()
if (WIN32)
add_definitions(-DNOMINMAX)
find_package(Boost)
if (Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
endif()
endif()
include_directories(${PROJECT_SOURCE_DIR})
add_definitions(-DPROJECT_SOURCE_DIR=\"${PROJECT_SOURCE_DIR}\")
include_directories(${PROJECT_SOURCE_DIR}/3rdparty)
if(BEAM_USE_STATIC)
if(MSVC)
include_directories($ENV{OPENSSL_ROOT_DIR}/include)
else()
find_package(OpenSSL REQUIRED)
if( OpenSSL_FOUND )
set(OPENSSL_USE_STATIC_LIBS TRUE)
link_directories(${OPENSSL_LIBRARIES})
include_directories(${OPENSSL_INCLUDE_DIR})
message(STATUS "Using OpenSSL ${OPENSSL_VERSION}")
else()
message(FATAL_ERROR "error, OpenSSL not found, please install: 'apt-get install libssl-dev' on Ubuntu")
endif()
endif()
# cmake can't find static lib on macos, harcoded
if(APPLE)
set(OPENSSL_LIBCRYPTO $ENV{OPENSSL_ROOT_DIR}/lib/libcrypto.a)
set(OPENSSL_LIBSSL $ENV{OPENSSL_ROOT_DIR}/lib/libssl.a)
elseif(UNIX)
set(OPENSSL_LIBCRYPTO /usr/lib/x86_64-linux-gnu/libcrypto.a)
set(OPENSSL_LIBSSL /usr/lib/x86_64-linux-gnu/libssl.a)
elseif(MSVC)
set(OPENSSL_LIBCRYPTO $ENV{OPENSSL_ROOT_DIR}/lib/VC/static/libcrypto64MT.lib crypt32.lib)
set(OPENSSL_LIBSSL $ENV{OPENSSL_ROOT_DIR}/lib/VC/static/libssl64MT.lib)
if(MSVC_VERSION GREATER_EQUAL 1900)
set(OPENSSL_LIBCRYPTO ${OPENSSL_LIBCRYPTO} legacy_stdio_definitions.lib)
endif()
endif()
else()
if(ANDROID)
include_directories(${OPENSSL_ROOT_DIR_ANDROID}/include)
set(OPENSSL_LIBCRYPTO ${OPENSSL_ROOT_DIR_ANDROID}/lib/libcrypto.a)
set(OPENSSL_LIBSSL ${OPENSSL_ROOT_DIR_ANDROID}/lib/libssl.a)
else()
find_package(OpenSSL REQUIRED)
if( OpenSSL_FOUND )
set(OPENSSL_USE_STATIC_LIBS TRUE)
link_directories(${OPENSSL_LIBRARIES})
include_directories(${OPENSSL_INCLUDE_DIR})
message(STATUS "Using OpenSSL ${OPENSSL_VERSION}")
set(OPENSSL_LIBCRYPTO OpenSSL::Crypto)
set(OPENSSL_LIBSSL OpenSSL::SSL)
else()
message(FATAL_ERROR "error, OpenSSL not found, please install: 'apt-get install libssl-dev' on Ubuntu")
endif()
endif()
endif()
add_subdirectory(3rdparty/sqlite)
add_subdirectory(utility)
add_subdirectory(core)
add_subdirectory(pow)
add_subdirectory(p2p)
add_subdirectory(http)
add_subdirectory(wallet)
add_subdirectory(node)
add_subdirectory(beam)
add_subdirectory(explorer)
add_subdirectory(mnemonic)
if(ANDROID OR BEAM_BUILD_JNI)
add_subdirectory(android)
endif()
# TODO: uncomment this later
if(NOT ANDROID AND BEAM_QT_UI_WALLET)
add_subdirectory(3rdparty/qrcode)
add_subdirectory(3rdparty/quazip)
add_subdirectory(ui)
endif()
########################################################
### PACKAGING ##########################################
########################################################
if (WIN32)
set(CPACK_GENERATOR "NSIS")
set(CPACK_SOURCE_GENERATOR "ZIP")
set(CPACK_NSIS_MUI_ICON "${PROJECT_SOURCE_DIR}/ui/icon.ico")
set(CPACK_NSIS_MUI_UNIICON "${PROJECT_SOURCE_DIR}/ui/icon.ico")
set(CPACK_NSIS_INSTALLED_ICON_NAME "${PROJECT_SOURCE_DIR}/ui/icon.ico")
set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "CreateShortCut \\\"$DESKTOP\\\\Beam Wallet.lnk\\\" \\\"$INSTDIR\\\\Beam Wallet.exe\\\"")
set(CPACK_NSIS_CREATE_ICONS_EXTRA "CreateShortCut \\\"$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\Beam Wallet.lnk\\\" \\\"$INSTDIR\\\\Beam Wallet.exe\\\"")
set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "Delete \\\"$DESKTOP\\\\Beam Wallet.lnk\\\"")
set(CPACK_NSIS_DELETE_ICONS_EXTRA "Delete \\\"$SMPROGRAMS\\\\$MUI_TEMP\\\\Beam Wallet.lnk\\\"")
set(CPACK_NSIS_EXECUTABLES_DIRECTORY .)
set(CPACK_NSIS_MUI_FINISHPAGE_RUN "Beam Wallet.exe")
set(CPACK_NSIS_PACKAGE_NAME "Beam Wallet")
elseif (APPLE)
set(CPACK_GENERATOR "DragNDrop")
elseif (LINUX)
set(CPACK_GENERATOR "DEB")
set(CPACK_DEBIAN_PACKAGE_NAME "beamwallet")
set(CPACK_DEBIAN_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Beam <[email protected]>")
set(CPACK_DEBIAN_PACKAGE_SECTION "Network")
endif ()
set(CPACK_PACKAGE_NAME "BeamWallet")
set(CPACK_PACKAGE_VENDOR "Beam Vendor")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Scalable confidential cryptocurrency")
set(CPACK_PACKAGE_VERSION_MAJOR "0")
set(CPACK_PACKAGE_VERSION_MINOR "0")
set(CPACK_PACKAGE_VERSION_PATCH "1")
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "Beam")
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/TERMS.txt")
include(CPack)