mirror of
https://github.com/raspberrypi/pico-sdk.git
synced 2025-08-06 06:02:39 +03:00
Clean extra output files (#2504)
Add bin/uf2/dis/hex output files as byproducts, so they get cleaned up This is only best-effort, because BYPRODUCTS doesn't support generator expressions, so everything must be evaluated at the time pico_add_extra_outputs is called
This commit is contained in:
@@ -15,24 +15,38 @@ function(pico_get_runtime_output_directory TARGET output_path_name)
|
||||
set(${output_path_name} ${output_path} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(pico_get_output_name TARGET output_name_var)
|
||||
get_target_property(output_name ${TARGET} OUTPUT_NAME)
|
||||
# Generator expressions not supported in byproducts
|
||||
set(output_name_copy ${output_name})
|
||||
string(GENEX_STRIP "${output_name}" output_name)
|
||||
if (NOT output_name OR (NOT output_name STREQUAL output_name_copy))
|
||||
get_target_property(output_name ${TARGET} NAME)
|
||||
endif()
|
||||
set(${output_name_var} ${output_name} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# pico_add_hex_output(TARGET)
|
||||
# \brief\ Generate a hex file for the target
|
||||
function(pico_add_hex_output TARGET)
|
||||
pico_get_runtime_output_directory(${TARGET} output_path)
|
||||
add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_OBJCOPY} -Oihex $<TARGET_FILE:${TARGET}> ${output_path}$<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>>,$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>,$<TARGET_PROPERTY:${TARGET},NAME>>.hex VERBATIM)
|
||||
pico_get_output_name(${TARGET} output_name)
|
||||
add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_OBJCOPY} -Oihex $<TARGET_FILE:${TARGET}> ${output_path}$<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>>,$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>,$<TARGET_PROPERTY:${TARGET},NAME>>.hex VERBATIM BYPRODUCTS "${output_path}${output_name}.hex")
|
||||
endfunction()
|
||||
|
||||
# pico_add_bin_output(TARGET)
|
||||
# \brief\ Generate a bin file for the target
|
||||
function(pico_add_bin_output TARGET)
|
||||
pico_get_runtime_output_directory(${TARGET} output_path)
|
||||
add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${TARGET}> ${output_path}$<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>>,$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>,$<TARGET_PROPERTY:${TARGET},NAME>>.bin VERBATIM)
|
||||
pico_get_output_name(${TARGET} output_name)
|
||||
add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${TARGET}> ${output_path}$<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>>,$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>,$<TARGET_PROPERTY:${TARGET},NAME>>.bin VERBATIM BYPRODUCTS "${output_path}${output_name}.bin")
|
||||
endfunction()
|
||||
|
||||
# pico_add_dis_output(TARGET)
|
||||
# \brief\ Generate a disassembly file for the target
|
||||
function(pico_add_dis_output TARGET)
|
||||
pico_get_runtime_output_directory(${TARGET} output_path)
|
||||
pico_get_output_name(${TARGET} output_name)
|
||||
|
||||
# PICO_CMAKE_CONFIG: PICO_NO_COPRO_DIS, Disable disassembly listing postprocessing that disassembles RP2350 coprocessor instructions, type=bool, default=0, group=build
|
||||
if (NOT (PICO_NO_COPRO_DIS OR PICO_NO_PICOTOOL OR PICO_RISCV OR PICO_RP2040))
|
||||
@@ -48,6 +62,7 @@ function(pico_add_dis_output TARGET)
|
||||
COMMAND ${CMAKE_OBJDUMP} -d ${PICO_DISASM_OBJDUMP_ARGS} $<TARGET_FILE:${TARGET}> >> ${output_path}$<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>>,$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>,$<TARGET_PROPERTY:${TARGET},NAME>>.dis
|
||||
${EXTRA_COMMAND}
|
||||
VERBATIM
|
||||
BYPRODUCTS "${output_path}${output_name}.dis"
|
||||
)
|
||||
endfunction()
|
||||
|
||||
@@ -88,6 +103,7 @@ function(pico_add_extra_outputs TARGET)
|
||||
COMMAND rm -f "${PICO_SYMLINK_ELF_AS_FILENAME}"
|
||||
COMMAND ln -s -r $<TARGET_FILE:${TARGET}> "${PICO_SYMLINK_ELF_AS_FILENAME}"
|
||||
COMMENT "Symlinking from ${PICO_SYMLINK_ELF_AS_FILENAME} to ${TARGET}"
|
||||
BYPRODUCTS "${PICO_SYMLINK_ELF_AS_FILENAME}"
|
||||
)
|
||||
endif ()
|
||||
# PICO_CMAKE_CONFIG: PICO_NO_UF2, Disable UF2 output, type=bool, default=0, group=build
|
||||
|
@@ -556,6 +556,7 @@ function(pico_add_uf2_output TARGET)
|
||||
else()
|
||||
set(output_path "")
|
||||
endif()
|
||||
pico_get_output_name(${TARGET} output_name)
|
||||
|
||||
get_target_property(${TARGET}_uf2_package_addr ${TARGET} PICOTOOL_UF2_PACKAGE_ADDR)
|
||||
if (${TARGET}_uf2_package_addr)
|
||||
@@ -594,7 +595,8 @@ function(pico_add_uf2_output TARGET)
|
||||
--family ${picotool_family}
|
||||
${extra_uf2_args}
|
||||
COMMAND_EXPAND_LISTS
|
||||
VERBATIM)
|
||||
VERBATIM
|
||||
BYPRODUCTS "${output_path}${output_name}.uf2")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
|
@@ -57,6 +57,7 @@ allowed_missing_functions = set([
|
||||
"pico_init_picotool",
|
||||
"pico_add_platform_library",
|
||||
"pico_get_runtime_output_directory",
|
||||
"pico_get_output_name",
|
||||
"pico_set_printf_implementation",
|
||||
"pico_expand_pico_platform",
|
||||
])
|
||||
|
Reference in New Issue
Block a user