@@ -63,20 +63,151 @@ function(DeclareCAmkESVM init_component)
6363 )
6464endfunction (DeclareCAmkESVM )
6565
66+ #
6667# Function defines a CAmkESVMFileServer using the declared fileserver images
6768# and fileserver dependencies. These images are placed into a CPIO archive.
69+ #
70+ # Parameters:
71+ #
72+ # TYPE <type>
73+ # Type of the file server CAmkES component.
74+ # Optional, defaults to "FileServer"
75+ #
76+ # INSTANCE <name>
77+ # Instance name of the file server CAmkES component.
78+ # Optional, defaults to "fserv"
79+ #
80+ # FILES <item>[ <item>[...]]
81+ # The files to be added. Each item has the form [<NAME>:]<FILE_NAME>, where
82+ # the optional <NAME> allows using a different name for the file in the
83+ # archive than on the disk. The build will abort if <FILE_NAME> is not found.
84+ # Each item can either be a single file item or a CMake list of items (such a
85+ # CMake list is basically a string with elements separated by ';'). This
86+ # allows building lists of files in advance, which may contain different files
87+ # for different configurations. An empty string as item is also explicitly
88+ # allowed for convenience reasons. Thus supports cases where a an item does
89+ # not exist in every configuration and the respective CMake variable used for
90+ # the item is just left empty.
91+ #
92+ # DEPENDS <dep>[ <dep>[...]]
93+ # Any additional dependencies for the file/image the caller is adding to the
94+ # file server
95+ #
96+ #
6897function (DefineCAmkESVMFileServer )
69- # Retrieve defined kernel images, rootfs images and extraction dependencies
70- get_target_property (fileserver_images vm_fserver_config FILES )
71- get_target_property (fileserver_deps vm_fserver_config DEPS )
72- set (FILESERVER_INSTANCE "fserv" )
73- set (INST_BIN_DIR "${CMAKE_CURRENT_BINARY_DIR} /${FILESERVER_INSTANCE} " )
74- # Build CPIO archive given the defined kernel and rootfs images
98+
99+ cmake_parse_arguments (
100+ PARSE_ARGV
101+ 0
102+ PARAM # variable prefix
103+ "" # option arguments
104+ "TYPE;INSTANCE" # optional single value arguments
105+ "FILES;DEPENDS" # optional multi value arguments
106+ )
107+
108+ if (PARAM_UNPARSED_ARGUMENTS)
109+ message (FATAL_ERROR "Unknown arguments: ${PARAM_UNPARSED_ARGUMENTS} " )
110+ endif ()
111+
112+ if (NOT PARAM_TYPE)
113+ set (PARAM_TYPE "FileServer" )
114+ endif ()
115+
116+ if (NOT PARAM_INSTANCE)
117+ set (PARAM_INSTANCE "fserv" )
118+ endif ()
119+
120+ if (PARAM_DEPENDS)
121+ set_property (
122+ TARGET vm_fserver_config
123+ APPEND
124+ PROPERTY DEPS_${PARAM_INSTANCE} ${PARAM_DEPENDS}
125+ )
126+ endif ()
127+
128+ foreach (element IN LISTS PARAM_FILES)
129+ foreach (item IN LISTS element) # [<CPIO_NAME>:]<FILENAME>
130+ if (NOT item)
131+ continue ()
132+ endif ()
133+ string (
134+ REGEX
135+ MATCH
136+ "^([^:]+)(:([^:]+))?$"
137+ cpio_item
138+ "${item} "
139+ )
140+ if (NOT cpio_item)
141+ message (FATAL_ERROR "invalid paramete format: '${item} '" )
142+ endif ()
143+ if (CMAKE_MATCH_3)
144+ set (CPIO_NAME "${CMAKE_MATCH_1} " )
145+ set (FILE_NAME "${CMAKE_MATCH_3} " )
146+ else ()
147+ set (FILE_NAME "${CMAKE_MATCH_1} " )
148+ get_filename_component (CPIO_NAME "${FILE_NAME} " NAME )
149+ endif ()
150+ # For legacy reasons, we still call AddToFileServer() here. It will
151+ # simplify things a lot, if this function is removed completely. It
152+ # is no longer needed, because we accept lists of files now., which
153+ # the caller is supposed to build then. For now, AddToFileServer()
154+ # is just a light wrapper that build such a list. Thus, there is no
155+ # need to pass dependencies from PARAM_DEPENDS here, have added them
156+ # above already.
157+ AddToFileServer ("${CPIO_NAME} " "${FILE_NAME} " INSTANCE "${PARAM_INSTANCE} " )
158+ endforeach ()
159+ endforeach ()
160+
161+ # now process the file/deps list
162+ get_target_property (files vm_fserver_config FILES_${PARAM_INSTANCE} )
163+ if (NOT files) # this also catches "files-NOTFOUND" if property is not set
164+ set (files "" )
165+ endif ()
166+ get_target_property (deps vm_fserver_config DEPS_${PARAM_INSTANCE} )
167+ if (NOT deps) # this also catches "deps-NOTFOUND" if property is not set
168+ set (deps "" )
169+ endif ()
170+
171+ set (INST_BIN_DIR "${CMAKE_CURRENT_BINARY_DIR} /${PARAM_INSTANCE} " )
172+
173+ set (CPIO_FILES "" )
174+ foreach (item IN LISTS files) # <CPIO_NAME>:<FILENAME>
175+ string (
176+ REGEX
177+ MATCH
178+ "^([^:]+):([^:]+)$"
179+ cpio_item
180+ "${item} "
181+ )
182+ if (NOT cpio_item)
183+ message (FATAL_ERROR "invalid CPIO file format: '${item} '" )
184+ endif ()
185+ set (CPIO_NAME "${CMAKE_MATCH_1} " )
186+ set (FILE_NAME "${CMAKE_MATCH_2} " )
187+ set (CPIO_FILE "${INST_BIN_DIR} /files/${CPIO_NAME} " )
188+ add_custom_command (
189+ OUTPUT "${CPIO_FILE} "
190+ COMMENT "copy: ${FILE_NAME} -> ${CPIO_FILE} "
191+ COMMAND
192+ ${CMAKE_COMMAND} -E copy "${FILE_NAME} " "${CPIO_FILE} "
193+ VERBATIM
194+ DEPENDS ${FILE_NAME} ${deps}
195+ )
196+ # There is no need to create an explicit target for the command above,
197+ # the archive creation depends on all files in CPIO_FILES, where the
198+ # command above is the creation rule for each one.
199+ list (APPEND CPIO_FILES "${CPIO_FILE} " )
200+ endforeach ()
201+
202+ # Build CPIO archive. It implicitly depends on all files in CPIO_FILES,
203+ # which have their own dependencies each from above. So we don't have any
204+ # additional explicit dependencies here.
75205 set (CPIO_ARCHIVE "${INST_BIN_DIR} /file_archive.o" )
76206 include (cpio )
77- MakeCPIO ("${CPIO_ARCHIVE} " "${fileserver_images} " DEPENDS "${fileserver_deps} " )
78- # Build a library from the CPIO archive
79- set (FILESERVER_LIB "file_archive_cpio" )
207+ MakeCPIO ("${CPIO_ARCHIVE} " "${CPIO_FILES} " )
208+ # Build a library from the CPIO archive. Ensure the lib has a unique name
209+ # within the project, as there could be more than one file server.
210+ set (FILESERVER_LIB "${PARAM_INSTANCE} _file_archive_cpio" )
80211 add_library ("${FILESERVER_LIB} " STATIC EXCLUDE_FROM_ALL "${CPIO_ARCHIVE} " )
81212 set_target_properties (
82213 "${FILESERVER_LIB} "
@@ -87,7 +218,8 @@ function(DefineCAmkESVMFileServer)
87218 "C"
88219 )
89220 # Add the CPIO-library to the FileServer component
90- ExtendCAmkESComponentInstance (FileServer "${FILESERVER_INSTANCE} " LIBS "${FILESERVER_LIB} " )
221+ ExtendCAmkESComponentInstance ("${PARAM_TYPE} " "${PARAM_INSTANCE} " LIBS "${FILESERVER_LIB} " )
222+
91223endfunction (DefineCAmkESVMFileServer )
92224
93225# Function for declaring the CAmkESVM root server. Taking the camkes application
@@ -113,41 +245,60 @@ function(DeclareCAmkESVMRootServer camkes_config)
113245 )
114246endfunction (DeclareCAmkESVMRootServer )
115247
248+ #
116249# Function for adding a file/image to the vm file server.
117- # filename_pref: The name the caller wishes to use to reference the file in the CPIO archive. This
118- # corresponds with the name set in the 'kernel_image' camkes variable for a given instance vm.
119- # file_dest: The location of the file/image the caller is adding to the file server
120- # DEPENDS: Any additional dependencies for the file/image the caller is adding to the
121- # file server
250+ #
251+ # Parameters:
252+ #
253+ # <filename_pref>
254+ # The name the caller wishes to use to reference the file in the CPIO archive.
255+ # This corresponds with the name set in the 'kernel_image' camkes variable for
256+ # a given instance vm.
257+ #
258+ # <file_dest>
259+ # The location of the file/image the caller is adding to the file server
260+ #
261+ # INSTANCE <name>
262+ # Instance name of the file server CAmkES component.
263+ # Optional, defaults to "fserv"
264+ #
265+ # DEPENDS <dep>[ <dep>[...]]
266+ # Any additional dependencies for the file/image the caller is adding to the
267+ # file server
268+ #
122269function (AddToFileServer filename_pref file_dest )
123- # Get any existing dependencies when adding the image into the file server archive
124- cmake_parse_arguments (PARSE_ARGV 2 CAMKES_FILESERVER "" "" "DEPENDS" )
125- if (NOT "${CAMKES_FILESERVER_UNPARSED_ARGUMENTS} " STREQUAL "" )
126- message (FATAL_ERROR "Unknown arguments to AddToFileServer" )
127- endif ()
128- # Create a copy of the file in the binary directory to the callers
129- # preferred name
130- add_custom_command (
131- OUTPUT file_server/${filename_pref}
132- COMMAND
133- ${CMAKE_COMMAND} -E copy "${file_dest} "
134- "${CMAKE_CURRENT_BINARY_DIR} /file_server/${filename_pref} "
135- VERBATIM
136- DEPENDS ${file_dest} ${CAMKES_FILESERVER_DEPENDS}
137- )
138- #Create custom target for copy command
139- add_custom_target (
140- copy_${filename_pref}
141- DEPENDS "${CMAKE_CURRENT_BINARY_DIR} /file_server/${filename_pref} "
270+
271+ cmake_parse_arguments (
272+ PARSE_ARGV
273+ 2
274+ PARAM # variable prefix
275+ "" # option arguments
276+ "INSTANCE" # optional single value arguments
277+ "DEPENDS" # optional multi value arguments
142278 )
143- # Store the rootfs file location. Used when building the CPIO at a later stage
279+
280+ if (PARAM_UNPARSED_ARGUMENTS)
281+ message (FATAL_ERROR "Unknown arguments: ${PARAM_UNPARSED_ARGUMENTS} " )
282+ endif ()
283+
284+ if (NOT PARAM_INSTANCE)
285+ set (PARAM_INSTANCE "fserv" )
286+ endif ()
287+
144288 set_property (
145289 TARGET vm_fserver_config
146290 APPEND
147- PROPERTY FILES "${CMAKE_CURRENT_BINARY_DIR} /file_server/ ${filename_pref } "
291+ PROPERTY FILES_${PARAM_INSTANCE} "${filename_pref} : ${file_dest } "
148292 )
149- # Append soft link dependency
150- set_property (TARGET vm_fserver_config APPEND PROPERTY DEPS "copy_${filename_pref} " )
293+
294+ if (PARAM_DEPENDS)
295+ set_property (
296+ TARGET vm_fserver_config
297+ APPEND
298+ PROPERTY DEPS_${PARAM_INSTANCE} ${PARAM_DEPENDS}
299+ )
300+ endif ()
301+
151302endfunction (AddToFileServer )
152303
153304# Function for decompressing/extracting a vmlinux file from a given kernel image
0 commit comments