forked from hyle-team/zano
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
317 lines (272 loc) · 12.1 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
cmake_minimum_required(VERSION 2.8.6)
list(INSERT CMAKE_MODULE_PATH 0
"${CMAKE_CURRENT_SOURCE_DIR}/contrib/cmake")
PROJECT(Lethean)
option (USE_CCACHE "Use ccache if a usable instance is found" ON)
if (USE_CCACHE)
include(FindCcache) # Has to be included after the project() macro, to be able to read the CXX variable.
else()
message(STATUS "ccache deselected")
endif()
option (USE_COMPILATION_TIME_PROFILER "Use compilation time profiler (for CLang >= 9 only)" OFF)
if (USE_COMPILATION_TIME_PROFILER)
if (NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
message(FATAL_ERROR "The flag USE_COMPILATION_TIME_PROFILER is meant to be set only for CLang compiler!")
endif()
add_compile_options("-ftime-trace")
endif()
if (${CMAKE_VERSION} VERSION_GREATER "3.0.0" AND CMAKE_MAKE_PROGRAM MATCHES "ninja")
set(CCACHE_PARALLEL_COMPILE_JOBS "" CACHE STRING "The maximum number of concurrent compilation jobs.")
if (CCACHE_PARALLEL_COMPILE_JOBS)
set_property(GLOBAL APPEND PROPERTY JOB_POOLS compile_job_pool=${CCACHE_PARALLEL_COMPILE_JOBS})
set(CMAKE_JOB_POOL_COMPILE compile_job_pool)
endif ()
set(CCACHE_PARALLEL_LINK_JOBS "" CACHE STRING "The maximum number of concurrent link jobs.")
if (CCACHE_PARALLEL_LINK_JOBS)
set_property(GLOBAL APPEND PROPERTY JOB_POOLS link_job_pool=${CCACHE_PARALLEL_LINK_JOBS})
set(CMAKE_JOB_POOL_LINK link_job_pool)
endif ()
endif ()
set(VERSION "1.0")
# if(POLICY CMP0043)
# cmake_policy(SET CMP0043 OLD)
# endif()
# if(POLICY CMP0020)
# cmake_policy(SET CMP0020 OLD)
# endif()
include(ConfigOpenSSL)
if(CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "Android")
add_definitions(-DMOBILE_WALLET_BUILD)
if(CMAKE_SYSTEM_NAME STREQUAL "iOS" )
add_definitions(-DIOS_BUILD)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fembed-bitcode")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fembed-bitcode")
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Android")
add_definitions(-DANDROID_BUILD)
message("Android sdk prefix: ${CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX}")
message("Android CMAKE_CXX_COMPILER prefix: ${CMAKE_CXX_COMPILER}")
message("Android ANDROID_LD: ${ANDROID_LD}")
endif()
endif()
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# build types
if (UNIX AND NOT APPLE)
# single configurations, defaults to Release
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
else()
# multi configurations for MSVC and XCode
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
set(CMAKE_CONFIGURATION_TYPES "Release")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
set(CMAKE_CONFIGURATION_TYPES "Debug;Release")
else()
set(CMAKE_CONFIGURATION_TYPES "Debug;Release")
endif()
endif()
message("Generated with config types: ${CMAKE_CONFIGURATION_TYPES}, and built type: ${CMAKE_BUILD_TYPE}")
enable_testing()
if(APPLE)
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.10.5 CACHE STRING "Minimum OS X deployment version")
endif()
set(USE_PCH FALSE CACHE BOOL "Use shared precompiled headers")
set(DISABLE_TOR FALSE CACHE BOOL "Disable TOR library(and related tor-connect submodule)")
set(TESTNET FALSE CACHE BOOL "Compile for testnet")
set(MUTE_ERRORS TRUE CACHE BOOL "Disable Error Suppression")
set(BUILD_GUI FALSE CACHE BOOL "Build qt-daemon")
if(TESTNET)
message("!!!!!! NOTICE: Project is building for TESTNET !!!!!!")
add_definitions(-DTESTNET)
if(MUTE_ERRORS)
# shhhhh sleepy time errors, we know...
add_definitions(-w)
endif()
else()
if(MUTE_ERRORS)
# shhhhh sleepy time errors, we know...
add_definitions(-w)
endif()
endif()
if(DISABLE_TOR)
message("NOTICE: Building with disabled TOR support!")
add_definitions(-DDISABLE_TOR)
endif()
include_directories(src contrib/eos_portable_archive contrib contrib/epee/include "${CMAKE_BINARY_DIR}/version" "${CMAKE_BINARY_DIR}/contrib/zlib")
add_definitions(-DSTATICLIB)
set(STATIC ${MSVC} CACHE BOOL "Link libraries statically")
if (UNIX AND NOT APPLE)
# Note that at the time of this writing the -Wstrict-prototypes flag added below will make this fail
find_package(Threads REQUIRED)
endif()
# TODO(unassigned): expand on types and versions, and then refactor.
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CLANG TRUE)
endif()
if(MSVC)
add_definitions("/D_CRT_SECURE_NO_WARNINGS /D_WIN32_WINNT=0x0600 /DWIN32_LEAN_AND_MEAN /DGTEST_HAS_TR1_TUPLE=0 /D__SSE4_1__")
add_compile_options(/bigobj /Zm1000 /Z7 /MP2 /W3 /GS- /wd4996 /wd4503 /wd4345 /wd4091 /FIinline_c.h)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:10485760 /DEBUG dbghelp.lib")
if(STATIC)
foreach(VAR CMAKE_C_FLAGS_DEBUG CMAKE_CXX_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELEASE)
string(REPLACE "/MD" "/MT" ${VAR} "${${VAR}}")
endforeach()
endif()
include_directories(SYSTEM src/platform/msc)
else()
set(ARCH default CACHE STRING "CPU to build for: -march value or default")
if("${ARCH}" STREQUAL "default")
set(ARCH_FLAG "")
else()
set(ARCH_FLAG "-march=${ARCH}")
endif()
set(WARNINGS "-Wall -Wextra -Wpointer-arith -Wvla -Wwrite-strings -Wno-error=extra -Wno-error=deprecated-declarations -Wno-error=sign-compare -Wno-error=strict-aliasing -Wno-error=type-limits -Wno-unused-parameter -Wno-error=unused-variable -Wno-aggregate-return")
# if(NOT APPLE)
# set(WARNINGS "${WARNINGS} -Werror")
# endif()
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
set(WARNINGS "${WARNINGS} -Wno-implicit-function-declaration -Wno-shift-count-overflow -Wno-error=mismatched-tags -Wno-error=null-conversion -Wno-overloaded-shift-op-parentheses -Wno-error=shift-count-overflow -Wno-error=tautological-constant-out-of-range-compare -Wno-error=unused-private-field -Wno-error=unneeded-internal-declaration")
else()
set(WARNINGS "${WARNINGS} -Wno-error=write-strings -Wlogical-op -Wno-error=maybe-uninitialized")
endif()
# Since gcc 4.9 the LTO format is non-standard (slim), so we need the gcc-specific ar and ranlib binaries
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.0) AND NOT (CMAKE_SYSTEM_NAME STREQUAL "Android"))
set(CMAKE_AR "gcc-ar")
set(CMAKE_RANLIB "gcc-ranlib")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT APPLE AND NOT (CMAKE_SYSTEM_NAME STREQUAL "Android"))
set(CMAKE_AR "llvm-ar")
set(CMAKE_RANLIB "llvm-ranlib")
endif()
if(MINGW)
set(WARNINGS "${WARNINGS} -Wno-error=unused-value")
set(MINGW_FLAG "-DWIN32_LEAN_AND_MEAN")
include_directories(SYSTEM src/platform/mingw)
else()
set(MINGW_FLAG "")
endif()
if(APPLE)
set(APPLE_FLAG "-DGTEST_USE_OWN_TR1_TUPLE=1")
else()
set(APPLE_FLAG "")
endif()
set(C_WARNINGS "-Waggregate-return -Wnested-externs -Wstrict-prototypes")
set(CXX_WARNINGS "-Wno-reorder -Wno-missing-field-initializers")
try_compile(STATIC_ASSERT_RES "${CMAKE_CURRENT_BINARY_DIR}/static-assert" "${CMAKE_CURRENT_SOURCE_DIR}/utils/test-static-assert.c" COMPILE_DEFINITIONS "-std=c11")
if(STATIC_ASSERT_RES)
set(STATIC_ASSERT_FLAG "")
else()
set(STATIC_ASSERT_FLAG "-Dstatic_assert=_Static_assert")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -D_GNU_SOURCE ${MINGW_FLAG} ${STATIC_ASSERT_FLAG} ${WARNINGS} ${C_WARNINGS} ${ARCH_FLAG}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive -ftemplate-depth-1024 -std=c++11 -D_GNU_SOURCE ${APPLE_FLAG} ${MINGW_FLAG} ${WARNINGS} ${CXX_WARNINGS} ${ARCH_FLAG}")
if (NOT APPLE AND NOT MSVC)
if (CLANG)
set(LLVM_USE_LINKER "gold")
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold")
endif()
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND NOT (CMAKE_C_COMPILER_VERSION VERSION_LESS 4.8))
set(DEBUG_FLAGS "-g3 -O0") #set(DEBUG_FLAGS "-g3 -Og")
else()
set(DEBUG_FLAGS "-g3 -O0")
endif()
set(RELEASE_FLAGS "-Ofast -DNDEBUG -Wno-unused-variable")
if(NOT APPLE AND NOT (CMAKE_SYSTEM_NAME STREQUAL "Android"))
set(RELEASE_FLAGS "${RELEASE_FLAGS} -flto")
endif()
#if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND NOT MINGW)
# set(RELEASE_FLAGS "${RELEASE_FLAGS} -fno-fat-lto-objects")
#endif()
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${DEBUG_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${DEBUG_FLAGS}")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${RELEASE_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${RELEASE_FLAGS}")
if(STATIC)
if(APPLE)
# message(SEND_ERROR "Static build is not supported on MacOS X")
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
endif()
endif()
endif()
if(MSVC)
set(Boost_USE_STATIC_LIBS ON)
endif()
if(STATIC)
set(Boost_USE_STATIC_LIBS ON)
# set(Boost_USE_STATIC_RUNTIME ON)
endif()
message("CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}")
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
set(Boost_LIBRARIES "libboost.a")
#workaround for new XCode 12 policy for builds(now it includes a slice for the "arm64" when builds for simulator)
set(__iphoneos_archs "armv7 armv7s arm64")
set(__iphonesimulator_archs "i386 x86_64")
set(CMAKE_XCODE_ATTRIBUTE_ARCHS[sdk=iphoneos*] "${__iphoneos_archs}")
set(CMAKE_XCODE_ATTRIBUTE_VALID_ARCHS[sdk=iphoneos*] "${__iphoneos_archs}")
set(CMAKE_XCODE_ATTRIBUTE_ARCHS[sdk=iphonesimulator*] "${__iphonesimulator_archs}")
set(CMAKE_XCODE_ATTRIBUTE_VALID_ARCHS[sdk=iphonesimulator*] "${__iphonesimulator_archs}")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
set(Boost_LIBRARY_DIRS "${Boost_LIBRARY_DIRS}/${CMAKE_ANDROID_ARCH_ABI}/")
set(Boost_LIBRARIES "${Boost_LIBRARY_DIRS}libboost_system.a;${Boost_LIBRARY_DIRS}libboost_filesystem.a;${Boost_LIBRARY_DIRS}libboost_thread.a;${Boost_LIBRARY_DIRS}libboost_timer.a;${Boost_LIBRARY_DIRS}libboost_date_time.a;${Boost_LIBRARY_DIRS}libboost_chrono.a;${Boost_LIBRARY_DIRS}libboost_regex.a;${Boost_LIBRARY_DIRS}libboost_serialization.a;${Boost_LIBRARY_DIRS}libboost_atomic.a;${Boost_LIBRARY_DIRS}libboost_program_options.a")
else()
find_package(Boost 1.70 REQUIRED COMPONENTS system filesystem thread timer date_time chrono regex serialization atomic program_options locale)
endif()
message(STATUS "Boost: ${Boost_VERSION} from ${Boost_LIBRARY_DIRS}")
include_directories(SYSTEM ${Boost_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/contrib/ethereum/libethash)
if(MINGW)
set(Boost_LIBRARIES "${Boost_LIBRARIES};ws2_32;mswsock")
elseif(NOT MSVC)
if(NOT APPLE)
set(Boost_LIBRARIES "${Boost_LIBRARIES};")
if(STATIC)
message("NOTICE: Including static ICU libraries")
set(Boost_LIBRARIES "${Boost_LIBRARIES};icui18n.a;icuuc.a;icudata.a;dl")
endif()
endif()
endif()
if(BUILD_GUI)
cmake_minimum_required(VERSION 2.8.11)
if(APPLE AND NOT CMAKE_PREFIX_PATH)
execute_process(COMMAND brew --prefix qt5 OUTPUT_VARIABLE QT5_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
list(APPEND CMAKE_PREFIX_PATH ${QT5_DIR})
endif()
find_package(Qt5Widgets REQUIRED)
endif()
set(COMMIT_ID_IN_VERSION ON CACHE BOOL "Include commit ID in version")
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/version")
if (NOT COMMIT_ID_IN_VERSION)
set(VERSION "${VERSION}-unknown")
configure_file("src/version.h.in" "version/version.h")
add_custom_target(version ALL)
elseif(DEFINED COMMIT)
string(REPLACE "." "\\." VERSION_RE "${VERSION}")
if(NOT REFS MATCHES "(\\(|, )tag: v${VERSION_RE}(\\)|, )")
set(VERSION "${VERSION}-g${COMMIT}")
endif()
configure_file("src/version.h.in" "version/version.h")
add_custom_target(version ALL)
else()
find_package(Git QUIET)
if(Git_FOUND OR GIT_FOUND)
message(STATUS "Found Git: ${GIT_EXECUTABLE}")
add_custom_target(version ALL "${CMAKE_COMMAND}" "-D" "VERSION=${VERSION}" "-D" "GIT=${GIT_EXECUTABLE}" "-D" "TO=${CMAKE_BINARY_DIR}/version/version.h" "-P" "src/version.cmake" WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
else()
message(STATUS "WARNING: Git was not found!")
set(VERSION "${VERSION}-unknown")
configure_file("src/version.h.in" "version/version.h")
add_custom_target(version ALL)
endif()
endif()
set(BUILD_TESTS FALSE CACHE BOOL "Build Lethean tests")
set(DISABLE_MDBX FALSE CACHE BOOL "Exclude mdbx from build(need for a first time)")
if(NOT DISABLE_MDBX)
add_definitions(-DENABLED_ENGINE_MDBX)
endif()
add_subdirectory(contrib)
add_subdirectory(src)
if (BUILD_TESTS)
add_subdirectory(tests)
endif()