1# SPDX-License-Identifier: Apache-2.0
2
3cmake_minimum_required(VERSION 3.20.0)
4
5find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6project(tls_configurations)
7
8target_sources(app PRIVATE src/main.c)
9
10set(gen_dir ${ZEPHYR_BINARY_DIR}/include/generated/)
11
12# Helper function to convert the content of a PEM file (generated by OpenSSL)
13# to a C string that can be parsed by Mbed TLS. The format is unchanged, it's
14# still PEM, but new lines are replaced by "\n", so that both C compiler and
15# Mbed TLS parser are happy.
16function(pem_to_mbedtls target input_file)
17  file(READ credentials/${input_file} input_file_content)
18  string(REGEX REPLACE "\n" "\\\\n" input_file_content ${input_file_content})
19  set(GENERATED_FILE ${gen_dir}/${input_file}.inc)
20  file(WRITE ${GENERATED_FILE} "\"${input_file_content}\"\n")
21  generate_unique_target_name_from_filename(${input_file} generated_target_name)
22  add_custom_target(${generated_target_name} DEPENDS ${GENERATED_FILE})
23  add_dependencies(${target} ${generated_target_name})
24endfunction()
25
26pem_to_mbedtls(app ec.crt)
27pem_to_mbedtls(app rsa.crt)
28