forked from bcndev/bytecoin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
216 lines (202 loc) · 9.54 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
# Copyright (c) 2012-2018, The CryptoNote developers, The Bytecoin developers.
# Licensed under the GNU Lesser General Public License. See LICENSE for details.
cmake_minimum_required(VERSION 3.0)
project(bytecoin)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_C_STANDARD 11)
set(CRYPTONOTE_NAME bytecoin)
add_definitions(-DCRYPTONOTE_NAME=\"${CRYPTONOTE_NAME}\" -DNDEBUG=1)
option(WITH_LEDGER "Builds with support of Ledger hardware wallets" OFF)
option(USE_INSTRUMENTATION "For testing - builds with address sanitizer instrument" OFF)
option(WITH_THREAD_SANITIZER "For testing - builds with thread sanitizer instrument, USE_INSTRUMENTATION must be also set" OFF)
option(BETTER_DEBUG "Disables optimizations. We do not use standard debug/realease configurations because they change too much" OFF)
get_filename_component(PARENT_DIR ${CMAKE_SOURCE_DIR} DIRECTORY)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
option(USE_SQLITE "Builds with SQLite instead of LMDB. 4x slower, but works on 32-bit and mobile platforms" OFF)
set(OPENSSL_ROOT ${PARENT_DIR}/openssl)
else()
option(USE_SQLITE "Builds with sqlite instead of LMDB. 4x slower, but works on 32-bit and mobile platforms" ON)
set(OPENSSL_ROOT ${PARENT_DIR}/openssl32)
endif()
if(APPLE)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.11")
endif()
if(WIN32)
add_definitions(-D_SCL_SECURE_NO_WARNINGS=1 -D_CRT_SECURE_NO_WARNINGS=1 -D_WIN32_WINNT=0x0501)
else()
# We can build on old Ubuntu 14 with clang by adding next line (does not work with add_compile_options)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
# Binaries will need sudo apt-get install libc++-dev to run on machines without clang
add_compile_options(-maes -g -Wall -Wextra -Werror=return-type -Wno-unused-parameter)
# We can use -Wshadow with clang occasionally
if(BETTER_DEBUG)
message(STATUS "Using better debug: " ${BETTER_DEBUG})
add_compile_options(-O0)
else()
add_compile_options(-O2)
endif()
message(STATUS "Instrumentation usage: " ${USE_INSTRUMENTATION})
message(STATUS "Thread sanitizer usage: " ${WITH_THREAD_SANITIZER})
if(USE_INSTRUMENTATION)
if(WITH_THREAD_SANITIZER)
add_compile_options(-fsanitize=thread)
else()
add_compile_options(-fno-omit-frame-pointer -fsanitize=address,undefined)
endif()
endif()
endif()
include_directories(vendor/sqlite)
include_directories(vendor/hmac)
set(SRC_WARNINGS_DB vendor/sqlite/sqlite3.c)
set(SRC_DB src/platform/DBsqlite3.cpp src/platform/DBsqlite3.hpp)
if(USE_SQLITE)
# Requires dl on Linux, we add it unconditionally for simplicity.
message(STATUS "Database selected: SQLite 3")
add_definitions(-Dplatform_USE_SQLITE=1)
else()
message(STATUS "Database selected: LMDB")
include_directories(../lmdb/libraries/liblmdb)
if(NOT EXISTS "${PARENT_DIR}/lmdb/libraries/liblmdb/mdb.c")
message(FATAL_ERROR "${PARENT_DIR}/lmdb/libraries/liblmdb/mdb.c not found. Make sure lmdb is cloned into ../lmdb/")
endif()
set(SRC_WARNINGS_DB ${SRC_WARNINGS_DB} ../lmdb/libraries/liblmdb/mdb.c ../lmdb/libraries/liblmdb/midl.c)
set(SRC_DB ${SRC_DB} src/platform/DBlmdb.cpp src/platform/DBlmdb.hpp)
endif()
message(STATUS "Make sure OpenSSL headers are in " ${OPENSSL_ROOT} "/include and static libs are in " ${OPENSSL_ROOT} "/")
include_directories(${OPENSSL_ROOT}/include)
link_directories(${OPENSSL_ROOT}) # Must be placed before add_executable, add_library.
set(LINK_OPENSSL ssl crypto)
add_definitions(-Dplatform_USE_SSL=1)
file(GLOB SRC_CRYPTO
src/crypto/*.cpp src/crypto/*.hpp
src/crypto/*.c src/crypto/*.h
src/crypto/bernstein/*.h src/crypto/bernstein/*.c
src/crypto/blake/*.h src/crypto/blake/*.c
src/crypto/groestl/*.h src/crypto/groestl/*.c
src/crypto/jh/*.h src/crypto/jh/*.c
src/crypto/keccak/*.c
src/crypto/oaes/*.h src/crypto/oaes/*.c
src/crypto/skein/*.h src/crypto/skein/*.c
)
file(GLOB SRC_COMMON src/common/*.cpp src/common/*.hpp)
file(GLOB SRC_SERIA src/seria/*.cpp src/seria/*.hpp)
file(GLOB SRC_LOGGING src/logging/*.cpp src/logging/*.hpp)
file(GLOB SRC_P2P src/p2p/*.cpp src/p2p/*.hpp)
file(GLOB SRC_CORE src/Core/*.cpp src/Core/*.hpp
src/Core/hardware/*.cpp src/Core/hardware/*.hpp
src/Core/hardware/trezor/*.cpp src/Core/hardware/trezor/*.hpp
src/CryptoNote.hpp src/CryptoNote.cpp
src/rpc_api.hpp src/rpc_api.cpp
vendor/hmac/*.h vendor/hmac/*.c)
file(GLOB SRC_HTTP src/http/*.cpp src/http/*.hpp)
file(GLOB SRC_PLATFORM
src/platform/ExclusiveLock.cpp src/platform/ExclusiveLock.hpp
src/platform/Files.cpp src/platform/Files.hpp
src/platform/Ledger.cpp src/platform/Ledger.hpp
src/platform/Time.cpp src/platform/Time.hpp
src/platform/Network.cpp src/platform/Network.hpp
src/platform/PathTools.cpp src/platform/PathTools.hpp
src/platform/PreventSleep.cpp src/platform/PreventSleep.hpp
src/platform/Windows.hpp src/platform/DB.hpp
)
# We compile those folders with full optimization even in debug mode, otherwise binaries will run much slower in debug
if(WIN32)
set_property(SOURCE ${SRC_CRYPTO} PROPERTY COMPILE_FLAGS -Ot)
set_property(SOURCE ${SRC_DB} PROPERTY COMPILE_FLAGS -Ot)
set_property(SOURCE ${SRC_WARNINGS_DB} PROPERTY COMPILE_FLAGS "-Ot -w")
set_property(SOURCE ${SRC_COMMON} PROPERTY COMPILE_FLAGS -Ot)
set_property(SOURCE ${SRC_SERIA} PROPERTY COMPILE_FLAGS -Ot)
else()
set_property(SOURCE ${SRC_CRYPTO} PROPERTY COMPILE_FLAGS -O3)
set_property(SOURCE ${SRC_DB} PROPERTY COMPILE_FLAGS -O3)
set_property(SOURCE ${SRC_WARNINGS_DB} PROPERTY COMPILE_FLAGS "-O3 -w")
set_property(SOURCE ${SRC_COMMON} PROPERTY COMPILE_FLAGS -O3)
set_property(SOURCE ${SRC_SERIA} PROPERTY COMPILE_FLAGS -O3)
endif()
include_directories(src)
include_directories(${CMAKE_BINARY_DIR})
set(SOURCE_FILES
${SRC_DB}
${SRC_WARNINGS_DB}
${SRC_COMMON}
${SRC_HTTP}
${SRC_CORE}
${SRC_SERIA}
${SRC_LOGGING}
${SRC_PLATFORM}
${SRC_P2P}
src/CryptoNote.hpp
src/CryptoNoteConfig.hpp
src/rpc_api.hpp
src/version.hpp
)
if(WITH_LEDGER)
# on Linux - apt-get install libusb-1.0-0-dev
# permission problem - https://raw.githubusercontent.com/LedgerHQ/udev-rules/master/add_udev_rules.sh
add_definitions(-Dcn_WITH_LEDGER=1)
set(LIBUSB_ROOT ${PARENT_DIR}/libusb)
if(WIN32)
# Link libusb dynamically.
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(USBLIB_LIBRARY ${LIBUSB_ROOT}/MS64/dll/libusb-1.0.lib)
else()
set(USBLIB_LIBRARY ${LIBUSB_ROOT}/MS32/dll/libusb-1.0.lib)
endif()
elseif(APPLE)
# Link libusb statically.
set(USBLIB_LIBRARY ${LIBUSB_ROOT}/lib/libusb-1.0.a "-framework Foundation" "-framework IOKit")
else()
set(USBLIB_LIBRARY "usb-1.0")
endif()
message(STATUS "With ledger " ${USBLIB_LIBRARY})
include_directories(${LIBUSB_ROOT}/include)
else()
endif()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/libs")
add_library(bytecoin-crypto ${SRC_CRYPTO})
add_library(bytecoin-core ${SOURCE_FILES})
target_link_libraries(bytecoin-core bytecoin-crypto ${USBLIB_LIBRARY})
link_libraries(bytecoin-crypto bytecoin-core)
if(APPLE)
link_libraries(-dead_strip)
endif()
if(NOT WIN32)
link_libraries(${LINK_OPENSSL} dl pthread)
endif()
if(WIN32)
add_executable(walletd src/main_walletd.cpp src/bytecoin.rc) # .rc works only if referenced directly in add_executable
add_executable(${CRYPTONOTE_NAME}d src/main_bytecoind.cpp src/bytecoin.rc) # .rc works only if referenced directly in add_executable
else()
add_executable(walletd src/main_walletd.cpp)
add_executable(${CRYPTONOTE_NAME}d src/main_bytecoind.cpp)
endif()
add_executable(minerd src/main_miner.cpp)
add_executable(tests src/main_tests.cpp tests/io.hpp tests/Random.hpp
tests/blockchain/test_blockchain.cpp tests/blockchain/test_blockchain.hpp
tests/crypto/test_crypto.cpp tests/crypto/test_crypto.hpp
tests/hash/test_hash.cpp tests/hash/test_hash.hpp
tests/json/test_json.cpp tests/json/test_json.hpp
tests/wallet_state/test_wallet_state.cpp tests/wallet_state/test_wallet_state.hpp
tests/wallet_file/test_wallet_file.cpp tests/wallet_file/test_wallet_file.hpp tests/crypto/benchmarks.cpp tests/crypto/benchmarks.hpp)
set(Boost_USE_STATIC_LIBS ON)
add_definitions(-DBOOST_BIND_NO_PLACEHOLDERS=1 -DBOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE=1) # boost::_1 conflicts with std::_1
add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY=1 -DBOOST_SYSTEM_NO_DEPRECATED=1) # required for header-only compilation
add_definitions(-DBOOST_DATE_TIME_NO_LIB=1 -DBOOST_SYSTEM_NO_LIB=1 -DBOOST_REGEX_NO_LIB=1) # required for header-only compilation
set(Boost_USE_MULTITHREADED OFF) # all boost libraries are multithreaded since some version
find_package(Boost 1.65)
if(Boost_FOUND)
message( STATUS "Boost found by find_boost, Boost_INCLUDE_DIRS: " ${Boost_INCLUDE_DIRS})
else()
if(NOT EXISTS "${PARENT_DIR}/boost/boost/version.hpp")
message(FATAL_ERROR "Boost not found, please download and unpack boost into ${PARENT_DIR}/boost")
endif()
set(Boost_INCLUDE_DIRS ${PARENT_DIR}/boost)
message( STATUS "Using boost from local folder, Boost_INCLUDE_DIRS: " ${Boost_INCLUDE_DIRS})
endif()
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(walletd ${USBLIB_LIBRARY})
if(APPLE)
target_link_libraries(walletd "-framework Foundation" "-framework IOKit") # -dead_strip_dylibs
target_link_libraries(${CRYPTONOTE_NAME}d "-framework Foundation" "-framework IOKit") # -dead_strip_dylibs
endif()