Skip to content

Commit

Permalink
CMake: remove AddToFileServer()
Browse files Browse the repository at this point in the history
With the new interface of DefineCAmkESVMFileServer() there is not need
to have AddToFileServer(). CMake lists with files can be built instead
and then passed to DefineCAmkESVMFileServer().

Signed-off-by: Axel Heider <[email protected]>
  • Loading branch information
Axel Heider committed Mar 30, 2023
1 parent c98e3de commit e4e1098
Showing 1 changed file with 15 additions and 113 deletions.
128 changes: 15 additions & 113 deletions camkes_vm_helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
cmake_minimum_required(VERSION 3.8.2)

set(VM_PROJECT_DIR "${CMAKE_CURRENT_LIST_DIR}" CACHE INTERNAL "")
if(NOT TARGET vm_fserver_config)
add_custom_target(vm_fserver_config)
endif()

# Function for declaring a CAmkESVM. This is called for each Init component in the applications
# camkes config.
Expand Down Expand Up @@ -117,13 +114,7 @@ function(DefineCAmkESVMFileServer)
set(PARAM_INSTANCE "fserv")
endif()

if(PARAM_DEPENDS)
set_property(
TARGET vm_fserver_config
APPEND
PROPERTY DEPS_${PARAM_INSTANCE} ${PARAM_DEPENDS}
)
endif()
set(INST_BIN_DIR "${CMAKE_CURRENT_BINARY_DIR}/${PARAM_INSTANCE}")

foreach(element IN LISTS PARAM_FILES)
foreach(item IN LISTS element) # [<CPIO_NAME>:]<FILENAME>
Expand All @@ -147,56 +138,22 @@ function(DefineCAmkESVMFileServer)
set(FILE_NAME "${CMAKE_MATCH_1}")
get_filename_component(CPIO_NAME "${FILE_NAME}" NAME)
endif()
# For legacy reasons, we still call AddToFileServer() here. It will
# simplify things a lot, if this function is removed completely. It
# is no longer needed, because we accept lists of files now., which
# the caller is supposed to build then. For now, AddToFileServer()
# is just a light wrapper that build such a list. Thus, there is no
# need to pass dependencies from PARAM_DEPENDS here, have added them
# above already.
AddToFileServer("${CPIO_NAME}" "${FILE_NAME}" INSTANCE "${PARAM_INSTANCE}")
endforeach()
endforeach()

# now process the file/deps list
get_target_property(files vm_fserver_config FILES_${PARAM_INSTANCE})
if(NOT files) # this also catches "files-NOTFOUND" if property is not set
set(files "")
endif()
get_target_property(deps vm_fserver_config DEPS_${PARAM_INSTANCE})
if(NOT deps) # this also catches "deps-NOTFOUND" if property is not set
set(deps "")
endif()

set(INST_BIN_DIR "${CMAKE_CURRENT_BINARY_DIR}/${PARAM_INSTANCE}")
set(CPIO_FILE "${INST_BIN_DIR}/files/${CPIO_NAME}")
add_custom_command(
OUTPUT "${CPIO_FILE}"
COMMENT "copy: ${FILE_NAME} -> ${CPIO_FILE}"
COMMAND
${CMAKE_COMMAND} -E copy "${FILE_NAME}" "${CPIO_FILE}"
VERBATIM
DEPENDS ${FILE_NAME} ${PARAM_DEPENDS}
)
# 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}")

set(CPIO_FILES "")
foreach(item IN LISTS files) # <CPIO_NAME>:<FILENAME>
string(
REGEX
MATCH
"^([^:]+):([^:]+)$"
cpio_item
"${item}"
)
if(NOT cpio_item)
message(FATAL_ERROR "invalid CPIO file format: '${item}'")
endif()
set(CPIO_NAME "${CMAKE_MATCH_1}")
set(FILE_NAME "${CMAKE_MATCH_2}")
set(CPIO_FILE "${INST_BIN_DIR}/files/${CPIO_NAME}")
add_custom_command(
OUTPUT "${CPIO_FILE}"
COMMENT "copy: ${FILE_NAME} -> ${CPIO_FILE}"
COMMAND
${CMAKE_COMMAND} -E copy "${FILE_NAME}" "${CPIO_FILE}"
VERBATIM
DEPENDS ${FILE_NAME} ${deps}
)
# 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()
endforeach()

# Build CPIO archive. It implicitly depends on all files in CPIO_FILES,
Expand Down Expand Up @@ -242,61 +199,6 @@ function(DeclareCAmkESVMRootServer camkes_config)
)
endfunction(DeclareCAmkESVMRootServer)

# Function for adding a file/image to the vm file server.
#
# Parameters:
#
# <filename_pref>
# The name the caller wishes to use to reference the file in the CPIO archive.
# This corresponds with the name set in the 'kernel_image' camkes variable for
# a given instance vm.
#
# <file_dest>
# The location of the file/image the caller is adding to the file server
#
# INSTANCE <name>
# Instance name of the file server CAmkES component.
# Optional, defaults to "fserv"
#
# DEPENDS <dep>[ <dep>[...]]
# Any additional dependencies for the file/image the caller is adding to the
# file server
#
function(AddToFileServer filename_pref file_dest)

cmake_parse_arguments(
PARSE_ARGV
2
PARAM # variable prefix
"" # option arguments
"INSTANCE" # optional single value arguments
"DEPENDS" # optional multi value arguments
)

if(PARAM_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "Unknown arguments: ${PARAM_UNPARSED_ARGUMENTS}")
endif()

if(NOT PARAM_INSTANCE)
set(PARAM_INSTANCE "fserv")
endif()

set_property(
TARGET vm_fserver_config
APPEND
PROPERTY FILES_${PARAM_INSTANCE} "${filename_pref}:${file_dest}"
)

if(PARAM_DEPENDS)
set_property(
TARGET vm_fserver_config
APPEND
PROPERTY DEPS_${PARAM_INSTANCE} ${PARAM_DEPENDS}
)
endif()

endfunction(AddToFileServer)

# Function for decompressing/extracting a vmlinux file from a given kernel image
# decompress_target: The target name the caller wishes to use to generate the decompressed kernel
# image
Expand Down

0 comments on commit e4e1098

Please sign in to comment.