summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-03-16 14:51:25 (GMT)
committerKitware Robot <kwrobot@kitware.com>2021-03-16 14:51:32 (GMT)
commit3cea13c2f33c9ac46332ba1aa1d5a67042849c7a (patch)
treeec8fc6b10740100d79af8395c394148234242ebc
parent84f94fb1964a7a8b09fb83e79f1ea6032add3b8d (diff)
parent0d497e159b5854ed050d9eb8c4e965976a03de11 (diff)
downloadCMake-3cea13c2f33c9ac46332ba1aa1d5a67042849c7a.zip
CMake-3cea13c2f33c9ac46332ba1aa1d5a67042849c7a.tar.gz
CMake-3cea13c2f33c9ac46332ba1aa1d5a67042849c7a.tar.bz2
Merge topic 'cmake-presets-host-system-name'
0d497e159b CMakePresets.json: Add ${hostSystemName} macro 79d03ab505 Help: Fix version numbers in CMakePresets.json documentation 69527a1979 Refactor: Pass CMakePresets.json version to ExpandMacros() functions ad19da011d Refactor: Add cmSystemTools::GetSystemName() Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !5902
-rw-r--r--Help/manual/cmake-presets.7.rst17
-rw-r--r--Help/release/dev/cmake-presets-host-system-name.rst5
-rw-r--r--Help/release/dev/cmake-system-name-version.rst10
-rw-r--r--Modules/CMakeDetermineSystem.cmake39
-rw-r--r--Source/cmCMakePresetsFile.cxx108
-rw-r--r--Source/cmCMakePresetsFile.h7
-rw-r--r--Source/cmStateSnapshot.cxx55
-rw-r--r--Source/cmSystemTools.cxx47
-rw-r--r--Source/cmSystemTools.h3
-rw-r--r--Tests/RunCMake/CMakePresets/HostSystemName.cmake3
-rw-r--r--Tests/RunCMake/CMakePresets/HostSystemName.json.in13
-rw-r--r--Tests/RunCMake/CMakePresets/HostSystemNameFuture-result.txt1
-rw-r--r--Tests/RunCMake/CMakePresets/HostSystemNameFuture-stderr.txt2
-rw-r--r--Tests/RunCMake/CMakePresets/HostSystemNameFuture.json.in13
-rw-r--r--Tests/RunCMake/CMakePresets/RunCMakeTest.cmake6
15 files changed, 219 insertions, 110 deletions
diff --git a/Help/manual/cmake-presets.7.rst b/Help/manual/cmake-presets.7.rst
index 3d2ada8..5273236 100644
--- a/Help/manual/cmake-presets.7.rst
+++ b/Help/manual/cmake-presets.7.rst
@@ -39,7 +39,7 @@ The root object recognizes the following fields:
``version``
A required integer representing the version of the JSON schema.
- The supported versions are ``1`` and ``2``.
+ The supported versions are ``1``, ``2``, and ``3``.
``cmakeMinimumRequired``
@@ -70,17 +70,17 @@ The root object recognizes the following fields:
``configurePresets``
An optional array of `Configure Preset`_ objects.
- This is allowed in preset files specifying version 1 or above.
+ This is allowed in preset files specifying version ``1`` or above.
``buildPresets``
An optional array of `Build Preset`_ objects.
- This is allowed in preset files specifying version 2 or above.
+ This is allowed in preset files specifying version ``2`` or above.
``testPresets``
An optional array of `Test Preset`_ objects.
- This is allowed in preset files specifying version 2 or above.
+ This is allowed in preset files specifying version ``2`` or above.
Configure Preset
^^^^^^^^^^^^^^^^
@@ -187,7 +187,8 @@ that may contain the following fields:
An optional string representing the path to the installation directory.
This field supports `macro expansion`_. If a relative path is specified,
- it is calculated relative to the source directory.
+ it is calculated relative to the source directory. This is allowed in
+ preset files specifying version ``3`` or above.
``cmakeExecutable``
@@ -829,6 +830,12 @@ Recognized macros include:
test presets, this will evaluate to the generator specified by
``configurePreset``.
+``${hostSystemName}``
+
+ The name of the host operating system. Contains the same value as
+ :variable:`CMAKE_HOST_SYSTEM_NAME`. This is allowed in preset files
+ specifying version ``3`` or above.
+
``${dollar}``
A literal dollar sign (``$``).
diff --git a/Help/release/dev/cmake-presets-host-system-name.rst b/Help/release/dev/cmake-presets-host-system-name.rst
new file mode 100644
index 0000000..8036939
--- /dev/null
+++ b/Help/release/dev/cmake-presets-host-system-name.rst
@@ -0,0 +1,5 @@
+cmake-presets-host-system-name
+------------------------------
+
+* :manual:`cmake-presets(7)` gained support for a new ``${hostSystemName}``
+ macro.
diff --git a/Help/release/dev/cmake-system-name-version.rst b/Help/release/dev/cmake-system-name-version.rst
new file mode 100644
index 0000000..9cfe401
--- /dev/null
+++ b/Help/release/dev/cmake-system-name-version.rst
@@ -0,0 +1,10 @@
+cmake-system-name-version
+-------------------------
+
+* :variable:`CMAKE_HOST_SYSTEM_NAME`'s undocumented version-stripping behavior
+ has been moved earlier, before :command:`project` or
+ :command:`enable_language` is called.
+* :variable:`CMAKE_SYSTEM_NAME`'s undocumented version-stripping behavior has
+ been removed entirely. If it is set by a ``-D`` flag or by a
+ :manual:`toolchain file <cmake-toolchains(7)>`, it is left unaltered, even if
+ it still contains a version number.
diff --git a/Modules/CMakeDetermineSystem.cmake b/Modules/CMakeDetermineSystem.cmake
index bae270d..c3f2b74 100644
--- a/Modules/CMakeDetermineSystem.cmake
+++ b/Modules/CMakeDetermineSystem.cmake
@@ -158,37 +158,14 @@ endif()
include(Platform/${CMAKE_SYSTEM_NAME}-Determine OPTIONAL)
-macro(ADJUST_CMAKE_SYSTEM_VARIABLES _PREFIX)
- if(NOT ${_PREFIX}_NAME)
- set(${_PREFIX}_NAME "UnknownOS")
- endif()
-
- # fix for BSD/OS , remove the /
- if(${_PREFIX}_NAME MATCHES BSD.OS)
- set(${_PREFIX}_NAME BSDOS)
- endif()
-
- # fix for GNU/kFreeBSD, remove the GNU/
- if(${_PREFIX}_NAME MATCHES kFreeBSD)
- set(${_PREFIX}_NAME kFreeBSD)
- endif()
-
- # fix for CYGWIN which has windows version in it
- if(${_PREFIX}_NAME MATCHES CYGWIN)
- set(${_PREFIX}_NAME CYGWIN)
- endif()
-
- # set CMAKE_SYSTEM to the CMAKE_SYSTEM_NAME
- set(${_PREFIX} ${${_PREFIX}_NAME})
- # if there is a CMAKE_SYSTEM_VERSION then add a -${CMAKE_SYSTEM_VERSION}
- if(${_PREFIX}_VERSION)
- set(${_PREFIX} ${${_PREFIX}}-${${_PREFIX}_VERSION})
- endif()
-
-endmacro()
-
-ADJUST_CMAKE_SYSTEM_VARIABLES(CMAKE_SYSTEM)
-ADJUST_CMAKE_SYSTEM_VARIABLES(CMAKE_HOST_SYSTEM)
+set(CMAKE_SYSTEM ${CMAKE_SYSTEM_NAME})
+if(CMAKE_SYSTEM_VERSION)
+ string(APPEND CMAKE_SYSTEM -${CMAKE_SYSTEM_VERSION})
+endif()
+set(CMAKE_HOST_SYSTEM ${CMAKE_HOST_SYSTEM_NAME})
+if(CMAKE_HOST_SYSTEM_VERSION)
+ string(APPEND CMAKE_HOST_SYSTEM -${CMAKE_HOST_SYSTEM_VERSION})
+endif()
# this file is also executed from cpack, then we don't need to generate these files
# in this case there is no CMAKE_BINARY_DIR
diff --git a/Source/cmCMakePresetsFile.cxx b/Source/cmCMakePresetsFile.cxx
index e9e8c4c..7726927 100644
--- a/Source/cmCMakePresetsFile.cxx
+++ b/Source/cmCMakePresetsFile.cxx
@@ -9,6 +9,7 @@
#include <iterator>
#include <utility>
+#include <cm/string_view>
#include <cmext/string_view>
#include <cm3p/json/reader.h>
@@ -28,9 +29,9 @@
return _result; \
}
-#define CHECK_EXPAND(out, field, expanders) \
+#define CHECK_EXPAND(out, field, expanders, version) \
{ \
- switch (ExpandMacros(field, expanders)) { \
+ switch (ExpandMacros(field, expanders, version)) { \
case ExpandMacroResult::Error: \
return false; \
case ExpandMacroResult::Ignore: \
@@ -849,16 +850,19 @@ enum class ExpandMacroResult
};
using MacroExpander = std::function<ExpandMacroResult(
- const std::string&, const std::string&, std::string&)>;
+ const std::string&, const std::string&, std::string&, int version)>;
ExpandMacroResult VisitEnv(std::string& value, CycleStatus& status,
- const std::vector<MacroExpander>& macroExpanders);
+ const std::vector<MacroExpander>& macroExpanders,
+ int version);
ExpandMacroResult ExpandMacros(
- std::string& out, const std::vector<MacroExpander>& macroExpanders);
-ExpandMacroResult ExpandMacro(
- std::string& out, const std::string& macroNamespace,
- const std::string& macroName,
- const std::vector<MacroExpander>& macroExpanders);
+ std::string& out, const std::vector<MacroExpander>& macroExpanders,
+ int version);
+ExpandMacroResult ExpandMacro(std::string& out,
+ const std::string& macroNamespace,
+ const std::string& macroName,
+ const std::vector<MacroExpander>& macroExpanders,
+ int version);
bool ExpandMacros(const cmCMakePresetsFile& file,
const ConfigurePreset& preset,
@@ -866,7 +870,7 @@ bool ExpandMacros(const cmCMakePresetsFile& file,
const std::vector<MacroExpander>& macroExpanders)
{
std::string binaryDir = preset.BinaryDir;
- CHECK_EXPAND(out, binaryDir, macroExpanders)
+ CHECK_EXPAND(out, binaryDir, macroExpanders, file.GetVersion(preset))
if (!cmSystemTools::FileIsFullPath(binaryDir)) {
binaryDir = cmStrCat(file.SourceDir, '/', binaryDir);
@@ -876,7 +880,7 @@ bool ExpandMacros(const cmCMakePresetsFile& file,
if (!preset.InstallDir.empty()) {
std::string installDir = preset.InstallDir;
- CHECK_EXPAND(out, installDir, macroExpanders)
+ CHECK_EXPAND(out, installDir, macroExpanders, file.GetVersion(preset))
if (!cmSystemTools::FileIsFullPath(installDir)) {
installDir = cmStrCat(file.SourceDir, '/', installDir);
@@ -887,67 +891,76 @@ bool ExpandMacros(const cmCMakePresetsFile& file,
for (auto& variable : out->CacheVariables) {
if (variable.second) {
- CHECK_EXPAND(out, variable.second->Value, macroExpanders)
+ CHECK_EXPAND(out, variable.second->Value, macroExpanders,
+ file.GetVersion(preset))
}
}
return true;
}
-bool ExpandMacros(const cmCMakePresetsFile&, const BuildPreset&,
+bool ExpandMacros(const cmCMakePresetsFile& file, const BuildPreset& preset,
cm::optional<BuildPreset>& out,
const std::vector<MacroExpander>& macroExpanders)
{
for (auto& target : out->Targets) {
- CHECK_EXPAND(out, target, macroExpanders)
+ CHECK_EXPAND(out, target, macroExpanders, file.GetVersion(preset))
}
for (auto& nativeToolOption : out->NativeToolOptions) {
- CHECK_EXPAND(out, nativeToolOption, macroExpanders)
+ CHECK_EXPAND(out, nativeToolOption, macroExpanders,
+ file.GetVersion(preset))
}
return true;
}
-bool ExpandMacros(const cmCMakePresetsFile&, const TestPreset&,
+bool ExpandMacros(const cmCMakePresetsFile& file, const TestPreset& preset,
cm::optional<TestPreset>& out,
const std::vector<MacroExpander>& macroExpanders)
{
for (auto& overwrite : out->OverwriteConfigurationFile) {
- CHECK_EXPAND(out, overwrite, macroExpanders);
+ CHECK_EXPAND(out, overwrite, macroExpanders, file.GetVersion(preset));
}
if (out->Output) {
- CHECK_EXPAND(out, out->Output->OutputLogFile, macroExpanders)
+ CHECK_EXPAND(out, out->Output->OutputLogFile, macroExpanders,
+ file.GetVersion(preset))
}
if (out->Filter) {
if (out->Filter->Include) {
- CHECK_EXPAND(out, out->Filter->Include->Name, macroExpanders)
- CHECK_EXPAND(out, out->Filter->Include->Label, macroExpanders)
+ CHECK_EXPAND(out, out->Filter->Include->Name, macroExpanders,
+ file.GetVersion(preset))
+ CHECK_EXPAND(out, out->Filter->Include->Label, macroExpanders,
+ file.GetVersion(preset))
if (out->Filter->Include->Index) {
CHECK_EXPAND(out, out->Filter->Include->Index->IndexFile,
- macroExpanders);
+ macroExpanders, file.GetVersion(preset));
}
}
if (out->Filter->Exclude) {
- CHECK_EXPAND(out, out->Filter->Exclude->Name, macroExpanders)
- CHECK_EXPAND(out, out->Filter->Exclude->Label, macroExpanders)
+ CHECK_EXPAND(out, out->Filter->Exclude->Name, macroExpanders,
+ file.GetVersion(preset))
+ CHECK_EXPAND(out, out->Filter->Exclude->Label, macroExpanders,
+ file.GetVersion(preset))
if (out->Filter->Exclude->Fixtures) {
- CHECK_EXPAND(out, out->Filter->Exclude->Fixtures->Any, macroExpanders)
+ CHECK_EXPAND(out, out->Filter->Exclude->Fixtures->Any, macroExpanders,
+ file.GetVersion(preset))
CHECK_EXPAND(out, out->Filter->Exclude->Fixtures->Setup,
- macroExpanders)
+ macroExpanders, file.GetVersion(preset))
CHECK_EXPAND(out, out->Filter->Exclude->Fixtures->Cleanup,
- macroExpanders)
+ macroExpanders, file.GetVersion(preset))
}
}
}
if (out->Execution) {
- CHECK_EXPAND(out, out->Execution->ResourceSpecFile, macroExpanders)
+ CHECK_EXPAND(out, out->Execution->ResourceSpecFile, macroExpanders,
+ file.GetVersion(preset))
}
return true;
@@ -968,8 +981,8 @@ bool ExpandMacros(const cmCMakePresetsFile& file, const T& preset,
MacroExpander defaultMacroExpander =
[&file, &preset](const std::string& macroNamespace,
- const std::string& macroName,
- std::string& macroOut) -> ExpandMacroResult {
+ const std::string& macroName, std::string& macroOut,
+ int version) -> ExpandMacroResult {
if (macroNamespace.empty()) {
if (macroName == "sourceDir") {
macroOut += file.SourceDir;
@@ -998,6 +1011,13 @@ bool ExpandMacros(const cmCMakePresetsFile& file, const T& preset,
macroOut += '$';
return ExpandMacroResult::Ok;
}
+ if (macroName == "hostSystemName") {
+ if (version < 3) {
+ return ExpandMacroResult::Error;
+ }
+ macroOut += cmSystemTools::GetSystemName();
+ return ExpandMacroResult::Ok;
+ }
}
return ExpandMacroResult::Ignore;
@@ -1006,11 +1026,12 @@ bool ExpandMacros(const cmCMakePresetsFile& file, const T& preset,
MacroExpander environmentMacroExpander =
[&macroExpanders, &out, &envCycles](
const std::string& macroNamespace, const std::string& macroName,
- std::string& result) -> ExpandMacroResult {
+ std::string& result, int version) -> ExpandMacroResult {
if (macroNamespace == "env" && !macroName.empty() && out) {
auto v = out->Environment.find(macroName);
if (v != out->Environment.end() && v->second) {
- auto e = VisitEnv(*v->second, envCycles[macroName], macroExpanders);
+ auto e =
+ VisitEnv(*v->second, envCycles[macroName], macroExpanders, version);
if (e != ExpandMacroResult::Ok) {
return e;
}
@@ -1038,7 +1059,8 @@ bool ExpandMacros(const cmCMakePresetsFile& file, const T& preset,
for (auto& v : out->Environment) {
if (v.second) {
- switch (VisitEnv(*v.second, envCycles[v.first], macroExpanders)) {
+ switch (VisitEnv(*v.second, envCycles[v.first], macroExpanders,
+ file.GetVersion(preset))) {
case ExpandMacroResult::Error:
return false;
case ExpandMacroResult::Ignore:
@@ -1054,7 +1076,8 @@ bool ExpandMacros(const cmCMakePresetsFile& file, const T& preset,
}
ExpandMacroResult VisitEnv(std::string& value, CycleStatus& status,
- const std::vector<MacroExpander>& macroExpanders)
+ const std::vector<MacroExpander>& macroExpanders,
+ int version)
{
if (status == CycleStatus::Verified) {
return ExpandMacroResult::Ok;
@@ -1064,7 +1087,7 @@ ExpandMacroResult VisitEnv(std::string& value, CycleStatus& status,
}
status = CycleStatus::InProgress;
- auto e = ExpandMacros(value, macroExpanders);
+ auto e = ExpandMacros(value, macroExpanders, version);
if (e != ExpandMacroResult::Ok) {
return e;
}
@@ -1073,7 +1096,8 @@ ExpandMacroResult VisitEnv(std::string& value, CycleStatus& status,
}
ExpandMacroResult ExpandMacros(
- std::string& out, const std::vector<MacroExpander>& macroExpanders)
+ std::string& out, const std::vector<MacroExpander>& macroExpanders,
+ int version)
{
std::string result;
std::string macroNamespace;
@@ -1120,8 +1144,8 @@ ExpandMacroResult ExpandMacros(
case State::MacroName:
if (c == '}') {
- auto e =
- ExpandMacro(result, macroNamespace, macroName, macroExpanders);
+ auto e = ExpandMacro(result, macroNamespace, macroName,
+ macroExpanders, version);
if (e != ExpandMacroResult::Ok) {
return e;
}
@@ -1153,10 +1177,11 @@ ExpandMacroResult ExpandMacros(
ExpandMacroResult ExpandMacro(std::string& out,
const std::string& macroNamespace,
const std::string& macroName,
- const std::vector<MacroExpander>& macroExpanders)
+ const std::vector<MacroExpander>& macroExpanders,
+ int version)
{
for (auto const& macroExpander : macroExpanders) {
- auto result = macroExpander(macroNamespace, macroName, out);
+ auto result = macroExpander(macroNamespace, macroName, out, version);
if (result != ExpandMacroResult::Ignore) {
return result;
}
@@ -1549,6 +1574,11 @@ cmCMakePresetsFile::ReadFileResult cmCMakePresetsFile::ReadJSONFile(
if (v < MIN_VERSION || v > MAX_VERSION) {
return ReadFileResult::UNRECOGNIZED_VERSION;
}
+ if (user) {
+ this->UserVersion = v;
+ } else {
+ this->Version = v;
+ }
// Support for build and test presets added in version 2.
if (v < 2 &&
diff --git a/Source/cmCMakePresetsFile.h b/Source/cmCMakePresetsFile.h
index 517215d..eed0eab 100644
--- a/Source/cmCMakePresetsFile.h
+++ b/Source/cmCMakePresetsFile.h
@@ -294,6 +294,13 @@ public:
std::vector<std::string> TestPresetOrder;
std::string SourceDir;
+ int Version;
+ int UserVersion;
+
+ int GetVersion(const Preset& preset) const
+ {
+ return preset.User ? this->UserVersion : this->Version;
+ }
static std::string GetFilename(const std::string& sourceDir);
static std::string GetUserFilename(const std::string& sourceDir);
diff --git a/Source/cmStateSnapshot.cxx b/Source/cmStateSnapshot.cxx
index 1e20abb..fbf47ef 100644
--- a/Source/cmStateSnapshot.cxx
+++ b/Source/cmStateSnapshot.cxx
@@ -16,16 +16,9 @@
#include "cmState.h"
#include "cmStateDirectory.h"
#include "cmStatePrivate.h"
+#include "cmSystemTools.h"
#include "cmVersion.h"
-#if !defined(_WIN32)
-# include <sys/utsname.h>
-#endif
-
-#if defined(__CYGWIN__)
-# include "cmSystemTools.h"
-#endif
-
cmStateSnapshot::cmStateSnapshot(cmState* state)
: State(state)
{
@@ -292,34 +285,26 @@ void InitializeContentFromParent(T& parentContent, T& thisContent,
void cmStateSnapshot::SetDefaultDefinitions()
{
-/* Up to CMake 2.4 here only WIN32, UNIX and APPLE were set.
- With CMake must separate between target and host platform. In most cases
- the tests for WIN32, UNIX and APPLE will be for the target system, so an
- additional set of variables for the host system is required ->
- CMAKE_HOST_WIN32, CMAKE_HOST_UNIX, CMAKE_HOST_APPLE.
- WIN32, UNIX and APPLE are now set in the platform files in
- Modules/Platforms/.
- To keep cmake scripts (-P) and custom language and compiler modules
- working, these variables are still also set here in this place, but they
- will be reset in CMakeSystemSpecificInformation.cmake before the platform
- files are executed. */
-#if defined(_WIN32)
- this->SetDefinition("WIN32", "1");
- this->SetDefinition("CMAKE_HOST_WIN32", "1");
- this->SetDefinition("CMAKE_HOST_SYSTEM_NAME", "Windows");
-#else
- this->SetDefinition("UNIX", "1");
- this->SetDefinition("CMAKE_HOST_UNIX", "1");
-
-# if defined(__ANDROID__)
- this->SetDefinition("CMAKE_HOST_SYSTEM_NAME", "Android");
-# else
- struct utsname uts_name;
- if (uname(&uts_name) >= 0) {
- this->SetDefinition("CMAKE_HOST_SYSTEM_NAME", uts_name.sysname);
+ /* Up to CMake 2.4 here only WIN32, UNIX and APPLE were set.
+ With CMake must separate between target and host platform. In most cases
+ the tests for WIN32, UNIX and APPLE will be for the target system, so an
+ additional set of variables for the host system is required ->
+ CMAKE_HOST_WIN32, CMAKE_HOST_UNIX, CMAKE_HOST_APPLE.
+ WIN32, UNIX and APPLE are now set in the platform files in
+ Modules/Platforms/.
+ To keep cmake scripts (-P) and custom language and compiler modules
+ working, these variables are still also set here in this place, but they
+ will be reset in CMakeSystemSpecificInformation.cmake before the platform
+ files are executed. */
+ cm::string_view hostSystemName = cmSystemTools::GetSystemName();
+ this->SetDefinition("CMAKE_HOST_SYSTEM_NAME", hostSystemName);
+ if (hostSystemName == "Windows") {
+ this->SetDefinition("WIN32", "1");
+ this->SetDefinition("CMAKE_HOST_WIN32", "1");
+ } else {
+ this->SetDefinition("UNIX", "1");
+ this->SetDefinition("CMAKE_HOST_UNIX", "1");
}
-# endif
-#endif
#if defined(__CYGWIN__)
std::string legacy;
if (cmSystemTools::GetEnv("CMAKE_LEGACY_CYGWIN_WIN32", legacy) &&
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 87ba152..e8e1018 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -103,6 +103,10 @@
# include <malloc.h> /* for malloc/free on QNX */
#endif
+#if !defined(_WIN32) && !defined(__ANDROID__)
+# include <sys/utsname.h>
+#endif
+
namespace {
cmSystemTools::InterruptCallback s_InterruptCallback;
@@ -3207,3 +3211,46 @@ bool cmSystemTools::CreateLink(const std::string& origName,
return true;
}
+
+cm::string_view cmSystemTools::GetSystemName()
+{
+#if defined(_WIN32)
+ return "Windows";
+#elif defined(__ANDROID__)
+ return "Android";
+#else
+ static struct utsname uts_name;
+ static bool initialized = false;
+ static cm::string_view systemName;
+ if (initialized) {
+ return systemName;
+ }
+ if (uname(&uts_name) >= 0) {
+ initialized = true;
+ systemName = uts_name.sysname;
+
+ if (cmIsOff(systemName)) {
+ systemName = "UnknownOS";
+ }
+
+ // fix for BSD/OS, remove the /
+ static const cmsys::RegularExpression bsdOsRegex("BSD.OS");
+ cmsys::RegularExpressionMatch match;
+ if (bsdOsRegex.find(uts_name.sysname, match)) {
+ systemName = "BSDOS";
+ }
+
+ // fix for GNU/kFreeBSD, remove the GNU/
+ if (systemName.find("kFreeBSD") != cm::string_view::npos) {
+ systemName = "kFreeBSD";
+ }
+
+ // fix for CYGWIN which has windows version in it
+ if (systemName.find("CYGWIN") != cm::string_view::npos) {
+ systemName = "CYGWIN";
+ }
+ return systemName;
+ }
+ return "";
+#endif
+}
diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h
index 2ff4c5d..5620899 100644
--- a/Source/cmSystemTools.h
+++ b/Source/cmSystemTools.h
@@ -498,6 +498,9 @@ public:
const std::string& newName,
std::string* errorMessage = nullptr);
+ /** Get the system name. */
+ static cm::string_view GetSystemName();
+
private:
static bool s_ForceUnixPaths;
static bool s_RunCommandHideConsole;
diff --git a/Tests/RunCMake/CMakePresets/HostSystemName.cmake b/Tests/RunCMake/CMakePresets/HostSystemName.cmake
new file mode 100644
index 0000000..dc0998a
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/HostSystemName.cmake
@@ -0,0 +1,3 @@
+include(${CMAKE_CURRENT_LIST_DIR}/TestVariable.cmake)
+
+test_variable(TEST_HOST_SYSTEM_NAME "" "${CMAKE_HOST_SYSTEM_NAME}")
diff --git a/Tests/RunCMake/CMakePresets/HostSystemName.json.in b/Tests/RunCMake/CMakePresets/HostSystemName.json.in
new file mode 100644
index 0000000..7fcd8c8
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/HostSystemName.json.in
@@ -0,0 +1,13 @@
+{
+ "version": 3,
+ "configurePresets": [
+ {
+ "name": "HostSystemName",
+ "generator": "@RunCMake_GENERATOR@",
+ "binaryDir": "${sourceDir}/build",
+ "cacheVariables": {
+ "TEST_HOST_SYSTEM_NAME": "${hostSystemName}"
+ }
+ }
+ ]
+}
diff --git a/Tests/RunCMake/CMakePresets/HostSystemNameFuture-result.txt b/Tests/RunCMake/CMakePresets/HostSystemNameFuture-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/HostSystemNameFuture-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMakePresets/HostSystemNameFuture-stderr.txt b/Tests/RunCMake/CMakePresets/HostSystemNameFuture-stderr.txt
new file mode 100644
index 0000000..7f4bb9a
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/HostSystemNameFuture-stderr.txt
@@ -0,0 +1,2 @@
+^CMake Error: Could not read presets from [^
+]*/Tests/RunCMake/CMakePresets/HostSystemNameFuture: Invalid macro expansion$
diff --git a/Tests/RunCMake/CMakePresets/HostSystemNameFuture.json.in b/Tests/RunCMake/CMakePresets/HostSystemNameFuture.json.in
new file mode 100644
index 0000000..7a2f0aa
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/HostSystemNameFuture.json.in
@@ -0,0 +1,13 @@
+{
+ "version": 2,
+ "configurePresets": [
+ {
+ "name": "HostSystemNameFuture",
+ "generator": "@RunCMake_GENERATOR@",
+ "binaryDir": "${sourceDir}/build",
+ "cacheVariables": {
+ "TEST_HOST_SYSTEM_NAME": "${hostSystemName}"
+ }
+ }
+ ]
+}
diff --git a/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake b/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake
index ee21130..24ac0e9 100644
--- a/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake
@@ -261,6 +261,12 @@ set(CMakePresets_FILE "${RunCMake_SOURCE_DIR}/Debug.json.in")
run_cmake_presets(NoDebug)
run_cmake_presets(Debug)
+# Test ${hostSystemName} macro
+set(CMakePresets_FILE "${RunCMake_SOURCE_DIR}/HostSystemName.json.in")
+run_cmake_presets(HostSystemName)
+set(CMakePresets_FILE "${RunCMake_SOURCE_DIR}/HostSystemNameFuture.json.in")
+run_cmake_presets(HostSystemNameFuture)
+
# Test the example from the documentation
file(READ "${RunCMake_SOURCE_DIR}/../../../Help/manual/presets/example.json" _example)
string(REPLACE "\"generator\": \"Ninja\"" "\"generator\": \"@RunCMake_GENERATOR@\"" _example "${_example}")