Merge pull request #4422 from haydenroche5/cmake
Add a CMake option to build wolfcrypt test and bench code as libraries.
This commit is contained in:
commit
97d96c6cf8
@ -1234,9 +1234,12 @@ else()
|
||||
set(CRYPT_TESTS_DEFAULT "yes")
|
||||
endif()
|
||||
|
||||
set(WOLFSSL_CRYPT_TESTS_HELP_STRING "Enable Crypt Bench/Test (default: enabled)")
|
||||
set(WOLFSSL_CRYPT_TESTS_HELP_STRING "Enable Crypt Bench/Test (default: enabled)")
|
||||
add_option("WOLFSSL_CRYPT_TESTS" ${WOLFSSL_CRYPT_TESTS_HELP_STRING} ${CRYPT_TESTS_DEFAULT} "yes;no")
|
||||
|
||||
set(WOLFSSL_CRYPT_TESTS_LIBS_HELP_STRING "Build static libraries from the wolfCrypt test and benchmark sources (default: disabled)")
|
||||
add_option("WOLFSSL_CRYPT_TESTS_LIBS" ${WOLFSSL_CRYPT_TESTS_LIBS_HELP_STRING} "no" "yes;no")
|
||||
|
||||
# TODO: - LIBZ
|
||||
# - PKCS#11
|
||||
# - PKCS#12
|
||||
@ -1510,7 +1513,27 @@ if(WOLFSSL_EXAMPLES)
|
||||
endif()
|
||||
|
||||
if(WOLFSSL_CRYPT_TESTS)
|
||||
# Build wolfCrypt test
|
||||
if(WOLFSSL_CRYPT_TESTS_LIBS)
|
||||
# Build wolfCrypt test as a library. This will compile test.c and make
|
||||
# its functions available as a CMake target that other CMake targets can
|
||||
# pull in, in addition to producing the library itself. Note that this
|
||||
# feature is not enabled by default, and the API of this library and
|
||||
# wofcryptbench_lib should NOT be treated as stable.
|
||||
add_library(wolfcrypttest_lib
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/test/test.c)
|
||||
set_target_properties(wolfcrypttest_lib PROPERTIES OUTPUT_NAME "wolfcrypttest")
|
||||
target_link_libraries(wolfcrypttest_lib wolfssl)
|
||||
target_compile_options(wolfcrypttest_lib PRIVATE "-DNO_MAIN_DRIVER")
|
||||
|
||||
# Make another library for the wolfCrypt benchmark code.
|
||||
add_library(wolfcryptbench_lib
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/benchmark/benchmark.c)
|
||||
set_target_properties(wolfcryptbench_lib PROPERTIES OUTPUT_NAME "wolfcryptbench")
|
||||
target_link_libraries(wolfcryptbench_lib wolfssl)
|
||||
target_compile_options(wolfcryptbench_lib PRIVATE "-DNO_MAIN_DRIVER")
|
||||
endif()
|
||||
|
||||
# Build wolfCrypt test executable.
|
||||
add_executable(wolfcrypttest
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/test/test.c)
|
||||
target_link_libraries(wolfcrypttest wolfssl)
|
||||
@ -1521,7 +1544,7 @@ if(WOLFSSL_CRYPT_TESTS)
|
||||
PROPERTY RUNTIME_OUTPUT_NAME
|
||||
testwolfcrypt)
|
||||
|
||||
# Build wolfCrypt benchmark
|
||||
# Build wolfCrypt benchmark executable.
|
||||
add_executable(wolfcryptbench
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/benchmark/benchmark.c)
|
||||
target_include_directories(wolfcryptbench PRIVATE
|
||||
|
@ -1,27 +1,34 @@
|
||||
function(add_option NAME HELP_STRING DEFAULT VALUES)
|
||||
list(FIND VALUES ${DEFAULT} IDX)
|
||||
if (${IDX} EQUAL -1)
|
||||
message(FATAL_ERROR "Failed to add option ${NAME}. Default value "
|
||||
"${DEFAULT} is not in list of possible values: ${VALUES}.")
|
||||
endif()
|
||||
|
||||
if(DEFINED ${NAME})
|
||||
list(FIND VALUES ${${NAME}} IDX)
|
||||
if (${IDX} EQUAL -1)
|
||||
message(FATAL_ERROR "Failed to set option ${NAME}. Value "
|
||||
"${${NAME}} is not in list of possible values: ${VALUES}.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(${NAME} ${DEFAULT} CACHE STRING ${HELP_STRING})
|
||||
set_property(CACHE ${NAME} PROPERTY STRINGS ${VALUES})
|
||||
endfunction()
|
||||
|
||||
function(override_cache VAR VAL)
|
||||
get_property(VAR_TYPE CACHE ${VAR} PROPERTY TYPE)
|
||||
set(${VAR} ${VAL} CACHE ${VAR_TYPE} ${${VAR}_HELP_STRING} FORCE)
|
||||
endfunction()
|
||||
|
||||
function(add_option NAME HELP_STRING DEFAULT VALUES)
|
||||
# Set the default value for the option.
|
||||
set(${NAME} ${DEFAULT} CACHE STRING ${HELP_STRING})
|
||||
# Set the list of allowed values for the option.
|
||||
set_property(CACHE ${NAME} PROPERTY STRINGS ${VALUES})
|
||||
|
||||
if(DEFINED ${NAME})
|
||||
list(FIND VALUES ${${NAME}} IDX)
|
||||
#
|
||||
# If the given value isn't in the list of allowed values for the option,
|
||||
# reduce it to yes/no according to CMake's "if" logic:
|
||||
# https://cmake.org/cmake/help/latest/command/if.html#basic-expressions
|
||||
#
|
||||
# This has no functional impact; it just makes the settings in
|
||||
# CMakeCache.txt and cmake-gui easier to read.
|
||||
#
|
||||
if (${IDX} EQUAL -1)
|
||||
if(${${NAME}})
|
||||
override_cache(${NAME} "yes")
|
||||
else()
|
||||
override_cache(${NAME} "no")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(generate_build_flags)
|
||||
set(BUILD_DISTRO ${WOLFSSL_DISTRO} PARENT_SCOPE)
|
||||
set(BUILD_ALL ${WOLFSSL_ALL} PARENT_SCOPE)
|
||||
|
10
configure.ac
10
configure.ac
@ -5072,6 +5072,15 @@ AC_ARG_ENABLE([crypttests],
|
||||
)
|
||||
AC_SUBST([ENABLED_CRYPT_TESTS])
|
||||
|
||||
# Build wolfCrypt test and benchmark as libraries. This will compile test.c and
|
||||
# benchmark.c and make their functions available via libraries, libwolfcrypttest
|
||||
# and libwolfcryptbench, respectively. Note that this feature is not enabled by
|
||||
# default, and the API of these libraries should NOT be treated as stable.
|
||||
AC_ARG_ENABLE([crypttests-libs],
|
||||
[AS_HELP_STRING([--enable-crypttests-libs],[Enable wolfcrypt test and benchmark libraries (default: disabled)])],
|
||||
[ ENABLED_CRYPT_TESTS_LIBS=$enableval ],
|
||||
[ ENABLED_CRYPT_TESTS_LIBS=no ]
|
||||
)
|
||||
|
||||
# LIBZ
|
||||
ENABLED_LIBZ="no"
|
||||
@ -6885,6 +6894,7 @@ AM_CONDITIONAL([BUILD_EXAMPLE_CLIENTS],[test "x$ENABLED_EXAMPLES" = "xyes"])
|
||||
AM_CONDITIONAL([BUILD_TESTS],[test "x$ENABLED_EXAMPLES" = "xyes"])
|
||||
AM_CONDITIONAL([BUILD_THREADED_EXAMPLES],[test "x$ENABLED_SINGLETHREADED" = "xno" && test "x$ENABLED_EXAMPLES" = "xyes" && test "x$ENABLED_LEANTLS" = "xno"])
|
||||
AM_CONDITIONAL([BUILD_WOLFCRYPT_TESTS],[test "x$ENABLED_CRYPT_TESTS" = "xyes"])
|
||||
AM_CONDITIONAL([BUILD_WOLFCRYPT_TESTS_LIBS],[test "x$ENABLED_CRYPT_TESTS_LIBS" = "xyes"])
|
||||
AM_CONDITIONAL([BUILD_LIBZ],[test "x$ENABLED_LIBZ" = "xyes"])
|
||||
AM_CONDITIONAL([BUILD_PKCS11],[test "x$ENABLED_PKCS11" = "xyes" || test "x$ENABLED_USERSETTINGS" = "xyes"])
|
||||
AM_CONDITIONAL([BUILD_PKCS12],[test "x$ENABLED_PKCS12" = "xyes" || test "x$ENABLED_USERSETTINGS" = "xyes"])
|
||||
|
@ -13,6 +13,14 @@ noinst_HEADERS += wolfcrypt/benchmark/benchmark.h
|
||||
endif
|
||||
endif
|
||||
|
||||
if BUILD_WOLFCRYPT_TESTS_LIBS
|
||||
lib_LTLIBRARIES += wolfcrypt/benchmark/libwolfcryptbench.la
|
||||
wolfcrypt_benchmark_libwolfcryptbench_la_SOURCES = wolfcrypt/benchmark/benchmark.c
|
||||
wolfcrypt_benchmark_libwolfcryptbench_la_CPPFLAGS = -DNO_MAIN_DRIVER
|
||||
wolfcrypt_benchmark_libwolfcryptbench_la_LIBADD = src/libwolfssl.la
|
||||
wolfcrypt_benchmark_libwolfcryptbench_la_DEPENDENCIES = src/libwolfssl.la
|
||||
endif
|
||||
|
||||
EXTRA_DIST += wolfcrypt/benchmark/benchmark.sln
|
||||
EXTRA_DIST += wolfcrypt/benchmark/benchmark.vcproj
|
||||
EXTRA_DIST += wolfcrypt/benchmark/README.md
|
||||
|
@ -16,6 +16,14 @@ noinst_HEADERS += wolfcrypt/test/test.h wolfcrypt/test/test_paths.h.in
|
||||
endif
|
||||
endif
|
||||
|
||||
if BUILD_WOLFCRYPT_TESTS_LIBS
|
||||
lib_LTLIBRARIES += wolfcrypt/test/libwolfcrypttest.la
|
||||
wolfcrypt_test_libwolfcrypttest_la_SOURCES = wolfcrypt/test/test.c
|
||||
wolfcrypt_test_libwolfcrypttest_la_CPPFLAGS = -DNO_MAIN_DRIVER
|
||||
wolfcrypt_test_libwolfcrypttest_la_LIBADD = src/libwolfssl.la
|
||||
wolfcrypt_test_libwolfcrypttest_la_DEPENDENCIES = src/libwolfssl.la
|
||||
endif
|
||||
|
||||
EXTRA_DIST += wolfcrypt/test/test.sln
|
||||
EXTRA_DIST += wolfcrypt/test/test.vcproj
|
||||
EXTRA_DIST += wolfcrypt/test/README.md
|
||||
|
Loading…
x
Reference in New Issue
Block a user