-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathCMakeLists.txt
307 lines (258 loc) · 12.3 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
cmake_minimum_required(VERSION 3.5.1)
set( CMAKE_CXX_STANDARD 17 )
project(libBLS)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0)
message(FATAL_ERROR "Require at least gcc-7.0")
endif()
endif()
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
message(STATUS "*** Have SIZEOF void * = 8, so 64-bit")
else ()
if (EMSCRIPTEN)
message(STATUS "*** SIZEOF void * = 4, while building with emscripten ")
else()
message(FATAL_ERROR "*** SIZEOF void * != 8, so not 64-bit - libBLS supports only 64-bit")
endif()
endif ()
if( NOT DEFINED DEPS_INSTALL_ROOT )
set( DEPS_SOURCES_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/deps")
set( DEPS_INSTALL_ROOT "${DEPS_SOURCES_ROOT}/deps_inst/x86_or_x64")
endif()
message(INFO "---- DEPS_INSTALL_ROOT in BLS is: ${DEPS_INSTALL_ROOT}")
include_directories( "${DEPS_INSTALL_ROOT}/include" ${CMAKE_BINARY_DIR}/deps/include )
link_directories( "${DEPS_INSTALL_ROOT}/lib" )
set( CMAKE_PREFIX_PATH "${DEPS_INSTALL_ROOT}" )
set( LIBBLS_CMAKE_DIR "${CMAKE_CURRENT_LIST_DIR}/cmake" CACHE PATH "The path to the cmake directory" )
list( APPEND CMAKE_MODULE_PATH ${LIBBLS_CMAKE_DIR} )
find_library( GMP_LIBRARY NAMES "gmp" PATHS "${DEPS_INSTALL_ROOT}/lib" )
find_library( GMPXX_LIBRARY NAMES "gmpxx" PATHS "${DEPS_INSTALL_ROOT}/lib" )
find_library( CRYPTOPP_LIBRARY NAMES "crypto" PATHS "${DEPS_INSTALL_ROOT}/lib" )
set( HUNTER_ENABLED OFF )
option(BUILD_TESTS "Build tests" ON)
option(BUILD_WITH_FPIC "Build with -fPIC" OFF)
option(BUILD_UTILS "Build utils" ON)
option( BLS_PROFILING "Build for profiling" OFF )
if( SKALED_PROFILING OR CONSENSUS_PROFILING )
set( BLS_PROFILING ON )
endif()
if( BLS_PROFILING )
set( CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -pg" )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg" )
set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg" )
set( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg" )
endif()
if( CMAKE_BUILD_TYPE STREQUAL "Release" )
set( CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -O3" )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3" )
elseif( CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" )
set( CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -O3" )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3" )
elseif( CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" )
set( CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -Os" )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os" )
elseif( CMAKE_BUILD_TYPE STREQUAL "Debug" )
set( CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -O0" )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0" )
else()
message( INFO "---- CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE} is not supported explicitly" )
endif()
if(BUILD_TESTS)
enable_testing()
endif()
option(COVERAGE "Build with code coverage support" OFF)
if(COVERAGE)
message(STATUS "**********************")
message(STATUS "*** COVERAGE is ON ***")
message(STATUS "**********************")
add_compile_options(-g --coverage)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_SHARED_LINKER_FLAGS "--coverage ${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "--coverage ${CMAKE_EXE_LINKER_FLAGS}")
endif()
set( CLANG_FORMAT_EXCLUDE_PATTERNS
${CMAKE_BINARY_DIR}
${DEPS_SOURCES_ROOT}
)
include( BlsFindClangFormat )
set( TOOLS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tools/")
set( DKG_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dkg/")
set(sourses_bls
bls/bls.cpp
bls/BLSPrivateKeyShare.cpp
bls/BLSPrivateKey.cpp
bls/BLSPublicKeyShare.cpp
bls/BLSPublicKey.cpp
bls/BLSSignature.cpp
bls/BLSSigShare.cpp
bls/BLSSigShareSet.cpp
dkg/dkg.cpp
dkg/DKGBLSWrapper.cpp
dkg/DKGBLSSecret.cpp
third_party/cryptlite/base64.cpp
tools/utils.cpp
)
set(headers_bls
libBLS.h
bls/bls.h
bls/BLSPrivateKeyShare.h
bls/BLSPrivateKey.h
bls/BLSPublicKeyShare.h
bls/BLSPublicKey.h
bls/BLSSignature.h
bls/BLSSigShare.h
bls/BLSSigShareSet.h
dkg/dkg.h
dkg/DKGBLSWrapper.h
dkg/DKGBLSSecret.h
third_party/json.hpp
third_party/cryptlite/sha256.h
third_party/cryptlite/sha1.h
third_party/cryptlite/hmac.h
third_party/cryptlite/base64.h
tools/utils.h
)
set(PROJECT_VERSION 0.2.0)
add_definitions(-DBLS_VERSION=${PROJECT_VERSION})
if ( APPLE )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wparentheses -Wunused -Wno-error=deprecated-copy -Wno-error=unused-parameter -Wno-error=unused-variable -Wno-error=maybe-uninitialized -Wunreachable-code -Wextra -fPIC -std=c++17")
else()
if (EMSCRIPTEN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -std=c++17")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wunreachable-code -Wextra -Wno-error=deprecated-copy -Wno-error=unused-parameter -Wno-error=unused-variable -Wno-error=maybe-uninitialized -Wno-error=int-in-bool-context -fPIC -std=c++17")
if( CMAKE_BUILD_TYPE STREQUAL "Debug" )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wparentheses -Wunused -Wno-error=deprecated-copy -Wno-error=unused-parameter -Wno-error=unused-variable -Wno-error=maybe-uninitialized" )
else()
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=deprecated-copy -Wno-error=unused-parameter -Wno-error=unused-variable -Wno-error=maybe-uninitialized" )
endif()
endif()
endif()
include_directories(${CMAKE_BINARY_DIR}/deps/include)
link_directories(${CMAKE_BINARY_DIR}/deps/lib)
add_library(bls ${sourses_bls} ${headers_bls})
include_directories(${Boost_INCLUDE_DIRS})
if( SKALE_HAVE_BOOST_FROM_HUNTER )
set( BOOST_LIBS_4_BLS Boost::program_options )
else()
set( BOOST_LIBS_4_BLS boost_program_options )
endif()
set (WITH_PROCPS OFF)
set(BLS_INCLUDE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/bls
${DEPS_SOURCES_ROOT}
${DEPS_INSTALL_ROOT}
${CMAKE_CURRENT_SOURCE_DIR}/deps/include
PARENT_SCOPE
)
target_include_directories(bls PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(bls PRIVATE ff ${CRYPTOPP_LIBRARY} ${GMPXX_LIBRARY} ${GMP_LIBRARY})
add_subdirectory(threshold_encryption)
if (BUILD_UTILS)
add_executable(dkg_keygen tools/dkg_key_gen.cpp)
target_include_directories(dkg_keygen PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
if (EMSCRIPTEN)
target_compile_options(dkg_keygen PRIVATE -s DISABLE_EXCEPTION_CATCHING=1)
set_target_properties(dkg_keygen PROPERTIES LINK_FLAGS "-s DISABLE_EXCEPTION_CATCHING=1")
endif()
target_link_libraries(dkg_keygen PRIVATE bls ${CRYPTOPP_LIBRARY} ff ${GMPXX_LIBRARY} ${GMP_LIBRARY} ${BOOST_LIBS_4_BLS})
add_executable(dkg_glue tools/dkg_glue.cpp)
target_include_directories(dkg_glue PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
if (EMSCRIPTEN)
target_compile_options(dkg_glue PRIVATE -s DISABLE_EXCEPTION_CATCHING=1)
set_target_properties(dkg_glue PROPERTIES LINK_FLAGS "-s DISABLE_EXCEPTION_CATCHING=1")
endif()
target_link_libraries(dkg_glue PRIVATE bls ${CRYPTOPP_LIBRARY} ff ${GMPXX_LIBRARY} ${GMP_LIBRARY} ${BOOST_LIBS_4_BLS})
add_executable(sign_bls tools/sign_bls.cpp)
target_include_directories(sign_bls PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
if (EMSCRIPTEN)
target_compile_options(sign_bls PRIVATE -s DISABLE_EXCEPTION_CATCHING=1)
set_target_properties(sign_bls PROPERTIES LINK_FLAGS "-s DISABLE_EXCEPTION_CATCHING=1")
endif()
target_link_libraries(sign_bls PRIVATE bls ${CRYPTOPP_LIBRARY} ff ${GMPXX_LIBRARY} ${GMP_LIBRARY} ${BOOST_LIBS_4_BLS})
add_executable(hash_g1 tools/hash_g1.cpp)
target_include_directories(hash_g1 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
if (EMSCRIPTEN)
target_compile_options(hash_g1 PRIVATE -s DISABLE_EXCEPTION_CATCHING=1)
set_target_properties(hash_g1 PROPERTIES LINK_FLAGS "-s DISABLE_EXCEPTION_CATCHING=1")
endif()
target_link_libraries(hash_g1 PRIVATE bls ${CRYPTOPP_LIBRARY} ff ${GMPXX_LIBRARY} ${GMP_LIBRARY} ${BOOST_LIBS_4_BLS})
add_executable(bls_glue tools/bls_glue.cpp)
target_include_directories(bls_glue PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
if (EMSCRIPTEN)
target_compile_options(bls_glue PRIVATE -s DISABLE_EXCEPTION_CATCHING=1)
set_target_properties(bls_glue PROPERTIES LINK_FLAGS "-s DISABLE_EXCEPTION_CATCHING=1")
endif()
target_link_libraries(bls_glue PRIVATE bls ${CRYPTOPP_LIBRARY} ff ${GMPXX_LIBRARY} ${GMP_LIBRARY} ${BOOST_LIBS_4_BLS})
add_executable(verify_bls tools/verify_bls.cpp)
target_include_directories(verify_bls PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
if (EMSCRIPTEN)
target_compile_options(verify_bls PRIVATE -s DISABLE_EXCEPTION_CATCHING=1)
set_target_properties(verify_bls PROPERTIES LINK_FLAGS "-s DISABLE_EXCEPTION_CATCHING=1")
endif()
target_link_libraries(verify_bls PRIVATE bls ${CRYPTOPP_LIBRARY} ff ${GMPXX_LIBRARY} ${GMP_LIBRARY} ${BOOST_LIBS_4_BLS})
add_executable(generate_key_system tools/generate_key_system.cpp)
target_include_directories(generate_key_system PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
if (EMSCRIPTEN)
target_compile_options(generate_key_system PRIVATE -s DISABLE_EXCEPTION_CATCHING=1)
set_target_properties(generate_key_system PROPERTIES LINK_FLAGS "-s DISABLE_EXCEPTION_CATCHING=1")
endif()
target_link_libraries(generate_key_system PRIVATE bls ${CRYPTOPP_LIBRARY} ff ${GMPXX_LIBRARY} ${GMP_LIBRARY} ${BOOST_LIBS_4_BLS})
endif()
if(BUILD_TESTS)
add_executable(bls_unit_test test/unit_tests_bls.cpp)
target_include_directories(bls_unit_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
if (EMSCRIPTEN)
target_compile_options(bls_unit_test PRIVATE -s DISABLE_EXCEPTION_CATCHING=1)
set_target_properties(bls_unit_test PROPERTIES LINK_FLAGS "-s DISABLE_EXCEPTION_CATCHING=1")
endif()
target_link_libraries(bls_unit_test PRIVATE bls ${CRYPTOPP_LIBRARY} ff ${GMPXX_LIBRARY} ${GMP_LIBRARY} ${BOOST_LIBS_4_BLS})
add_test(NAME bls_tests COMMAND bls_unit_test)
add_executable(dkg_unit_test test/unit_tests_dkg.cpp)
target_include_directories(dkg_unit_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
if (EMSCRIPTEN)
target_compile_options(dkg_unit_test PRIVATE -s DISABLE_EXCEPTION_CATCHING=1)
set_target_properties(dkg_unit_test PROPERTIES LINK_FLAGS "-s DISABLE_EXCEPTION_CATCHING=1")
endif()
target_link_libraries(dkg_unit_test PRIVATE bls ${CRYPTOPP_LIBRARY} ff ${GMP_LIBRARY} ${GMPXX_LIBRARY} ${BOOST_LIBS_4_BLS})
add_test(NAME dkg_tests COMMAND dkg_unit_test)
add_executable(bls_test test/test_bls.cpp)
target_include_directories(bls_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
if (EMSCRIPTEN)
target_compile_options(bls_test PRIVATE -s DISABLE_EXCEPTION_CATCHING=1)
set_target_properties(bls_test PROPERTIES LINK_FLAGS "-s DISABLE_EXCEPTION_CATCHING=1")
endif()
target_link_libraries(bls_test PRIVATE bls ${CRYPTOPP_LIBRARY} ff ${GMP_LIBRARY} ${GMPXX_LIBRARY} ${BOOST_LIBS_4_BLS})
add_test(NAME bls_test COMMAND bls_test)
add_executable(dkg_attack test/dkg_attack.cpp)
target_include_directories(dkg_attack PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(dkg_attack PRIVATE bls ${CRYPTOPP_LIBRARY} ff ${GMP_LIBRARY} ${GMPXX_LIBRARY} ${BOOST_LIBS_4_BLS})
add_test(NAME dkg_attack COMMAND dkg_attack)
add_executable(utils_unit_test test/unit_tests_utils.cpp)
target_include_directories(utils_unit_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
if (EMSCRIPTEN)
target_compile_options(utils_unit_test PRIVATE -s DISABLE_EXCEPTION_CATCHING=1)
set_target_properties(utils_unit_test PROPERTIES LINK_FLAGS "-s DISABLE_EXCEPTION_CATCHING=1")
endif()
target_link_libraries(utils_unit_test PRIVATE bls te ${CRYPTOPP_LIBRARY} ff ${GMPXX_LIBRARY} ${GMP_LIBRARY} ${BOOST_LIBS_4_BLS})
add_test(NAME utils_tests COMMAND utils_unit_test)
add_custom_target(all_bls_tests
COMMAND ./bls_unit_test
COMMAND ./dkg_unit_test
COMMAND ./bls_test
COMMAND ./utils_unit_test
DEPENDS bls_unit_test dkg_unit_test
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Run all BLS and DKG tests"
)
endif()
if(NOT SKALE_SKIP_INSTALLING_DIRECTIVES)
install( TARGETS bls DESTINATION lib )
install( TARGETS dkg_keygen DESTINATION bin )
install( TARGETS dkg_glue DESTINATION bin )
install( TARGETS sign_bls DESTINATION bin )
install( TARGETS bls_glue DESTINATION bin )
install( TARGETS verify_bls DESTINATION bin )
endif()