From a0b9129e857428bc49fcc4f1b13e72e30055e8fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B8e?= Date: Sun, 31 Dec 2017 10:56:32 +0100 Subject: [PATCH] cmake: Ninja: ld: Use the correct depfile in the second pass MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When building for Ninja we were accidentally using the wrong depfile in the second pass. This commit moves the LINKER_SCRIPT_DEP logic into the custom command function so that it can be linker-pass-aware and set the depfile appropriately. This should fix an issue where Ninja reported: ninja: error: expected depfile 'zephyr/linker.cmd.dep' to mention 'zephyr/linker_pass2.cmd', got 'zephyr/linker.cmd' But this has not been reproduced. It has however been confirmed that a dependency issue with linker_pass2.cmd has been fixed because ninja no longer regenerates linker_pass2.cmd on every build like this: $ ninja [1/79] Generating always_rebuild Building for board qemu_x86 [2/3] Generating linker_pass2.cmd [3/3] Linking C executable zephyr/zephyr.elf Now: $ ninja [1/78] Generating always_rebuild Building for board qemu_x86 Signed-off-by: Sebastian Bøe --- CMakeLists.txt | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 08a9eababa..04d4753d1c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -404,25 +404,6 @@ endforeach() get_property(OUTPUT_FORMAT GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT) -# Run the pre-processor on the linker script -# -# Deal with the un-preprocessed linker scripts differently with -# different generators. -if(CMAKE_GENERATOR STREQUAL "Unix Makefiles") - # Note that the IMPLICIT_DEPENDS option is currently supported only - # for Makefile generators and will be ignored by other generators. - set(LINKER_SCRIPT_DEP IMPLICIT_DEPENDS C ${LINKER_SCRIPT}) -elseif(CMAKE_GENERATOR STREQUAL "Ninja") - # Using DEPFILE with other generators than Ninja is an error. - set(LINKER_SCRIPT_DEP DEPFILE ${PROJECT_BINARY_DIR}/linker.cmd.dep) -else() - # TODO: How would the linker script dependencies work for non-linker - # script generators. - message(STATUS "Warning; this generator is not well supported. The - Linker script may not be regenerated when it should.") - set(LINKER_SCRIPT_DEP "") -endif() - get_property(LINKER_SCRIPT_DEFINES GLOBAL PROPERTY PROPERTY_LINKER_SCRIPT_DEFINES) if(CONFIG_APPLICATION_MEMORY) @@ -529,6 +510,22 @@ function(construct_add_custom_command_for_linker_pass linker_pass_number output_ set(LINKER_PASS_DEFINE -DLINKER_PASS${linker_pass_number}) endif() + # Different generators deal with depfiles differently. + if(CMAKE_GENERATOR STREQUAL "Unix Makefiles") + # Note that the IMPLICIT_DEPENDS option is currently supported only + # for Makefile generators and will be ignored by other generators. + set(LINKER_SCRIPT_DEP IMPLICIT_DEPENDS C ${LINKER_SCRIPT}) + elseif(CMAKE_GENERATOR STREQUAL "Ninja") + # Using DEPFILE with other generators than Ninja is an error. + set(LINKER_SCRIPT_DEP DEPFILE ${PROJECT_BINARY_DIR}/${linker_cmd_file_name}.dep) + else() + # TODO: How would the linker script dependencies work for non-linker + # script generators. + message(STATUS "Warning; this generator is not well supported. The + Linker script may not be regenerated when it should.") + set(LINKER_SCRIPT_DEP "") + endif() + set(${output_variable} OUTPUT ${linker_cmd_file_name} DEPENDS ${LINKER_SCRIPT}