1set(libs
2    ${mbedtls_target}
3    ${CMAKE_THREAD_LIBS_INIT}
4)
5
6find_library(FUZZINGENGINE_LIB FuzzingEngine)
7if(FUZZINGENGINE_LIB)
8    project(fuzz CXX)
9endif()
10
11set(executables_no_common_c
12    fuzz_x509crl
13    fuzz_x509crt
14    fuzz_x509csr
15    fuzz_pkcs7
16)
17add_dependencies(${programs_target} ${executables_no_common_c})
18
19set(executables_with_common_c
20    fuzz_client
21    fuzz_dtlsclient
22    fuzz_dtlsserver
23    fuzz_server
24)
25add_dependencies(${programs_target} ${executables_with_common_c})
26
27foreach(exe IN LISTS executables_no_common_c executables_with_common_c)
28
29    set(exe_sources
30        ${exe}.c
31        $<TARGET_OBJECTS:mbedtls_test_helpers>
32        $<TARGET_OBJECTS:mbedtls_test>)
33    if(NOT FUZZINGENGINE_LIB)
34        list(APPEND exe_sources ${MBEDTLS_DIR}/tf-psa-crypto/programs/fuzz/fuzz_onefile.c)
35    endif()
36
37    # This emulates "if ( ... IN_LIST ... )" which becomes available in CMake 3.3
38    list(FIND executables_with_common_c ${exe} exe_index)
39    if(${exe_index} GREATER -1)
40        list(APPEND exe_sources ${MBEDTLS_DIR}/tf-psa-crypto/programs/fuzz/fuzz_common.c)
41    endif()
42
43    add_executable(${exe} ${exe_sources})
44    set_base_compile_options(${exe})
45    target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../framework/tests/include
46                                              ${CMAKE_CURRENT_SOURCE_DIR}/../../tf-psa-crypto/programs/fuzz/
47                                              ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include)
48
49    if (NOT FUZZINGENGINE_LIB)
50        target_link_libraries(${exe} ${libs})
51    else()
52        target_link_libraries(${exe} ${libs} FuzzingEngine)
53        SET_TARGET_PROPERTIES(${exe} PROPERTIES LINKER_LANGUAGE CXX)
54    endif()
55
56endforeach()
57