[ENH] cmake_path: path manipulation command
Introduce a new command dedicated to manipulating paths. Only syntactic aspects of paths are handled: the pathname may represent a non-existing path or even one that is not allowed to exist on the current file system or OS.
This issue is a proposition based on [ENH] Paths handling discourse discussion and will rely on !4968 (merged) for the implementation.
The semantic of this command is based on std::filesystem::path C++ class.
The goal is re-group all actions on paths, currently dispatched on various commands, under one command with well-defined semantic (i.e. no access to the file-system).
This command adopts the same approach as list
command: it works on a variable holding a path. It will support the following actions (action names are strongly inspired from std::filesystem::name
, actions modifying the path will work in-place or will be stored in the variable specified by OUTPUT_VARIABLE
option):
Decomposition
- cmake_path(GET <path> ROOT_NAME <output>)
- cmake_path(GET <path> ROOT_DIRECTORY <output>)
- cmake_path(GET <path> ROOT_PATH <output>)
- cmake_path(GET <path> FILENAME <output>)
- same as
get_filename_component(...NAME...)
- same as
- cmake_path(GET <path> EXTENSION [LAST_ONLY] <output>)
- same as
get_filename_component(...EXT...)
andget_filename_component(...LAST_EXT...)
- same as
- cmake_path(GET <path> STEM [LAST_ONLY] <output>)
- same as
get_filename_component(...NAME_WE...)
andget_filename_component(...NAME_WLE...)
- same as
- cmake_path(GET <path> RELATIVE_PATH <output>)
- cmake_path(GET <path> PARENT_PATH <output>)
- same as
get_filename_component(...DIRECTORY...)
- same as
Manipulation
- cmake_path(APPEND <path> [<input>...] [OUTPUT_VARIABLE <output>])
- cmake_path(CONCAT <path> [<input>...] [OUTPUT_VARIABLE <output>])
- cmake_path(REMOVE_FILENAME <path> [OUTPUT_VARIABLE <output>])
- cmake_path(REPLACE_FILENAME <path> [<input>] [OUTPUT_VARIABLE <output>])
- cmake_path(REPLACE_EXTENSION <path> [LAST_ONLY] [<input>] [OUTPUT_VARIABLE <output>])
Generation
- cmake_path(NORMALIZE <path> [OUTPUT_VARIABLE <output>])
- cmake_path(RELATIVE_PATH <path> BASE_DIRECTORY <path> [OUTPUT_VARIABLE <output>])
- equivalent to
file(RELATIVE_PATH...)
- equivalent to
- cmake_path(PROXIMATE_PATH <path> BASE_DIRECTORY <path> [OUTPUT_VARIABLE <output>])
- cmake_path(ABSOLUTE_PATH <path> [BASE_DIRECTORY <path>] [OUTPUT_VARIABLE <output>])
- equivalent to
get_filename_component(...ABSOLUTE...)
- equivalent to
- cmake_path(TO_CMAKE_PATH <path> [OUTPUT_VARIABLE <output>])
- equivalent to
file(TO_CMAKE_PATH...)
- equivalent to
- cmake_path(TO_NATIVE_PATH <path> [OUTPUT_VARIABLE <output>])
- equivalent to
file(TO_NATIVE_PATH...)
- equivalent to
Comparison
cmake_path(COMPARE <path1> LESS <path2> <output>)cmake_path(COMPARE <path1> GREATER <path2> <output>)- cmake_path(COMPARE <path1> EQUAL <path2> <output>)
- cmake_path(COMPARE <path1> NOT_EQUAL <path2> <output>)
cmake_path(COMPARE <path1> LESS_EQUAL <path2> <output>)cmake_path(COMPARE <path1> GREATER_EQUAL <path2> <output>)
Query
- cmake_path(IS_ABSOLUTE <path> <output>)
- cmake_path(IS_RELATIVE <path> <output>)
- cmake_path(IS_PREFIX <path> <path> <output>)
Hashing
- cmake_path(HASH <path> <output>)