cmake: add Zephyr image output files as byproducts

Export Zephyr image byproducts through `BYPRODUCT_<VAR>` cache
variables.

This allow external tools, such as sysbuild, to read information on
products produced by a Zephyr build from the image CMake cache.

For sysbuild, this means that all byproducts will be added to a phony
build target, which again allow sysbuild itself to depends on target
output and properly describe dependencies between byproducts and their
producing targets.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
Torsten Rasmussen 2023-04-13 12:10:08 +02:00 committed by Carles Cufí
commit b6095a878c
3 changed files with 49 additions and 0 deletions

View file

@ -1436,6 +1436,7 @@ target_link_libraries_ifdef(CONFIG_NATIVE_LIBRARY ${ZEPHYR_LINK_STAGE_EXECUTABLE
target_byproducts(TARGET ${ZEPHYR_LINK_STAGE_EXECUTABLE}
BYPRODUCTS ${PROJECT_BINARY_DIR}/${ZEPHYR_LINK_STAGE_EXECUTABLE}.map
)
set(BYPRODUCT_KERNEL_ELF_NAME "${PROJECT_BINARY_DIR}/${KERNEL_ELF_NAME}" CACHE FILEPATH "Kernel elf file" FORCE)
set_property(TARGET
${ZEPHYR_LINK_STAGE_EXECUTABLE}
PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/${ZEPHYR_CURRENT_LINKER_CMD}
@ -1582,6 +1583,7 @@ if(CONFIG_BUILD_OUTPUT_HEX OR BOARD_FLASH_RUNNER STREQUAL openocd)
post_build_byproducts
${KERNEL_HEX_NAME}
)
set(BYPRODUCT_KERNEL_HEX_NAME "${PROJECT_BINARY_DIR}/${KERNEL_HEX_NAME}" CACHE FILEPATH "Kernel hex file" FORCE)
endif()
endif()
@ -1603,6 +1605,7 @@ if(CONFIG_BUILD_OUTPUT_BIN)
post_build_byproducts
${KERNEL_BIN_NAME}
)
set(BYPRODUCT_KERNEL_BIN_NAME "${PROJECT_BINARY_DIR}/${KERNEL_BIN_NAME}" CACHE FILEPATH "Kernel binary file" FORCE)
endif()
endif()
@ -1635,6 +1638,7 @@ if(CONFIG_BUILD_OUTPUT_BIN AND CONFIG_BUILD_OUTPUT_UF2)
post_build_byproducts
${KERNEL_UF2_NAME}
)
set(BYPRODUCT_KERNEL_UF2_NAME "${PROJECT_BINARY_DIR}/${KERNEL_UF2_NAME}" CACHE FILEPATH "Kernel uf2 file" FORCE)
endif()
if(CONFIG_BUILD_OUTPUT_META)
@ -1684,6 +1688,7 @@ if(CONFIG_BUILD_OUTPUT_S19)
post_build_byproducts
${KERNEL_S19_NAME}
)
set(BYPRODUCT_KERNEL_S19_NAME "${PROJECT_BINARY_DIR}/${KERNEL_S19_NAME}" CACHE FILEPATH "Kernel s19 file" FORCE)
endif()
endif()
@ -1766,6 +1771,7 @@ if(CONFIG_BUILD_OUTPUT_EXE)
post_build_byproducts
${KERNEL_EXE_NAME}
)
set(BYPRODUCT_KERNEL_EXE_NAME "${PROJECT_BINARY_DIR}/${KERNEL_EXE_NAME}" CACHE FILEPATH "Kernel exe file" FORCE)
else()
if(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
set(MAKE "${CMAKE_MAKE_PROGRAM}" CACHE FILEPATH "cmake defined make")