Skip to content

Commit ae1b548

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 ae1b548

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
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}

0 commit comments

Comments
 (0)