QCBOR: Link qcbor against test suite library

Reduce dependency of NS app in case of default config build.

Change-Id: Ib02e3dcdd2255385fe9c99a9fb1a753ee4de3b15
Signed-off-by: Tamas Ban <tamas.ban@arm.com>
diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt
index df8f1e7..4e1e4fd 100644
--- a/app/CMakeLists.txt
+++ b/app/CMakeLists.txt
@@ -166,7 +166,7 @@
 	set(VENEER_NAME ${_MY_PARAMS_VENEER_NAME}${_MY_PARAMS_POSTFIX}.o)
 
 	#Create linker target: add object library to executable
-	add_executable(${EXE_NAME} $<TARGET_OBJECTS:${PROJECT_OBJ_LIB}> $<TARGET_OBJECTS:tfm_qcbor>)
+	add_executable(${EXE_NAME} $<TARGET_OBJECTS:${PROJECT_OBJ_LIB}>)
 
 	#Set common linker flags
 	config_setting_shared_linker_flags(${EXE_NAME})
@@ -279,10 +279,6 @@
 	add_subdirectory(../secure_fw ${CMAKE_CURRENT_BINARY_DIR}/secure_fw)
 endif()
 
-if (NOT TARGET tfm_qcbor)
-	add_subdirectory(${TFM_ROOT_DIR}/lib/ext/qcbor ${CMAKE_CURRENT_BINARY_DIR}/qcbor)
-endif()
-
 if (LINK_TO_BOTH_MEMORY_REGION)
 	#Link to primary memory region
 	set_up_app_build(NS_TARGET     ${PROJECT_NAME}
diff --git a/secure_fw/services/initial_attestation/CMakeLists.txt b/secure_fw/services/initial_attestation/CMakeLists.txt
index e4b4ff5..905d5df 100644
--- a/secure_fw/services/initial_attestation/CMakeLists.txt
+++ b/secure_fw/services/initial_attestation/CMakeLists.txt
@@ -30,7 +30,9 @@
 	message(FATAL_ERROR "Incomplete build configuration: TFM_LVL is undefined.")
 endif()
 
-add_subdirectory(${TFM_ROOT_DIR}/lib/ext/qcbor ${CMAKE_CURRENT_BINARY_DIR}/qcbor)
+if (NOT TARGET tfm_qcbor)
+	add_subdirectory(${TFM_ROOT_DIR}/lib/ext/qcbor ${CMAKE_CURRENT_BINARY_DIR}/qcbor)
+endif()
 
 if (NOT TARGET tfm_t_cose_sign)
 	add_subdirectory(${TFM_ROOT_DIR}/lib/t_cose ${CMAKE_CURRENT_BINARY_DIR}/t_cose)
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index f489f24..8f3fdf5 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -58,7 +58,13 @@
 	add_subdirectory(${TFM_ROOT_DIR}/lib/t_cose ${CMAKE_CURRENT_BINARY_DIR}/t_cose)
 endif()
 
-#Build the secure library
+if (NOT TARGET tfm_qcbor)
+	add_subdirectory(${TFM_ROOT_DIR}/lib/ext/qcbor ${CMAKE_CURRENT_BINARY_DIR}/qcbor)
+endif()
+
+#Build the secure library. Even though secure tests files depend on tfm_qcbor,
+#this is not expressed here as the tfm_attest library is expected to hold the
+#compiled tfm_qcbor files.
 add_library(tfm_secure_tests STATIC ${ALL_SRC_C} ${ALL_SRC_C_S} $<TARGET_OBJECTS:tfm_t_cose_verify>)
 
 #Set common compiler and linker flags
@@ -70,7 +76,7 @@
 
 #Build the non-secure library
 set(CMAKE_STATIC_LIBRARY_PREFIX_C "lib")
-add_library(tfm_non_secure_tests STATIC ${ALL_SRC_C} ${ALL_SRC_C_NS} $<TARGET_OBJECTS:tfm_t_cose_verify>)
+add_library(tfm_non_secure_tests STATIC ${ALL_SRC_C} ${ALL_SRC_C_NS} $<TARGET_OBJECTS:tfm_t_cose_verify> $<TARGET_OBJECTS:tfm_qcbor>)
 
 #Set common compiler and linker flags
 config_setting_shared_compiler_flags(tfm_non_secure_tests)