Skip to content

Commit 02a8b6c

Browse files
committed
Clean extra output files
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
1 parent a9146b6 commit 02a8b6c

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

src/cmake/on_device.cmake

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,38 @@ function(pico_get_runtime_output_directory TARGET output_path_name)
1515
set(${output_path_name} ${output_path} PARENT_SCOPE)
1616
endfunction()
1717

18+
function(pico_get_output_name TARGET output_name_var)
19+
get_target_property(output_name ${TARGET} OUTPUT_NAME)
20+
# Generator expressions not supported in byproducts
21+
set(output_name_copy ${output_name})
22+
string(GENEX_STRIP "${output_name}" output_name)
23+
if (NOT output_name OR (NOT output_name STREQUAL output_name_copy))
24+
get_target_property(output_name ${TARGET} NAME)
25+
endif()
26+
set(${output_name_var} ${output_name} PARENT_SCOPE)
27+
endfunction()
28+
1829
# pico_add_hex_output(TARGET)
1930
# \brief\ Generate a hex file for the target
2031
function(pico_add_hex_output TARGET)
2132
pico_get_runtime_output_directory(${TARGET} output_path)
22-
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)
33+
pico_get_output_name(${TARGET} output_name)
34+
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")
2335
endfunction()
2436

2537
# pico_add_bin_output(TARGET)
2638
# \brief\ Generate a bin file for the target
2739
function(pico_add_bin_output TARGET)
2840
pico_get_runtime_output_directory(${TARGET} output_path)
29-
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)
41+
pico_get_output_name(${TARGET} output_name)
42+
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")
3043
endfunction()
3144

3245
# pico_add_dis_output(TARGET)
3346
# \brief\ Generate a disassembly file for the target
3447
function(pico_add_dis_output TARGET)
3548
pico_get_runtime_output_directory(${TARGET} output_path)
49+
pico_get_output_name(${TARGET} output_name)
3650

3751
# PICO_CMAKE_CONFIG: PICO_NO_COPRO_DIS, Disable disassembly listing postprocessing that disassembles RP2350 coprocessor instructions, type=bool, default=0, group=build
3852
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)
4862
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
4963
${EXTRA_COMMAND}
5064
VERBATIM
65+
BYPRODUCTS "${output_path}${output_name}.dis"
5166
)
5267
endfunction()
5368

@@ -88,6 +103,7 @@ function(pico_add_extra_outputs TARGET)
88103
COMMAND rm -f "${PICO_SYMLINK_ELF_AS_FILENAME}"
89104
COMMAND ln -s -r $<TARGET_FILE:${TARGET}> "${PICO_SYMLINK_ELF_AS_FILENAME}"
90105
COMMENT "Symlinking from ${PICO_SYMLINK_ELF_AS_FILENAME} to ${TARGET}"
106+
BYPRODUCTS "${PICO_SYMLINK_ELF_AS_FILENAME}"
91107
)
92108
endif ()
93109
# PICO_CMAKE_CONFIG: PICO_NO_UF2, Disable UF2 output, type=bool, default=0, group=build

tools/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ function(pico_add_uf2_output TARGET)
556556
else()
557557
set(output_path "")
558558
endif()
559+
pico_get_output_name(${TARGET} output_name)
559560

560561
get_target_property(${TARGET}_uf2_package_addr ${TARGET} PICOTOOL_UF2_PACKAGE_ADDR)
561562
if (${TARGET}_uf2_package_addr)
@@ -594,7 +595,8 @@ function(pico_add_uf2_output TARGET)
594595
--family ${picotool_family}
595596
${extra_uf2_args}
596597
COMMAND_EXPAND_LISTS
597-
VERBATIM)
598+
VERBATIM
599+
BYPRODUCTS "${output_path}${output_name}.uf2")
598600
endif()
599601
endfunction()
600602

tools/extract_cmake_functions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"pico_init_picotool",
5151
"pico_add_platform_library",
5252
"pico_get_runtime_output_directory",
53+
"pico_get_output_name",
5354
"pico_set_printf_implementation",
5455
"pico_expand_pico_platform",
5556
])

0 commit comments

Comments
 (0)