1a8e1175bSopenharmony_ciset(libs
2a8e1175bSopenharmony_ci    ${mbedtls_target}
3a8e1175bSopenharmony_ci)
4a8e1175bSopenharmony_ci
5a8e1175bSopenharmony_ciset(executables_libs
6a8e1175bSopenharmony_ci    metatest
7a8e1175bSopenharmony_ci    query_included_headers
8a8e1175bSopenharmony_ci    selftest
9a8e1175bSopenharmony_ci    udp_proxy
10a8e1175bSopenharmony_ci)
11a8e1175bSopenharmony_ci
12a8e1175bSopenharmony_ciset(executables_mbedcrypto
13a8e1175bSopenharmony_ci    benchmark
14a8e1175bSopenharmony_ci    query_compile_time_config
15a8e1175bSopenharmony_ci    zeroize
16a8e1175bSopenharmony_ci)
17a8e1175bSopenharmony_ci
18a8e1175bSopenharmony_ciif(TEST_CPP)
19a8e1175bSopenharmony_ci    set(cpp_dummy_build_cpp "${CMAKE_CURRENT_BINARY_DIR}/cpp_dummy_build.cpp")
20a8e1175bSopenharmony_ci    set(generate_cpp_dummy_build "${CMAKE_CURRENT_SOURCE_DIR}/generate_cpp_dummy_build.sh")
21a8e1175bSopenharmony_ci    add_custom_command(
22a8e1175bSopenharmony_ci        OUTPUT "${cpp_dummy_build_cpp}"
23a8e1175bSopenharmony_ci        COMMAND "${generate_cpp_dummy_build}" "${cpp_dummy_build_cpp}"
24a8e1175bSopenharmony_ci        DEPENDS "${generate_cpp_dummy_build}"
25a8e1175bSopenharmony_ci        WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
26a8e1175bSopenharmony_ci    )
27a8e1175bSopenharmony_ci    add_executable(cpp_dummy_build "${cpp_dummy_build_cpp}")
28a8e1175bSopenharmony_ci    target_include_directories(cpp_dummy_build PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../include)
29a8e1175bSopenharmony_ci    target_link_libraries(cpp_dummy_build ${mbedcrypto_target} ${CMAKE_THREAD_LIBS_INIT})
30a8e1175bSopenharmony_ciendif()
31a8e1175bSopenharmony_ci
32a8e1175bSopenharmony_ciif(USE_SHARED_MBEDTLS_LIBRARY AND
33a8e1175bSopenharmony_ci   NOT ${CMAKE_SYSTEM_NAME} MATCHES "[Ww][Ii][Nn]")
34a8e1175bSopenharmony_ci    add_executable(dlopen "dlopen.c")
35a8e1175bSopenharmony_ci    target_include_directories(dlopen PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../include)
36a8e1175bSopenharmony_ci    target_link_libraries(dlopen ${CMAKE_DL_LIBS})
37a8e1175bSopenharmony_ciendif()
38a8e1175bSopenharmony_ci
39a8e1175bSopenharmony_ciif(GEN_FILES)
40a8e1175bSopenharmony_ci    find_package(Perl REQUIRED)
41a8e1175bSopenharmony_ci
42a8e1175bSopenharmony_ci    add_custom_command(
43a8e1175bSopenharmony_ci        OUTPUT
44a8e1175bSopenharmony_ci            ${CMAKE_CURRENT_BINARY_DIR}/query_config.c
45a8e1175bSopenharmony_ci        COMMAND
46a8e1175bSopenharmony_ci            ${PERL}
47a8e1175bSopenharmony_ci                ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/generate_query_config.pl
48a8e1175bSopenharmony_ci                ${CMAKE_CURRENT_SOURCE_DIR}/../../include/mbedtls/mbedtls_config.h
49a8e1175bSopenharmony_ci                ${CMAKE_CURRENT_SOURCE_DIR}/../../include/psa/crypto_config.h
50a8e1175bSopenharmony_ci                ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/data_files/query_config.fmt
51a8e1175bSopenharmony_ci                ${CMAKE_CURRENT_BINARY_DIR}/query_config.c
52a8e1175bSopenharmony_ci        DEPENDS
53a8e1175bSopenharmony_ci            ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/generate_query_config.pl
54a8e1175bSopenharmony_ci            ${CMAKE_CURRENT_SOURCE_DIR}/../../include/mbedtls/mbedtls_config.h
55a8e1175bSopenharmony_ci            ${CMAKE_CURRENT_SOURCE_DIR}/../../include/psa/crypto_config.h
56a8e1175bSopenharmony_ci            ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/data_files/query_config.fmt
57a8e1175bSopenharmony_ci    )
58a8e1175bSopenharmony_ci    # this file will also be used in another directory, so create a target, see
59a8e1175bSopenharmony_ci    # https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#how-can-i-add-a-dependency-to-a-source-file-which-is-generated-in-a-subdirectory
60a8e1175bSopenharmony_ci    add_custom_target(generate_query_config_c
61a8e1175bSopenharmony_ci        DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/query_config.c)
62a8e1175bSopenharmony_cielse()
63a8e1175bSopenharmony_ci    link_to_source(query_config.c)
64a8e1175bSopenharmony_ciendif()
65a8e1175bSopenharmony_ci
66a8e1175bSopenharmony_ciforeach(exe IN LISTS executables_libs executables_mbedcrypto)
67a8e1175bSopenharmony_ci    set(extra_sources "")
68a8e1175bSopenharmony_ci    if(exe STREQUAL "query_compile_time_config")
69a8e1175bSopenharmony_ci        list(APPEND extra_sources
70a8e1175bSopenharmony_ci            ${CMAKE_CURRENT_SOURCE_DIR}/query_config.h
71a8e1175bSopenharmony_ci            ${CMAKE_CURRENT_BINARY_DIR}/query_config.c)
72a8e1175bSopenharmony_ci    endif()
73a8e1175bSopenharmony_ci    add_executable(${exe} ${exe}.c $<TARGET_OBJECTS:mbedtls_test>
74a8e1175bSopenharmony_ci        ${extra_sources})
75a8e1175bSopenharmony_ci    target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include)
76a8e1175bSopenharmony_ci    target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../library)
77a8e1175bSopenharmony_ci    if(exe STREQUAL "query_compile_time_config")
78a8e1175bSopenharmony_ci        target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
79a8e1175bSopenharmony_ci    endif()
80a8e1175bSopenharmony_ci
81a8e1175bSopenharmony_ci    # Request C11, required for memory poisoning
82a8e1175bSopenharmony_ci    set_target_properties(${exe} PROPERTIES C_STANDARD 11)
83a8e1175bSopenharmony_ci
84a8e1175bSopenharmony_ci    # This emulates "if ( ... IN_LIST ... )" which becomes available in CMake 3.3
85a8e1175bSopenharmony_ci    list(FIND executables_libs ${exe} exe_index)
86a8e1175bSopenharmony_ci    if (${exe_index} GREATER -1)
87a8e1175bSopenharmony_ci        target_link_libraries(${exe} ${libs} ${CMAKE_THREAD_LIBS_INIT})
88a8e1175bSopenharmony_ci    else()
89a8e1175bSopenharmony_ci        target_link_libraries(${exe} ${mbedcrypto_target} ${CMAKE_THREAD_LIBS_INIT})
90a8e1175bSopenharmony_ci    endif()
91a8e1175bSopenharmony_ciendforeach()
92a8e1175bSopenharmony_ci
93a8e1175bSopenharmony_ciinstall(TARGETS ${executables_libs} ${executables_mbedcrypto}
94a8e1175bSopenharmony_ci        DESTINATION "bin"
95a8e1175bSopenharmony_ci        PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
96