Skip to content

Commit

Permalink
CMake: create cpio archive in folder
Browse files Browse the repository at this point in the history
Do not pollute the root folder.

Signed-off-by: Axel Heider <[email protected]>
  • Loading branch information
Axel Heider committed Mar 23, 2023
1 parent fcc4968 commit 0a858c7
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions camkes_vm_helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,20 @@ function(DefineCAmkESVMFileServer)

# For legacy reasons, we add the files via AddToFileServer() here. Once day
# the function AddToFileServer() should be removed completely, as it is no
# longer needed. Insteat lists of files can be built in CMake lists and then
# these list can be passed here.
# longer needed. Instead, lists of files can be built in CMake lists and
# then these list can be passed here.
foreach(element IN LISTS PARAM_FILES)
foreach(item IN LISTS element) # [<CPIO_NAME>:]<FILENAME>
if(NOT item)
continue()
endif()
string(REGEX MATCH "^([^:]+)(:([^:]+))?$" cpio_item "${item}")
string(
REGEX
MATCH
"^([^:]+)(:([^:]+))?$"
cpio_item
"${item}"
)
if(NOT cpio_item)
message(FATAL_ERROR "invalid paramete format: '${item}'")
endif()
Expand All @@ -146,7 +152,6 @@ function(DefineCAmkESVMFileServer)
get_filename_component(CPIO_NAME "${FILE_NAME}" NAME)
endif()
# No need to pass dependencies here, we have already added them above.
message("##### ${CPIO_NAME} : ${FILE_NAME}")
AddToFileServer("${CPIO_NAME}" "${FILE_NAME}" INSTANCE "${PARAM_INSTANCE}")
endforeach()
endforeach()
Expand All @@ -165,7 +170,13 @@ function(DefineCAmkESVMFileServer)

set(CPIO_FILES "")
foreach(item IN LISTS files) # <CPIO_NAME>:<FILENAME>
string(REGEX MATCH "^([^:]+):([^:]+)$" cpio_item "${item}")
string(
REGEX
MATCH
"^([^:]+):([^:]+)$"
cpio_item
"${item}"
)
if(NOT cpio_item)
message(FATAL_ERROR "invalid CPIO file format: '${item}'")
endif()
Expand All @@ -180,16 +191,18 @@ function(DefineCAmkESVMFileServer)
VERBATIM
DEPENDS ${FILE_NAME} ${deps}
)
add_custom_target(copy_${PARAM_INSTANCE}_${CPIO_NAME} DEPENDS "${CPIO_FILE}")
# There is no need to create an explicit target for the command above,
# the archive creation depends on all files in CPIO_FILES, where the
# command above is the creation rule for each one.
list(APPEND CPIO_FILES "${CPIO_FILE}")
endforeach()

# Build CPIO archive. Unfortunately MakeCPIO() support plain file names only
# and does not support paths. Archive will be created in the built output
# root folder, where using BIN_DIR would be a bit cleaner actually.
set(CPIO_ARCHIVE "${PARAM_INSTANCE}_cpio_archive.o")
# Build CPIO archive. It implicitly depends on all files in CPIO_FILES,
# which have their own dependencies each from above. So we don't have any
# additional explicit dependencies here.
set(CPIO_ARCHIVE "${INST_BIN_DIR}/cpio_archive.o")
include(cpio)
MakeCPIO(${CPIO_ARCHIVE} "${CPIO_FILES}" DEPENDS "${deps}")
MakeCPIO(${CPIO_ARCHIVE} "${CPIO_FILES}")

# Build a library from the CPIO archive
set(FILESERVER_LIB "${PARAM_INSTANCE}_cpio")
Expand Down

0 comments on commit 0a858c7

Please sign in to comment.