diff --git a/CMakeLists.txt b/CMakeLists.txt index bf38665f454..3fb025d9abc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1298,7 +1298,12 @@ set_property(TARGET ${ZEPHYR_PREBUILT_EXECUTABLE} PROPERTY LINK_DEPENDS ${PROJ add_dependencies( ${ZEPHYR_PREBUILT_EXECUTABLE} ${ALIGN_SIZING_DEP} ${PRIV_STACK_DEP} ${LINKER_SCRIPT_TARGET} ${OFFSETS_LIB}) -if(GKOF OR GKSF) +set(generated_kernel_files ${GKSF} ${GKOF}) +if(NOT generated_kernel_files) + # Use the prebuilt elf as the final elf since we don't have a + # generation stage. + set(logical_target_for_zephyr_elf ${ZEPHYR_PREBUILT_EXECUTABLE}) +else() set(KERNEL_ELF kernel_elf) set(logical_target_for_zephyr_elf ${KERNEL_ELF}) @@ -1334,18 +1339,16 @@ if(GKOF OR GKSF) target_link_libraries(${KERNEL_ELF} ${GKOF} ${TOPT} ${PROJECT_BINARY_DIR}/linker_pass_final.cmd ${zephyr_lnk} ${CODE_RELOCATION_DEP}) set_property(TARGET ${KERNEL_ELF} PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/linker_pass_final.cmd) add_dependencies( ${KERNEL_ELF} ${ALIGN_SIZING_DEP} ${PRIV_STACK_DEP} ${LINKER_PASS_FINAL_SCRIPT_TARGET}) -else() - set(logical_target_for_zephyr_elf ${ZEPHYR_PREBUILT_EXECUTABLE}) - # Use the prebuilt elf as the final elf since we don't have a - # generation stage. endif() # Export the variable to the application's scope to allow the # application to know what the name of the final elf target is. set(logical_target_for_zephyr_elf ${logical_target_for_zephyr_elf} PARENT_SCOPE) -# To avoid having the same logical target name for the zephyr lib and -# the zephyr elf, we set the kernel_elf file name to zephyr.elf. +# Override the base name of final .elf so: +# 1. it doesn't depend on the number of passes above and the +# post_build_commands below can always find it no matter which is it; +# 2. it can be defined in Kconfig set_target_properties(${logical_target_for_zephyr_elf} PROPERTIES OUTPUT_NAME ${KERNEL_NAME}) set(post_build_commands "") @@ -1412,11 +1415,14 @@ list(APPEND ${extra_post_build_commands} ) +# Add post_build_commands to post-process the final .elf file produced by +# either the ZEPHYR_PREBUILT_EXECUTABLE or the KERNEL_ELF executable +# targets above. add_custom_command( TARGET ${logical_target_for_zephyr_elf} POST_BUILD ${post_build_commands} - COMMENT "Generating files from zephyr.elf for board: ${BOARD}" + COMMENT "Generating files from ${KERNEL_ELF_NAME} for board: ${BOARD}" # NB: COMMENT only works for some CMake-Generators )