From a62431a51a317e308a17fecc8d4ffc2ebd524ff9 Mon Sep 17 00:00:00 2001 From: Axel Heider Date: Thu, 7 Jul 2022 00:12:37 +0200 Subject: [PATCH] cpio.cmake: allow passing a directory also This allows creating the archive in a subfolder, so "pollution" of the root folder can be avoided. Signed-off-by: Axel Heider --- cmake-tool/helpers/cpio.cmake | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/cmake-tool/helpers/cpio.cmake b/cmake-tool/helpers/cpio.cmake index 13511577b..ec4e9b256 100644 --- a/cmake-tool/helpers/cpio.cmake +++ b/cmake-tool/helpers/cpio.cmake @@ -44,9 +44,15 @@ function(MakeCPIO output_name input_files) set(archive_symbol ${MAKE_CPIO_CPIO_SYMBOL}) endif() + get_filename_component(cpio_lib_name "${output_name}" NAME) + get_filename_component(cpio_lib_dir "${output_name}" DIRECTORY) + if(NOT cpio_lib_dir) + set(cpio_lib_dir "${CMAKE_CURRENT_BINARY_DIR}") + endif() + # intermediate files - set(cpio_archive "archive.${output_name}.cpio") - set(cpio_archive_s "${output_name}.S") + set(cpio_archive "${cpio_lib_dir}/${cpio_lib_name}.cpio") + set(cpio_archive_s "${cpio_lib_dir}/${cpio_lib_name}.S") # Try to generate reproducible cpio archives using a command sequence that # runs in a separate shell in a temp folder. It creates an empty archive @@ -60,10 +66,9 @@ function(MakeCPIO output_name input_files) CheckCPIOArgument(cpio_reproducible_flag "--reproducible") set( cpio_cmd - "cpio ${cpio_reproducible_flag} --quiet --create --format=newc --file=${CMAKE_CURRENT_BINARY_DIR}/${cpio_archive}" + "cpio ${cpio_reproducible_flag} --quiet --create --format=newc --file=${cpio_archive}" ) - - set(tmp_dir "temp_${output_name}") + set(tmp_dir "${cpio_lib_dir}/temp_${cpio_lib_name}") set(make_cpio "cd ${tmp_dir} && ${cpio_cmd}") foreach(file IN LISTS input_files) string( @@ -79,7 +84,7 @@ function(MakeCPIO output_name input_files) # contains the cpio archive. file( WRITE - "${CMAKE_CURRENT_BINARY_DIR}/${cpio_archive_s}" + "${cpio_archive_s}" "# auto-generated file from MakeCPIO(), do not edit\n" ".section ._archive_cpio, \"aw\"\n" ".globl ${archive_symbol}, ${archive_symbol}_end\n"