Change t-cose integration to use PropertyCopy
Pass libc specific compilation settings to t-cose build using
PropertyCopy. This way not only system include and include paths are
handled but compilation flags and linker flags too.
This change makes t-cose build use the -nostdinc flag, which is
needed for proper newlib integration and was missing.
Change-Id: I372fe908406c63104f833f2ec2dffb49bbe22b41
Signed-off-by: Gyorgy Szing <Gyorgy.Szing@arm.com>
diff --git a/deployments/attestation/attestation.cmake b/deployments/attestation/attestation.cmake
index 7184990..307de3b 100644
--- a/deployments/attestation/attestation.cmake
+++ b/deployments/attestation/attestation.cmake
@@ -55,15 +55,11 @@
#
#-------------------------------------------------------------------------------
-# Get libc include dir
-get_property(LIBC_INCLUDE_PATH TARGET c PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
-
# Qcbor
include(${TS_ROOT}/external/qcbor/qcbor.cmake)
target_link_libraries(attestation PRIVATE qcbor)
# t_cose
-set (TCOSE_EXTERNAL_INCLUDE_PATHS ${LIBC_INCLUDE_PATH})
include(${TS_ROOT}/external/t_cose/t_cose.cmake)
target_link_libraries(attestation PRIVATE t_cose)
diff --git a/external/t_cose/0002-Fix-stop-overriding-C_FLAGS-from-environment.patch b/external/t_cose/0002-Fix-stop-overriding-C_FLAGS-from-environment.patch
new file mode 100644
index 0000000..56a42b4
--- /dev/null
+++ b/external/t_cose/0002-Fix-stop-overriding-C_FLAGS-from-environment.patch
@@ -0,0 +1,31 @@
+From 74f6f0f70f8eb0a073e20008b962a415c6c9c9f9 Mon Sep 17 00:00:00 2001
+From: Gyorgy Szing <Gyorgy.Szing@arm.com>
+Date: Sat, 5 Mar 2022 02:18:06 +0000
+Subject: [PATCH 2/2] Fix stop overriding C_FLAGS from environment.
+
+Directly setting CMAKE_C_FLAGS is bad practice as it is overriding
+values taken from C_FLAGS environment variable or from
+CMAKE_C_FLAGS_INIT. The latter is used in toolchain files or in
+initial cache files.
+
+Signed-off-by: Gyorgy Szing <Gyorgy.Szing@arm.com>
+---
+ CMakeLists.txt | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 343b325..3b43a2e 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -4,7 +4,7 @@ project(t_cose
+ LANGUAGES C
+ VERSION 1.0.1)
+
+-set(CMAKE_C_FLAGS "-pedantic -Wall -O3 -ffunction-sections")
++add_compile_options(-pedantic -Wall -O3 -ffunction-sections)
+
+ include_directories(inc)
+ include_directories(src)
+--
+2.17.1
+
diff --git a/external/t_cose/t_cose-init-cache.cmake.in b/external/t_cose/t_cose-init-cache.cmake.in
index 3c2879f..abd3eba 100644
--- a/external/t_cose/t_cose-init-cache.cmake.in
+++ b/external/t_cose/t_cose-init-cache.cmake.in
@@ -8,9 +8,6 @@
set(CMAKE_INSTALL_PREFIX "@BUILD_INSTALL_DIR@" CACHE STRING "")
set(CMAKE_TOOLCHAIN_FILE "@TS_EXTERNAL_LIB_TOOLCHAIN_FILE@" CACHE STRING "")
-set(TCOSE_EXTERNAL_INCLUDE_PATHS "@TCOSE_EXTERNAL_INCLUDE_PATHS@")
-if (TCOSE_EXTERNAL_INCLUDE_PATHS)
- set(thirdparty_inc "${TCOSE_EXTERNAL_INCLUDE_PATHS}" CACHE STRING "")
-endif()
-
set(MBEDTLS On CACHE STRING "")
+
+@_cmake_fragment@
diff --git a/external/t_cose/t_cose.cmake b/external/t_cose/t_cose.cmake
index 9ed14c4..c616fac 100644
--- a/external/t_cose/t_cose.cmake
+++ b/external/t_cose/t_cose.cmake
@@ -19,12 +19,35 @@
PATCH_COMMAND git stash
COMMAND git branch -f bf-patch
COMMAND git am ${CMAKE_CURRENT_LIST_DIR}/0001-add-install-definition.patch
+ ${CMAKE_CURRENT_LIST_DIR}/0002-Fix-stop-overriding-C_FLAGS-from-environment.patch
COMMAND git reset bf-patch
)
+include(${TS_ROOT}/tools/cmake/common/PropertyCopy.cmake)
+
+# Only pass libc settings to t-cose if needed. For environments where the standard
+# library is not overridden, this is not needed.
+if(TARGET stdlib::c)
+ # Save libc settings
+ save_interface_target_properties(TGT stdlib::c PREFIX LIBC)
+ # Translate libc settings to cmake code fragment. Will be inserted into
+ # t_cose-init-cache.cmake.in when LazyFetch configures the file.
+ translate_interface_target_properties(PREFIX LIBC RES _cmake_fragment)
+ unset_saved_properties(LIBC)
+endif()
+
# Prepare include paths for dependencies that t_codse has on external components
-get_target_property(_qcbor_inc qcbor INTERFACE_INCLUDE_DIRECTORIES)
-list(APPEND TCOSE_EXTERNAL_INCLUDE_PATHS ${_qcbor_inc} ${PSA_CRYPTO_API_INCLUDE})
+save_interface_target_properties(TGT qcbor PREFIX QCBOR)
+translate_interface_target_properties(PREFIX QCBOR RES _cmake_fragment1)
+unset_saved_properties(QCBOR)
+string(APPEND _cmake_fragment "\n${_cmake_fragment1}")
+unset(_cmake_fragment1)
+
+translate_value_as_property(VALUE "${PSA_CRYPTO_API_INCLUDE}"
+ PROPERTY INTERFACE_INCLUDE_DIRECTORIES
+ RES _cmake_fragment1)
+string(APPEND _cmake_fragment "\n${_cmake_fragment1}")
+unset(_cmake_fragment1)
include(${TS_ROOT}/tools/cmake/common/LazyFetch.cmake REQUIRED)
LazyFetch_MakeAvailable(DEP_NAME t_cose
@@ -33,8 +56,7 @@
CACHE_FILE "${CMAKE_CURRENT_LIST_DIR}/t_cose-init-cache.cmake.in"
SOURCE_DIR "${T_COSE_SOURCE_DIR}"
)
-
-unset(TCOSE_EXTERNAL_INCLUDE_PATHS)
+unset(_cmake_fragment)
# Create an imported target to have clean abstraction in the build-system.
add_library(t_cose STATIC IMPORTED)