From 855bdb4f55bce276c91442f3cc0881e5791fabcf Mon Sep 17 00:00:00 2001 From: Alberto Nidasio Date: Sat, 19 Oct 2024 21:12:39 +0200 Subject: [PATCH] Add program target for romfs image in CMake --- miosix/cmake/AddProgramTarget.cmake | 49 +++++++++++++++++++++++++++++ miosix/cmake/AddRomfsImage.cmake | 4 +++ miosix/cmake/LinkTarget.cmake | 16 +--------- 3 files changed, 54 insertions(+), 15 deletions(-) create mode 100644 miosix/cmake/AddProgramTarget.cmake diff --git a/miosix/cmake/AddProgramTarget.cmake b/miosix/cmake/AddProgramTarget.cmake new file mode 100644 index 000000000..b02fea466 --- /dev/null +++ b/miosix/cmake/AddProgramTarget.cmake @@ -0,0 +1,49 @@ +# Copyright (C) 2024 by Skyward +# +# This program is free software; you can redistribute it and/or +# it under the terms of the GNU General Public License as published +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# As a special exception, if other files instantiate templates or use +# macros or inline functions from this file, or you compile this file +# and link it with other works to produce a work based on this file, +# this file does not by itself cause the resulting work to be covered +# by the GNU General Public License. However the source code for this +# file must still be made available in accordance with the GNU +# Public License. This exception does not invalidate any other +# why a work based on this file might be covered by the GNU General +# Public License. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see + +# Creates a custom target to program the board +# +# miosix_add_program_target( [DEPENDS ...]) +# +function(miosix_add_program_target TARGET) + cmake_parse_arguments(PROGRAM "" "" "DEPENDS" ${ARGN}) + + if(NOT PROGRAM_DEPENDS) + set(PROGRAM_DEPENDS ${TARGET}_bin ${TARGET}_hex) + endif() + + get_target_property(PROGRAM_CMDLINE miosix PROGRAM_CMDLINE) + if(PROGRAM_CMDLINE STREQUAL "PROGRAM_CMDLINE-NOTFOUND") + set(PROGRAM_CMDLINE st-flash --connect-under-reset --reset write 0x8000000) + endif() + + list(TRANSFORM PROGRAM_CMDLINE REPLACE ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.bin) + list(TRANSFORM PROGRAM_CMDLINE REPLACE ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.hex) + + add_custom_target(${TARGET}_program ${PROGRAM_CMDLINE} + DEPENDS ${PROGRAM_DEPENDS} + VERBATIM + ) +endfunction() diff --git a/miosix/cmake/AddRomfsImage.cmake b/miosix/cmake/AddRomfsImage.cmake index 40a5ec01e..5132361ee 100644 --- a/miosix/cmake/AddRomfsImage.cmake +++ b/miosix/cmake/AddRomfsImage.cmake @@ -24,6 +24,7 @@ # along with this program; if not, see include(ExternalProject) +include(AddProgramTarget) include(CreateProcessesDir) # Create a target that builds the buildromfs tool @@ -79,4 +80,7 @@ function(miosix_add_romfs_image) # Create the custom romfs target add_custom_target(${ROMFS_IMAGE_NAME} ALL DEPENDS ${PROJECT_BINARY_DIR}/${ROMFS_IMAGE_NAME}.bin) + + # And a target to flash the image + miosix_add_program_target(${ROMFS_IMAGE_NAME} TARGETS ${ROMFS_IMAGE_NAME}) endfunction() diff --git a/miosix/cmake/LinkTarget.cmake b/miosix/cmake/LinkTarget.cmake index 43cc35e94..a9ffad8ec 100644 --- a/miosix/cmake/LinkTarget.cmake +++ b/miosix/cmake/LinkTarget.cmake @@ -23,21 +23,7 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, see -# Creates a custom target to program the board -function(miosix_add_program_target TARGET) - get_target_property(PROGRAM_CMDLINE miosix PROGRAM_CMDLINE) - if(PROGRAM_CMDLINE STREQUAL "PROGRAM_CMDLINE-NOTFOUND") - set(PROGRAM_CMDLINE st-flash --connect-under-reset --reset write 0x8000000) - endif() - - list(TRANSFORM PROGRAM_CMDLINE REPLACE ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.bin) - list(TRANSFORM PROGRAM_CMDLINE REPLACE ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.hex) - - add_custom_target(${TARGET}_program ${PROGRAM_CMDLINE} - DEPENDS ${TARGET}_bin ${TARGET}_hex - VERBATIM - ) -endfunction() +include(AddProgramTarget) # Function to link the Miosix libraries to a target and register the build command #