forked from m-chrome/libakrypt-0.x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
380 lines (347 loc) · 15.1 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
# -------------------------------------------------------------------------------------------------- #
# сборка по умолчанию
# cmake path && make
# где path это путь к каталогу, в котором расположен файл MakeLists.txt
# сборка с использованием с использованием clang
# cmake -D CMAKE_C_COMPILER=clang path && make
# сборка с использованием с использованием TinyCC
# cmake -D CMAKE_C_COMPILER=tcc path && make
# сборка при помощи MSVC из консоли (Visual Studio Console Prompt)
# cmake -G "NMake Makefiles" path && nmake
# сборка при MinGW из консоли MSYS (WINDOWS)
# cmake -G "MinGW Makefiles" -D CMAKE_C_COMPILER=gcc path && mingw32-make
# -------------------------------------------------------------------------------------------------- #
cmake_minimum_required( VERSION 3.2 )
project( libakrypt C )
set( HEAD_VERSION 0 )
set( MAIN_VERSION 7 )
set( MINOR_VERSION 13 )
set( MAJOR_VERSION ${HEAD_VERSION}.${MAIN_VERSION} )
set( FULL_VERSION ${MAJOR_VERSION}.${MINOR_VERSION} )
# для включения опции: cmake -D LIBAKRYPT_GMP_TESTS=ON path
option( LIBAKRYPT_STATIC_LIB "Build the static library" ON )
option( LIBAKRYPT_SHARED_LIB "Build the shared library" OFF )
option( LIBAKRYPT_INTERNAL_TESTS "Build collection of internal tests using non-export functions" OFF )
option( LIBAKRYPT_GMP_TESTS "Build comparison tests for gmp and libakrypt" OFF )
option( LIBAKRYPT_HTML_DOC "Build documentation in HTML format" OFF )
option( LIBAKRYPT_PDF_DOC "Build documentation in PDF format" OFF )
option( LIBAKRYPT_CRYPTO_FUNCTIONS "Build library with crypto functions" ON )
option( LIBAKRYPT_CONST_CRYPTO_PARAMS "Build library with const values of crypto parameters" OFF )
option( LIBAKRYPT_NETWORK "Build library with network communications support" OFF )
option( LIBAKRYPT_FIOT "Build library with FIOT protocol support" OFF )
option( LIBAKRYPT_TLS_13 "Build library with TLS 1.3 protocol support" OFF )
option( LIBAKRYPT_AKRYPT "Build console akrypt application" OFF )
# -------------------------------------------------------------------------------------------------- #
if( LIBAKRYPT_FIOT )
set( LIBAKRYPT_CRYPTO_FUNCTIONS ON )
set( LIBAKRYPT_NETWORK ON )
endif()
if( LIBAKRYPT_TLS_13 )
# в настоящее время реализация протокола отсутствует
# set( LIBAKRYPT_CRYPTO_FUNCTIONS ON )
# set( LIBAKRYPT_NETWORK ON )
endif()
if( LIBAKRYPT_AKRYPT )
set( LIBAKRYPT_CRYPTO_FUNCTIONS ON )
endif()
# -------------------------------------------------------------------------------------------------- #
# подключаем модули CMake для тонкой настройки параметров сборки
set( CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH} )
include( DetectFlags )
include( DetectHeaders )
include( DetectLibraries )
include( DetectIntrinsics )
# -------------------------------------------------------------------------------------------------- #
# множество исходных текстов библиотеки и вспомогательных файлов
set( MAIN_HEADER source/libakrypt.h )
set( HEADERS source/ak_tools.h
source/ak_buffer.h
source/ak_oid.h
source/ak_random.h
source/ak_mpzn.h
source/ak_curves.h
source/ak_parameters.h
source/ak_gf2n.h
source/ak_network.h
)
set( SOURCES source/ak_tools.c
source/ak_buffer.c
source/ak_oid.c
source/ak_mpzn.c
source/ak_curves.c
source/ak_random.c
source/ak_gf2n.c
source/ak_libakrypt.c
)
# -------------------------------------------------------------------------------------------------- #
if( LIBAKRYPT_CRYPTO_FUNCTIONS )
set( HEADERS ${HEADERS}
source/ak_hash.h
source/ak_skey.h
source/ak_hmac.h
source/ak_mac.h
source/ak_context_manager.h
source/ak_sign.h
source/ak_bckey.h
source/ak_omac.h
source/ak_mgm.h
)
set( SOURCES ${SOURCES}
source/ak_hash.c
source/ak_streebog.c
source/ak_hashrnd.c
source/ak_skey.c
source/ak_hmac.c
source/ak_mac.c
source/ak_context_manager.c
source/ak_sign.c
source/ak_bckey.c
source/ak_kuznechik.c
source/ak_magma.c
source/ak_omac.c
source/ak_mgm.c
source/ak_acpkm.c
)
add_compile_options( -DLIBAKRYPT_CRYPTO_FUNCTIONS=ON )
if( LIBAKRYPT_HAVE_SYSUN )
set( SOURCES ${SOURCES}
source/ak_udsrnd.c )
endif()
if( LIBAKRYPT_HAVE_WINDOWS )
set( SOURCES ${SOURCES}
source/ak_winrnd.c )
endif()
endif()
# -------------------------------------------------------------------------------------------------- #
if( LIBAKRYPT_AKRYPT )
set( AKRYPT_SOURCES
akrypt/akrypt.c
akrypt/akrypt_show.c
akrypt/akrypt_hash.c )
set( AKRYPT_FILES
akrypt/akrypt.h
akrypt/akrypt.po
akrypt/getopt.h
akrypt/getopt.c
akrypt/Readme.md )
endif()
# -------------------------------------------------------------------------------------------------- #
if( LIBAKRYPT_NETWORK )
set( HEADERS ${HEADERS}
source/ak_network.h
)
set( SOURCES ${SOURCES}
source/ak_network.c
)
add_compile_options( -DLIBAKRYPT_NETWORK=ON )
endif()
# -------------------------------------------------------------------------------------------------- #
if( LIBAKRYPT_FIOT )
set( HEADERS ${HEADERS}
source/ak_fiot.h
)
set( SOURCES ${SOURCES}
source/ak_fiot.c
source/ak_fiot_tlp.c
source/ak_fiot_kgp.c
)
add_compile_options( -DLIBAKRYPT_FIOT=ON )
endif()
# -------------------------------------------------------------------------------------------------- #
set( CMAKES cmake/DetectFlags.cmake
cmake/DetectHeaders.cmake
cmake/DetectIntrinsics.cmake
cmake/DetectLibraries.cmake
cmake/MakeDist.cmake
cmake/MakeDoc.cmake
cmake/MakeInstall.cmake
)
set( DOCS doc/00-introduction.md
doc/01-install-guide.md
doc/02-primciples.md
doc/Doxyfile.in
doc/refman_footer.in
doc/refman_header.in
)
set( OTHERS CMakeLists.txt
Readme.md
Changelog.md
libakrypt.conf
libakrypt.rc.in
LICENSE
)
# -------------------------------------------------------------------------------------------------- #
# определяемся с местом хранения файла с конфигурацией библиотеки
if( LIBAKRYPT_CONF )
else()
if( CMAKE_HOST_UNIX )
set( LIBAKRYPT_CONF "/etc" )
endif()
if( WIN32 )
set( LIBAKRYPT_CONF "C:\\\\Program Files\\\\Akrypt" )
endif()
endif()
# -------------------------------------------------------------------------------------------------- #
if( LIBAKRYPT_CONST_CRYPTO_PARAMS )
add_compile_options( -DLIBAKRYPT_CONST_CRYPTO_PARAMS=ON )
endif()
# -------------------------------------------------------------------------------------------------- #
# сборка библиотек - статической и, если нужно, динамической
include_directories( "source" )
message("-- Path for libakrypt.conf is ${LIBAKRYPT_CONF}")
add_compile_options( -DLIBAKRYPT_OPTIONS_PATH="${LIBAKRYPT_CONF}" )
add_compile_options( -DLIBAKRYPT_VERSION="${FULL_VERSION}" )
#
if( LIBAKRYPT_SHARED_LIB )
add_library( akrypt-shared SHARED ${MAIN_HEADER} ${SOURCES} ${ASN1_SOURCES} )
set_target_properties( akrypt-shared PROPERTIES VERSION ${MAJOR_VERSION} SOVERSION ${FULL_VERSION} )
target_link_libraries( akrypt-shared ${LIBAKRYPT_LIBS} )
endif()
#
if( LIBAKRYPT_STATIC_LIB )
add_library( akrypt-static STATIC ${MAIN_HEADER} ${SOURCES} ${ASN1_SOURCES} )
set_target_properties( akrypt-static PROPERTIES VERSION ${MAJOR_VERSION} SOVERSION ${FULL_VERSION} )
endif()
# -------------------------------------------------------------------------------------------------- #
message("-- Compiler options is ${CMAKE_C_FLAGS}" )
if( LIBAKRYPT_LIBS )
message("-- Additional libraries is ${LIBAKRYPT_LIBS}" )
endif()
# -------------------------------------------------------------------------------------------------- #
# сборка консольной утилиты для работы с функциями библиотеки
if( LIBAKRYPT_AKRYPT )
if( LIBAKRYPT_HAVE_GETOPT )
else()
set( AKRYPT_SOURCES ${AKRYPT_SOURCES} akrypt/getopt.c )
endif()
if( LIBAKRYPT_STATIC_LIB )
add_executable( akrypt${LIBAKRYPT_EXT} ${AKRYPT_SOURCES} )
target_include_directories( akrypt${LIBAKRYPT_EXT} PUBLIC "akrypt" )
target_link_libraries( akrypt${LIBAKRYPT_EXT} akrypt-static ${LIBAKRYPT_LIBS} )
endif()
endif()
# -------------------------------------------------------------------------------------------------- #
# тестовые примеры для арифметических операций
set( ARITHMETIC_TESTS_LIST
mpzn-convert
mpzn-arithmetic
mpzn-montgomery
mpzn-rem
)
if( LIBAKRYPT_GMP_TESTS )
set( ARITHMETIC_TESTS_LIST ${ARITHMETIC_TESTS_LIST}
mpzn-password
)
enable_testing()
if( LIBAKRYPT_STATIC_LIB )
foreach( programm ${ARITHMETIC_TESTS_LIST} )
add_executable( test-${programm}${LIBAKRYPT_EXT} tests/test-${programm}.c )
target_link_libraries( test-${programm}${LIBAKRYPT_EXT} akrypt-static gmp )
add_test( NAME test-${programm} COMMAND test-${programm}${LIBAKRYPT_EXT} )
endforeach()
endif()
message("-- Added tests for integer arithmetic and comparizon with libgmp (now \"make test\" enabled)")
endif()
# -------------------------------------------------------------------------------------------------- #
# сборка примеров, иллюстрирующих работу с внешним интерфейсом библиотеки
set( EXAMPLES_LIST hello
log
buffer
)
# организуем сборку примеров со статической линковкой
if( LIBAKRYPT_STATIC_LIB )
foreach( programm ${EXAMPLES_LIST} )
add_executable( example-${programm}${LIBAKRYPT_EXT} examples/example-${programm}.c )
target_link_libraries( example-${programm}${LIBAKRYPT_EXT} akrypt-static ${LIBAKRYPT_LIBS} )
endforeach()
endif()
# организуем сборку примеров с динамической линковкой
if( LIBAKRYPT_SHARED_LIB )
foreach( programm ${EXAMPLES_LIST} )
add_executable( example-dynamic-${programm}${LIBAKRYPT_EXT} examples/example-${programm}.c )
target_link_libraries( example-dynamic-${programm}${LIBAKRYPT_EXT} akrypt-shared ${LIBAKRYPT_LIBS} )
endforeach()
endif()
# -------------------------------------------------------------------------------------------------- #
# теперь примеры, использующие неэкспортируемые функции
set( INTERNAL_TEST_LIST
internal-random01
internal-oid01
internal-oid02
internal-mpzn01
)
if( LIBAKRYPT_CRYPTO_FUNCTIONS )
set( INTERNAL_TEST_LIST ${INTERNAL_TEST_LIST}
internal-hash01
internal-hash02
internal-hash03
internal-oid03
internal-random02
internal-sign01
internal-sign02
internal-bckey01
internal-bckey01a
internal-bckey02
internal-bckey02-magma
internal-bckey03
internal-bckey05
internal-mac01
internal-mgm01
internal-mgm02
internal-mgm03
)
set( INTERNAL_TEST_LIST_EXAMPLES # эти программы компилируются, но не вызываются
# при запуске make test
internal-bckey04
internal-mgm04
)
if( LIBAKRYPT_HAVE_SYSUN )
set( INTERNAL_TEST_LIST_EXAMPLES
${INTERNAL_TEST_LIST_EXAMPLES}
internal-random03 )
endif()
endif()
if( LIBAKRYPT_FIOT )
set( INTERNAL_FIOT_TEST_LIST
internal-fiot-algconst
internal-fiot-context
internal-fiot-echo-client
)
if( UNIX )
set( INTERNAL_FIOT_TEST_LIST
${INTERNAL_FIOT_TEST_LIST}
internal-fiot-echo-server
)
endif()
endif()
# -------------------------------------------------------------------------------------------------- #
if( LIBAKRYPT_INTERNAL_TESTS )
enable_testing()
# добавляем примеры в случае сборки статической библиотеки
if( LIBAKRYPT_STATIC_LIB )
foreach( programm ${INTERNAL_TEST_LIST} )
add_executable( test-${programm}${LIBAKRYPT_EXT} tests/test-${programm}.c )
target_link_libraries( test-${programm}${LIBAKRYPT_EXT} akrypt-static ${LIBAKRYPT_LIBS} )
add_test( NAME test-${programm}${LIBAKRYPT_EXT} COMMAND test-${programm}${LIBAKRYPT_EXT} )
endforeach()
# компилируемые тесты, не попадающие в вызов команды make test
foreach( programm ${INTERNAL_TEST_LIST_EXAMPLES} )
add_executable( test-${programm}${LIBAKRYPT_EXT} tests/test-${programm}.c )
target_link_libraries( test-${programm}${LIBAKRYPT_EXT} akrypt-static ${LIBAKRYPT_LIBS} )
endforeach()
endif()
message("-- Added tests for internal functions (now \"make test\" enabled)")
# добавляем примеры для тестирования протокольной части (командой make test не затрагиваются)
if( LIBAKRYPT_STATIC_LIB )
foreach( programm ${INTERNAL_FIOT_TEST_LIST} )
add_executable( test-${programm}${LIBAKRYPT_EXT} tests/test-${programm}.c )
target_link_libraries( test-${programm}${LIBAKRYPT_EXT} akrypt-static ${LIBAKRYPT_LIBS} )
endforeach()
endif()
endif()
# -------------------------------------------------------------------------------------------------- #
if( CMAKE_HOST_UNIX )
include( MakeDoc )
include( MakeInstall )
include( MakeDist )
endif()