Skip to content

Commit 7a90250

Browse files
ashesmanPatater
authored andcommitted
Remove use of CMAKE_SOURCE_DIR
Remove use of CMAKE_SOURCE_DIR in case mbedtls is built from within another CMake project. Define MBEDTLS_DIR to ${CMAKE_CURRENT_SOURCE_DIR} in the main CMakeLists.txt file and refer to that when defining target include paths to enable mbedtls to be built as a sub project. Fixes Mbed-TLS/mbedtls#2609 Signed-off-by: Ashley Duncan <[email protected]> Signed-off-by: Jaeden Amero <[email protected]>
1 parent 47f2de1 commit 7a90250

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ else()
55
project("mbed TLS" C)
66
endif()
77

8+
# Set the project root directory.
9+
set(MBEDTLS_DIR ${CMAKE_CURRENT_SOURCE_DIR})
10+
811
option(ENABLE_PROGRAMS "Build mbed TLS programs." ON)
912

1013
option(UNSAFE_BUILD "Allow unsafe builds. These builds ARE NOT SECURE." OFF)

library/CMakeLists.txt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ option(USE_STATIC_MBEDTLS_LIBRARY "Build mbed TLS static library." ON)
22
option(USE_SHARED_MBEDTLS_LIBRARY "Build mbed TLS shared library." OFF)
33
option(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+
512
set(src_crypto
613
aes.c
714
aesni.c
@@ -72,9 +79,9 @@ set(src_crypto
7279
if(USE_CRYPTO_SUBMODULE)
7380
set(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
)
7986
else()
8087
set(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}

tests/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ function(add_test_suite suite_name)
4343
add_executable(${exe_name} test_suite_${data_name}.c)
4444
target_link_libraries(${exe_name} ${libs})
4545
target_include_directories(${exe_name}
46-
PUBLIC ${CMAKE_SOURCE_DIR}/include/
47-
PUBLIC ${CMAKE_SOURCE_DIR}/crypto/include/
48-
PRIVATE ${CMAKE_SOURCE_DIR}/crypto/library/)
46+
PUBLIC ${MBEDTLS_DIR}/include/
47+
PUBLIC ${MBEDTLS_DIR}/crypto/include/
48+
PRIVATE ${MBEDTLS_DIR}/crypto/library/)
4949

5050
if(${data_name} MATCHES ${SKIP_TEST_SUITES_REGEX})
5151
message(STATUS "The test suite ${data_name} will not be executed.")

0 commit comments

Comments
 (0)