diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 59e175bb0a..231e74e018 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -259,22 +259,49 @@ foreach(target IN LISTS tf_psa_crypto_library_targets) get_target_property(target_type ${target} TYPE) if (target_type STREQUAL STATIC_LIBRARY) add_custom_command( - TARGET ${mbedtls_target} - POST_BUILD - COMMAND ${CMAKE_COMMAND} - ARGS -E copy $ ${CMAKE_BINARY_DIR}/library) + TARGET ${mbedtls_target} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + $ + $ + ) else() + # Copy the crypto shared library from tf-psa-crypto: + # - ".so." on Unix + # - ".dylib" on macOS + # - ".dll" on Windows + # The full path to the file is given by $. + # + # On systems that use .so versioning, also create the symbolic links + # ".so." and ".so", which correspond to + # $ and $, + # respectively. + # + # On Windows, also copy the ".lib" file, whose full path is + # $. + add_custom_command( - TARGET ${mbedtls_target} - POST_BUILD - COMMAND ${CMAKE_COMMAND} - ARGS -E copy $ - ${CMAKE_BINARY_DIR}/library/$) - add_custom_command( - TARGET ${mbedtls_target} - POST_BUILD - COMMAND ${CMAKE_COMMAND} - ARGS -E copy $ - ${CMAKE_BINARY_DIR}/library/$) + TARGET ${mbedtls_target} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + $ + $ + ) + if(WIN32 AND NOT CYGWIN) + add_custom_command( + TARGET ${mbedtls_target} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + $ + $ + ) + else() + add_custom_command( + TARGET ${mbedtls_target} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E create_symlink + $ + $ + COMMAND ${CMAKE_COMMAND} -E create_symlink + $ + $ + ) + endif() endif() endforeach(target)