1cmake_minimum_required(VERSION 2.8.12)
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        "-DCMAKE_INSTALL_PREFIX=${MbedTLS_INSTALL_DIR}")
19
20execute_process(
21    COMMAND "${CMAKE_COMMAND}"
22        --build "${MbedTLS_BINARY_DIR}"
23        --target install)
24
25#
26# Locate the package.
27#
28
29set(MbedTLS_DIR "${MbedTLS_INSTALL_DIR}/cmake")
30find_package(MbedTLS REQUIRED)
31
32#
33# At this point, the Mbed TLS targets should have been imported, and we can now
34# link to them from our own program.
35#
36
37add_executable(cmake_package_install cmake_package_install.c)
38target_link_libraries(cmake_package_install
39    MbedTLS::mbedcrypto MbedTLS::mbedtls MbedTLS::mbedx509)
40