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