From 0a858c745ddba06c8a5d0c30742c79d824a2fc2a Mon Sep 17 00:00:00 2001 From: Axel Heider Date: Wed, 10 Aug 2022 16:08:31 +0200 Subject: [PATCH] CMake: create cpio archive in folder Do not pollute the root folder. Signed-off-by: Axel Heider --- camkes_vm_helpers.cmake | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/camkes_vm_helpers.cmake b/camkes_vm_helpers.cmake index 851401a1..01774062 100644 --- a/camkes_vm_helpers.cmake +++ b/camkes_vm_helpers.cmake @@ -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) # [:] 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() @@ -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() @@ -165,7 +170,13 @@ function(DefineCAmkESVMFileServer) set(CPIO_FILES "") foreach(item IN LISTS files) # : - 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() @@ -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")