Skip to content

Commit

Permalink
Add program target for romfs image in CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
NidasioAlberto committed Oct 19, 2024
1 parent fd9e6e5 commit 855bdb4
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 15 deletions.
49 changes: 49 additions & 0 deletions miosix/cmake/AddProgramTarget.cmake
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>

# Creates a custom target to program the board
#
# miosix_add_program_target(<target> [DEPENDS <target1> <target2> ...])
#
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 <binary> 0x8000000)
endif()

list(TRANSFORM PROGRAM_CMDLINE REPLACE <binary> ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.bin)
list(TRANSFORM PROGRAM_CMDLINE REPLACE <hex> ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.hex)

add_custom_target(${TARGET}_program ${PROGRAM_CMDLINE}
DEPENDS ${PROGRAM_DEPENDS}
VERBATIM
)
endfunction()
4 changes: 4 additions & 0 deletions miosix/cmake/AddRomfsImage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# along with this program; if not, see <http://www.gnu.org/licenses/>

include(ExternalProject)
include(AddProgramTarget)
include(CreateProcessesDir)

# Create a target that builds the buildromfs tool
Expand Down Expand Up @@ -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()
16 changes: 1 addition & 15 deletions miosix/cmake/LinkTarget.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,7 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>

# 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 <binary> 0x8000000)
endif()

list(TRANSFORM PROGRAM_CMDLINE REPLACE <binary> ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.bin)
list(TRANSFORM PROGRAM_CMDLINE REPLACE <hex> ${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
#
Expand Down

0 comments on commit 855bdb4

Please sign in to comment.