Skip to content

Commit

Permalink
Make SDF/SKF optional in CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
guanzhi committed Apr 15, 2024
1 parent bd12c4e commit afed7a0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 25 deletions.
59 changes: 37 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,6 @@ set(src
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
Expand Down Expand Up @@ -130,8 +119,6 @@ set(tools
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
Expand Down Expand Up @@ -529,7 +516,9 @@ add_library(gmssl ${src})
if (WIN32)
target_link_libraries(gmssl -lws2_32)
elseif (APPLE)
target_link_libraries(gmssl dl)
if (ENABLE_SDF)
target_link_libraries(gmssl dl)
endif()
target_link_libraries(gmssl "-framework Security")
if (ENABLE_SM4_CL)
# FIXME: different rules for cl and OpenCL framework
Expand All @@ -539,7 +528,9 @@ elseif (APPLE)
elseif (MINGW)
target_link_libraries(gmssl PRIVATE wsock32)
else()
target_link_libraries(gmssl dl)
if (ENABLE_SDF)
target_link_libraries(gmssl dl)
endif()
endif()


Expand All @@ -552,6 +543,37 @@ install(TARGETS gmssl ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DE
install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/gmssl DESTINATION include)


option(ENABLE_SDF "Enable SDF module" OFF)
if (ENABLE_SDF)
message(STATUS "ENABLE_SDF is ON")
list(APPEND src
src/sdf/sdf.c
src/sdf/sdf_lib.c
src/sdf/sdf_meth.c
src/sdf/sdf_ext.c
src/sdf/sdf_sansec.c)
list(APPEND tools tools/sdfutil.c)
add_library(sdf_dummy SHARED src/sdf/sdf_dummy.c)
set_target_properties(sdf_dummy PROPERTIES VERSION 3.1 SOVERSION 3)
endif()


option(ENABLE_SKF "Enable SKF module" OFF)
if (ENABLE_SKF)
message(STATUS "ENABLE_SKF is ON")
list(APPEND src
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)
list(APPEND tools tools/skfutil.c)
add_library(skf_dummy SHARED src/skf/skf_dummy.c)
set_target_properties(skf_dummy PROPERTIES VERSION 3.1 SOVERSION 3)
endif()


option(ENABLE_SOFT_SDF "Enable Software SDF Implementation" OFF)
if (ENABLE_SOFT_SDF)
message(STATUS "ENABLE_SOFT_SDF is ON")
Expand All @@ -563,13 +585,6 @@ endif()


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.1 SOVERSION 3)

add_library(skf_dummy SHARED src/skf/skf_dummy.c)
set_target_properties(skf_dummy PROPERTIES VERSION 3.1 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)
Expand Down
15 changes: 12 additions & 3 deletions tools/gmssl.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2023 The GmSSL Project. All Rights Reserved.
* Copyright 2014-2024 The GmSSL Project. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
Expand Down Expand Up @@ -54,9 +54,12 @@ extern int tls12_client_main(int argc, char **argv);
extern int tls12_server_main(int argc, char **argv);
extern int tls13_client_main(int argc, char **argv);
extern int tls13_server_main(int argc, char **argv);
#ifdef ENABLE_SDF
extern int sdfutil_main(int argc, char **argv);
#endif
#ifdef ENABLE_SKF
extern int skfutil_main(int argc, char **argv);

#endif

static const char *options =
"command [options]\n"
Expand Down Expand Up @@ -99,8 +102,12 @@ static const char *options =
" cmsdecrypt Decrypt CMS EnvelopedData\n"
" cmssign Generate CMS SignedData\n"
" cmsverify Verify CMS SignedData\n"
#ifdef ENABLE_SDF
" sdfutil SDF crypto device utility\n"
#endif
#ifdef ENABLE_SKF
" skfutil SKF crypto device utility\n"
#endif
" tlcp_client TLCP client\n"
" tlcp_server TLCP server\n"
" tls12_client TLS 1.2 client\n"
Expand Down Expand Up @@ -211,9 +218,11 @@ int main(int argc, char **argv)
return tls13_client_main(argc, argv);
} else if (!strcmp(*argv, "tls13_server")) {
return tls13_server_main(argc, argv);
#ifndef WIN32
#ifdef ENABLE_SDF
} else if (!strcmp(*argv, "sdfutil")) {
return sdfutil_main(argc, argv);
#endif
#ifdef ENABLE_SKF
} else if (!strcmp(*argv, "skfutil")) {
return skfutil_main(argc, argv);
#endif
Expand Down

0 comments on commit afed7a0

Please sign in to comment.