1cmake_minimum_required(VERSION 3.5.1) 2 3# 4# Simulate configuring and building Mbed TLS as the user might do it. We'll 5# skip installing it, and use the build directory directly instead. 6# 7 8set(MbedTLS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../..") 9set(MbedTLS_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/mbedtls") 10 11execute_process( 12 COMMAND "${CMAKE_COMMAND}" 13 "-H${MbedTLS_SOURCE_DIR}" 14 "-B${MbedTLS_BINARY_DIR}" 15 "-DENABLE_PROGRAMS=NO" 16 "-DENABLE_TESTING=NO" 17 # Turn on generated files explicitly in case this is a release 18 "-DGEN_FILES=ON") 19 20execute_process( 21 COMMAND "${CMAKE_COMMAND}" 22 --build "${MbedTLS_BINARY_DIR}") 23 24# 25# Locate the package. 26# 27 28set(MbedTLS_DIR "${MbedTLS_BINARY_DIR}/cmake") 29find_package(MbedTLS REQUIRED) 30 31# 32# At this point, the Mbed TLS targets should have been imported, and we can now 33# link to them from our own program. 34# 35 36add_executable(cmake_package cmake_package.c) 37target_link_libraries(cmake_package 38 MbedTLS::mbedcrypto MbedTLS::mbedtls MbedTLS::mbedx509) 39