d259e347e6
This change enables automatic detection and consumption of Mbed TLS library targets from within other CMake projects. By generating an `MbedTLSConfig.cmake` file, consuming projects receive a more complete view of these targets, allowing them to be used as dependencies which properly inherit the transitive dependencies of the libraries. This is fairly fragile, as it seems Mbed TLS's libraries do not appear to properly model their dependencies on other targets, including third-party dependencies. It is, however, sufficient for building and linking the compiled Mbed TLS libraries when there are no third-party dependencies involved. Further work is needed for more complex use-cases, but this will likely meet the needs of most projects. Resolves #298. Probably useful for #2857. Signed-off-by: Chris Kay <chris.kay@arm.com>
36 lines
954 B
CMake
36 lines
954 B
CMake
cmake_minimum_required(VERSION 2.8.12)
|
|
|
|
#
|
|
# Simulate configuring and building Mbed TLS as the user might do it. We'll
|
|
# skip installing it, and use the build directory directly instead.
|
|
#
|
|
|
|
set(MbedTLS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../..")
|
|
set(MbedTLS_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/mbedtls")
|
|
|
|
execute_process(
|
|
COMMAND "${CMAKE_COMMAND}"
|
|
"-H${MbedTLS_SOURCE_DIR}"
|
|
"-B${MbedTLS_BINARY_DIR}"
|
|
"-DENABLE_PROGRAMS=NO"
|
|
"-DENABLE_TESTING=NO")
|
|
|
|
execute_process(
|
|
COMMAND "${CMAKE_COMMAND}"
|
|
--build "${MbedTLS_BINARY_DIR}")
|
|
|
|
#
|
|
# Locate the package.
|
|
#
|
|
|
|
set(MbedTLS_DIR "${MbedTLS_BINARY_DIR}/cmake")
|
|
find_package(MbedTLS REQUIRED)
|
|
|
|
#
|
|
# At this point, the Mbed TLS targets should have been imported, and we can now
|
|
# link to them from our own program.
|
|
#
|
|
|
|
add_executable(cmake_package cmake_package.c)
|
|
target_link_libraries(cmake_package
|
|
MbedTLS::mbedcrypto MbedTLS::mbedtls MbedTLS::mbedx509)
|