fix(build): Fix path of EL0 apps linker script
To create the linker scripts of EL0 apps, we copy the common script to
the binary directory then use arm_target_linker_script() which calls
arm_preprocess_source(). At the moment arm_preprocess_source() expects
the input to be in the source directory and doesn't work properly when
it is in the binary directory, because it tries to get a relative path
from CMAKE_CURRENT_SOURCE_DIR to the input, which in this case is in
CMAKE_CURRENT_BINARY_DIR. For example with:
CMAKE_CURRENT_SOURCE_DIR=/my/source/
CMAKE_CURRENT_BINARY_DIR=/path/to/build/
ATTEST_APP_LINKER_SCRIPT=/path/to/build/linker_attest.lds.i
then after:
file(RELATIVE_PATH preprocessed_source "${CMAKE_CURRENT_SOURCE_DIR}"
"${preprocessed_source}")
string(PREPEND preprocessed_source "${CMAKE_CURRENT_BINARY_DIR}/")
we end up with:
preprocessed_source=
/path/to/build/../../path/to/build/linker_attest.lds.i
whose directory doesn't exist, resulting in the error:
CMake Error at app/attestation/el0_app/CMakeLists.txt:145 (file):
file failed to create directory:
/path/to/build/../../path/to/build/linker_attest.lds.i
because: No such file or directory
Since we preprocess the source script we don't actually need the extra
step of copying the common script, we can just give it as input to the
preprocessor. Pass the common script as argument and rework the output
path calculation.
Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
Change-Id: Iec6ce7f695b1316e4e4efcf5b3b7185b3d5f6aa1
diff --git a/cmake/Modules/ArmPreprocessSource.cmake b/cmake/Modules/ArmPreprocessSource.cmake
index a3f511b..a950246 100644
--- a/cmake/Modules/ArmPreprocessSource.cmake
+++ b/cmake/Modules/ArmPreprocessSource.cmake
@@ -22,6 +22,9 @@
target. The output file can be retrieved from the :prop_tgt:`LOCATION_<CONFIG>
<prop_tgt:LOCATION_<CONFIG>>` target property.
+The path of the output file is built using only the file name of the source, so
+the source does not have to be in CMAKE_CURRENT_SOURCE_DIR.
+
The following target properties are passed to the preprocessor:
- :prop_tgt:`COMPILE_OPTIONS <prop_tgt:COMPILE_OPTIONS>`
@@ -55,16 +58,11 @@
include_guard()
macro(arm_preprocess_source target source)
- #
- # We start by trying to get the source file relative to the current source
- # directory, which means that we can mirror where it goes in the binary
- # directory. This just replicates what CMake does with source files it's
- # aware of.
- #
-
- get_filename_component(preprocessed_source "${source}.i" ABSOLUTE)
- file(RELATIVE_PATH preprocessed_source "${CMAKE_CURRENT_SOURCE_DIR}"
- "${preprocessed_source}")
+ ##
+ ## Create the output file path from the basename of the source, and the
+ ## current binary directory.
+ ##
+ get_filename_component(preprocessed_source "${source}.i" NAME)
#
# If we're using a multi-config generator, we need to place the output file