Findmbedtls.cmake 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. find_path(MBEDTLS_INCLUDE_DIR mbedtls/ssl.h)
  2. find_library(MBEDTLS_SSL_LIBRARY mbedtls)
  3. find_library(MBEDTLS_X509_LIBRARY mbedx509)
  4. find_library(MBEDTLS_CRYPTO_LIBRARY mbedcrypto)
  5. set(MBEDTLS_LIBRARIES ${MBEDTLS_SSL_LIBRARY} ${MBEDTLS_X509_LIBRARY} ${MBEDTLS_CRYPTO_LIBRARY})
  6. set(MBEDTLS_LIBRARIES ${MBEDTLS_LIBRARIES} PARENT_SCOPE)
  7. if (MBEDTLS_INCLUDE_DIR)
  8. if (EXISTS "${MBEDTLS_INCLUDE_DIR}/mbedtls/build_info.h")
  9. file(STRINGS ${MBEDTLS_INCLUDE_DIR}/mbedtls/build_info.h _MBEDTLS_VERSION_LINE REGEX "^#define[ \t]+MBEDTLS_VERSION_STRING[\t ].*")
  10. string(REGEX REPLACE ".*MBEDTLS_VERSION_STRING[\t ]+\"(.*)\"" "\\1" MBEDTLS_VERSION ${_MBEDTLS_VERSION_LINE})
  11. set (MBEDTLS_VERSION ${MBEDTLS_VERSION} PARENT_SCOPE)
  12. elseif(EXISTS "${MBEDTLS_INCLUDE_DIR}/mbedtls/version.h")
  13. file(STRINGS "${MBEDTLS_INCLUDE_DIR}/mbedtls/version.h" _MBEDTLS_VERSION_STRING REGEX "^#[\t ]*define[\t ]+MBEDTLS_VERSION_STRING[\t ]+\"[0-9]+.[0-9]+.[0-9]+\"")
  14. string(REGEX REPLACE "^.*MBEDTLS_VERSION_STRING.*([0-9]+.[0-9]+.[0-9]+).*" "\\1" MBEDTLS_VERSION "${_MBEDTLS_VERSION_STRING}")
  15. set (MBEDTLS_VERSION ${MBEDTLS_VERSION} PARENT_SCOPE)
  16. endif()
  17. endif ()
  18. if (MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARIES AND MBEDTLS_VERSION)
  19. include(FindPackageHandleStandardArgs)
  20. find_package_handle_standard_args(mbedtls
  21. REQUIRED_VARS
  22. MBEDTLS_INCLUDE_DIR
  23. MBEDTLS_LIBRARIES
  24. VERSION_VAR
  25. MBEDTLS_VERSION
  26. )
  27. mark_as_advanced (MBEDTLS_INCLUDE_DIR MBEDTLS_LIBRARIES MBEDTLS_SSL_LIBRARY MBEDTLS_X509_LIBRARY MBEDTLS_CRYPTO_LIBRARY MBEDTLS_VERSION)
  28. endif (MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARIES AND MBEDTLS_VERSION)