Behavior changes to CMakeLists.txt

- Allows static library compilation
 - Links to MBedTLS/OpenSSL based on build option
 - Limits visibility of some defines and headers
This commit is contained in:
Mariotaku Lee
2021-04-29 00:47:32 +09:00
committed by Cameron Gutman
parent bc1b5a1b2f
commit 179970a0d5
2 changed files with 63 additions and 19 deletions

21
cmake/FindMbedTLS.cmake Normal file
View File

@@ -0,0 +1,21 @@
find_path(MBEDTLS_INCLUDE_DIRS mbedtls/version.h)
if (MBEDTLS_INCLUDE_DIRS AND EXISTS ${MBEDTLS_INCLUDE_DIRS}/mbedtls/version.h)
file(STRINGS "${MBEDTLS_INCLUDE_DIRS}/mbedtls/version.h" MBEDTLS_VERSION_STRING_LINE REGEX "^#define[ \t]+MBEDTLS_VERSION_STRING[ \t]+\"[0-9.]+\"$")
string(REGEX REPLACE "^#define[ \t]+MBEDTLS_VERSION_STRING[ \t]+\"([0-9.]+)\"$" "\\1" MBEDTLS_VERSION_STRING "${MBEDTLS_VERSION_STRING_LINE}")
unset(MBEDTLS_VERSION_STRING_LINE)
endif()
find_library(MBEDTLS_LIBRARY mbedtls)
find_library(MBEDX509_LIBRARY mbedx509)
find_library(MBEDCRYPTO_LIBRARY mbedcrypto)
set(MBEDTLS_LIBRARIES "${MBEDTLS_LIBRARY}" "${MBEDX509_LIBRARY}" "${MBEDCRYPTO_LIBRARY}")
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(MbedTLS
REQUIRED_VARS MBEDTLS_LIBRARIES MBEDTLS_INCLUDE_DIRS
VERSION_VAR MBEDTLS_VERSION_STRING
)
mark_as_advanced(MBEDTLS_INCLUDE_DIRS MBEDTLS_LIBRARY MBEDX509_LIBRARY MBEDCRYPTO_LIBRARY)