Skip to content

Commit 9bdf8dd

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 9bdf8dd

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

CMakeLists.txt

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

8+
if(NOT USE_CRYPTO_SUBMODULE)
9+
set(MBEDTLS_DIR ${CMAKE_CURRENT_SOURCE_DIR})
10+
elseif(NOT DEFINED MBEDTLS_DIR)
11+
set(MBEDTLS_DIR ${CMAKE_SOURCE_DIR})
12+
endif()
13+
814
option(ENABLE_PROGRAMS "Build mbed TLS programs." ON)
915

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

library/CMakeLists.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ set(src_crypto
7272
if(USE_CRYPTO_SUBMODULE)
7373
set(src_crypto
7474
${src_crypto}
75-
${CMAKE_SOURCE_DIR}/library/version.c
76-
${CMAKE_SOURCE_DIR}/library/version_features.c
77-
${CMAKE_SOURCE_DIR}/library/error.c
75+
${MBEDTLS_DIR}/library/version.c
76+
${MBEDTLS_DIR}/library/version_features.c
77+
${MBEDTLS_DIR}/library/error.c
7878
)
7979
else()
8080
set(src_crypto
@@ -133,8 +133,8 @@ if(USE_STATIC_MBEDTLS_LIBRARY)
133133
set_target_properties(${mbedcrypto_static_target} PROPERTIES OUTPUT_NAME mbedcrypto)
134134
target_link_libraries(${mbedcrypto_static_target} ${libs})
135135
target_include_directories(${mbedcrypto_static_target}
136-
PUBLIC ${CMAKE_SOURCE_DIR}/include/
137-
PUBLIC ${CMAKE_SOURCE_DIR}/crypto/include/)
136+
PUBLIC ${MBEDTLS_DIR}/include/
137+
PUBLIC ${MBEDTLS_DIR}/crypto/include/)
138138

139139
install(TARGETS ${mbedcrypto_static_target}
140140
DESTINATION ${LIB_INSTALL_DIR}
@@ -146,8 +146,8 @@ if(USE_SHARED_MBEDTLS_LIBRARY)
146146
set_target_properties(mbedcrypto PROPERTIES VERSION 2.17.0 SOVERSION 3)
147147
target_link_libraries(mbedcrypto ${libs})
148148
target_include_directories(mbedcrypto
149-
PUBLIC ${CMAKE_SOURCE_DIR}/include/
150-
PUBLIC ${CMAKE_SOURCE_DIR}/crypto/include/)
149+
PUBLIC ${MBEDTLS_DIR}/include/
150+
PUBLIC ${MBEDTLS_DIR}/crypto/include/)
151151

152152
install(TARGETS mbedcrypto
153153
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)