-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
166 lines (156 loc) · 6.43 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
cmake_minimum_required(VERSION 3.20)
project(pastel_lite VERSION 0.1 DESCRIPTION "Lite Version of Pastel Node" LANGUAGES CXX)
# Set the C++ standard for the project
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
include(FetchContent)
include(ExternalProject)
set(BOTAN_VERBOSE_OUTPUT ON)
set(BOTAN_VERBOSE_CONFIGURE ON)
set(BOTAN_VERBOSE_BUILD ON)
set(BOTAN_VERBOSE_INSTALL ON)
set(ZSTD_VERBOSE_INSTALL ON)
if (NOT EMSCRIPTEN)
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "")
# libsodium
find_package(unofficial-sodium CONFIG REQUIRED)
# zstd
find_package(zstd CONFIG REQUIRED)
# bitcoin/libsecp256k1cc
set(SECP256K1_DISABLE_SHARED ON CACHE INTERNAL "")
set(SECP256K1_ENABLE_MODULE_RECOVERY ON CACHE INTERNAL "")
FetchContent_Declare(
libsecp256k1
GIT_REPOSITORY https://github.com/bitcoin-core/secp256k1
GIT_TAG master # or specific commit/tag
)
FetchContent_MakeAvailable(libsecp256k1)
# fmt
FetchContent_Declare(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG master
)
FetchContent_MakeAvailable(fmt)
set_target_properties(fmt PROPERTIES POSITION_INDEPENDENT_CODE ON)
# Botan
set(BOTAN_LIB_DIR "${CMAKE_BINARY_DIR}/libbotan-lib")
if (EXISTS ${BOTAN_LIB_DIR})
message(STATUS "${BOTAN_LIB_DIR} already built. Skipping build.")
else()
ExternalProject_Add(
libbotan
GIT_REPOSITORY https://github.com/randombit/botan.git
GIT_TAG master
PREFIX ${CMAKE_BINARY_DIR}/libbotan
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND ./configure.py --cxxflags=-fPIC --prefix=${BOTAN_LIB_DIR} --disable-shared-library --minimized-build --enable-modules=auto_rng,system_rng,hash,shake,shake_xof,sha3,ed448,pbkdf2,hmac,x448,base64,sha2_32,sha2_64
BUILD_COMMAND make -j 1 # stupid botan fails to build otherwise
INSTALL_COMMAND make install
LOG_DOWNLOAD ON
LOG_BUILD ON
LOG_INSTALL ON
)
endif ()
add_subdirectory(lib)
add_subdirectory(app)
else () # EMSCRIPTEN
# Add libsodium as an external project
set(SODIUM_WASM_DIR "${CMAKE_BINARY_DIR}/libsodium-wasm")
if (EXISTS ${SODIUM_WASM_DIR})
message(STATUS "${SODIUM_WASM_DIR} already built. Skipping build.")
else()
ExternalProject_Add(
libsodium
GIT_REPOSITORY https://github.com/jedisct1/libsodium.git
GIT_TAG stable
PREFIX ${CMAKE_BINARY_DIR}/libsodium
BUILD_IN_SOURCE 1 # Build in the source directory
CONFIGURE_COMMAND ""
BUILD_IN_SOURCE 1
BUILD_COMMAND sh ${CMAKE_BINARY_DIR}/libsodium/src/libsodium/dist-build/emscripten.sh --standard
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_BINARY_DIR}/libsodium/src/libsodium/libsodium-js ${SODIUM_WASM_DIR}
LOG_DOWNLOAD ON
LOG_BUILD ON
LOG_INSTALL ON
)
endif()
# Add libsecp256k1 as an external project
set(SECP256K1_WASM_DIR "${CMAKE_BINARY_DIR}/libsecp256k1-wasm")
if (EXISTS ${SECP256K1_WASM_DIR})
message(STATUS "${SECP256K1_WASM_DIR} already built. Skipping build.")
else()
ExternalProject_Add(
libsecp256k1
GIT_REPOSITORY https://github.com/bitcoin-core/secp256k1.git
GIT_TAG master # or a specific commit/tag
PREFIX ${CMAKE_BINARY_DIR}/libsecp256k1
BUILD_IN_SOURCE 1 # Build in the source directory
UPDATE_COMMAND ./autogen.sh
CONFIGURE_COMMAND emconfigure ./configure --enable-module-recovery --disable-shared --prefix=${SECP256K1_WASM_DIR}
BUILD_COMMAND emmake make
INSTALL_COMMAND make install
LOG_DOWNLOAD ON
LOG_BUILD ON
LOG_INSTALL ON
)
endif()
# Add libbotan as an external project
set(BOTAN_WASM_DIR "${CMAKE_BINARY_DIR}/libbotan-wasm")
if (EXISTS ${BOTAN_WASM_DIR})
message(STATUS "${BOTAN_WASM_DIR} already built. Skipping build.")
else()
ExternalProject_Add(
libbotan
GIT_REPOSITORY https://github.com/randombit/botan.git
GIT_TAG master
PREFIX ${CMAKE_BINARY_DIR}/libbotan
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND ./configure.py --prefix=${BOTAN_WASM_DIR} --os=emscripten --cpu=wasm --cc=emcc --disable-shared-library --minimized-build --enable-modules=auto_rng,system_rng,hash,shake,shake_xof,sha3,ed448,pbkdf2,hmac,x448,base64,sha2_32,sha2_64
BUILD_COMMAND make
INSTALL_COMMAND make install
LOG_DOWNLOAD ON
LOG_BUILD ON
LOG_INSTALL ON
)
endif()
# Add fmt as an external project
set(FMT_WASM_DIR "${CMAKE_BINARY_DIR}/fmt-wasm")
if (EXISTS ${FMT_WASM_DIR})
message(STATUS "${FMT_WASM_DIR} already built. Skipping build.")
else()
ExternalProject_Add(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG master
PREFIX ${CMAKE_BINARY_DIR}/fmt
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND emcmake cmake -DFMT_TEST=OFF -DCMAKE_INSTALL_PREFIX=${FMT_WASM_DIR}
BUILD_COMMAND emmake make
INSTALL_COMMAND make install
LOG_DOWNLOAD ON
LOG_BUILD ON
LOG_INSTALL ON
)
endif()
#
set(ZSTD_WASM_DIR "${CMAKE_BINARY_DIR}/zstd-wasm")
if (EXISTS ${ZSTD_WASM_DIR})
message(STATUS "${ZSTD_WASM_DIR} already built. Skipping build.")
else()
ExternalProject_Add(
zstd
GIT_REPOSITORY https://github.com/facebook/zstd.git
GIT_TAG v1.5.5
PREFIX ${CMAKE_BINARY_DIR}/zstd
# BUILD_IN_SOURCE 1
CONFIGURE_COMMAND emcmake cmake ${CMAKE_BINARY_DIR}/zstd/src/zstd/build/cmake -DCMAKE_INSTALL_PREFIX=${ZSTD_WASM_DIR} -DZSTD_BUILD_TESTS=OFF -DZSTD_LEGACY_SUPPORT=OFF -DZSTD_BUILD_SHARED=OFF -DZSTD_BUILD_PROGRAMS=OFF -DZSTD_BUILD_STATIC=ON
BUILD_COMMAND emmake make
INSTALL_COMMAND make install
LOG_DOWNLOAD ON
LOG_BUILD ON
LOG_INSTALL ON
)
endif()
add_subdirectory(wasm)
endif ()