FileManip¶
Operations on files. It requires CMake 3.20 or newer.
Synopsis¶
file_manip(RELATIVE_PATH <file-list-var> BASE_DIR <directory-path> [OUTPUT_VARIABLE <output-list-var>]) file_manip(ABSOLUTE_PATH <file-list-var> BASE_DIR <directory-path> [OUTPUT_VARIABLE <output-list-var>]) file_manip(STRIP_PATH <file-list-var> BASE_DIR <directory-path> [OUTPUT_VARIABLE <output-list-var>]) file_manip(GET_COMPONENT <file-path>... MODE <mode> OUTPUT_VARIABLE <output-list-var>)
Usage¶
- file_manip(RELATIVE_PATH <file-list-var> BASE_DIR <directory-path> [OUTPUT_VARIABLE <output-list-var>])¶
Computes the relative path from a given
BASE_DIR
for each file in the list variable named<file-list-var>
. The result is stored either in-place in<file-list-var>
, or in the variable specified by<output-list-var>
, if theOUTPUT_VARIABLE
option is provided.Example usage:
set(files "/project/src/main.cpp" "/project/include/lib.h" ) file_manip(RELATIVE_PATH "${files}" BASE_DIR "/project") # output is: # src/main.cpp;include/lib.hpp
- file_manip(ABSOLUTE_PATH <file-list-var> BASE_DIR <directory-path> [OUTPUT_VARIABLE <output-list-var>])¶
Computes the absolute path from a given
BASE_DIR
for each file in the list variable named<file-list-var>
. The result is stored either in-place in<file-list-var>
, or in the variable specified by<output-list-var>
, if theOUTPUT_VARIABLE
option is provided.Example usage:
set(files "src/main.cpp" "include/lib.hpp" ) file_manip(ABSOLUTE_PATH "${files}" BASE_DIR "/project") # output is: # /project/src/main.cpp;/project/include/lib.h
- file_manip(STRIP_PATH <file-list-var> BASE_DIR <directory-path> [OUTPUT_VARIABLE <output-list-var>])¶
Removes the
BASE_DIR
prefix from each file path in<file-list-var>
. The result is stored either in-place in<file-list-var>
, or in the variable specified by<output-list-var>
, if theOUTPUT_VARIABLE
option is provided. Unlike tofile_manip(RELATIVE_PATH)
, it performs no checks on the existence of files. Paths are processed like any string.Example usage:
set(files "/project/src/main.cpp" "/project/include/lib.h" ) file_manip(STRIP_PATH "${files}" BASE_DIR "/project") # output is: # src/main.cpp;include/lib.hpp
- file_manip(GET_COMPONENT <file-path>... MODE <mode> OUTPUT_VARIABLE <output-list-var>)¶
Extracts a specific component from each path in the given
<file-path>
list and stores the result in the variable specified byOUTPUT_VARIABLE
option.The
MODE
argument determines which component to extract and must be one of:DIRECTORY
- Directory without file name.NAME
- File name without directory.
Example usage:
set(files "/project/src/main.cpp" "/project/include/lib.hpp" ) file_manip(GET_COMPONENT "${files}" MODE DIRECTORY OUTPUT_VARIABLE dirs) # output is: # /project/src;/project/include