cmake: link programs that only use crypto with libmbedcrypto

When building with CMake, for sample programs that only use
functionality in libmbedcrypto (i.e. crypto and platform), link with
libmbedcrypto, not with libmbedtls.

This doesn't change the result, because the linker skips libraries in
which no symbol is used, but it changes the build dependencies, and it
has the advantage of bringing programs/*/CMakeLists.txt closer to the
corresponding files under crypto/.

The programs concerned are crypto sample and test programs, and
programs that only use (potential) platform functions such as
mbedtls_printf. dh_client and dh_server keep linking with mbedtls
because they use functions from the net_sockets module.
This commit is contained in:
Gilles Peskine 2020-02-11 16:51:34 +01:00
parent 7cb47de12a
commit e123395317
6 changed files with 30 additions and 30 deletions

View file

@ -1,8 +1,8 @@
add_executable(aescrypt2 aescrypt2.c)
target_link_libraries(aescrypt2 mbedtls)
target_link_libraries(aescrypt2 mbedcrypto)
add_executable(crypt_and_hash crypt_and_hash.c)
target_link_libraries(crypt_and_hash mbedtls)
target_link_libraries(crypt_and_hash mbedcrypto)
install(TARGETS aescrypt2 crypt_and_hash
DESTINATION "bin"

View file

@ -1,8 +1,8 @@
add_executable(hello hello.c)
target_link_libraries(hello mbedtls)
target_link_libraries(hello mbedcrypto)
add_executable(generic_sum generic_sum.c)
target_link_libraries(generic_sum mbedtls)
target_link_libraries(generic_sum mbedcrypto)
install(TARGETS hello generic_sum
DESTINATION "bin"

View file

@ -2,61 +2,61 @@ add_executable(dh_client dh_client.c)
target_link_libraries(dh_client mbedtls)
add_executable(dh_genprime dh_genprime.c)
target_link_libraries(dh_genprime mbedtls)
target_link_libraries(dh_genprime mbedcrypto)
add_executable(dh_server dh_server.c)
target_link_libraries(dh_server mbedtls)
add_executable(ecdh_curve25519 ecdh_curve25519.c)
target_link_libraries(ecdh_curve25519 mbedtls)
target_link_libraries(ecdh_curve25519 mbedcrypto)
add_executable(ecdsa ecdsa.c)
target_link_libraries(ecdsa mbedtls)
target_link_libraries(ecdsa mbedcrypto)
add_executable(gen_key gen_key.c)
target_link_libraries(gen_key mbedtls)
target_link_libraries(gen_key mbedcrypto)
add_executable(key_app key_app.c)
target_link_libraries(key_app mbedtls)
target_link_libraries(key_app mbedcrypto)
add_executable(key_app_writer key_app_writer.c)
target_link_libraries(key_app_writer mbedtls)
target_link_libraries(key_app_writer mbedcrypto)
add_executable(mpi_demo mpi_demo.c)
target_link_libraries(mpi_demo mbedtls)
target_link_libraries(mpi_demo mbedcrypto)
add_executable(rsa_genkey rsa_genkey.c)
target_link_libraries(rsa_genkey mbedtls)
target_link_libraries(rsa_genkey mbedcrypto)
add_executable(rsa_sign rsa_sign.c)
target_link_libraries(rsa_sign mbedtls)
target_link_libraries(rsa_sign mbedcrypto)
add_executable(rsa_verify rsa_verify.c)
target_link_libraries(rsa_verify mbedtls)
target_link_libraries(rsa_verify mbedcrypto)
add_executable(rsa_sign_pss rsa_sign_pss.c)
target_link_libraries(rsa_sign_pss mbedtls)
target_link_libraries(rsa_sign_pss mbedcrypto)
add_executable(rsa_verify_pss rsa_verify_pss.c)
target_link_libraries(rsa_verify_pss mbedtls)
target_link_libraries(rsa_verify_pss mbedcrypto)
add_executable(rsa_encrypt rsa_encrypt.c)
target_link_libraries(rsa_encrypt mbedtls)
target_link_libraries(rsa_encrypt mbedcrypto)
add_executable(rsa_decrypt rsa_decrypt.c)
target_link_libraries(rsa_decrypt mbedtls)
target_link_libraries(rsa_decrypt mbedcrypto)
add_executable(pk_sign pk_sign.c)
target_link_libraries(pk_sign mbedtls)
target_link_libraries(pk_sign mbedcrypto)
add_executable(pk_verify pk_verify.c)
target_link_libraries(pk_verify mbedtls)
target_link_libraries(pk_verify mbedcrypto)
add_executable(pk_encrypt pk_encrypt.c)
target_link_libraries(pk_encrypt mbedtls)
target_link_libraries(pk_encrypt mbedcrypto)
add_executable(pk_decrypt pk_decrypt.c)
target_link_libraries(pk_decrypt mbedtls)
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
DESTINATION "bin"

View file

@ -1,11 +1,11 @@
add_executable(gen_random_havege gen_random_havege.c)
target_link_libraries(gen_random_havege mbedtls)
target_link_libraries(gen_random_havege mbedcrypto)
add_executable(gen_random_ctr_drbg gen_random_ctr_drbg.c)
target_link_libraries(gen_random_ctr_drbg mbedtls)
target_link_libraries(gen_random_ctr_drbg mbedcrypto)
add_executable(gen_entropy gen_entropy.c)
target_link_libraries(gen_entropy mbedtls)
target_link_libraries(gen_entropy mbedcrypto)
install(TARGETS gen_random_havege gen_random_ctr_drbg gen_entropy
DESTINATION "bin"

View file

@ -14,22 +14,22 @@ add_executable(selftest selftest.c)
target_link_libraries(selftest ${libs})
add_executable(benchmark benchmark.c)
target_link_libraries(benchmark ${libs})
target_link_libraries(benchmark mbedcrypto)
if(TEST_CPP)
add_executable(cpp_dummy_build cpp_dummy_build.cpp)
target_link_libraries(cpp_dummy_build ${libs})
target_link_libraries(cpp_dummy_build mbedcrypto)
endif()
add_executable(udp_proxy udp_proxy.c)
target_link_libraries(udp_proxy ${libs})
add_executable(zeroize zeroize.c)
target_link_libraries(zeroize ${libs})
target_link_libraries(zeroize mbedcrypto)
add_executable(query_compile_time_config query_compile_time_config.c)
target_sources(query_compile_time_config PUBLIC query_config.c)
target_link_libraries(query_compile_time_config ${libs})
target_link_libraries(query_compile_time_config mbedcrypto)
install(TARGETS selftest benchmark udp_proxy query_compile_time_config
DESTINATION "bin"

View file

@ -1,5 +1,5 @@
set(libs
mbedtls
mbedcrypto
)
add_executable(strerror strerror.c)