Skip to content

Commit ba57427

Browse files
Merge pull request #5283 from adeaarm/development
Make CMakeLists.txt discover if mbed TLS is being built as subproject
2 parents cb4dc37 + 2869c67 commit ba57427

File tree

1 file changed

+44
-32
lines changed

1 file changed

+44
-32
lines changed

CMakeLists.txt

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ else()
3939
project("mbed TLS" C)
4040
endif()
4141

42+
# Determine if mbed TLS is being built as a subproject using add_subdirectory()
43+
if(NOT DEFINED MBEDTLS_AS_SUBPROJECT)
44+
set(MBEDTLS_AS_SUBPROJECT ON)
45+
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
46+
set(MBEDTLS_AS_SUBPROJECT OFF)
47+
endif()
48+
endif()
49+
4250
# Set the project root directory.
4351
set(MBEDTLS_DIR ${CMAKE_CURRENT_SOURCE_DIR})
4452

@@ -52,6 +60,8 @@ else()
5260
option(GEN_FILES "Generate the auto-generated files as needed" ON)
5361
endif()
5462

63+
option(DISABLE_PACKAGE_CONFIG_AND_INSTALL "Disable package configuration, target export and installation" ${MBEDTLS_AS_SUBPROJECT})
64+
5565
string(REGEX MATCH "Clang" CMAKE_COMPILER_IS_CLANG "${CMAKE_C_COMPILER_ID}")
5666
string(REGEX MATCH "GNU" CMAKE_COMPILER_IS_GNU "${CMAKE_C_COMPILER_ID}")
5767
string(REGEX MATCH "IAR" CMAKE_COMPILER_IS_IAR "${CMAKE_C_COMPILER_ID}")
@@ -325,36 +335,38 @@ if(ENABLE_TESTING)
325335
endif()
326336
endif()
327337

328-
configure_package_config_file(
329-
"cmake/MbedTLSConfig.cmake.in"
330-
"cmake/MbedTLSConfig.cmake"
331-
INSTALL_DESTINATION "cmake")
332-
333-
write_basic_package_version_file(
334-
"cmake/MbedTLSConfigVersion.cmake"
335-
COMPATIBILITY SameMajorVersion
336-
VERSION 3.0.0)
337-
338-
install(
339-
FILES "${CMAKE_CURRENT_BINARY_DIR}/cmake/MbedTLSConfig.cmake"
340-
"${CMAKE_CURRENT_BINARY_DIR}/cmake/MbedTLSConfigVersion.cmake"
341-
DESTINATION "cmake")
342-
343-
export(
344-
EXPORT MbedTLSTargets
345-
NAMESPACE MbedTLS::
346-
FILE "cmake/MbedTLSTargets.cmake")
347-
348-
install(
349-
EXPORT MbedTLSTargets
350-
NAMESPACE MbedTLS::
351-
DESTINATION "cmake"
352-
FILE "MbedTLSTargets.cmake")
353-
354-
if(CMAKE_VERSION VERSION_GREATER 3.15 OR CMAKE_VERSION VERSION_EQUAL 3.15)
355-
# Do not export the package by default
356-
cmake_policy(SET CMP0090 NEW)
357-
358-
# Make this package visible to the system
359-
export(PACKAGE MbedTLS)
338+
if(NOT DISABLE_PACKAGE_CONFIG_AND_INSTALL)
339+
configure_package_config_file(
340+
"cmake/MbedTLSConfig.cmake.in"
341+
"cmake/MbedTLSConfig.cmake"
342+
INSTALL_DESTINATION "cmake")
343+
344+
write_basic_package_version_file(
345+
"cmake/MbedTLSConfigVersion.cmake"
346+
COMPATIBILITY SameMajorVersion
347+
VERSION 3.0.0)
348+
349+
install(
350+
FILES "${CMAKE_CURRENT_BINARY_DIR}/cmake/MbedTLSConfig.cmake"
351+
"${CMAKE_CURRENT_BINARY_DIR}/cmake/MbedTLSConfigVersion.cmake"
352+
DESTINATION "cmake")
353+
354+
export(
355+
EXPORT MbedTLSTargets
356+
NAMESPACE MbedTLS::
357+
FILE "cmake/MbedTLSTargets.cmake")
358+
359+
install(
360+
EXPORT MbedTLSTargets
361+
NAMESPACE MbedTLS::
362+
DESTINATION "cmake"
363+
FILE "MbedTLSTargets.cmake")
364+
365+
if(CMAKE_VERSION VERSION_GREATER 3.15 OR CMAKE_VERSION VERSION_EQUAL 3.15)
366+
# Do not export the package by default
367+
cmake_policy(SET CMP0090 NEW)
368+
369+
# Make this package visible to the system
370+
export(PACKAGE MbedTLS)
371+
endif()
360372
endif()

0 commit comments

Comments
 (0)