From a88baafc169f4543503e75c2936f677868781dbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Treffenst=C3=A4dt?= <52167116+dtreffenstaedt@users.noreply.github.com> Date: Fri, 21 Oct 2022 16:01:55 +0200 Subject: [PATCH] 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 --- tools/CMakeLists.txt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index bc49c98..3ae3b0a 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -44,12 +44,21 @@ function(pico_generate_pio_header TARGET PIO) endfunction() 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) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PICO_SDK_PATH}/tools) find_package(ELF2UF2) endif() if (ELF2UF2_FOUND) add_custom_command(TARGET ${TARGET} POST_BUILD - COMMAND ELF2UF2 $ $>,$,$>.uf2) + COMMAND ELF2UF2 $ ${output_path}$>,$,$>.uf2) endif() endfunction()