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