ARM-software/MDK-Middleware

HTTP-Server file system using `fcarm` utility via CMakeLists.txt template in `execute` node for pre-processing

jkrech opened this issue · 1 comments

Action: add CMakeLists.txt as a component template to the Network component for pre-build step creating a
HTTP-Server file system using fcarm utility in execute node. (discussed in Open-CMSIS-Pack/devtools#1545)

In CMake Script Mode no configure or generate step is performed. It means adding targets and processing dependencies is not supported.
For certain use cases, for example when handling a huge number of input files, it could be useful to use a standalone CMake project described via CMakeLists.txt instead of a CMake script.
In such case the input dependencies can be processed in the standalone project and for instance features like file globbing can be used.

For example the execute node could be like this:

    - execute: Run FCARM
      run: ${CMAKE_COMMAND} -G Ninja -S ${INPUT_0} -B ${CMAKE_CURRENT_BINARY_DIR}/fcarm-cmake -DINPUT_DIRECTORY=${INPUT_1} -DOUTPUT=${OUTPUT} && cmake --build ${CMAKE_CURRENT_BINARY_DIR}/fcarm-cmake -- --quiet
      always:
      input:
        - fcarm-cmake
        - Web
      output:
        - project/Web.c

And the fcarm-cmake/CMakeLists.txt:

cmake_minimum_required(VERSION 3.22)
include(ExternalProject)
	
project("FCARM" NONE)

file(GLOB INPUT ${INPUT_DIRECTORY}/*)

foreach(ITEM ${INPUT})
  cmake_path(GET ITEM FILENAME FILE)
  list(APPEND FILES ${FILE})
endforeach()
string(REPLACE ";" "," FILES "${FILES}")

cmake_path(RELATIVE_PATH OUTPUT BASE_DIRECTORY ${INPUT_DIRECTORY} OUTPUT_VARIABLE RELATIVE_OUTPUT)
cmake_path(GET INPUT_DIRECTORY FILENAME INPUT_DIRECTORY_NAME)
cmake_path(GET INPUT_DIRECTORY PARENT_PATH WORKING_DIRECTORY)

add_custom_target(FCARM ALL DEPENDS ${OUTPUT})
add_custom_command(OUTPUT ${OUTPUT} DEPENDS ${INPUT}
  COMMAND fcarm ${FILES} TO ${RELATIVE_OUTPUT} RTE NOPRINT ROOT(${INPUT_DIRECTORY_NAME})
  WORKING_DIRECTORY ${WORKING_DIRECTORY}
)

Example: https://github.com/user-attachments/files/15874256/http-server.zip

Implemented by #38