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