summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErin Melucci <emelucci@opera.com>2022-05-09 17:18:53 (GMT)
committerBrad King <brad.king@kitware.com>2022-05-12 14:37:49 (GMT)
commitba969ce5fe3a363b52dd4f0290e4b827272101fb (patch)
treeb3a8747cdf46785bd05851fccb2f35e7778723bd
parentef10e61b6b7d3bb264cdbf72e143dbef7be8c736 (diff)
downloadCMake-ba969ce5fe3a363b52dd4f0290e4b827272101fb.zip
CMake-ba969ce5fe3a363b52dd4f0290e4b827272101fb.tar.gz
CMake-ba969ce5fe3a363b52dd4f0290e4b827272101fb.tar.bz2
cmake-presets: add ${pathListSep} macro
Fixes: #23282
-rw-r--r--Help/manual/cmake-presets.7.rst11
-rw-r--r--Help/release/dev/presets-pathListSep.rst5
-rw-r--r--Source/cmCMakePresetsGraph.cxx7
-rw-r--r--Source/cmSystemTools.cxx9
-rw-r--r--Source/cmSystemTools.h3
-rw-r--r--Tests/RunCMake/CMakePresets/PathListSep.cmake7
-rw-r--r--Tests/RunCMake/CMakePresets/PathListSep.json.in13
-rw-r--r--Tests/RunCMake/CMakePresets/PathListSepFuture-result.txt1
-rw-r--r--Tests/RunCMake/CMakePresets/PathListSepFuture-stderr.txt2
-rw-r--r--Tests/RunCMake/CMakePresets/PathListSepFuture.json.in13
-rw-r--r--Tests/RunCMake/CMakePresets/RunCMakeTest.cmake6
11 files changed, 77 insertions, 0 deletions
diff --git a/Help/manual/cmake-presets.7.rst b/Help/manual/cmake-presets.7.rst
index c8d24f2..948d87a 100644
--- a/Help/manual/cmake-presets.7.rst
+++ b/Help/manual/cmake-presets.7.rst
@@ -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
diff --git a/Help/release/dev/presets-pathListSep.rst b/Help/release/dev/presets-pathListSep.rst
new file mode 100644
index 0000000..84b129f
--- /dev/null
+++ b/Help/release/dev/presets-pathListSep.rst
@@ -0,0 +1,5 @@
+presets-pathListSep
+-------------------
+
+* :manual:`cmake-presets(7)` files now support a ``${pathListSep}`` macro,
+ which expands to ``:`` or ``;`` based on the platform.
diff --git a/Source/cmCMakePresetsGraph.cxx b/Source/cmCMakePresetsGraph.cxx
index 478c175..b737c1f 100644
--- a/Source/cmCMakePresetsGraph.cxx
+++ b/Source/cmCMakePresetsGraph.cxx
@@ -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;
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index cb32172..527175d 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -3429,3 +3429,12 @@ cm::string_view cmSystemTools::GetSystemName()
return "";
#endif
}
+
+char cmSystemTools::GetSystemPathlistSeparator()
+{
+#if defined(_WIN32)
+ return ';';
+#else
+ return ':';
+#endif
+}
diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h
index c17ecbd..4865a4b 100644
--- a/Source/cmSystemTools.h
+++ b/Source/cmSystemTools.h
@@ -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;
diff --git a/Tests/RunCMake/CMakePresets/PathListSep.cmake b/Tests/RunCMake/CMakePresets/PathListSep.cmake
new file mode 100644
index 0000000..52c225b
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/PathListSep.cmake
@@ -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()
diff --git a/Tests/RunCMake/CMakePresets/PathListSep.json.in b/Tests/RunCMake/CMakePresets/PathListSep.json.in
new file mode 100644
index 0000000..4c25029
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/PathListSep.json.in
@@ -0,0 +1,13 @@
+{
+ "version": 5,
+ "configurePresets": [
+ {
+ "name": "PathListSep",
+ "generator": "@RunCMake_GENERATOR@",
+ "binaryDir": "${sourceDir}/build",
+ "cacheVariables": {
+ "TEST_PATH_LIST_SEP": "${sourceDir}${pathListSep}${sourceDir}"
+ }
+ }
+ ]
+}
diff --git a/Tests/RunCMake/CMakePresets/PathListSepFuture-result.txt b/Tests/RunCMake/CMakePresets/PathListSepFuture-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/PathListSepFuture-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMakePresets/PathListSepFuture-stderr.txt b/Tests/RunCMake/CMakePresets/PathListSepFuture-stderr.txt
new file mode 100644
index 0000000..b961aaf
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/PathListSepFuture-stderr.txt
@@ -0,0 +1,2 @@
+^CMake Error: Could not read presets from [^
+]*/Tests/RunCMake/CMakePresets/PathListSepFuture: Invalid macro expansion$
diff --git a/Tests/RunCMake/CMakePresets/PathListSepFuture.json.in b/Tests/RunCMake/CMakePresets/PathListSepFuture.json.in
new file mode 100644
index 0000000..2fd6b7e
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/PathListSepFuture.json.in
@@ -0,0 +1,13 @@
+{
+ "version": 4,
+ "configurePresets": [
+ {
+ "name": "PathListSepFuture",
+ "generator": "@RunCMake_GENERATOR@",
+ "binaryDir": "${sourceDir}/build",
+ "cacheVariables": {
+ "TEST_PATH_LIST_SEP": "${sourceDir}${pathListSep}${sourceDir}"
+ }
+ }
+ ]
+}
diff --git a/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake b/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake
index 5867efd..d097086 100644
--- a/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake
@@ -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)