forked from guanzhi/GmSSL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
366 lines (322 loc) · 7.89 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
cmake_minimum_required(VERSION 3.6)
project(GmSSL)
SET(CMAKE_PROJECT_HOMEPAGE_URL "http://gmssl.org")
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
SET(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include_directories(include)
set(src
src/version.c
src/debug.c
src/sm4_common.c
src/sm4_enc.c
src/sm4_modes.c
src/sm4_setkey.c
src/sm3.c
src/sm3_hmac.c
src/sm3_kdf.c
src/sm2_alg.c
src/sm2_key.c
src/sm2_lib.c
src/sm9_alg.c
src/sm9_key.c
src/sm9_lib.c
src/zuc.c
src/zuc_modes.c
src/aes.c
src/aes_modes.c
src/sha256.c
src/sha512.c
src/chacha20.c
src/hash_drbg.c
src/block_cipher.c
src/digest.c
src/hmac.c
src/hkdf.c
src/pbkdf2.c
src/gf128.c
src/gcm.c
src/aead.c
src/pkcs8.c
src/ec.c
src/rsa.c
src/asn1.c
src/hex.c
src/base64.c
src/pem.c
src/x509_alg.c
src/x509_cer.c
src/x509_ext.c
src/x509_req.c
src/x509_crl.c
src/x509_new.c
src/cms.c
src/sdf/sdf.c
src/sdf/sdf_lib.c
src/sdf/sdf_meth.c
src/sdf/sdf_ext.c
src/sdf/sdf_sansec.c
src/skf/skf.c
src/skf/skf_lib.c
src/skf/skf_meth.c
src/skf/skf_ext.c
src/skf/skf_prn.c
src/skf/skf_wisec.c
src/socket.c
src/tls.c
src/tls_ext.c
src/tls_trace.c
src/tlcp.c
src/tls12.c
src/tls13.c
src/file.c
)
set(tools
tools/gmssl.c
tools/version.c
tools/sm4.c
tools/sm3.c
tools/sm3hmac.c
tools/sm2keygen.c
tools/sm2sign.c
tools/sm2verify.c
tools/sm2encrypt.c
tools/sm2decrypt.c
tools/sm9setup.c
tools/sm9keygen.c
tools/sm9sign.c
tools/sm9verify.c
tools/sm9encrypt.c
tools/sm9decrypt.c
tools/zuc.c
tools/rand.c
tools/pbkdf2.c
tools/certgen.c
tools/certparse.c
tools/certverify.c
tools/certrevoke.c
tools/reqgen.c
tools/reqparse.c
tools/reqsign.c
tools/crlgen.c
tools/crlget.c
tools/crlparse.c
tools/crlverify.c
tools/cmssign.c
tools/cmsverify.c
tools/cmsencrypt.c
tools/cmsdecrypt.c
tools/cmsparse.c
tools/sdfutil.c
tools/skfutil.c
tools/tlcp_client.c
tools/tlcp_server.c
tools/tls12_client.c
tools/tls12_server.c
tools/tls13_client.c
tools/tls13_server.c
)
set(tests
sm4
sm3
sm2
sm9
zuc
aes
sha224
sha256
sha384
sha512
chacha20
hash_drbg
block_cipher
digest
hmac
hkdf
pbkdf2
gf128
gcm
aead
pkcs8
ec
asn1
hex
base64
pem
x509
x509_oid
x509_alg
x509_str
x509_ext
x509_req
x509_crl
cms
tls
tls13
)
set(demos
demo_sm2_encrypt
demo_sm2_keygen
demo_sm2_keyparse
demo_sm2_private_key
demo_sm2_private_key_parse
demo_sm2_public_key
demo_sm2_sign
demo_sm2_sign_ctx
demo_sm3
demo_sm3_hmac
demo_sm3_kdf
demo_sm4
demo_sm4_cbc
demo_sm4_cbc_decrypt_update
demo_sm4_cbc_encrypt_update
demo_sm4_cbc_padding
demo_sm4_ctr
demo_sm4_ctr_encrypt_update
demo_sm4_gcm
demo_sm9_encrypt
demo_sm9_keygen
demo_sm9_sign
# demo_tlcp_get
# demo_tlcp_post
# demo_wget
demo_zuc
)
# when an option has been enabled, `cmake ..` will not refresh the value
# use `cmake .. -DENABLE_XXX=OFF` to disable the option
option(ENABLE_SM2_ALGOR_ID_ENCODE_NULL "Enable AlgorithmIdenifier with algorithm sm2sign_with_sm3 encode a NULL object as parameters" OFF)
if (ENABLE_SM2_ALGOR_ID_ENCODE_NULL)
message(STATUS "ENABLE_SM2_ALGOR_ID_ENCODE_NULL")
add_definitions(-DSM2_ALGOR_ID_ENCODE_NULL)
endif()
option(ENABLE_SM2_PRIVATE_KEY_EXPORT "Enable export un-encrypted SM2 private key" OFF)
if (ENABLE_SM2_PRIVATE_KEY_EXPORT)
message(STATUS "ENABLE_SM2_PRIVATE_KEY_EXPORT")
add_definitions(-DSM2_PRIVATE_KEY_EXPORT)
list(APPEND demos demo_sm2_key_export)
endif()
option(ENABLE_TLS_DEBUG "Enable TLS and TLCP print debug message" OFF)
if (ENABLE_TLS_DEBUG)
message(STATUS "ENABLE_TLS_DEBUG")
add_definitions(-DTLS_DEBUG)
endif()
option(ENABLE_SM3_AVX_BMI2 "Enable SM3 AVX+BMI2 assembly implementation" OFF)
if (ENABLE_SM3_AVX_BMI2)
message(STATUS "ENABLE_SM3_AVX_BMI2")
add_definitions(-DSM3_AVX_BMI2)
enable_language(ASM)
list(APPEND src src/sm3_avx_bmi2.s)
endif()
option(ENABLE_SM4_AESNI_AVX "Enable SM4 AESNI+AVX assembly implementation" OFF)
if (ENABLE_SM4_AESNI_AVX)
message(STATUS "ENABLE_SM4_AESNI_AVX")
add_definitions(-DSM4_AESNI_AVX)
list(APPEND src src/sm4_aesni_avx.c)
list(APPEND tests sm4_aesni_avx)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
endif()
option(ENABLE_SM2_EXTS "Enable SM2 Extensions" OFF)
if (ENABLE_SM2_EXTS)
message(STATUS "ENABLE_SM4_AESNI_AVX")
list(APPEND src
src/sm2_key_share.c
src/sm2_recover.c
src/sm2_blind.c
src/sm2_ring.c
src/sm2_elgamal.c
src/sm2_commit.c)
list(APPEND tests sm2_key_share sm2_blind sm2_ring sm2_elgamal sm2_commit)
endif()
option(ENABLE_BROKEN_CRYPTO "Enable broken crypto algorithms" OFF)
if (ENABLE_BROKEN_CRYPTO)
message(STATUS "ENABLE_BROKEN_CRYPTO")
list(APPEND src src/des.c src/sha1.c src/md5.c src/rc4.c)
list(APPEND tests des sha1 md5 rc4)
endif()
option(ENABLE_RDRND "Enable Intel RDRND instructions" OFF)
if (${CMAKE_SYSTEM_PROCESSOR} MATCHES x86_64)
set(ENABLE_RDRND ON)
endif()
if (ENABLE_RDRND)
message(STATUS "ENABLE_RDRND")
list(APPEND src src/rdrand.c)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mrdrnd -mrdseed")
endif()
option(ENABLE_GMT_0105_RNG "Enable GM/T 0105 Software RNG" OFF)
if (ENABLE_GMT_0105_RNG)
message(STATUS "ENABLE_GMT_0105_RNG")
list(APPEND src src/sm3_rng.c src/sm4_cbc_mac.c src/sm4_rng.c)
list(APPEND tests sm3_rng sm4_cbc_mac sm4_rng)
endif()
if (WIN32)
list(APPEND src src/rand_win.c src/http_win.c)
elseif (APPLE)
list(APPEND src src/rand_apple.c src/http.c)
elseif (ANDROID)
list(APPEND src src/rand.c src/http.c)
else()
list(APPEND src src/rand_unix.c src/http.c)
endif()
option(ENABLE_HTTP_TESTS "Enable HTTP GET/POST related tests" OFF)
if (ENABLE_HTTP_TESTS)
message(STATUS "ENABLE_HTTP_TESTS")
list(APPEND tests http http_crl)
endif()
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
if (CMAKE_C_COMPILER_ID MATCHES "MSVC")
message(STATUS "CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS")
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) # set before add_library
endif()
add_library(gmssl ${src})
if (WIN32)
target_link_libraries(gmssl -lws2_32)
elseif (APPLE)
target_link_libraries(gmssl dl)
target_link_libraries(gmssl "-framework Security")
#target_link_libraries(gmssl "-framework CoreFoundation") # rand_apple.c CFRelease()
elseif (MINGW)
target_link_libraries(gmssl PRIVATE wsock32)
else()
target_link_libraries(gmssl dl)
endif()
SET_TARGET_PROPERTIES(gmssl PROPERTIES VERSION 3.0 SOVERSION 3)
install(TARGETS gmssl ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/gmssl DESTINATION include)
if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "iOS")
add_library(sdf_dummy SHARED src/sdf/sdf_dummy.c)
set_target_properties(sdf_dummy PROPERTIES VERSION 3.0 SOVERSION 3)
add_library(skf_dummy SHARED src/skf/skf_dummy.c)
set_target_properties(skf_dummy PROPERTIES VERSION 3.0 SOVERSION 3)
add_executable(gmssl-bin ${tools})
target_link_libraries(gmssl-bin LINK_PUBLIC gmssl)
set_target_properties(gmssl-bin PROPERTIES RUNTIME_OUTPUT_NAME gmssl)
if (MINGW)
target_link_libraries(gmssl-bin PRIVATE Ws2_32)
endif()
enable_testing()
foreach(name ${tests})
add_test(NAME ${name} COMMAND ${name}test)
add_executable(${name}test tests/${name}test.c)
target_link_libraries (${name}test LINK_PUBLIC gmssl)
endforeach()
foreach(name ${demos})
add_executable(${name} demos/src/${name}.c)
target_link_libraries(${name} LINK_PUBLIC gmssl)
endforeach()
install(TARGETS gmssl-bin RUNTIME DESTINATION bin)
endif()
if (CMAKE_C_COMPILER_ID MATCHES "MSVC")
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT gmssl-bin)
set(CMAKE_INSTALL_PREFIX "C:/Program Files/GmSSL") # change by `cmake -DCMAKE_INSTALL_PREFIX=C:\path\to\install`
# run `set path=%path%;C:\Program Files\GmSSL\bin`
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
# target_compile_options(gmssl PRIVATE /wd4996)
# target_compile_options(gmssl-bin PRIVATE /wd4996)
endif()
if (UNIX)
# packaging
include(LinuxPacking)
include(DebPacking)
include(RpmPacking)
include(CPack)
endif (UNIX)