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# install into a directory inside our own build directory. 6# 7 8set(MbedTLS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../..") 9set(MbedTLS_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/mbedtls") 10set(MbedTLS_BINARY_DIR "${MbedTLS_INSTALL_DIR}${CMAKE_FILES_DIRECTORY}") 11 12execute_process( 13 COMMAND "${CMAKE_COMMAND}" 14 "-H${MbedTLS_SOURCE_DIR}" 15 "-B${MbedTLS_BINARY_DIR}" 16 "-DENABLE_PROGRAMS=NO" 17 "-DENABLE_TESTING=NO" 18 # Turn on generated files explicitly in case this is a release 19 "-DGEN_FILES=ON" 20 "-DCMAKE_INSTALL_PREFIX=${MbedTLS_INSTALL_DIR}") 21 22execute_process( 23 COMMAND "${CMAKE_COMMAND}" 24 --build "${MbedTLS_BINARY_DIR}" 25 --target install) 26 27# 28# Locate the package. 29# 30 31list(INSERT CMAKE_PREFIX_PATH 0 "${MbedTLS_INSTALL_DIR}") 32find_package(MbedTLS REQUIRED) 33 34# 35# At this point, the Mbed TLS targets should have been imported, and we can now 36# link to them from our own program. 37# 38 39add_executable(cmake_package_install cmake_package_install.c) 40target_link_libraries(cmake_package_install 41 MbedTLS::mbedcrypto MbedTLS::mbedtls MbedTLS::mbedx509) 42