Skip to content

Commit a88baaf

Browse files
Implemented ARCHIVE_OUTPUT_DIRECTORY for uf2 output in CMake. Fixes earlephilhower#1012 (earlephilhower#1036)
* Added ARCHIVE_OUTPUT_DIRECTORY to uf2 output in CMake This Commit enables the use of the ARCHIVE_OUTPUT_DIRECTORY target properties in CMake for the generation of uf2 files. The changeset in lines 47..51 is necessary due to CMake not automatically creating the ARCHIVE_OUTPUT_DIRECTORY if no archive target is present. * rework cmake changes to make it friendler for non absolute paths Co-authored-by: Graham Sanderson <graham.sanderson@raspberrypi.com>
1 parent 6d15974 commit a88baaf

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

tools/CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,21 @@ function(pico_generate_pio_header TARGET PIO)
4444
endfunction()
4545

4646
function(pico_add_uf2_output TARGET)
47+
get_target_property(${TARGET}_archive_directory ${TARGET} ARCHIVE_OUTPUT_DIRECTORY)
48+
if (${TARGET}_archive_directory)
49+
get_filename_component(output_path "${${TARGET}_archive_directory}"
50+
REALPATH BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
51+
file(MAKE_DIRECTORY "${output_path}")
52+
set(output_path "${output_path}/")
53+
else()
54+
set(output_path "")
55+
endif()
4756
if (NOT ELF2UF2_FOUND)
4857
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PICO_SDK_PATH}/tools)
4958
find_package(ELF2UF2)
5059
endif()
5160
if (ELF2UF2_FOUND)
5261
add_custom_command(TARGET ${TARGET} POST_BUILD
53-
COMMAND ELF2UF2 $<TARGET_FILE:${TARGET}> $<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>>,$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>,$<TARGET_PROPERTY:${TARGET},NAME>>.uf2)
62+
COMMAND ELF2UF2 $<TARGET_FILE:${TARGET}> ${output_path}$<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>>,$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>,$<TARGET_PROPERTY:${TARGET},NAME>>.uf2)
5463
endif()
5564
endfunction()

0 commit comments

Comments
 (0)