Upstream-Status: Pending [Not submitted to upstream yet]
Signed-off-by: Emekcan Aras <Emekcan.Aras@arm.com>

From 386a086debf70f739a7dfc0bdce9c4f1053ba8d5 Mon Sep 17 00:00:00 2001
From: Vishnu Banavath <vishnu.banavath@arm.com>
Date: Wed, 16 Feb 2022 15:55:55 +0000
Subject: [PATCH 11/15] pass sysroot_yocto

---
 deployments/libts/libts-import.cmake         |  3 +++
 external/MbedTLS/MbedTLS.cmake               |  1 +
 external/psa_arch_tests/psa_arch_tests.cmake | 25 +++++++++++++-------
 3 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/deployments/libts/libts-import.cmake b/deployments/libts/libts-import.cmake
index 792ba86c..b900ce3f 100644
--- a/deployments/libts/libts-import.cmake
+++ b/deployments/libts/libts-import.cmake
@@ -27,9 +27,12 @@ set(LIBTS_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/_deps/libts-build" CACHE PATH

 file(MAKE_DIRECTORY ${LIBTS_BINARY_DIR})

+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --sysroot=${SYSROOT_YOCTO}")
+
 #Configure the library
 execute_process(COMMAND
 	${CMAKE_COMMAND}
+                -DCMAKE_SYSROOT=${SYSROOT_YOCTO}
 		-DCMAKE_INSTALL_PREFIX=${LIBTS_INSTALL_PATH}
 		-GUnix\ Makefiles
 		${LIBTS_SOURCE_DIR}
diff --git a/external/MbedTLS/MbedTLS.cmake b/external/MbedTLS/MbedTLS.cmake
index 3350d8a0..33467cf0 100644
--- a/external/MbedTLS/MbedTLS.cmake
+++ b/external/MbedTLS/MbedTLS.cmake
@@ -103,6 +103,7 @@ if (NOT MBEDCRYPTO_LIB_FILE)
 	execute_process(COMMAND
 		${CMAKE_COMMAND} -E env CROSS_COMPILE=${CROSS_COMPILE}
 			${CMAKE_COMMAND}
+                                -DCMAKE_SYSROOT=${SYSROOT_YOCTO}
 				-DENABLE_PROGRAMS=OFF
 				-DENABLE_TESTING=OFF
 				-DUNSAFE_BUILD=ON
diff --git a/external/psa_arch_tests/psa_arch_tests.cmake b/external/psa_arch_tests/psa_arch_tests.cmake
index f6d2fb9f..42f73a37 100644
--- a/external/psa_arch_tests/psa_arch_tests.cmake
+++ b/external/psa_arch_tests/psa_arch_tests.cmake
@@ -5,30 +5,33 @@
 #
 #-------------------------------------------------------------------------------

-# Temporarily using modified tests used for tf-m verification
+# Determine the number of processes to run while running parallel builds.
+# Pass -DPROCESSOR_COUNT=<n> to cmake to override.
+if(NOT DEFINED PROCESSOR_COUNT)
+	include(ProcessorCount)
+	ProcessorCount(PROCESSOR_COUNT)
+	set(PROCESSOR_COUNT ${PROCESSOR_COUNT} CACHE STRING "Number of cores to use for parallel builds.")
+endif()
+
 set(PSA_ARCH_TESTS_URL "https://github.com/bensze01/psa-arch-tests.git" CACHE STRING "psa-arch-tests repository URL")
 set(PSA_ARCH_TESTS_REFSPEC "fix-multipart-aead" CACHE STRING "psa-arch-tests git refspec")
-
-#set(PSA_ARCH_TESTS_URL "https://github.com/ARM-software/psa-arch-tests.git" CACHE STRING "psa-arch-tests repository URL")
-#set(PSA_ARCH_TESTS_REFSPEC "2a1852252a9b9af655cbe02d5d3c930952d0d798" CACHE STRING "psa-arch-tests v22.01_API1.4_ADAC_BETA")
 set(PSA_ARCH_TESTS_INSTALL_PATH "${CMAKE_CURRENT_BINARY_DIR}/psa-arch-tests_install" CACHE PATH "psa-arch-tests installation directory")
 set(PSA_ARCH_TESTS_PACKAGE_PATH "${PSA_ARCH_TESTS_INSTALL_PATH}/libpsa-arch-tests/cmake" CACHE PATH "psa-arch-tests CMake package directory")
-set(PSA_ARCH_TESTS_SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/_deps/psa_arch_tests-src" CACHE PATH "psa-arch-tests source.")
+
+include(FetchContent)

 # Checking git
 find_program(GIT_COMMAND "git")
 if (NOT GIT_COMMAND)
 	message(FATAL_ERROR "Please install git")
 endif()
-
+if ("${PSA_ARCH_TESTS_PATH}" STREQUAL "DOWNLOAD")
 # Fetching psa-arch-tests
 FetchContent_Declare(
 	psa-arch-tests
 	GIT_REPOSITORY ${PSA_ARCH_TESTS_URL}
 	GIT_TAG ${PSA_ARCH_TESTS_REFSPEC}
 	GIT_SHALLOW TRUE
-	PATCH_COMMAND git stash
-		COMMAND git apply ${CMAKE_CURRENT_LIST_DIR}/modify_attest_config.patch
 )

 # FetchContent_GetProperties exports psa-arch-tests_SOURCE_DIR and psa-arch-tests_BINARY_DIR variables
@@ -37,7 +40,10 @@ if(NOT psa-arch-tests_POPULATED)
 	message(STATUS "Fetching psa-arch-tests")
 	FetchContent_Populate(psa-arch-tests)
 endif()
-
+else()
+    set(psa-arch-tests_SOURCE_DIR "${TS_ROOT}/../psa-arch-tests")
+    set(psa-arch-tests_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
+endif()
 # Ensure list of include paths is separated correctly
 string(REPLACE ";" "\\;" PSA_ARCH_TESTS_EXTERNAL_INCLUDE_PATHS "${PSA_ARCH_TESTS_EXTERNAL_INCLUDE_PATHS}")

@@ -47,6 +53,7 @@ string(REPLACE ";" " " PSA_ARCH_TEST_EXTERNAL_DEFS "${PSA_ARCH_TEST_EXTERNAL_DEF
 # Configure the psa-arch-test library
 execute_process(COMMAND
 	${CMAKE_COMMAND}
+			-DCMAKE_SYSROOT=${SYSROOT_YOCTO}
 			-DTOOLCHAIN=INHERIT
 			-DCMAKE_TOOLCHAIN_FILE=${TS_EXTERNAL_LIB_TOOLCHAIN_FILE}
 			-DPSA_INCLUDE_PATHS=${PSA_ARCH_TESTS_EXTERNAL_INCLUDE_PATHS}
--
2.25.1
