Remove dependency on unsupported MbedTLS build interface
To build libmbedcrypto (part of MbedTLS) for different
deployments, it is necessary to provide a suitable TS project
defined configuration header file and include paths for PSA
storage. It turns out that we have been using an unsupported
CMake based interface to pass in the configuration path and
include paths (using 'thirdparty_inc' and 'thirdparty_defs'
cmake variables). These variables disappear in MbedTLS v3.0.0
so an alternative method is needed before upgrading.
MbedTLS doesn't currently provide its own cmake interface for
providing these parameters. This commit adds a general purpose
configuration interface that exploits the cmake toolchain file
functionality where the toolchain file is actioned early on
when a new cmake context is created. A common cmake file
called config_iface.cmake gets run when an environment's
toochain file is run. The caller may optionally define
the variables EXTERNAL_DEFINITIONS and EXTERNAL_INCLUDE_PATHS
to inject configuration parameters into the child cmake build.
This facility is used by the external component cmake file
for MbedTLS.
Signed-off-by: Julian Hall <julian.hall@arm.com>
Change-Id: I7356c0d1da23bc789090d3299b8e66f2e28ab979
diff --git a/environments/arm-linux/default_toolchain_file.cmake b/environments/arm-linux/default_toolchain_file.cmake
index d530b0d..7ac1621 100644
--- a/environments/arm-linux/default_toolchain_file.cmake
+++ b/environments/arm-linux/default_toolchain_file.cmake
@@ -16,3 +16,4 @@
set(CMAKE_CXX_FLAGS_INIT "-fdiagnostics-show-option -gdwarf-2 -mstrict-align -O0 -DARM64=1")
include($ENV{TS_ROOT}/tools/cmake/compiler/GCC.cmake REQUIRED)
+include($ENV{TS_ROOT}/tools/cmake/compiler/config_iface.cmake REQUIRED)
diff --git a/environments/linux-pc/default_toolchain_file.cmake b/environments/linux-pc/default_toolchain_file.cmake
index 93e716f..6978dbf 100644
--- a/environments/linux-pc/default_toolchain_file.cmake
+++ b/environments/linux-pc/default_toolchain_file.cmake
@@ -1,8 +1,8 @@
#-------------------------------------------------------------------------------
-# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
#-------------------------------------------------------------------------------
-# Empty.
+include($ENV{TS_ROOT}/tools/cmake/compiler/config_iface.cmake REQUIRED)
diff --git a/environments/opteesp/default_toolchain_file.cmake b/environments/opteesp/default_toolchain_file.cmake
index c73345f..34ca0c9 100644
--- a/environments/opteesp/default_toolchain_file.cmake
+++ b/environments/opteesp/default_toolchain_file.cmake
@@ -20,7 +20,7 @@
#set(CMAKE_EXE_LINKER_FLAGS_INIT --specs=nosys.specs)
include($ENV{TS_ROOT}/tools/cmake/compiler/GCC.cmake REQUIRED)
-
+include($ENV{TS_ROOT}/tools/cmake/compiler/config_iface.cmake REQUIRED)
# Set mandatory compiler and linker flags for this environment:
# - This environment uses a libc implementation from SPDEV-KIT. Disable standard
# include search paths, startup files and default libraries.
diff --git a/external/MbedTLS/MbedTLS.cmake b/external/MbedTLS/MbedTLS.cmake
index 45c1251..041af5c 100644
--- a/external/MbedTLS/MbedTLS.cmake
+++ b/external/MbedTLS/MbedTLS.cmake
@@ -57,42 +57,25 @@
set(PSA_CRYPTO_API_INCLUDE "${MBEDTLS_INSTALL_PATH}/include" CACHE STRING "PSA Crypto API include path")
#Configure the library
-if(NOT CMAKE_CROSSCOMPILING)
- execute_process(COMMAND
- ${CMAKE_COMMAND}
- -DENABLE_PROGRAMS=OFF
- -DENABLE_TESTING=OFF
- -DUNSAFE_BUILD=ON
- -DCMAKE_INSTALL_PREFIX=${MBEDTLS_INSTALL_PATH}
- -DCMAKE_TOOLCHAIN_FILE=${TS_EXTERNAL_LIB_TOOLCHAIN_FILE}
- -Dthirdparty_def=-DMBEDTLS_USER_CONFIG_FILE="${MBEDTLS_USER_CONFIG_FILE}"
- -Dthirdparty_inc=${MBEDTLS_EXTRA_INCLUDES}
- -GUnix\ Makefiles
- ${mbedtls_SOURCE_DIR}
- WORKING_DIRECTORY
- ${mbedtls_BINARY_DIR}
- )
-else()
- execute_process(COMMAND
- ${CMAKE_COMMAND}
- -DENABLE_PROGRAMS=OFF
- -DENABLE_TESTING=OFF
- -DUNSAFE_BUILD=ON
- -DCMAKE_INSTALL_PREFIX=${MBEDTLS_INSTALL_PATH}
- -DCMAKE_TOOLCHAIN_FILE=${TS_EXTERNAL_LIB_TOOLCHAIN_FILE}
- -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY
- -Dthirdparty_def=-DMBEDTLS_USER_CONFIG_FILE="${MBEDTLS_USER_CONFIG_FILE}"
- -Dthirdparty_inc=${MBEDTLS_EXTRA_INCLUDES}
- -GUnix\ Makefiles
- ${mbedtls_SOURCE_DIR}
- WORKING_DIRECTORY
- ${mbedtls_BINARY_DIR}
- RESULT_VARIABLE _exec_error
- )
+execute_process(COMMAND
+ ${CMAKE_COMMAND}
+ -DENABLE_PROGRAMS=OFF
+ -DENABLE_TESTING=OFF
+ -DUNSAFE_BUILD=ON
+ -DCMAKE_INSTALL_PREFIX=${MBEDTLS_INSTALL_PATH}
+ -DCMAKE_TOOLCHAIN_FILE=${TS_EXTERNAL_LIB_TOOLCHAIN_FILE}
+ -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY
+ -DEXTERNAL_DEFINITIONS=-DMBEDTLS_USER_CONFIG_FILE="${MBEDTLS_USER_CONFIG_FILE}"
+ -DEXTERNAL_INCLUDE_PATHS=${MBEDTLS_EXTRA_INCLUDES}
+ -GUnix\ Makefiles
+ ${mbedtls_SOURCE_DIR}
+ WORKING_DIRECTORY
+ ${mbedtls_BINARY_DIR}
+ RESULT_VARIABLE _exec_error
+)
- if (_exec_error)
- message(FATAL_ERROR "Configuration step of Mbed TLS failed with ${_exec_error}.")
- endif()
+if (_exec_error)
+ message(FATAL_ERROR "Configuration step of Mbed TLS failed with ${_exec_error}.")
endif()
#TODO: add dependency to generated project on this file!
diff --git a/tools/cmake/compiler/config_iface.cmake b/tools/cmake/compiler/config_iface.cmake
new file mode 100644
index 0000000..4afa799
--- /dev/null
+++ b/tools/cmake/compiler/config_iface.cmake
@@ -0,0 +1,15 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+# This provides a common interface for injecting definitions and include paths
+# into a cmake build for the purpose of applying an externally defined
+# build configuration. Although some cmake based external components provide
+# their own cmake based configuration interface, not all do. This file gets
+# included by environment specific cmake toolchain files that get actioned
+# early on when a new cmake build context is created.
+add_definitions(${EXTERNAL_DEFINITIONS})
+include_directories(${EXTERNAL_INCLUDE_PATHS})