forked from theQRL/qrllib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
443 lines (356 loc) · 14.8 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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
# Distributed under the MIT software license, see the accompanying
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
cmake_minimum_required(VERSION 3.5)
project(qrllib)
string(REPLACE "\\" "/" CMAKE_CURRENT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
string(REPLACE "\\" "/" CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set(CMAKE_CXX_STANDARD 14)
if(WIN32)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -DWIN32_LEAN_AND_MEAN)
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -fPIC -Wno-deprecated-declarations")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -Wno-deprecated")
endif()
set(CMAKE_VERBOSE_MAKEFILE TRUE)
set(CMAKE_ERROR_DEPRECATED FALSE)
set(CMAKE_WARN_DEPRECATED FALSE)
option(BUILD_TESTS "Enable tests" ON )
option(BUILD_GO "Enable go wrapper" OFF )
option(BUILD_PYTHON "Enable python wrapper" OFF)
option(BUILD_WEBASSEMBLY "Enable emscripten build" OFF)
if (BUILD_WEBASSEMBLY)
message(WARNING "webassembly enabled. Disabling other modules")
set(BUILD_PYTHON 0)
set(BUILD_GO 0)
set(BUILD_TESTS 0)
endif ()
message(STATUS "BUILD_TESTS " ${BUILD_TESTS})
message(STATUS "GOLANG WRAPPER " ${BUILD_GO})
message(STATUS "PYTHON WRAPPER " ${BUILD_PYTHON})
message(STATUS "WEBASSEMBLY " ${BUILD_WEBASSEMBLY})
if (BUILD_PYTHON OR BUILD_GO)
find_package(SWIG REQUIRED)
INCLUDE(${SWIG_USE_FILE})
unset(SWIG_LANG_TYPE)
endif ()
if (BUILD_PYTHON)
set(Python_ADDITIONAL_VERSIONS 3 3.6 3.5)
find_package(PythonLibs REQUIRED)
find_package(PythonInterp REQUIRED)
endif ()
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/src/api
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/deps
)
file(GLOB LIB_QRL_INCLUDES
src/xmss-alt
${CMAKE_CURRENT_SOURCE_DIR}/src/qrl
)
file(GLOB LIB_SHASHA_INCLUDES
${CMAKE_CURRENT_SOURCE_DIR}/src/shasha
)
file(GLOB LIB_DILITHIUM_INCLUDES
${CMAKE_CURRENT_SOURCE_DIR}/deps/dilithium
${CMAKE_CURRENT_SOURCE_DIR}/src/dilithium
)
file(GLOB LIB_KYBER_INCLUDES
${CMAKE_CURRENT_SOURCE_DIR}/deps/kyber
${CMAKE_CURRENT_SOURCE_DIR}/src/kyber
)
file(GLOB_RECURSE LIB_QRL_SRC
"${CMAKE_CURRENT_SOURCE_DIR}/src/qrl/*.cpp")
file(GLOB_RECURSE LIB_DILITHIUM_SRC
"${CMAKE_CURRENT_SOURCE_DIR}/src/dilithium/*.cpp")
file(GLOB_RECURSE LIB_KYBER_SRC
"${CMAKE_CURRENT_SOURCE_DIR}/src/kyber/*.cpp")
set(LIBXMSSALT_SRC
src/xmss-alt/algsxmss_fast.c
src/xmss-alt/algsxmss.c
src/xmss-alt/hash.c
src/xmss-alt/hash_address.c
src/xmss-alt/xmss_common.c
src/xmss-alt/wots.c
src/xmss-alt/fips202.c
)
file(GLOB_RECURSE LIB_SHASHA_SRC
${CMAKE_CURRENT_SOURCE_DIR}/src/shasha/*.cpp
)
set(REF_DILITHIUM_SRC
${CMAKE_CURRENT_SOURCE_DIR}/deps/dilithium/ref/randombytes.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/dilithium/ref/sign.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/dilithium/ref/polyvec.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/dilithium/ref/packing.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/dilithium/ref/poly.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/dilithium/ref/reduce.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/dilithium/ref/ntt.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/dilithium/ref/rounding.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/dilithium/ref/fips202.c
)
set(REF_KYBER_SRC
${CMAKE_CURRENT_SOURCE_DIR}/deps/kyber/ref/randombytes.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/kyber/ref/kem.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/kyber/ref/poly.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/kyber/ref/polyvec.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/kyber/ref/reduce.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/kyber/ref/cbd.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/kyber/ref/precomp.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/kyber/ref/ntt.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/kyber/ref/verify.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/kyber/ref/indcpa.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/kyber/ref/kex.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/kyber/ref/fips202.c
)
file(GLOB_RECURSE TEST_QRL_SRC
"${CMAKE_CURRENT_SOURCE_DIR}/tests/cpp/qrl/*.cpp")
file(GLOB_RECURSE TEST_SHASHA_SRC
"${CMAKE_CURRENT_SOURCE_DIR}/tests/cpp/shasha/*.cpp")
file(GLOB_RECURSE TEST_DILITHIUM_SRC
"${CMAKE_CURRENT_SOURCE_DIR}/tests/cpp/dilithium/*.cpp")
file(GLOB_RECURSE TEST_KYBER_SRC
"${CMAKE_CURRENT_SOURCE_DIR}/tests/cpp/kyber/*.cpp")
# Forcing XMSS to be compiled as C++
SET_SOURCE_FILES_PROPERTIES(${LIB_QRL_SRC} PROPERTIES LANGUAGE CXX)
SET_SOURCE_FILES_PROPERTIES(${LIBXMSSALT_SRC} PROPERTIES LANGUAGE CXX)
SET_SOURCE_FILES_PROPERTIES(${LIB_SHASHA_SRC} PROPERTIES LANGUAGE CXX)
SET_SOURCE_FILES_PROPERTIES(${TEST_QRL_SRC} PROPERTIES LANGUAGE CXX)
SET_SOURCE_FILES_PROPERTIES(${TEST_DILITHIUM_SRC} PROPERTIES LANGUAGE CXX)
SET_SOURCE_FILES_PROPERTIES(${TEST_KYBER_SRC} PROPERTIES LANGUAGE CXX)
SET_SOURCE_FILES_PROPERTIES(${REF_DILITHIUM_SRC} PROPERTIES LANGUAGE CXX)
SET_SOURCE_FILES_PROPERTIES(${REF_KYBER_SRC} PROPERTIES LANGUAGE CXX)
add_library(shasha STATIC
${LIB_SHASHA_SRC})
target_include_directories(shasha PRIVATE ${LIB_SHASHA_INCLUDES} )
add_library(qrllib STATIC
${LIB_QRL_SRC}
${LIBXMSSALT_SRC})
target_include_directories(qrllib PRIVATE
${LIB_QRL_INCLUDES}
${LIB_SHASHA_INCLUDES})
target_link_libraries(qrllib shasha)
add_library(dilithium STATIC
${LIB_DILITHIUM_SRC}
${REF_DILITHIUM_SRC})
target_include_directories(dilithium PRIVATE
${LIB_DILITHIUM_INCLUDES} )
add_library(kyber STATIC
${LIB_KYBER_SRC}
${REF_KYBER_SRC})
target_include_directories(kyber PRIVATE
${LIB_KYBER_INCLUDES} )
if (BUILD_TESTS)
message(STATUS "GTests enabled")
##############################
# Google Test
# Based on instructions in https://github.com/google/googletest/tree/master/googletest#incorporating-into-an-existing-cmake-project
# Download and unpack googletest at configure time
configure_file(CMakeLists.txt.gtest.in googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download)
if (result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif ()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download)
if (result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif ()
# Prevent overriding the parent project's compiler/linker settings on Windows
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory(
${CMAKE_BINARY_DIR}/googletest-src
${CMAKE_BINARY_DIR}/googletest-build
)
# The gtest/gtest_main targets carry header search path
# dependencies automatically when using CMake 2.8.11 or
# later. Otherwise we have to add them here ourselves.
if (CMAKE_VERSION VERSION_LESS 2.8.11)
include_directories("${gtest_SOURCE_DIR}/include")
endif ()
###########################
include(CTest)
enable_testing()
add_executable(qrllib_test
${TEST_QRL_SRC})
target_include_directories( qrllib_test PRIVATE
${LIB_QRL_INCLUDES}
${LIB_SHASHA_INCLUDES})
target_link_libraries(qrllib_test qrllib gtest_main)
add_test(gtest ${PROJECT_BINARY_DIR}/qrllib_test)
###########################
add_executable(shasha_test
${TEST_SHASHA_SRC})
target_include_directories( shasha_test PRIVATE
${LIB_SHASHA_INCLUDES} )
target_link_libraries(shasha_test shasha qrllib gtest_main)
add_test(gtest ${PROJECT_BINARY_DIR}/shasha_test)
###########################
add_executable(dilithium_test
${TEST_DILITHIUM_SRC})
target_include_directories( dilithium_test PRIVATE
${LIB_DILITHIUM_INCLUDES} )
target_link_libraries(dilithium_test dilithium gtest_main)
add_test(gtest ${PROJECT_BINARY_DIR}/dilithium_test)
###########################
add_executable(kyber_test
${TEST_KYBER_SRC})
target_include_directories( kyber_test PRIVATE
${LIB_KYBER_INCLUDES} )
target_link_libraries(kyber_test kyber gtest_main)
add_test(gtest ${PROJECT_BINARY_DIR}/kyber_test)
endif ()
## SWIG + API - Python related stuff
if (BUILD_PYTHON)
message(STATUS "Python wrapper enabled")
if (NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
endif ()
set(language python)
include_directories(
${PYTHON_INCLUDE_PATH}
)
set(CMAKE_SWIG_OUTDIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/pyqrllib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/pyqrllib)
set(SWIG_INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/src/api/pyqrllib.i)
set(SWIG_LANG_LIBRARIES ${PYTHON_LIBRARIES})
set_source_files_properties(${SWIG_INTERFACE} PROPERTIES CPLUSPLUS ON)
set_property(SOURCE ${SWIG_INTERFACE} PROPERTY SWIG_FLAGS "-includeall" "-ignoremissing")
message(STATUS "CMAKE_SWIG_OUTDIR: " ${CMAKE_SWIG_OUTDIR})
message(STATUS "CMAKE_LIBRARY_OUTPUT_DIRECTORY: " ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
# Intentionally use a deprecated version to provide support for the raspberry pi
# Basic pyqrllib - XmssBasic, etc.
SWIG_ADD_MODULE(pyqrllib
${language}
${SWIG_INTERFACE}
${LIB_QRL_SRC}
${LIBXMSSALT_SRC}
)
SWIG_LINK_LIBRARIES(pyqrllib
shasha
${SWIG_LANG_LIBRARIES})
if(WIN32)
SWIG_LINK_LIBRARIES(pyqrllib bcrypt.lib)
endif()
include_directories(
${PYTHON_INCLUDE_PATH}
${LIB_QRL_INCLUDES}
${LIB_SHASHA_INCLUDES}
)
add_custom_command(TARGET ${SWIG_MODULE_pyqrllib_REAL_NAME}
POST_BUILD
COMMENT "Moving SWIG files to output dir"
COMMAND ${CMAKE_COMMAND} -E
copy_if_different $<TARGET_FILE:${SWIG_MODULE_pyqrllib_REAL_NAME}>
${CMAKE_CURRENT_SOURCE_DIR}/pyqrllib/$<TARGET_LINKER_FILE_NAME:${SWIG_MODULE_pyqrllib_REAL_NAME}>
)
add_custom_command(TARGET ${SWIG_MODULE_pyqrllib_REAL_NAME}
POST_BUILD
COMMENT ${swig_extra_generated_files}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${swig_extra_generated_files} ${CMAKE_CURRENT_SOURCE_DIR}/pyqrllib/pyqrllib.py
)
###################################################
# Dilithium
set(SWIG_INTERFACE src/api/dilithium.i)
set(SWIG_LANG_LIBRARIES ${PYTHON_LIBRARIES})
set_source_files_properties(${SWIG_INTERFACE} PROPERTIES CPLUSPLUS ON)
set_property(SOURCE ${SWIG_INTERFACE} PROPERTY SWIG_FLAGS "-includeall" "-ignoremissing")
message(STATUS "CMAKE_SWIG_OUTDIR: " ${CMAKE_SWIG_OUTDIR})
message(STATUS "CMAKE_LIBRARY_OUTPUT_DIRECTORY: " ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set(SWIG_INTERFACE
src/api/dilithium.i)
include_directories(
${PYTHON_INCLUDE_PATH}
${LIB_DILITHIUM_INCLUDES}
)
SWIG_ADD_MODULE(dilithium
${language}
${SWIG_INTERFACE}
${LIB_DILITHIUM_SRC}
${REF_DILITHIUM_SRC}
)
SWIG_LINK_LIBRARIES(dilithium
${SWIG_LANG_LIBRARIES})
if(WIN32)
SWIG_LINK_LIBRARIES(dilithium bcrypt.lib)
endif()
add_custom_command(TARGET ${SWIG_MODULE_dilithium_REAL_NAME}
POST_BUILD
COMMENT "Moving SWIG files to output dir"
COMMAND ${CMAKE_COMMAND} -E
copy_if_different $<TARGET_FILE:${SWIG_MODULE_dilithium_REAL_NAME}>
${CMAKE_CURRENT_SOURCE_DIR}/pyqrllib/$<TARGET_LINKER_FILE_NAME:${SWIG_MODULE_dilithium_REAL_NAME}>
)
add_custom_command(TARGET ${SWIG_MODULE_dilithium_REAL_NAME}
POST_BUILD
COMMENT ${swig_extra_generated_files}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${swig_extra_generated_files} ${CMAKE_CURRENT_SOURCE_DIR}/pyqrllib/dilithium.py
)
# Kyber
set(SWIG_INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/src/api/kyber.i)
set(SWIG_LANG_LIBRARIES ${PYTHON_LIBRARIES})
set_source_files_properties(${SWIG_INTERFACE} PROPERTIES CPLUSPLUS ON)
set_property(SOURCE ${SWIG_INTERFACE} PROPERTY SWIG_FLAGS "-includeall" "-ignoremissing")
message(STATUS "CMAKE_SWIG_OUTDIR: " ${CMAKE_SWIG_OUTDIR})
message(STATUS "CMAKE_LIBRARY_OUTPUT_DIRECTORY: " ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
SWIG_ADD_MODULE(kyber
${language}
${SWIG_INTERFACE}
${LIB_KYBER_SRC}
${REF_KYBER_SRC}
)
SWIG_LINK_LIBRARIES(kyber
${SWIG_LANG_LIBRARIES})
if(WIN32)
SWIG_LINK_LIBRARIES(kyber bcrypt.lib)
endif()
add_custom_command(TARGET ${SWIG_MODULE_kyber_REAL_NAME}
POST_BUILD
COMMENT "Moving SWIG files to output dir"
COMMAND ${CMAKE_COMMAND} -E
copy_if_different $<TARGET_FILE:${SWIG_MODULE_kyber_REAL_NAME}>
${CMAKE_CURRENT_SOURCE_DIR}/pyqrllib/$<TARGET_LINKER_FILE_NAME:${SWIG_MODULE_kyber_REAL_NAME}>
)
add_custom_command(TARGET ${SWIG_MODULE_kyber_REAL_NAME}
POST_BUILD
COMMENT ${swig_extra_generated_files}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${swig_extra_generated_files} ${CMAKE_CURRENT_SOURCE_DIR}/pyqrllib/kyber.py
)
endif ()
if (BUILD_WEBASSEMBLY)
set(JS_QRL_INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/src/jswrapper/jsqrlwrapper.cpp)
message(WARNING "webassembly enabled")
add_library(jsqrl SHARED
${JS_QRL_INTERFACE}
${LIB_QRL_SRC}
${LIB_SHASHA_SRC}
${LIBXMSSALT_SRC}
)
target_include_directories( jsqrl PRIVATE
${LIB_QRL_INCLUDES}
${LIB_SHASHA_INCLUDES})
set_target_properties(jsqrl
PROPERTIES LINK_FLAGS "-s DISABLE_EXCEPTION_CATCHING=0"
)
# set(JS_DILITHIUM_INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/src/jswrapper/jsdilwrapper.cpp)
# set(JS_KYBINTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/src/jswrapper/jskybwrapper.cpp)
# add_library(jsdilithium SHARED
# ${JS_DILITHIUM_INTERFACE}
# ${LIB_KYBER_SRC}
# ${LIBDILITHIUM_SRC}
# )
# target_include_directories( jsdilithium PRIVATE
# ${LIB_DILITHIUM_INCLUDES} )
#
# add_library(jskyber SHARED
# ${JS_KYBER_INTERFACE}
# ${LIB_KYBER_SRC}
# ${LIBKYBER_SRC}
# )
# target_include_directories( jskyber PRIVATE
# ${LIB_KYBER_INCLUDES} )
endif ()