Implemented ARCHIVE_OUTPUT_DIRECTORY for uf2 output in CMake. Fixes #1012 (#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>
This commit is contained in:
Daniel Treffenstädt 2022-10-21 16:01:55 +02:00 committed by GitHub
parent 6d15974e96
commit a88baafc16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,12 +44,21 @@ function(pico_generate_pio_header TARGET PIO)
endfunction() endfunction()
function(pico_add_uf2_output TARGET) function(pico_add_uf2_output TARGET)
get_target_property(${TARGET}_archive_directory ${TARGET} ARCHIVE_OUTPUT_DIRECTORY)
if (${TARGET}_archive_directory)
get_filename_component(output_path "${${TARGET}_archive_directory}"
REALPATH BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
file(MAKE_DIRECTORY "${output_path}")
set(output_path "${output_path}/")
else()
set(output_path "")
endif()
if (NOT ELF2UF2_FOUND) if (NOT ELF2UF2_FOUND)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PICO_SDK_PATH}/tools) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PICO_SDK_PATH}/tools)
find_package(ELF2UF2) find_package(ELF2UF2)
endif() endif()
if (ELF2UF2_FOUND) if (ELF2UF2_FOUND)
add_custom_command(TARGET ${TARGET} POST_BUILD add_custom_command(TARGET ${TARGET} POST_BUILD
COMMAND ELF2UF2 $<TARGET_FILE:${TARGET}> $<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>>,$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>,$<TARGET_PROPERTY:${TARGET},NAME>>.uf2) COMMAND ELF2UF2 $<TARGET_FILE:${TARGET}> ${output_path}$<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>>,$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>,$<TARGET_PROPERTY:${TARGET},NAME>>.uf2)
endif() endif()
endfunction() endfunction()