Clean extra output files #2504

Merged
will-v-pi merged 1 commit from clean-uf2s into develop 2025-06-18 17:07:34 -05:00
will-v-pi commented 2025-06-05 09:53:11 -05:00 (Migrated from github.com)

Add bin/uf2/dis/hex output files as byproducts, so they get cleaned up when using make clean (or similar)

This is only best-effort, because BYPRODUCTS doesn't support generator expressions (https://gitlab.kitware.com/cmake/cmake/-/issues/12877), so everything must be evaluated at the time pico_add_extra_outputs is called. This shouldn't have any ill effects, other than not cleaning up the extra output files if OUTPUT_NAME is set after calling pico_add_extra_outputs.

Add bin/uf2/dis/hex output files as byproducts, so they get cleaned up when using `make clean` (or similar) This is only best-effort, because `BYPRODUCTS` doesn't support generator expressions (https://gitlab.kitware.com/cmake/cmake/-/issues/12877), so everything must be evaluated at the time `pico_add_extra_outputs` is called. This shouldn't have any ill effects, other than not cleaning up the extra output files if `OUTPUT_NAME` is set after calling `pico_add_extra_outputs`.
kilograham (Migrated from github.com) reviewed 2025-06-18 09:06:09 -05:00
@ -22,2 +33,3 @@
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()
kilograham (Migrated from github.com) commented 2025-06-18 09:06:09 -05:00

seems like we could just use output_name instead of the generator expression now

seems like we could just use `output_name` instead of the generator expression now
will-v-pi (Migrated from github.com) reviewed 2025-06-18 09:31:46 -05:00
@ -22,2 +33,3 @@
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()
will-v-pi (Migrated from github.com) commented 2025-06-18 09:31:46 -05:00

Technically they could evaluate to different things, if you change OUTPUT_NAME property after calling pico_add_extra_outputs in you CMakeLists.txt, so I thought leaving the generator expressions in for the commands was probably best? If you do change it after, then your build will still work fine, but the extra outputs won't be cleaned.

Technically they could evaluate to different things, if you change `OUTPUT_NAME` property after calling `pico_add_extra_outputs` in you CMakeLists.txt, so I thought leaving the generator expressions in for the commands was probably best? If you do change it after, then your build will still work fine, but the extra outputs won't be cleaned.
kilograham (Migrated from github.com) reviewed 2025-06-18 09:36:07 -05:00
@ -22,2 +33,3 @@
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()
kilograham (Migrated from github.com) commented 2025-06-18 09:36:07 -05:00

oh ok - fair enough then

oh ok - fair enough then
kilograham (Migrated from github.com) approved these changes 2025-06-18 09:36:15 -05:00
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-raspberrypi/pico-sdk!2504
No description provided.