Fix: Stop opteesp environment using default libc

The opteesp environment uses the libc implementation part of the
SPDEV-KIT. Projects targeting the opteesp environment shall be
configured to stop using the standard library and its header files
part of the compiler package.
This patch:
  - adds the missing compiler and linker options
  - adds header files missing from SPDEV-KITs libc implementation
  - extends the external component cmake files to align build options
    with the main project
  - moves environment specific mandatory flags to a common file
  - fixes the supported C standard from gnuc99 to c99

The following files where forked from TF-A
 (https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git; SHA: 7737fdf0ed):
- stdarg.h
- stdbool.h
- stddef.h
- stddef_.h

Signed-off-by: Andrew Beggs <andrew.beggs@arm.com>
Signed-off-by: Gyorgy Szing <Gyorgy.Szing@arm.com>
Change-Id: I3890453a29b003c60c8f44dfd19d553e96b1796c
diff --git a/deployments/attestation/opteesp/CMakeLists.txt b/deployments/attestation/opteesp/CMakeLists.txt
index 6852950..cd54450 100644
--- a/deployments/attestation/opteesp/CMakeLists.txt
+++ b/deployments/attestation/opteesp/CMakeLists.txt
@@ -85,16 +85,19 @@
 set(MBEDTLS_USER_CONFIG_FILE
 	"${TS_ROOT}/components/service/crypto/client/cpp/config_mbedtls_user.h"
 	CACHE STRING "Configuration file for mbedcrypto")
+list(APPEND MBEDTLS_EXTRA_INCLUDES ${SP_DEV_KIT_INCLUDE_DIR})
 
 # Mbed TLS provides libmbedcrypto
 include(../../../external/MbedTLS/MbedTLS.cmake)
 target_link_libraries(attestation PRIVATE mbedcrypto)
 
 # Qcbor
+set (QCBOR_EXTERNAL_INCLUDE_PATHS ${SP_DEV_KIT_INCLUDE_DIR})
 include(${TS_ROOT}/external/qcbor/qcbor.cmake)
 target_link_libraries(attestation PRIVATE qcbor)
 
 # t_cose
+set (TCOSE_EXTERNAL_INCLUDE_PATHS ${SP_DEV_KIT_INCLUDE_DIR})
 include(${TS_ROOT}/external/t_cose/t_cose.cmake)
 target_link_libraries(attestation PRIVATE t_cose)
 
@@ -117,19 +120,14 @@
 if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
 	target_compile_options(attestation PRIVATE
 		-fdiagnostics-show-option
-		-fpic
 		-gdwarf-2
 		-mstrict-align
 		-O0
-		-std=gnu99
+		-std=c99
 	)
 
 	# Options for GCC that control linking
 	target_link_options(attestation PRIVATE
-		-e __sp_entry
-		-fno-lto
-		-nostdlib
-		-pie
 		-zmax-page-size=4096
 	)
 	# Options directly for LD, these are not understood by GCC
diff --git a/deployments/crypto/opteesp/CMakeLists.txt b/deployments/crypto/opteesp/CMakeLists.txt
index 4eb1a51..8a857b8 100644
--- a/deployments/crypto/opteesp/CMakeLists.txt
+++ b/deployments/crypto/opteesp/CMakeLists.txt
@@ -81,11 +81,15 @@
 #-------------------------------------------------------------------------------
 
 # Nanopb
+list(APPEND NANOPB_EXTERNAL_INCLUDE_PATHS ${SP_DEV_KIT_INCLUDE_DIR})
 include(../../../external/nanopb/nanopb.cmake)
 target_link_libraries(crypto-sp PRIVATE nanopb::protobuf-nanopb-static)
 protobuf_generate_all(TGT "crypto-sp" NAMESPACE "protobuf" BASE_DIR "${TS_ROOT}/protocols")
 
 # Mbed TLS provides libmbedcrypto
+list(APPEND MBEDTLS_EXTRA_INCLUDES ${SP_DEV_KIT_INCLUDE_DIR})
+set(MBEDTLS_EXTRA_INCLUDES ${MBEDTLS_EXTRA_INCLUDES}
+	CACHE STRING "PSA ITS for Mbed TLS" FORCE)
 include(../../../external/MbedTLS/MbedTLS.cmake)
 target_link_libraries(crypto-sp PRIVATE mbedcrypto)
 
@@ -108,19 +112,14 @@
 if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
 	target_compile_options(crypto-sp PRIVATE
 		-fdiagnostics-show-option
-		-fpic
 		-gdwarf-2
 		-mstrict-align
 		-O0
-		-std=gnu99
+		-std=c99
 	)
 
 	# Options for GCC that control linking
 	target_link_options(crypto-sp PRIVATE
-		-e __sp_entry
-		-fno-lto
-		-nostdlib
-		-pie
 		-zmax-page-size=4096
 	)
 	# Options directly for LD, these are not understood by GCC
diff --git a/deployments/env-test/env_test.cmake b/deployments/env-test/env_test.cmake
index 9c0926b..ee46eba 100644
--- a/deployments/env-test/env_test.cmake
+++ b/deployments/env-test/env_test.cmake
@@ -44,5 +44,8 @@
 #-------------------------------------------------------------------------------
 
 # Mbed TLS provides libmbedcrypto
+list(APPEND MBEDTLS_EXTRA_INCLUDES ${SP_DEV_KIT_INCLUDE_DIR})
+set(MBEDTLS_EXTRA_INCLUDES ${MBEDTLS_EXTRA_INCLUDES}
+	CACHE STRING "PSA ITS for Mbed TLS" FORCE)
 include(${TS_ROOT}/external/MbedTLS/MbedTLS.cmake)
 target_link_libraries(env-test PRIVATE mbedcrypto)
diff --git a/deployments/env-test/opteesp/CMakeLists.txt b/deployments/env-test/opteesp/CMakeLists.txt
index 044fae0..1ec681b 100644
--- a/deployments/env-test/opteesp/CMakeLists.txt
+++ b/deployments/env-test/opteesp/CMakeLists.txt
@@ -85,20 +85,15 @@
 if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
 	target_compile_options(env-test PRIVATE
 		-fdiagnostics-show-option
-		-fpic
 		-gdwarf-2
 		-mstrict-align
 		-O0
-		$<$<COMPILE_LANGUAGE:C>:-std=gnu99>
+		$<$<COMPILE_LANGUAGE:C>:-std=c99>
 		$<$<COMPILE_LANGUAGE:CXX>:-fno-use-cxa-atexit>
 	)
 
 	# Options for GCC that control linking
 	target_link_options(env-test PRIVATE
-		-e __sp_entry
-		-fno-lto
-		-nostdlib
-		-pie
 		-zmax-page-size=4096
 	)
 	# Options directly for LD, these are not understood by GCC
diff --git a/deployments/internal-trusted-storage/opteesp/CMakeLists.txt b/deployments/internal-trusted-storage/opteesp/CMakeLists.txt
index 5b3450a..c86dcc4 100644
--- a/deployments/internal-trusted-storage/opteesp/CMakeLists.txt
+++ b/deployments/internal-trusted-storage/opteesp/CMakeLists.txt
@@ -64,19 +64,14 @@
 if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
 	target_compile_options(internal-trusted-storage PRIVATE
 		-fdiagnostics-show-option
-		-fpic
 		-gdwarf-2
 		-mstrict-align
 		-O0
-		-std=gnu99
+		-std=c99
 	)
 
 	# Options for GCC that control linking
 	target_link_options(internal-trusted-storage PRIVATE
-		-e __sp_entry
-		-fno-lto
-		-nostdlib
-		-pie
 		-zmax-page-size=4096
 	)
 	# Options directly for LD, these are not understood by GCC
diff --git a/deployments/libsp/opteesp/CMakeLists.txt b/deployments/libsp/opteesp/CMakeLists.txt
index f65713b..6f3907f 100644
--- a/deployments/libsp/opteesp/CMakeLists.txt
+++ b/deployments/libsp/opteesp/CMakeLists.txt
@@ -38,6 +38,7 @@
 	COMPONENTS
 		components/messaging/ffa/libsp
 		components/common/utils
+		environments/opteesp
 )
 
 target_compile_definitions("sp" PRIVATE
@@ -47,11 +48,10 @@
 if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
 	target_compile_options("sp" PRIVATE
 		-fdiagnostics-show-option
-		-fpic
 		-gdwarf-2
 		-mstrict-align
 		-O0
-		-std=gnu99
+		-std=c99
 	)
 endif()
 
diff --git a/deployments/protected-storage/opteesp/CMakeLists.txt b/deployments/protected-storage/opteesp/CMakeLists.txt
index 7106a01..740553b 100644
--- a/deployments/protected-storage/opteesp/CMakeLists.txt
+++ b/deployments/protected-storage/opteesp/CMakeLists.txt
@@ -65,19 +65,14 @@
 if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
 	target_compile_options(protected-storage PRIVATE
 		-fdiagnostics-show-option
-		-fpic
 		-gdwarf-2
 		-mstrict-align
 		-O0
-		-std=gnu99
+		-std=c99
 	)
 
 	# Options for GCC that control linking
 	target_link_options(protected-storage PRIVATE
-		-e __sp_entry
-		-fno-lto
-		-nostdlib
-		-pie
 		-zmax-page-size=4096
 	)
 	# Options directly for LD, these are not understood by GCC
diff --git a/deployments/sfs-demo/opteesp/CMakeLists.txt b/deployments/sfs-demo/opteesp/CMakeLists.txt
index 0eaefd3..47f4e9a 100644
--- a/deployments/sfs-demo/opteesp/CMakeLists.txt
+++ b/deployments/sfs-demo/opteesp/CMakeLists.txt
@@ -60,19 +60,14 @@
 if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
 	target_compile_options(sfs-demo PRIVATE
 		-fdiagnostics-show-option
-		-fpic
 		-gdwarf-2
 		-mstrict-align
 		-O0
-		-std=gnu99
+		-std=c99
 	)
 
 	# Options for GCC that control linking
 	target_link_options(sfs-demo PRIVATE
-		-e __sp_entry
-		-fno-lto
-		-nostdlib
-		-pie
 		-zmax-page-size=4096
 	)
 	# Options directly for LD, these are not understood by GCC