-
Notifications
You must be signed in to change notification settings - Fork 71
/
CMakeLists.txt
345 lines (296 loc) · 11.4 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
cmake_minimum_required(VERSION 3.4.1)
project(monero-javascript-wasm)
# build with exception whitelist from file
file(STRINGS wasm_exception_whitelist.txt WASM_EXCEPTION_WHITELIST)
string(REPLACE ";" "," WASM_EXCEPTION_WHITELIST "${WASM_EXCEPTION_WHITELIST}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Oz -s EXCEPTION_CATCHING_ALLOWED='[${WASM_EXCEPTION_WHITELIST}]'")
add_definitions(-DAUTO_INITIALIZE_EASYLOGGINGPP -DNO_AES)
set(BUILD_MONERO_WALLET_FULL_WASM ON)
set(BUILD_MONERO_WALLET_KEYS_WASM ON)
##############
# C++ bridge
##############
include_directories("src/cpp")
#####################
# monero-cpp
#####################
set(MONERO_CPP "external/monero-cpp")
set(MONERO_CPP_SRC "${MONERO_CPP}/src")
# headers
include_directories("${MONERO_CPP_SRC}")
include_directories("${MONERO_CPP}/external/libsodium/include")
include_directories("${MONERO_CPP}/external/libsodium/include/sodium")
##################
# monero-project
##################
set(MONERO_PROJECT "${MONERO_CPP}/external/monero-project")
set(MONERO_PROJECT_SRC "${MONERO_PROJECT}/src")
# headers
include_directories("src/main/cpp")
include_directories("${MONERO_PROJECT_SRC}/")
include_directories("${MONERO_PROJECT_SRC}/checkpoints")
include_directories("${MONERO_PROJECT_SRC}/common")
#include_directories("${MONERO_PROJECT_SRC}/crypto")
#include_directories("${MONERO_PROJECT_SRC}/crypto/crypto_ops_builder/include/") # DISABLED?
#include_directories("${MONERO_PROJECT_SRC}/crypto/crypto_ops_builder/include/sodium") # DISABLED?
include_directories("${MONERO_PROJECT_SRC}/cryptonote_basic")
#include_directories("${MONERO_PROJECT_SRC}/multisig")
#include_directories("${MONERO_PROJECT_SRC}/cryptonote_core")
#include_directories("${MONERO_PROJECT_SRC}/cryptonote_protocol")
#include_directories("${MONERO_PROJECT_SRC}/wallet")
#include_directories("${MONERO_PROJECT_SRC}/rpc")
#include_directories("${MONERO_PROJECT_SRC}/mnemonics")
include_directories("${MONERO_PROJECT}/external/")
include_directories("${MONERO_PROJECT}/external/easylogging++")
include_directories("${MONERO_PROJECT}/external/rapidjson/include")
include_directories("${MONERO_PROJECT}/external/unbound/libunbound")
include_directories("${MONERO_PROJECT}/external/db_drivers/liblmdb")
include_directories("${MONERO_PROJECT}/contrib/epee/include")
include_directories("${MONERO_PROJECT}/contrib/epee/include/net")
#include_directories("${CMAKE_CURRENT_BINARY_DIR}")
#include_directories("${MONERO_PROJECT_SRC}/wallet/api")
include_directories("${MONERO_PROJECT}/build/release/translations")
include_directories("${MONERO_PROJECT}/build/release/generated_include")
#############
# OpenSSL
#############
#find_package(OpenSSL REQUIRED)
#message(STATUS "Using OpenSSL include dir at ${OPENSSL}")
set(OPENSSL ${CMAKE_SOURCE_DIR}/build/openssl)
include_directories("${OPENSSL}")
include_directories("${OPENSSL}/include") # must exist already - run bin/build-openssl-emscripten.sh
add_library(openssl_crypto STATIC IMPORTED)
set_target_properties(
openssl_crypto PROPERTIES IMPORTED_LOCATION
${OPENSSL}/lib/libcrypto.a
)
add_library(openssl_ssl STATIC IMPORTED)
set_target_properties(
openssl_ssl PROPERTIES IMPORTED_LOCATION
${OPENSSL}/lib/libssl.a
)
#############
# Boost
#############
set(BOOST ${CMAKE_SOURCE_DIR}/build/boost)
include_directories("${BOOST}")
include_directories("${BOOST}/include") # must exist already - run bin/build-boost-emscripten.sh
add_library(boost_chrono STATIC IMPORTED)
set_target_properties(
boost_chrono PROPERTIES IMPORTED_LOCATION
${BOOST}/lib/libboost_chrono.a
)
add_library(boost_system STATIC IMPORTED)
set_target_properties(
boost_system PROPERTIES IMPORTED_LOCATION
${BOOST}/lib/libboost_system.a
)
add_library(boost_thread STATIC IMPORTED)
set_target_properties(
boost_thread PROPERTIES IMPORTED_LOCATION
${BOOST}/lib/libboost_thread.a
)
add_library(boost_serialization STATIC IMPORTED)
set_target_properties(
boost_serialization PROPERTIES IMPORTED_LOCATION
${BOOST}/lib/libboost_serialization.a
)
add_library(boost_filesystem STATIC IMPORTED)
set_target_properties(
boost_filesystem PROPERTIES IMPORTED_LOCATION
${BOOST}/lib/libboost_filesystem.a
)
add_library(boost_regex STATIC IMPORTED)
set_target_properties(
boost_regex PROPERTIES IMPORTED_LOCATION
${BOOST}/lib/libboost_regex.a
)
#add_library(boost_atomic STATIC IMPORTED)
#set_target_properties(
#boost_atomic PROPERTIES IMPORTED_LOCATION
#${BOOST}/lib/libboost_atomic.a
#)
################################
# Keys-only wallet source files
################################
set(
MONERO_WALLET_KEYS_SRC_FILES
# monero-javascript WASM bridge
src/main/cpp/index.cpp
src/main/cpp/monero_wasm_bridge.cpp
# monero-cpp (modified for WASM)
${MONERO_CPP_SRC}/utils/monero_utils.cpp
${MONERO_CPP_SRC}/daemon/monero_daemon_model.cpp
${MONERO_CPP_SRC}/wallet/monero_wallet_model.cpp
${MONERO_CPP_SRC}/wallet/monero_wallet_keys.cpp
${MONERO_CPP}/external/libsodium/src/crypto_verify/verify.c
# monero-project (modified for WASM)
${MONERO_PROJECT_SRC}/cryptonote_basic/cryptonote_basic_impl.cpp
${MONERO_PROJECT_SRC}/cryptonote_basic/account.cpp
${MONERO_PROJECT_SRC}/cryptonote_basic/cryptonote_format_utils.cpp
${MONERO_PROJECT_SRC}/cryptonote_basic/cryptonote_format_utils_basic.cpp
${MONERO_PROJECT_SRC}/crypto/crypto.cpp
${MONERO_PROJECT_SRC}/crypto/hash.c
${MONERO_PROJECT_SRC}/crypto/slow-hash.c
${MONERO_PROJECT_SRC}/crypto/oaes_lib.c
${MONERO_PROJECT_SRC}/crypto/crypto-ops.c
${MONERO_PROJECT_SRC}/crypto/crypto-ops-data.c
${MONERO_PROJECT_SRC}/crypto/keccak.c
${MONERO_PROJECT_SRC}/crypto/chacha.c
${MONERO_PROJECT_SRC}/crypto/random.c
${MONERO_PROJECT_SRC}/crypto/aesb.c
${MONERO_PROJECT_SRC}/crypto/tree-hash.c
${MONERO_PROJECT_SRC}/crypto/hash-extra-blake.c
${MONERO_PROJECT_SRC}/crypto/blake256.c
${MONERO_PROJECT_SRC}/crypto/hash-extra-groestl.c
${MONERO_PROJECT_SRC}/crypto/hash-extra-jh.c
${MONERO_PROJECT_SRC}/crypto/hash-extra-skein.c
${MONERO_PROJECT_SRC}/crypto/groestl.c
${MONERO_PROJECT_SRC}/crypto/jh.c
${MONERO_PROJECT_SRC}/crypto/skein.c
${MONERO_PROJECT_SRC}/cryptonote_core/cryptonote_tx_utils.cpp
${MONERO_PROJECT}/contrib/epee/src/byte_stream.cpp
${MONERO_PROJECT}/contrib/epee/src/byte_slice.cpp
${MONERO_PROJECT}/contrib/epee/src/hex.cpp
${MONERO_PROJECT}/contrib/epee/src/string_tools.cpp
${MONERO_PROJECT}/contrib/epee/src/memwipe.c
${MONERO_PROJECT}/contrib/epee/src/mlocker.cpp
${MONERO_PROJECT}/contrib/epee/src/wipeable_string.cpp
${MONERO_PROJECT_SRC}/common/base58.cpp
${MONERO_PROJECT_SRC}/device/device.cpp
${MONERO_PROJECT_SRC}/device/device_default.cpp
${MONERO_PROJECT_SRC}/multisig/multisig.cpp
${MONERO_PROJECT_SRC}/ringct/rctOps.cpp
${MONERO_PROJECT_SRC}/ringct/rctTypes.cpp
${MONERO_PROJECT_SRC}/ringct/rctCryptoOps.c
${MONERO_PROJECT_SRC}/ringct/rctSigs.cpp
${MONERO_PROJECT_SRC}/ringct/bulletproofs.cc
${MONERO_PROJECT_SRC}/ringct/multiexp.cc
${MONERO_PROJECT_SRC}/mnemonics/electrum-words.cpp
${MONERO_PROJECT}/external/easylogging++/easylogging++.cc
)
################################
# Full wallet source files
################################
set(
MONERO_WALLET_FULL_SRC_FILES
# monero-javascript WASM bridge
src/main/cpp/http_client_wasm.cpp
# monero-cpp (modified for WASM)
${MONERO_CPP_SRC}/wallet/monero_wallet_full.cpp
# monero-project (modified for WASM)
${MONERO_PROJECT}/external/db_drivers/liblmdb/mdb.c
${MONERO_PROJECT}/external/db_drivers/liblmdb/midl.c
${MONERO_PROJECT}/contrib/epee/src/abstract_http_client.cpp
#${MONERO_PROJECT}/contrib/epee/src/http_auth.cpp
${MONERO_PROJECT_SRC}/wallet/wallet2.cpp
${MONERO_PROJECT_SRC}/wallet/message_store.cpp
${MONERO_PROJECT_SRC}/wallet/message_transporter.cpp
${MONERO_PROJECT_SRC}/wallet/node_rpc_proxy.cpp
${MONERO_PROJECT_SRC}/wallet/wallet_rpc_payments.cpp
#${MONERO_PROJECT_SRC}/blockchain_db/lmdb/db_lmdb.cpp
${MONERO_PROJECT_SRC}/cryptonote_core/cryptonote_tx_utils.cpp
${MONERO_PROJECT_SRC}/checkpoints/checkpoints.cpp
${MONERO_PROJECT_SRC}/common/perf_timer.cpp
${MONERO_PROJECT_SRC}/common/threadpool.cpp
${MONERO_PROJECT_SRC}/common/aligned.c
${MONERO_PROJECT_SRC}/common/util.cpp
${MONERO_PROJECT_SRC}/common/i18n.cpp
${MONERO_PROJECT_SRC}/common/combinator.cpp
${MONERO_PROJECT_SRC}/rpc/rpc_payment_signature.cpp
${MONERO_PROJECT_SRC}/wallet/ringdb.cpp
${MONERO_PROJECT_SRC}/cryptonote_basic/miner.cpp
${MONERO_PROJECT_SRC}/cryptonote_basic/difficulty.cpp
${MONERO_PROJECT_SRC}/cryptonote_core/tx_sanity_check.cpp
)
####################
# Build parameters
####################
#-s USE_PTHREADS=1 \
#-s PTHREAD_POOL_SIZE=2 \
#-s PROXY_TO_PTHREAD \
#-s DISABLE_EXCEPTION_CATCHING=0 \
#-s ASYNCIFY=1 \
#-s 'ASYNCIFY_IMPORTS=[\"js_send_json_request\",\"js_send_binary_request\",\"emscripten_sleep\"]' \
#-s ALLOW_MEMORY_GROWTH=0 \
#-s INITIAL_MEMORY=1536MB \
set (
EMCC_LINKER_FLAGS_BASE
# unsure if the -I...boost..include is necessary here due to include above
# TODO? does EXPORT_NAME need to be the same for both targets? (or should it be set per-target with …_WASM, …_ASMJS?)
"-Wall -Werror -Wl,--allow-undefined -std=c++11 -Oz \
--bind -s MODULARIZE=1 \
-s 'EXPORT_NAME=\"monero_javascript\"' \
-s ERROR_ON_UNDEFINED_SYMBOLS=0 \
-s ASSERTIONS=0 \
-s EXIT_RUNTIME=0 \
-s PRECISE_F32=1 \
-s EXCEPTION_DEBUG=0 \
-s DEMANGLE_SUPPORT=0 \
-s NO_DYNAMIC_EXECUTION=1 \
-s NODEJS_CATCH_EXIT=0 \
-s RESERVED_FUNCTION_POINTERS=5 \
-s EXPORTED_RUNTIME_METHODS='[\"UTF8ToString\",\"stringToUTF8\",\"lengthBytesUTF8\",\"intArrayToString\",\"getTempRet0\",\"addFunction\"]' \
-s WASM=1 \
-s ALLOW_MEMORY_GROWTH=1 \
"
# • Disabling exception catching does not introduce silent failures
# • Probably don't need PRECISE_F32 but wouldn't want to not use it
#
#
# -s SAFE_HEAP=1 \
# -g \
)
set(
EMCC_LINKER_FLAGS_KEYS
"${EMCC_LINKER_FLAGS_BASE} \
"
)
set(
EMCC_LINKER_FLAGS_FULL
"${EMCC_LINKER_FLAGS_BASE} \
-s ASYNCIFY=1 \
-s 'ASYNCIFY_IMPORTS=[\"js_send_json_request\",\"js_send_binary_request\",\"emscripten_sleep\"]' \
"
)
message(STATUS "EMCC_LINKER_FLAGS_KEYS ${EMCC_LINKER_FLAGS_KEYS}")
message(STATUS "EMCC_LINKER_FLAGS_FULL ${EMCC_LINKER_FLAGS_FULL}")
####################
# Build targets
####################
if (BUILD_MONERO_WALLET_KEYS_WASM)
add_executable(monero_wallet_keys ${MONERO_WALLET_KEYS_SRC_FILES})
set_target_properties(monero_wallet_keys PROPERTIES LINK_FLAGS "${EMCC_LINKER_FLAGS_KEYS}")
target_link_libraries(
monero_wallet_keys
#
boost_chrono
boost_system
boost_thread
#
${log-lib}
)
endif()
if (BUILD_MONERO_WALLET_FULL_WASM)
add_executable(monero_wallet_full ${MONERO_WALLET_FULL_SRC_FILES} ${MONERO_WALLET_KEYS_SRC_FILES})
set_target_properties(monero_wallet_full PROPERTIES LINK_FLAGS "${EMCC_LINKER_FLAGS_FULL}")
target_compile_definitions(monero_wallet_full PRIVATE BUILD_WALLET_FULL=1)
target_link_libraries(
monero_wallet_full
#
#openssl_ssl
#openssl_crypto
#
boost_chrono
boost_system
boost_thread
boost_serialization
#boost_filesystem
boost_regex
#boost_atomic
#
${log-lib}
)
endif()
# build to bitcode instead of wasm
#SET(CMAKE_EXECUTABLE_SUFFIX ".bc")