Crypto: Restructure dependencies on psa_crypto_config

Targets that are explicit callers of PSA Crypto APIs (i.e. that
need to include psa/crypto.h) need to be explicitly linked with
psa_crypto_config. Also, the psa_crypto_config now is a proper
target that gets exported by the SPE build, so make sure it is
visible to psa_arch_tests val_nspe/pal_nspe and that in turn
links against the platform so that platform includes are available


Signed-off-by: Antonio de Angelis <antonio.deangelis@arm.com>
Change-Id: Ib75d090397ef15df26fd0c3677141215855d133c
diff --git a/tests_psa_arch/CMakeLists.txt b/tests_psa_arch/CMakeLists.txt
index c1546c8..eecac85 100644
--- a/tests_psa_arch/CMakeLists.txt
+++ b/tests_psa_arch/CMakeLists.txt
@@ -91,16 +91,17 @@
 
 set(PLATFORM_PSA_ISOLATION_LEVEL ${TFM_ISOLATION_LEVEL})
 
-# A workaround to co-work with local patch "Crypto: Add psa crypto config link for crypto tests".
-# Specify the PSA crypto config file to make sure PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_BASIC are defined.
-add_library(psa_crypto_config INTERFACE)
-target_compile_definitions(psa_crypto_config
-    INTERFACE
-        MBEDTLS_PSA_CRYPTO_CONFIG_FILE="${TFM_MBEDCRYPTO_PSA_CRYPTO_CONFIG_PATH}"
-)
-
 add_subdirectory(${PSA_ARCH_TESTS_PATH}/api-tests ${CMAKE_BINARY_DIR}/api-tests)
 
+if ("${TEST_PSA_API}" STREQUAL "CRYPTO")
+    # psa_crypto_config needs to have visibility of the platform includes
+    target_link_libraries(psa_crypto_config INTERFACE platform_ns)
+    # val_nspe/pal_nspe targets are calling PSA Crypto APIs so they need
+    # to include the psa_crypto_config which exports the config file defs
+    target_link_libraries(val_nspe PUBLIC psa_crypto_config)
+    target_link_libraries(pal_nspe PUBLIC psa_crypto_config)
+endif()
+
 ############################# TFM NS main app ##################################
 
 target_sources(tfm_ns
diff --git a/tests_reg/test/secure_fw/common_test_services/tfm_secure_client_2/CMakeLists.txt b/tests_reg/test/secure_fw/common_test_services/tfm_secure_client_2/CMakeLists.txt
index 26e971a..a317434 100644
--- a/tests_reg/test/secure_fw/common_test_services/tfm_secure_client_2/CMakeLists.txt
+++ b/tests_reg/test/secure_fw/common_test_services/tfm_secure_client_2/CMakeLists.txt
@@ -42,6 +42,7 @@
     PRIVATE
         tfm_sprt
         platform_s
+        psa_crypto_config
 )
 
 target_link_libraries(tfm_spm
diff --git a/tests_reg/test/secure_fw/suites/crypto/non_secure/CMakeLists.txt b/tests_reg/test/secure_fw/suites/crypto/non_secure/CMakeLists.txt
index 2e2c511..34e4ed2 100644
--- a/tests_reg/test/secure_fw/suites/crypto/non_secure/CMakeLists.txt
+++ b/tests_reg/test/secure_fw/suites/crypto/non_secure/CMakeLists.txt
@@ -21,13 +21,14 @@
 
 target_include_directories(tfm_test_suite_crypto_ns
     PUBLIC
-        .
+        ${CMAKE_CURRENT_LIST_DIR}
 )
 
 target_link_libraries(tfm_test_suite_crypto_ns
     PRIVATE
         tfm_config
         tfm_test_framework_ns
+        psa_crypto_config
 )
 
 target_link_libraries(tfm_ns_tests
@@ -54,7 +55,6 @@
         $<$<BOOL:${TFM_CRYPTO_TEST_ALG_CHACHA20_POLY1305}>:TFM_CRYPTO_TEST_ALG_CHACHA20_POLY1305>
         $<$<BOOL:${TFM_CRYPTO_TEST_ALG_RSASSA_PSS_VERIFICATION}>:TFM_CRYPTO_TEST_ALG_RSASSA_PSS_VERIFICATION>
         $<$<BOOL:${TFM_CRYPTO_TEST_SINGLE_PART_FUNCS}>:TFM_CRYPTO_TEST_SINGLE_PART_FUNCS>
-        $<$<BOOL:${TFM_MBEDCRYPTO_PSA_CRYPTO_CONFIG_PATH}>:MBEDTLS_PSA_CRYPTO_CONFIG_FILE="${TFM_MBEDCRYPTO_PSA_CRYPTO_CONFIG_PATH}">
         $<$<BOOL:${TFM_CRYPTO_TEST_UNSUPPORTED_ALG}>:TFM_CRYPTO_TEST_UNSUPPORTED_ALG>
         $<$<BOOL:${TFM_CRYPTO_TEST_ALG_DETERMINISTIC_ECDSA}>:TFM_CRYPTO_TEST_ALG_DETERMINISTIC_ECDSA>
         $<$<BOOL:${TFM_CRYPTO_TEST_ALG_ECDSA}>:TFM_CRYPTO_TEST_ALG_ECDSA>
diff --git a/tests_reg/test/secure_fw/suites/crypto/secure/CMakeLists.txt b/tests_reg/test/secure_fw/suites/crypto/secure/CMakeLists.txt
index a1b365d..b468e98 100644
--- a/tests_reg/test/secure_fw/suites/crypto/secure/CMakeLists.txt
+++ b/tests_reg/test/secure_fw/suites/crypto/secure/CMakeLists.txt
@@ -19,7 +19,7 @@
 
 target_include_directories(tfm_test_suite_crypto_s
     PUBLIC
-        .
+        ${CMAKE_CURRENT_LIST_DIR}
 )
 
 target_link_libraries(tfm_test_suite_crypto_s
@@ -28,6 +28,7 @@
         tfm_test_framework_s
         tfm_app_rot_partition_secure_client_2
         platform_s
+        psa_crypto_config
 )
 
 target_link_libraries(tfm_s_tests
@@ -53,7 +54,6 @@
         $<$<BOOL:${TFM_CRYPTO_TEST_ALG_CHACHA20_POLY1305}>:TFM_CRYPTO_TEST_ALG_CHACHA20_POLY1305>
         $<$<BOOL:${TFM_CRYPTO_TEST_ALG_RSASSA_PSS_VERIFICATION}>:TFM_CRYPTO_TEST_ALG_RSASSA_PSS_VERIFICATION>
         $<$<BOOL:${TFM_CRYPTO_TEST_SINGLE_PART_FUNCS}>:TFM_CRYPTO_TEST_SINGLE_PART_FUNCS>
-        $<$<BOOL:${TFM_MBEDCRYPTO_PSA_CRYPTO_CONFIG_PATH}>:MBEDTLS_PSA_CRYPTO_CONFIG_FILE="${TFM_MBEDCRYPTO_PSA_CRYPTO_CONFIG_PATH}">
         $<$<BOOL:${TFM_CRYPTO_TEST_UNSUPPORTED_ALG}>:TFM_CRYPTO_TEST_UNSUPPORTED_ALG>
         $<$<BOOL:${TFM_CRYPTO_TEST_ALG_DETERMINISTIC_ECDSA}>:TFM_CRYPTO_TEST_ALG_DETERMINISTIC_ECDSA>
         $<$<BOOL:${TFM_CRYPTO_TEST_ALG_ECDSA}>:TFM_CRYPTO_TEST_ALG_ECDSA>