1set(THREADS_USE_PTHREADS_WIN32 true)
2find_package(Threads)
3
4set(libs
5    ${mbedtls_target}
6)
7
8set(executables
9    dtls_client
10    dtls_server
11    mini_client
12    ssl_client1
13    ssl_client2
14    ssl_context_info
15    ssl_fork_server
16    ssl_mail_client
17    ssl_server
18    ssl_server2
19)
20
21if(GEN_FILES)
22    # Inform CMake that the following file will be generated as part of the build
23    # process, so it doesn't complain that it doesn't exist yet. Starting from
24    # CMake 3.20, this will no longer be necessary as CMake will automatically
25    # propagate this information across the tree, for now it's only visible
26    # inside the same directory, so we need to propagate manually.
27    set_source_files_properties(
28        ${CMAKE_CURRENT_BINARY_DIR}/../test/query_config.c
29        PROPERTIES GENERATED TRUE)
30endif()
31
32foreach(exe IN LISTS executables)
33    set(extra_sources "")
34    if(exe STREQUAL "ssl_client2" OR exe STREQUAL "ssl_server2")
35        list(APPEND extra_sources
36            ssl_test_lib.c
37            ${CMAKE_CURRENT_SOURCE_DIR}/../test/query_config.h
38            ${CMAKE_CURRENT_BINARY_DIR}/../test/query_config.c)
39    endif()
40    add_executable(${exe} ${exe}.c $<TARGET_OBJECTS:mbedtls_test>
41        ${extra_sources})
42    target_link_libraries(${exe} ${libs})
43    target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include)
44    if(exe STREQUAL "ssl_client2" OR exe STREQUAL "ssl_server2")
45        if(GEN_FILES)
46            add_dependencies(${exe} generate_query_config_c)
47        endif()
48        target_include_directories(${exe}
49            PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../test)
50    endif()
51endforeach()
52
53if(THREADS_FOUND)
54    add_executable(ssl_pthread_server ssl_pthread_server.c $<TARGET_OBJECTS:mbedtls_test>)
55    target_include_directories(ssl_pthread_server PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include)
56    target_link_libraries(ssl_pthread_server ${libs} ${CMAKE_THREAD_LIBS_INIT})
57    list(APPEND executables ssl_pthread_server)
58endif(THREADS_FOUND)
59
60install(TARGETS ${executables}
61        DESTINATION "bin"
62        PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
63