forked from gridcoin-community/Gridcoin-Research
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
262 lines (203 loc) · 7.91 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
# CMake build system is intended to be used by maintainers to package Gridcoin
# for software repositories. For that reason, only external dependencies are
# supported.
#
# Use Autotools build system for all other needs.
#
# CMake support is experimental. Use with caution and report any bugs.
cmake_minimum_required(VERSION 3.18)
project("Gridcoin"
VERSION 5.4.5.4
DESCRIPTION "POS-based cryptocurrency that rewards BOINC computation"
HOMEPAGE_URL "https://gridcoin.us"
LANGUAGES ASM C CXX
)
set(CLIENT_VERSION_IS_RELEASE "false")
set(COPYRIGHT_YEAR "2023")
set(COPYRIGHT_HOLDERS_FINAL "The Gridcoin developers")
# Toolchain configuration
# =======================
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Remove '-DNDEBUG' from flags because we need asserts
string(REPLACE "NDEBUG" "_NDEBUG" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
string(REPLACE "NDEBUG" "_NDEBUG" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
# Load modules from the source tree
# =================================
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/build-aux/cmake")
include(CheckCXXSymbolExists)
include(CheckFunctionExists)
include(CheckIncludeFile)
include(CheckPIESupported)
include(CheckSSE)
include(CheckStrerrorR)
include(CheckSymbolExists)
include(VersionFromGit)
# Define options
# ==============
# Build configuration
option(ENABLE_DAEMON "Enable daemon" ON)
option(ENABLE_GUI "Enable Qt-based GUI" OFF)
option(ENABLE_DOCS "Build Doxygen documentation" OFF)
option(ENABLE_TESTS "Build tests" OFF)
option(LUPDATE "Update translation files" OFF)
# CPU-dependent options
option(ENABLE_SSE41 "Build code that uses SSE4.1 intrinsics" ${HAS_SSE41})
option(ENABLE_AVX2 "Build code that uses AVX2 intrinsics" ${HAS_AVX2})
option(ENABLE_X86_SHANI "Build code that uses x86 SHA-NI intrinsics" ${HAS_X86_SHANI})
option(ENABLE_ARM_SHANI "Build code that uses ARM SHA-NI intrinsics" ${HAS_ARM_SHANI})
option(USE_ASM "Enable assembly routines" ON)
# Optional functionality
option(ENABLE_PIE "Build position-independent executables" OFF)
option(ENABLE_QRENCODE "Enable generation of QR Codes for receiving payments" OFF)
option(ENABLE_UPNP "Enable UPnP port mapping support" OFF)
option(DEFAULT_UPNP "Turn UPnP on startup" OFF)
option(USE_DBUS "Enable DBus support" OFF)
option(SYSTEM_BDB "Find system installation of Berkeley DB CXX 5.3" OFF)
option(SYSTEM_LEVELDB "Find system installation of leveldb" OFF)
option(SYSTEM_SECP256K1 "Find system installation of libsecp256k1 with pkg-config" OFF)
option(SYSTEM_UNIVALUE "Find system installation of Univalue with pkg-config" OFF)
option(SYSTEM_XXD "Find system xxd binary" OFF)
# Find dependencies
# =================
set(BOOST_MINIMUM_VERSION 1.63.0)
set(QT5_MINIMUM_VERSION 5.15.0)
find_package(Atomics REQUIRED)
find_package(Boost ${BOOST_MINIMUM_VERSION} COMPONENTS filesystem iostreams thread REQUIRED)
find_package(CURL COMPONENTS HTTP HTTPS SSL REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(Threads REQUIRED)
find_package(libzip REQUIRED)
if(SYSTEM_BDB)
find_package(BerkeleyDB 5.3...<5.4 COMPONENTS CXX REQUIRED)
else()
find_program(MAKE_EXE NAMES gmake nmake make)
endif()
if(SYSTEM_LEVELDB)
find_package(leveldb REQUIRED)
endif()
if(SYSTEM_SECP256K1)
find_package(PkgConfig)
pkg_check_modules(SECP256K1 REQUIRED IMPORTED_TARGET "libsecp256k1 >= 0.2.0")
endif()
if(SYSTEM_UNIVALUE)
find_package(PkgConfig)
pkg_check_modules(UNIVALUE REQUIRED IMPORTED_TARGET libunivalue)
endif()
if(ENABLE_GUI)
find_package(Qt5 ${QT5_MINIMUM_VERSION} REQUIRED COMPONENTS
Concurrent
Core
Gui
LinguistTools
Network
Widgets
)
if(USE_DBUS)
find_package(Qt5 ${QT5_MINIMUM_VERSION} COMPONENTS DBus REQUIRED)
endif()
if(ENABLE_TESTS)
find_package(Qt5 ${QT5_MINIMUM_VERSION} COMPONENTS Test REQUIRED)
endif()
if(ENABLE_QRENCODE)
pkg_check_modules(QRENCODE REQUIRED IMPORTED_TARGET libqrencode)
endif()
endif()
if(ENABLE_UPNP)
pkg_check_modules(MINIUPNPC REQUIRED IMPORTED_TARGET miniupnpc>=1.9)
endif()
if(ENABLE_TESTS)
find_package(Boost ${BOOST_MINIMUM_VERSION} COMPONENTS unit_test_framework REQUIRED)
enable_testing()
if(SYSTEM_XXD)
find_program(XXD xxd REQUIRED)
endif()
endif()
if(UNIX)
find_package(Rt REQUIRED)
endif()
if(WIN32)
enable_language(RC)
find_program(MAKENSIS makensis)
elseif(APPLE)
enable_language(OBJCXX)
endif()
# Run probes
# ==========
if(ENABLE_PIE)
check_pie_supported()
if(NOT CMAKE_CXX_LINK_PIE_SUPPORTED)
message(FATAL_ERROR "PIE is not supported by the current linker")
endif()
endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ${ENABLE_PIE})
# Set compiler flags
if (APPLE)
add_compile_options(-Wno-error=deprecated-declarations)
add_compile_options(-Wno-error=thread-safety-analysis)
add_compile_options(-Wno-error=thread-safety-reference)
endif()
# Set endianness
if(CMAKE_CXX_BYTE_ORDER EQUAL BIG_ENDIAN)
set(WORDS_BIGENDIAN 1)
endif()
# Check headers
check_include_file("byteswap.h" HAVE_BYTESWAP_H)
check_include_file("endian.h" HAVE_ENDIAN_H)
check_include_file("sys/endian.h" HAVE_SYS_ENDIAN_H)
check_include_file("sys/prctl.h" HAVE_SYS_PRCTL_H)
if(HAVE_ENDIAN_H)
set(ENDIAN_INCLUDES "endian.h")
else()
set(ENDIAN_INCLUDES "sys/endian.h")
endif()
if(HAVE_BYTESWAP_H)
set(BYTESWAP_INCLUDES "byteswap.h")
endif()
# Check symbols
check_symbol_exists(fork "unistd.h" HAVE_DECL_FORK)
check_symbol_exists(pipe2 "unistd.h" HAVE_DECL_PIPE2)
check_symbol_exists(setsid "unistd.h" HAVE_DECL_SETSID)
check_symbol_exists(le16toh "${ENDIAN_INCLUDES}" HAVE_DECL_LE16TOH)
check_symbol_exists(le32toh "${ENDIAN_INCLUDES}" HAVE_DECL_LE32TOH)
check_symbol_exists(le64toh "${ENDIAN_INCLUDES}" HAVE_DECL_LE64TOH)
check_symbol_exists(htole16 "${ENDIAN_INCLUDES}" HAVE_DECL_HTOLE16)
check_symbol_exists(htole32 "${ENDIAN_INCLUDES}" HAVE_DECL_HTOLE32)
check_symbol_exists(htole64 "${ENDIAN_INCLUDES}" HAVE_DECL_HTOLE64)
check_symbol_exists(be16toh "${ENDIAN_INCLUDES}" HAVE_DECL_BE16TOH)
check_symbol_exists(be32toh "${ENDIAN_INCLUDES}" HAVE_DECL_BE32TOH)
check_symbol_exists(be64toh "${ENDIAN_INCLUDES}" HAVE_DECL_BE64TOH)
check_symbol_exists(htobe16 "${ENDIAN_INCLUDES}" HAVE_DECL_HTOBE16)
check_symbol_exists(htobe32 "${ENDIAN_INCLUDES}" HAVE_DECL_HTOBE32)
check_symbol_exists(htobe64 "${ENDIAN_INCLUDES}" HAVE_DECL_HTOBE64)
check_symbol_exists(bswap_16 "${BYTESWAP_INCLUDES}" HAVE_DECL_BSWAP_16)
check_symbol_exists(bswap_32 "${BYTESWAP_INCLUDES}" HAVE_DECL_BSWAP_32)
check_symbol_exists(bswap_64 "${BYTESWAP_INCLUDES}" HAVE_DECL_BSWAP_64)
check_function_exists(__builtin_clzl HAVE_BUILTIN_CLZL)
check_function_exists(__builtin_clzll HAVE_BUILTIN_CLZLL)
check_symbol_exists(MSG_NOSIGNAL "sys/socket.h" HAVE_MSG_NOSIGNAL)
check_symbol_exists(MSG_DONTWAIT "sys/socket.h" HAVE_MSG_DONTWAIT)
check_symbol_exists(malloc_info "malloc.h" HAVE_MALLOC_INFO)
check_symbol_exists(M_ARENA_MAX "malloc.h" HAVE_MALLOPT_ARENA_MAX)
check_cxx_symbol_exists(std::system "cstdlib" HAVE_SYSTEM)
check_cxx_symbol_exists(gmtime_r "ctime" HAVE_GMTIME_R)
if(NOT HAVE_GMTIME_R)
check_cxx_symbol_exists(gmtime_s "ctime" HAVE_GMTIME_S)
if(NOT HAVE_GMTIME_S)
message(FATAL_ERROR "Both gmtime_r and gmtime_s are unavailable")
endif()
endif()
check_symbol_exists(SYS_getrandom "sys/syscall.h" HAVE_SYS_GETRANDOM)
check_symbol_exists(getentropy "unistd.h" HAVE_GETENTROPY)
check_symbol_exists(KERN_ARND "sys/sysctl.h" HAVE_SYSCTL_ARND)
check_symbol_exists(O_CLOEXEC "fcntl.h" HAVE_O_CLOEXEC)
check_symbol_exists(getauxval "sys/auxv.h" HAVE_STRONG_GETAUXVAL)
# Descend into subdirectories
# ===========================
add_subdirectory(src)
if(ENABLE_DOCS)
add_subdirectory(doc)
endif()