cmake-presets: add ${pathListSep} macro

Fixes: #23282
This commit is contained in:
Erin Melucci
2022-05-09 19:18:53 +02:00
committed by Brad King
parent ef10e61b6b
commit ba969ce5fe
11 changed files with 77 additions and 0 deletions

View File

@@ -1068,6 +1068,17 @@ Recognized macros include:
A literal dollar sign (``$``).
``${pathListSep}``
Native character for separating lists of paths, such as ``:`` or ``;``.
For example, by setting ``PATH`` to
``/path/to/ninja/bin${pathListSep}$env{PATH}``, ``${pathListSep}`` will
expand to the underlying operating system's character used for
concatenation in ``PATH``.
This is allowed in preset files specifying version ``5`` or above.
``$env{<variable-name>}``
Environment variable with name ``<variable-name>``. The variable name may

View File

@@ -0,0 +1,5 @@
presets-pathListSep
-------------------
* :manual:`cmake-presets(7)` files now support a ``${pathListSep}`` macro,
which expands to ``:`` or ``;`` based on the platform.

View File

@@ -361,6 +361,13 @@ bool ExpandMacros(const cmCMakePresetsGraph& graph, const T& preset,
cmSystemTools::GetParentDirectory(preset.OriginFile->Filename);
return ExpandMacroResult::Ok;
}
if (macroName == "pathListSep") {
if (version < 5) {
return ExpandMacroResult::Error;
}
macroOut += cmSystemTools::GetSystemPathlistSeparator();
return ExpandMacroResult::Ok;
}
}
return ExpandMacroResult::Ignore;

View File

@@ -3429,3 +3429,12 @@ cm::string_view cmSystemTools::GetSystemName()
return "";
#endif
}
char cmSystemTools::GetSystemPathlistSeparator()
{
#if defined(_WIN32)
return ';';
#else
return ':';
#endif
}

View File

@@ -535,6 +535,9 @@ public:
/** Get the system name. */
static cm::string_view GetSystemName();
/** Get the system path separator character */
static char GetSystemPathlistSeparator();
private:
static bool s_ForceUnixPaths;
static bool s_RunCommandHideConsole;

View File

@@ -0,0 +1,7 @@
include(${CMAKE_CURRENT_LIST_DIR}/TestVariable.cmake)
if(CMAKE_HOST_WIN32)
test_variable(TEST_PATH_LIST_SEP "" "${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}")
else()
test_variable(TEST_PATH_LIST_SEP "" "${CMAKE_CURRENT_SOURCE_DIR}:${CMAKE_CURRENT_SOURCE_DIR}")
endif()

View File

@@ -0,0 +1,13 @@
{
"version": 5,
"configurePresets": [
{
"name": "PathListSep",
"generator": "@RunCMake_GENERATOR@",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"TEST_PATH_LIST_SEP": "${sourceDir}${pathListSep}${sourceDir}"
}
}
]
}

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1,2 @@
^CMake Error: Could not read presets from [^
]*/Tests/RunCMake/CMakePresets/PathListSepFuture: Invalid macro expansion$

View File

@@ -0,0 +1,13 @@
{
"version": 4,
"configurePresets": [
{
"name": "PathListSepFuture",
"generator": "@RunCMake_GENERATOR@",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"TEST_PATH_LIST_SEP": "${sourceDir}${pathListSep}${sourceDir}"
}
}
]
}

View File

@@ -335,6 +335,12 @@ unset(CMakePresets_EXTRA_FILES)
set(CMakePresets_FILE "${RunCMake_SOURCE_DIR}/FileDirFuture.json.in")
run_cmake_presets(FileDirFuture)
# Test ${pathListSep} macro
set(CMakePresets_FILE "${RunCMake_SOURCE_DIR}/PathListSep.json.in")
run_cmake_presets(PathListSep)
set(CMakePresets_FILE "${RunCMake_SOURCE_DIR}/PathListSepFuture.json.in")
run_cmake_presets(PathListSepFuture)
# Test conditions
set(CMakePresets_FILE "${RunCMake_SOURCE_DIR}/Conditions.json.in")
run_cmake_presets(ListConditions --list-presets)