-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCMakeLists.txt
306 lines (262 loc) · 10 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
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.8)
PROJECT(tongsuo-mini LANGUAGES C)
if (MSVC)
# warning level 4 and all warnings as errors
add_compile_options(/W4 /WX)
else()
# lots of warnings and all warnings as errors
add_compile_options(-Wall -Wextra -pedantic -Werror)
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(MSVC)
set(CMAKE_INSTALL_PREFIX C:/tongsuo-mini)
else()
set(CMAKE_INSTALL_PREFIX /opt/tongsuo-mini)
endif()
set(CMAKE_MACOSX_RPATH 1)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
include_directories(include)
set(libsrc
src/error.c
src/mem.c
src/meth.c
src/pool.c
src/version.c
)
# All options, in alphabetic order
OPTION(WITH_ALL "Build with all modules" OFF)
OPTION(WITH_ASCON "Build with ASCON module" OFF)
OPTION(WITH_ASN1 "Build with asn1 module" OFF)
OPTION(WITH_DEBUG "Enable debug" OFF)
OPTION(WITH_ERRSTR "Build with error string" OFF)
OPTION(WITH_EXAMPLE "Build example program" OFF)
OPTION(WITH_HMAC "Build with HMAC module" OFF)
OPTION(WITH_LOG "Build with log module" OFF)
OPTION(WITH_OSCORE "Build with OSCORE module" OFF)
OPTION(WITH_PERF "Build performance test program" OFF)
OPTION(WITH_SM3 "Build with SM3 module" OFF)
OPTION(WITH_SM4 "Build with SM4 module" OFF)
if(WITH_ALL)
set(WITH_ASCON ON)
set(WITH_ASN1 ON)
set(WITH_DEBUG ON)
set(WITH_ERRSTR ON)
set(WITH_EXAMPLE ON)
set(WITH_HMAC ON)
set(WITH_LOG ON)
set(WITH_OSCORE ON)
set(WITH_PERF ON)
set(WITH_SM3 ON)
set(WITH_SM4 ON)
endif()
if(WITH_DEBUG)
add_definitions(-DDEBUG)
set(CMAKE_BUILD_TYPE "Debug")
else()
add_definitions(-DNDEBUG)
set(CMAKE_BUILD_TYPE "Release")
endif()
if(WITH_LOG)
add_definitions(-DTSM_LOG)
list(APPEND libsrc src/log.c)
endif()
if(WITH_ERRSTR)
add_definitions(-DTSM_ERRSTR)
endif()
if(WITH_ASN1)
list(APPEND libsrc src/asn1.c)
add_executable(test_asn1 test/test_asn1.c)
target_include_directories(test_asn1 PUBLIC test)
target_link_libraries(test_asn1 LINK_PUBLIC tongsuo-mini)
add_test(NAME test_asn1
COMMAND python3 -m pytest test_asn1.py
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test
)
endif()
if(WITH_SM3 OR WITH_PERF)
list(APPEND libsrc src/sm3.c)
add_definitions(-DTSM_HAVE_SM3)
add_executable(test_sm3 test/test_sm3.c)
target_include_directories(test_sm3 PUBLIC test)
target_link_libraries(test_sm3 LINK_PUBLIC tongsuo-mini)
add_test(NAME test_sm3
COMMAND python3 -m pytest test_sm3.py
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test
)
endif()
if(WITH_SM4 OR WITH_PERF)
list(APPEND libsrc src/sm4.c)
add_definitions(-DTSM_HAVE_SM4)
add_executable(test_sm4_api test/test_sm4_api.c)
target_include_directories(test_sm4_api PUBLIC test)
target_link_libraries(test_sm4_api LINK_PUBLIC tongsuo-mini)
add_test(NAME test_sm4
COMMAND python3 -m pytest test_sm4.py
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test
)
endif()
if(WITH_OSCORE)
set(WITH_ASCON ON)
set(WITH_HMAC ON)
list(APPEND libsrc src/oscore_cbor.c src/oscore_context.c src/oscore_cose.c src/oscore_crypto.c src/oscore.c)
add_executable(test_oscore test/test_oscore.c)
target_include_directories(test_oscore PUBLIC test)
target_link_libraries(test_oscore LINK_PUBLIC tongsuo-mini)
add_test(NAME test_oscore
COMMAND python3 -m pytest test_oscore.py
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test
)
endif()
if(WITH_ASCON OR WITH_PERF)
list(APPEND libsrc src/ascon.c)
add_definitions(-DTSM_HAVE_ASCON)
add_executable(test_ascon_aead test/test_ascon_aead.c)
add_executable(test_ascon_hash test/test_ascon_hash.c)
target_include_directories(test_ascon_aead PUBLIC test)
target_include_directories(test_ascon_hash PUBLIC test)
target_link_libraries(test_ascon_aead LINK_PUBLIC tongsuo-mini)
target_link_libraries(test_ascon_hash LINK_PUBLIC tongsuo-mini)
add_test(NAME test_ascon_aead
COMMAND python3 -m pytest test_ascon_aead.py
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test
)
add_test(NAME test_ascon_hash
COMMAND python3 -m pytest test_ascon_hash.py
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test
)
endif()
if(WITH_HMAC)
list(APPEND libsrc src/hmac.c)
if(WITH_SM3)
add_executable(test_hmac_sm3 test/test_hmac_sm3.c)
target_include_directories(test_hmac_sm3 PUBLIC test)
target_link_libraries(test_hmac_sm3 LINK_PUBLIC tongsuo-mini)
add_test(NAME test_hmac_sm3
COMMAND python3 -m pytest test_hmac_sm3.py
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test
)
endif(WITH_SM3)
if(WITH_ASCON)
add_executable(test_hmac_ascon test/test_hmac_ascon.c)
target_include_directories(test_hmac_ascon PUBLIC test)
target_link_libraries(test_hmac_ascon LINK_PUBLIC tongsuo-mini)
add_test(NAME test_hmac_ascon
COMMAND python3 -m pytest test_hmac_ascon.py
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test
)
endif(WITH_ASCON)
endif()
add_library(tongsuo-mini-obj OBJECT ${libsrc})
# static library does not need to be a PIC...
set_property(TARGET tongsuo-mini-obj PROPERTY POSITION_INDEPENDENT_CODE 1)
add_library(tongsuo-mini SHARED $<TARGET_OBJECTS:tongsuo-mini-obj>)
add_library(tongsuo-mini-static STATIC $<TARGET_OBJECTS:tongsuo-mini-obj>)
set_target_properties(tongsuo-mini-static PROPERTIES OUTPUT_NAME tongsuo-mini)
add_executable(minisuo app/minisuo.c)
target_link_libraries(minisuo LINK_PUBLIC tongsuo-mini)
if(WITH_PERF)
add_executable(minisuo-perf perf/perf.c)
target_link_libraries(minisuo-perf LINK_PUBLIC tongsuo-mini)
endif()
if(WITH_EXAMPLE)
if(WITH_SM3)
add_executable(sm3_demo examples/sm3_demo.c)
target_link_libraries(sm3_demo LINK_PUBLIC tongsuo-mini)
set_property(TARGET sm3_demo
PROPERTY RUNTIME_OUTPUT_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/examples)
add_executable(sm3_oneshot examples/sm3_oneshot.c)
target_link_libraries(sm3_oneshot LINK_PUBLIC tongsuo-mini)
set_property(TARGET sm3_oneshot
PROPERTY RUNTIME_OUTPUT_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/examples)
endif(WITH_SM3)
if(WITH_SM4)
add_executable(sm4_cbc_enc examples/sm4_cbc_enc.c)
target_link_libraries(sm4_cbc_enc LINK_PUBLIC tongsuo-mini)
set_property(TARGET sm4_cbc_enc
PROPERTY RUNTIME_OUTPUT_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/examples)
add_executable(sm4_oneshot examples/sm4_oneshot.c)
target_link_libraries(sm4_oneshot LINK_PUBLIC tongsuo-mini)
set_property(TARGET sm4_oneshot
PROPERTY RUNTIME_OUTPUT_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/examples)
endif(WITH_SM4)
if(WITH_ASCON)
add_executable(ascon_aead_enc examples/ascon_aead_enc.c)
target_link_libraries(ascon_aead_enc LINK_PUBLIC tongsuo-mini)
set_property(TARGET ascon_aead_enc
PROPERTY RUNTIME_OUTPUT_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/examples)
add_executable(ascon_aead_oneshot examples/ascon_aead_oneshot.c)
target_link_libraries(ascon_aead_oneshot LINK_PUBLIC tongsuo-mini)
set_property(TARGET ascon_aead_oneshot
PROPERTY RUNTIME_OUTPUT_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/examples)
add_executable(ascon_hash examples/ascon_hash.c)
target_link_libraries(ascon_hash LINK_PUBLIC tongsuo-mini)
set_property(TARGET ascon_hash
PROPERTY RUNTIME_OUTPUT_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/examples)
add_executable(ascon_hash_oneshot examples/ascon_hash_oneshot.c)
target_link_libraries(ascon_hash_oneshot LINK_PUBLIC tongsuo-mini)
set_property(TARGET ascon_hash_oneshot
PROPERTY RUNTIME_OUTPUT_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/examples)
endif(WITH_ASCON)
if(WITH_HMAC)
if(WITH_ASCON)
add_executable(hmac_ascon examples/hmac_ascon.c)
target_link_libraries(hmac_ascon LINK_PUBLIC tongsuo-mini)
set_property(TARGET hmac_ascon
PROPERTY RUNTIME_OUTPUT_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/examples)
endif(WITH_ASCON)
if(WITH_SM3)
add_executable(hmac_sm3 examples/hmac_sm3.c)
target_link_libraries(hmac_sm3 LINK_PUBLIC tongsuo-mini)
set_property(TARGET hmac_sm3
PROPERTY RUNTIME_OUTPUT_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/examples)
endif(WITH_SM3)
endif(WITH_HMAC)
endif()
enable_testing()
add_test(NAME test_minisuo
COMMAND python3 -m pytest test_minisuo.py
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test
)
# show options
message(STATUS "")
message(STATUS "Tongsuo Mini Configuration Summary:")
message(STATUS "")
message(STATUS "WITH_ALL...................${WITH_ALL}")
message(STATUS "WITH_ASCON.................${WITH_ASCON}")
message(STATUS "WITH_ASN1..................${WITH_ASN1}")
message(STATUS "WITH_DEBUG.................${WITH_DEBUG}")
message(STATUS "WITH_ERRSTR................${WITH_ERRSTR}")
message(STATUS "WITH_EXAMPLE...............${WITH_EXAMPLE}")
message(STATUS "WITH_HMAC..................${WITH_HMAC}")
message(STATUS "WITH_LOG...................${WITH_LOG}")
message(STATUS "WITH_OSCORE................${WITH_OSCORE}")
message(STATUS "WITH_PERF..................${WITH_PERF}")
message(STATUS "WITH_SM3...................${WITH_SM3}")
message(STATUS "WITH_SM4...................${WITH_SM4}")
#
# install
#
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include/tongsuo
DESTINATION ${CMAKE_INSTALL_PREFIX}/include
COMPONENT dev)
install(TARGETS tongsuo-mini tongsuo-mini-static
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib COMPONENT lib
ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib COMPONENT lib)
install(TARGETS minisuo
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
COMPONENT dev)
if(WITH_PERF)
install(TARGETS minisuo-perf
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
COMPONENT dev)
endif()