Fix libc dependency of external components
Currently the stdlib::c library, which represents the standard
library in deployments compiled for "freestanding" environments (SPs)
is added early to link dependencies of the target. As a result the
link order is incorrect and symbol search for external components
added later and depending on libc fails with GCC.
As a workaround make external components depend on libc directly.
Change-Id: Idb9da18bb8228dea56ef539cacf36964d2349937
Signed-off-by: Gyorgy Szing <Gyorgy.Szing@arm.com>
diff --git a/deployments/crypto/crypto.cmake b/deployments/crypto/crypto.cmake
index 9020cc0..9ca26cd 100644
--- a/deployments/crypto/crypto.cmake
+++ b/deployments/crypto/crypto.cmake
@@ -1,5 +1,5 @@
#-------------------------------------------------------------------------------
-# Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2020-2023, Arm Limited and Contributors. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
@@ -47,7 +47,6 @@
# Mbed TLS provides libmbedcrypto
include(${TS_ROOT}/external/MbedTLS/MbedTLS.cmake)
target_link_libraries(crypto PRIVATE mbedcrypto)
-target_link_libraries(mbedcrypto INTERFACE stdlib::c)
#################################################################
diff --git a/deployments/libsp/opteesp/CMakeLists.txt b/deployments/libsp/opteesp/CMakeLists.txt
index fb47a60..0e83302 100644
--- a/deployments/libsp/opteesp/CMakeLists.txt
+++ b/deployments/libsp/opteesp/CMakeLists.txt
@@ -1,5 +1,5 @@
#-------------------------------------------------------------------------------
-# Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2020-2023, Arm Limited and Contributors. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
@@ -55,7 +55,7 @@
get_newlib_compile_flags()
# Get libc specific settings from newlib.
-target_link_libraries(sp PRIVATE stdlib::c)
+target_link_libraries(sp PUBLIC stdlib::c)
target_compile_definitions(sp PRIVATE
ARM64=1
diff --git a/external/MbedTLS/MbedTLS.cmake b/external/MbedTLS/MbedTLS.cmake
index 88aa68b..83b190a 100644
--- a/external/MbedTLS/MbedTLS.cmake
+++ b/external/MbedTLS/MbedTLS.cmake
@@ -1,5 +1,5 @@
#-------------------------------------------------------------------------------
-# Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2020-2023, Arm Limited and Contributors. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
@@ -164,3 +164,6 @@
set_property(DIRECTORY ${CMAKE_SOURCE_DIR} APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${MBEDCRYPTO_LIB_FILE})
set_property(TARGET mbedcrypto PROPERTY IMPORTED_LOCATION ${MBEDCRYPTO_LIB_FILE})
set_property(TARGET mbedcrypto PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${MBEDTLS_INSTALL_DIR}/include")
+if(TARGET stdlib::c)
+ target_link_libraries(mbedcrypto INTERFACE stdlib::c)
+endif()
\ No newline at end of file
diff --git a/external/nanopb/nanopb.cmake b/external/nanopb/nanopb.cmake
index 92c6e5b..36465f6 100644
--- a/external/nanopb/nanopb.cmake
+++ b/external/nanopb/nanopb.cmake
@@ -1,5 +1,5 @@
#-------------------------------------------------------------------------------
-# Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2020-2023, Arm Limited and Contributors. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
@@ -75,7 +75,9 @@
)
unset(_cmake_fragment)
-#set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${NANOPB_INSTALL_DIR}/)
+if(TARGET stdlib::c)
+ target_link_libraries(nanopb::protobuf-nanopb-static INTERFACE stdlib::c)
+endif()
#### Build access to the protobuf compiler
#TODO: verify protoc dependencies: python3-protobuf
diff --git a/external/qcbor/qcbor.cmake b/external/qcbor/qcbor.cmake
index 47ddb6c..c51ca71 100644
--- a/external/qcbor/qcbor.cmake
+++ b/external/qcbor/qcbor.cmake
@@ -1,5 +1,5 @@
#-------------------------------------------------------------------------------
-# Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2021-2023, Arm Limited and Contributors. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
@@ -51,5 +51,7 @@
add_library(qcbor STATIC IMPORTED)
set_property(TARGET qcbor PROPERTY IMPORTED_LOCATION "${QCBOR_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}qcbor${CMAKE_STATIC_LIBRARY_SUFFIX}")
set_property(TARGET qcbor PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${QCBOR_INSTALL_DIR}/include")
-
+if(TARGET stdlib::c)
+ target_link_libraries(qcbor INTERFACE stdlib::c)
+endif()
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${QCBOR_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}qcbor${CMAKE_STATIC_LIBRARY_SUFFIX}")
diff --git a/external/t_cose/t_cose.cmake b/external/t_cose/t_cose.cmake
index cf4f7f4..32a81e3 100644
--- a/external/t_cose/t_cose.cmake
+++ b/external/t_cose/t_cose.cmake
@@ -1,5 +1,5 @@
#-------------------------------------------------------------------------------
-# Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2021-2023, Arm Limited and Contributors. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
@@ -71,4 +71,7 @@
target_link_libraries(t_cose INTERFACE qcbor)
set_property(TARGET t_cose PROPERTY IMPORTED_LOCATION "${T_COSE_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}t_cose${CMAKE_STATIC_LIBRARY_SUFFIX}")
set_property(TARGET t_cose PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${T_COSE_INSTALL_DIR}/include")
+if(TARGET stdlib::c)
+ target_link_libraries(t_cose INTERFACE stdlib::c)
+endif()
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${T_COSE_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}t_cose${CMAKE_STATIC_LIBRARY_SUFFIX}")