cmake: Invoke compilations without echo and xargs

Newer versions of cmake provide a COMMAND_EXPAND_LISTS option that allows a quoted string,
such as "a;b" to be given to a COMMAND parameter and have it expand into multiple arguments.
Using this we can much more nicely generate some of our COMMAND invocations, at the cost of
requiring a more recent cmake version
This commit is contained in:
Adrian Danis
2017-11-02 16:50:13 +11:00
parent 2b6e302008
commit 89fb678db8
2 changed files with 12 additions and 12 deletions

View File

@@ -10,7 +10,7 @@
# @TAG(DATA61_GPL)
#
cmake_minimum_required(VERSION 3.7.2)
cmake_minimum_required(VERSION 3.8.2)
include(CheckCCompilerFlag)
project(seL4 C ASM)
@@ -354,16 +354,17 @@ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -T ${linker_lds_path}")
# Need a custom build command as we need to not have our already pre-processed file get
# processed again, which means either using a .ii file or explicitly saying -x cpp-output.
# Unfortunately and cmake doesn't understand .ii files directly so we do the latter approach
separate_arguments(args NATIVE_COMMAND "${custom_command_c_flags} ${CMAKE_C_FLAGS}")
add_custom_command(OUTPUT kernel_all.o
# Take the opportunity to check for circular includes
COMMAND ${CIRCULAR_INCLUDES} < kernel_all_pp.c
COMMAND echo "${custom_command_c_flags}" "${CMAKE_C_FLAGS}" -x cpp-output kernel_all_pp.c |
xargs ${ccache} ${CMAKE_C_COMPILER} -ffreestanding -c -o kernel_all.o
COMMAND ${ccache} ${CMAKE_C_COMPILER} -ffreestanding -c -o kernel_all.o "${args}" -x cpp-output kernel_all_pp.c
# Cannot make the kernel.elf executable properly depend upon the linker script so depend upon it
# here
DEPENDS kernel_all_pp.c kernel_all_pp_wrapper ${c_arguments_deps} linker_ld_wrapper "${linker_lds_path}"
VERBATIM
COMMENT "Compiling concatenated kernel sources"
COMMAND_EXPAND_LISTS
)
add_custom_target(kernel_all_wrapper

View File

@@ -10,7 +10,7 @@
# @TAG(DATA61_GPL)
#
cmake_minimum_required(VERSION 3.7.2)
cmake_minimum_required(VERSION 3.8.2)
include(CMakeDependentOption)
@@ -56,19 +56,18 @@ function(GenCPPCommand output input)
get_filename_component(output_absolute "${output}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
get_absolute_source_or_binary(input_absolute "${input}")
file(RELATIVE_PATH rel_target_path "${CMAKE_BINARY_DIR}" "${output_absolute}")
# The flags are stored as regular space separated command line. As we use COMMAND_EXPAND_LISTS
# in the COMMAND we need to first turn our arguments into a proper list for re-expansion
separate_arguments(args NATIVE_COMMAND "${CPP_EXTRA_FLAGS} ${CMAKE_C_FLAGS}")
add_custom_command(OUTPUT "${output_absolute}" OUTPUT "${output_absolute}.d"
# Pipe are arguments through sed to turn lists from generator expressions into
# proper space separated argument lists. Note that lists from generator expressions
# will *not* be separated by the separate_arguments cmake command since separate_arguments
# is invoke during generation, not during building and hence generator expressions will
# not yet be filled in
COMMAND echo "${CPP_EXTRA_FLAGS}" "${CMAKE_C_FLAGS}" -x c ${input_absolute}
| xargs "${CMAKE_C_COMPILER}" -MMD -MT "${rel_target_path}"
-MF "${output_absolute}.d" -E -o "${output_absolute}"
COMMAND "${CMAKE_C_COMPILER}" -MMD -MT "${rel_target_path}"
-MF "${output_absolute}.d" -E -o "${output_absolute}" "${args}"
-x c "${input_absolute}"
DEPENDS "${input_absolute}" ${CPP_EXTRA_DEPS}
COMMENT "Preprocessing ${input} into ${output}"
DEPFILE "${output_absolute}.d"
VERBATIM
COMMAND_EXPAND_LISTS
)
if(NOT "${CPP_TARGET}" STREQUAL "")
add_custom_target(${CPP_TARGET}