@@ -2,6 +2,13 @@ option(USE_STATIC_MBEDTLS_LIBRARY "Build mbed TLS static library." ON)
22option (USE_SHARED_MBEDTLS_LIBRARY "Build mbed TLS shared library." OFF )
33option (LINK_WITH_PTHREAD "Explicitly link mbed TLS library to pthread." OFF )
44
5+ # Set the project root directory if it's not already defined, as may happen if
6+ # the library folder is included directly by a parent project, without
7+ # including the top level CMakeLists.txt.
8+ if (NOT DEFINED MBEDTLS_DIR)
9+ set (MBEDTLS_DIR ${CMAKE_SOURCE_DIR} )
10+ endif ()
11+
512set (src_crypto
613 aes.c
714 aesni.c
@@ -72,9 +79,9 @@ set(src_crypto
7279if (USE_CRYPTO_SUBMODULE)
7380set (src_crypto
7481 ${src_crypto}
75- ${CMAKE_SOURCE_DIR } /library/version .c
76- ${CMAKE_SOURCE_DIR } /library/version_features.c
77- ${CMAKE_SOURCE_DIR } /library/error.c
82+ ${MBEDTLS_DIR } /library/version .c
83+ ${MBEDTLS_DIR } /library/version_features.c
84+ ${MBEDTLS_DIR } /library/error.c
7885)
7986else ()
8087set (src_crypto
@@ -133,8 +140,8 @@ if(USE_STATIC_MBEDTLS_LIBRARY)
133140 set_target_properties (${mbedcrypto_static_target} PROPERTIES OUTPUT_NAME mbedcrypto)
134141 target_link_libraries (${mbedcrypto_static_target} ${libs} )
135142 target_include_directories (${mbedcrypto_static_target}
136- PUBLIC ${CMAKE_SOURCE_DIR } /include /
137- PUBLIC ${CMAKE_SOURCE_DIR } /crypto/include /)
143+ PUBLIC ${MBEDTLS_DIR } /include /
144+ PUBLIC ${MBEDTLS_DIR } /crypto/include /)
138145
139146 install (TARGETS ${mbedcrypto_static_target}
140147 DESTINATION ${LIB_INSTALL_DIR}
@@ -146,8 +153,8 @@ if(USE_SHARED_MBEDTLS_LIBRARY)
146153 set_target_properties (mbedcrypto PROPERTIES VERSION 2.17.0 SOVERSION 3)
147154 target_link_libraries (mbedcrypto ${libs} )
148155 target_include_directories (mbedcrypto
149- PUBLIC ${CMAKE_SOURCE_DIR } /include /
150- PUBLIC ${CMAKE_SOURCE_DIR } /crypto/include /)
156+ PUBLIC ${MBEDTLS_DIR } /include /
157+ PUBLIC ${MBEDTLS_DIR } /crypto/include /)
151158
152159 install (TARGETS mbedcrypto
153160 DESTINATION ${LIB_INSTALL_DIR}
0 commit comments