programs: cmake: Use list of executables

Use list of executables to:
- factorize the code to define executables
- highlight the similarities and differences of the executable definitions
- avoid list duplication

Use alphabetic order for executables in lists.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
This commit is contained in:
Ronald Cron 2020-06-05 11:15:31 +02:00
parent 0b90c9d747
commit bfd45f1f11
10 changed files with 165 additions and 220 deletions

View File

@ -1,9 +1,13 @@
add_executable(aescrypt2 aescrypt2.c)
target_link_libraries(aescrypt2 mbedcrypto)
set(executables
aescrypt2
crypt_and_hash
)
add_executable(crypt_and_hash crypt_and_hash.c)
target_link_libraries(crypt_and_hash mbedcrypto)
foreach(exe IN LISTS executables)
add_executable(${exe} ${exe}.c)
target_link_libraries(${exe} mbedcrypto)
endforeach()
install(TARGETS aescrypt2 crypt_and_hash
install(TARGETS ${executables}
DESTINATION "bin"
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)

View File

@ -11,70 +11,41 @@ if(ENABLE_ZLIB_SUPPORT)
endif(ENABLE_ZLIB_SUPPORT)
find_library(FUZZINGENGINE_LIB FuzzingEngine)
if(NOT FUZZINGENGINE_LIB)
add_executable(fuzz_x509csr fuzz_x509csr.c onefile.c)
target_link_libraries(fuzz_x509csr ${libs})
add_executable(fuzz_x509crl fuzz_x509crl.c onefile.c)
target_link_libraries(fuzz_x509crl ${libs})
add_executable(fuzz_x509crt fuzz_x509crt.c onefile.c)
target_link_libraries(fuzz_x509crt ${libs})
add_executable(fuzz_privkey fuzz_privkey.c onefile.c)
target_link_libraries(fuzz_privkey ${libs})
add_executable(fuzz_pubkey fuzz_pubkey.c onefile.c)
target_link_libraries(fuzz_pubkey ${libs})
add_executable(fuzz_client fuzz_client.c common.c onefile.c)
target_link_libraries(fuzz_client ${libs})
add_executable(fuzz_server fuzz_server.c common.c onefile.c)
target_link_libraries(fuzz_server ${libs})
add_executable(fuzz_dtlsclient fuzz_dtlsclient.c common.c onefile.c)
target_link_libraries(fuzz_dtlsclient ${libs})
add_executable(fuzz_dtlsserver fuzz_dtlsserver.c common.c onefile.c)
target_link_libraries(fuzz_dtlsserver ${libs})
else()
if(FUZZINGENGINE_LIB)
project(fuzz CXX)
add_executable(fuzz_x509csr fuzz_x509csr.c)
target_link_libraries(fuzz_x509csr ${libs} FuzzingEngine)
SET_TARGET_PROPERTIES(fuzz_x509csr PROPERTIES LINKER_LANGUAGE CXX)
add_executable(fuzz_x509crl fuzz_x509crl.c)
target_link_libraries(fuzz_x509crl ${libs} FuzzingEngine)
SET_TARGET_PROPERTIES(fuzz_x509crl PROPERTIES LINKER_LANGUAGE CXX)
add_executable(fuzz_x509crt fuzz_x509crt.c)
target_link_libraries(fuzz_x509crt ${libs} FuzzingEngine)
SET_TARGET_PROPERTIES(fuzz_x509crt PROPERTIES LINKER_LANGUAGE CXX)
add_executable(fuzz_privkey fuzz_privkey.c)
target_link_libraries(fuzz_privkey ${libs} FuzzingEngine)
SET_TARGET_PROPERTIES(fuzz_privkey PROPERTIES LINKER_LANGUAGE CXX)
add_executable(fuzz_pubkey fuzz_pubkey.c)
target_link_libraries(fuzz_pubkey ${libs} FuzzingEngine)
SET_TARGET_PROPERTIES(fuzz_pubkey PROPERTIES LINKER_LANGUAGE CXX)
add_executable(fuzz_client fuzz_client.c common.c)
target_link_libraries(fuzz_client ${libs} FuzzingEngine)
SET_TARGET_PROPERTIES(fuzz_client PROPERTIES LINKER_LANGUAGE CXX)
add_executable(fuzz_server fuzz_server.c common.c)
target_link_libraries(fuzz_server ${libs} FuzzingEngine)
SET_TARGET_PROPERTIES(fuzz_server PROPERTIES LINKER_LANGUAGE CXX)
add_executable(fuzz_dtlsclient fuzz_dtlsclient.c common.c)
target_link_libraries(fuzz_dtlsclient ${libs} FuzzingEngine)
SET_TARGET_PROPERTIES(fuzz_dtlsclient PROPERTIES LINKER_LANGUAGE CXX)
add_executable(fuzz_dtlsserver fuzz_dtlsserver.c common.c)
target_link_libraries(fuzz_dtlsserver ${libs} FuzzingEngine)
SET_TARGET_PROPERTIES(fuzz_dtlsserver PROPERTIES LINKER_LANGUAGE CXX)
endif()
set(executables_no_common_c
fuzz_privkey
fuzz_pubkey
fuzz_x509crl
fuzz_x509crt
fuzz_x509csr
)
set(executables_with_common_c
fuzz_client
fuzz_dtlsclient
fuzz_dtlsserver
fuzz_server
)
foreach(exe IN LISTS executables_no_common_c executables_with_common_c)
add_executable(${exe} ${exe}.c)
if (NOT FUZZINGENGINE_LIB)
target_link_libraries(${exe} ${libs})
target_sources(${exe} PRIVATE onefile.c)
else()
target_link_libraries(${exe} ${libs} FuzzingEngine)
SET_TARGET_PROPERTIES(${exe} PROPERTIES LINKER_LANGUAGE CXX)
endif()
# This emulates "if ( ... IN_LIST ... )" which becomes available in CMake 3.3
list(FIND executables_with_common_c ${exe} exe_index)
if (${exe_index} GREATER -1)
target_sources(${exe} PRIVATE common.c)
endif()
endforeach()

View File

@ -1,9 +1,13 @@
add_executable(hello hello.c)
target_link_libraries(hello mbedcrypto)
set(executables
generic_sum
hello
)
add_executable(generic_sum generic_sum.c)
target_link_libraries(generic_sum mbedcrypto)
foreach(exe IN LISTS executables)
add_executable(${exe} ${exe}.c)
target_link_libraries(${exe} mbedcrypto)
endforeach()
install(TARGETS hello generic_sum
install(TARGETS ${executables}
DESTINATION "bin"
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)

View File

@ -1,63 +1,39 @@
add_executable(dh_client dh_client.c)
target_link_libraries(dh_client mbedtls)
set(executables_mbedtls
dh_client
dh_server
)
add_executable(dh_genprime dh_genprime.c)
target_link_libraries(dh_genprime mbedcrypto)
foreach(exe IN LISTS executables_mbedtls)
add_executable(${exe} ${exe}.c)
target_link_libraries(${exe} mbedtls)
endforeach()
add_executable(dh_server dh_server.c)
target_link_libraries(dh_server mbedtls)
set(executables_mbedcrypto
dh_genprime
ecdh_curve25519
ecdsa
gen_key
key_app
key_app_writer
mpi_demo
pk_encrypt
pk_decrypt
pk_sign
pk_verify
rsa_decrypt
rsa_encrypt
rsa_genkey
rsa_sign
rsa_sign_pss
rsa_verify
rsa_verify_pss
)
add_executable(ecdh_curve25519 ecdh_curve25519.c)
target_link_libraries(ecdh_curve25519 mbedcrypto)
foreach(exe IN LISTS executables_mbedcrypto)
add_executable(${exe} ${exe}.c)
target_link_libraries(${exe} mbedcrypto)
endforeach()
add_executable(ecdsa ecdsa.c)
target_link_libraries(ecdsa mbedcrypto)
add_executable(gen_key gen_key.c)
target_link_libraries(gen_key mbedcrypto)
add_executable(key_app key_app.c)
target_link_libraries(key_app mbedcrypto)
add_executable(key_app_writer key_app_writer.c)
target_link_libraries(key_app_writer mbedcrypto)
add_executable(mpi_demo mpi_demo.c)
target_link_libraries(mpi_demo mbedcrypto)
add_executable(rsa_genkey rsa_genkey.c)
target_link_libraries(rsa_genkey mbedcrypto)
add_executable(rsa_sign rsa_sign.c)
target_link_libraries(rsa_sign mbedcrypto)
add_executable(rsa_verify rsa_verify.c)
target_link_libraries(rsa_verify mbedcrypto)
add_executable(rsa_sign_pss rsa_sign_pss.c)
target_link_libraries(rsa_sign_pss mbedcrypto)
add_executable(rsa_verify_pss rsa_verify_pss.c)
target_link_libraries(rsa_verify_pss mbedcrypto)
add_executable(rsa_encrypt rsa_encrypt.c)
target_link_libraries(rsa_encrypt mbedcrypto)
add_executable(rsa_decrypt rsa_decrypt.c)
target_link_libraries(rsa_decrypt mbedcrypto)
add_executable(pk_sign pk_sign.c)
target_link_libraries(pk_sign mbedcrypto)
add_executable(pk_verify pk_verify.c)
target_link_libraries(pk_verify mbedcrypto)
add_executable(pk_encrypt pk_encrypt.c)
target_link_libraries(pk_encrypt mbedcrypto)
add_executable(pk_decrypt pk_decrypt.c)
target_link_libraries(pk_decrypt mbedcrypto)
install(TARGETS dh_client dh_genprime dh_server key_app mpi_demo rsa_genkey rsa_sign rsa_verify rsa_encrypt rsa_decrypt pk_encrypt pk_decrypt pk_sign pk_verify gen_key
install(TARGETS ${executables_mbedtls} ${executables_mbedcrypto}
DESTINATION "bin"
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)

View File

@ -1,12 +1,15 @@
add_executable(crypto_examples crypto_examples.c)
target_link_libraries(crypto_examples mbedtls)
set(executables
crypto_examples
key_ladder_demo
psa_constant_names
)
add_executable(key_ladder_demo key_ladder_demo.c)
target_link_libraries(key_ladder_demo mbedtls)
foreach(exe IN LISTS executables)
add_executable(${exe} ${exe}.c)
target_link_libraries(${exe} mbedtls)
endforeach()
add_executable(psa_constant_names psa_constant_names.c)
target_include_directories(psa_constant_names PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(psa_constant_names mbedtls)
add_custom_target(
psa_constant_names_generated
@ -15,10 +18,7 @@ add_custom_target(
)
add_dependencies(psa_constant_names psa_constant_names_generated)
install(TARGETS
crypto_examples
key_ladder_demo
psa_constant_names
install(TARGETS ${executables}
DESTINATION "bin"
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)

View File

@ -1,12 +1,14 @@
add_executable(gen_random_havege gen_random_havege.c)
target_link_libraries(gen_random_havege mbedcrypto)
set(executables
gen_entropy
gen_random_ctr_drbg
gen_random_havege
)
add_executable(gen_random_ctr_drbg gen_random_ctr_drbg.c)
target_link_libraries(gen_random_ctr_drbg mbedcrypto)
foreach(exe IN LISTS executables)
add_executable(${exe} ${exe}.c)
target_link_libraries(${exe} mbedcrypto)
endforeach()
add_executable(gen_entropy gen_entropy.c)
target_link_libraries(gen_entropy mbedcrypto)
install(TARGETS gen_random_havege gen_random_ctr_drbg gen_entropy
install(TARGETS ${executables}
DESTINATION "bin"
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)

View File

@ -5,7 +5,15 @@ set(libs
mbedtls
)
set(targets
if(USE_PKCS11_HELPER_LIBRARY)
set(libs ${libs} pkcs11-helper)
endif(USE_PKCS11_HELPER_LIBRARY)
if(ENABLE_ZLIB_SUPPORT)
set(libs ${libs} ${ZLIB_LIBRARIES})
endif(ENABLE_ZLIB_SUPPORT)
set(executables
dtls_client
dtls_server
mini_client
@ -18,52 +26,20 @@ set(targets
ssl_server2
)
if(USE_PKCS11_HELPER_LIBRARY)
set(libs ${libs} pkcs11-helper)
endif(USE_PKCS11_HELPER_LIBRARY)
foreach(exe IN LISTS executables)
add_executable(${exe} ${exe}.c)
target_link_libraries(${exe} ${libs})
endforeach()
if(ENABLE_ZLIB_SUPPORT)
set(libs ${libs} ${ZLIB_LIBRARIES})
endif(ENABLE_ZLIB_SUPPORT)
add_executable(dtls_client dtls_client.c)
target_link_libraries(dtls_client ${libs})
add_executable(dtls_server dtls_server.c)
target_link_libraries(dtls_server ${libs})
add_executable(mini_client mini_client.c)
target_link_libraries(mini_client ${libs})
add_executable(ssl_client1 ssl_client1.c)
target_link_libraries(ssl_client1 ${libs})
add_executable(ssl_client2 ssl_client2.c)
target_sources(ssl_client2 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../test/query_config.c)
target_link_libraries(ssl_client2 ${libs})
add_executable(ssl_context_info ssl_context_info.c)
target_link_libraries(ssl_context_info ${libs})
add_executable(ssl_fork_server ssl_fork_server.c)
target_link_libraries(ssl_fork_server ${libs})
add_executable(ssl_mail_client ssl_mail_client.c)
target_link_libraries(ssl_mail_client ${libs})
add_executable(ssl_server ssl_server.c)
target_link_libraries(ssl_server ${libs})
add_executable(ssl_server2 ssl_server2.c)
target_sources(ssl_server2 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../test/query_config.c)
target_link_libraries(ssl_server2 ${libs})
if(THREADS_FOUND)
add_executable(ssl_pthread_server ssl_pthread_server.c)
target_link_libraries(ssl_pthread_server ${libs} ${CMAKE_THREAD_LIBS_INIT})
set(targets ${targets} ssl_pthread_server)
list(APPEND executables ssl_pthread_server)
endif(THREADS_FOUND)
install(TARGETS ${targets}
install(TARGETS ${executables}
DESTINATION "bin"
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)

View File

@ -10,27 +10,35 @@ if(ENABLE_ZLIB_SUPPORT)
set(libs ${libs} ${ZLIB_LIBRARIES})
endif(ENABLE_ZLIB_SUPPORT)
add_executable(selftest selftest.c)
target_link_libraries(selftest ${libs})
set(executables_libs
selftest
udp_proxy
)
add_executable(benchmark benchmark.c)
target_link_libraries(benchmark mbedcrypto)
set(executables_mbedcrypto
benchmark
query_compile_time_config
zeroize
)
if(TEST_CPP)
add_executable(cpp_dummy_build cpp_dummy_build.cpp)
target_link_libraries(cpp_dummy_build mbedcrypto)
list(APPEND executables_mbedcrypto cpp_dummy_build)
endif()
add_executable(udp_proxy udp_proxy.c)
target_link_libraries(udp_proxy ${libs})
foreach(exe IN LISTS executables_libs executables_mbedcrypto)
add_executable(${exe} ${exe}.c)
add_executable(zeroize zeroize.c)
target_link_libraries(zeroize mbedcrypto)
# This emulates "if ( ... IN_LIST ... )" which becomes available in CMake 3.3
list(FIND executables_libs ${exe} exe_index)
if (${exe_index} GREATER -1)
target_link_libraries(${exe} ${libs})
else()
target_link_libraries(${exe} mbedcrypto)
endif()
endforeach()
add_executable(query_compile_time_config query_compile_time_config.c)
target_sources(query_compile_time_config PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/query_config.c)
target_link_libraries(query_compile_time_config mbedcrypto)
install(TARGETS selftest benchmark udp_proxy query_compile_time_config
install(TARGETS ${executables_libs} ${executables_mbedcrypto}
DESTINATION "bin"
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)

View File

@ -2,12 +2,16 @@ set(libs
mbedcrypto
)
add_executable(strerror strerror.c)
target_link_libraries(strerror ${libs})
set(executables
pem2der
strerror
)
add_executable(pem2der pem2der.c)
target_link_libraries(pem2der ${libs})
foreach(exe IN LISTS executables)
add_executable(${exe} ${exe}.c)
target_link_libraries(${exe} ${libs})
endforeach()
install(TARGETS strerror pem2der
install(TARGETS ${executables}
DESTINATION "bin"
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)

View File

@ -10,21 +10,21 @@ if(ENABLE_ZLIB_SUPPORT)
set(libs ${libs} ${ZLIB_LIBRARIES})
endif(ENABLE_ZLIB_SUPPORT)
add_executable(cert_app cert_app.c)
target_link_libraries(cert_app ${libs} mbedtls)
set(executables
cert_app
cert_req
cert_write
crl_app
req_app
)
add_executable(crl_app crl_app.c)
target_link_libraries(crl_app ${libs})
foreach(exe IN LISTS executables)
add_executable(${exe} ${exe}.c)
target_link_libraries(${exe} ${libs})
endforeach()
add_executable(req_app req_app.c)
target_link_libraries(req_app ${libs})
target_link_libraries(cert_app mbedtls)
add_executable(cert_req cert_req.c)
target_link_libraries(cert_req ${libs})
add_executable(cert_write cert_write.c)
target_link_libraries(cert_write ${libs})
install(TARGETS cert_app crl_app req_app cert_req cert_write
install(TARGETS ${executables}
DESTINATION "bin"
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)