Skip to content

Clean extra output files #2504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/cmake/on_device.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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()

Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()

Expand Down
1 change: 1 addition & 0 deletions tools/extract_cmake_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"pico_init_picotool",
"pico_add_platform_library",
"pico_get_runtime_output_directory",
"pico_get_output_name",
"pico_set_printf_implementation",
"pico_expand_pico_platform",
])
Expand Down
Loading