diff options
author | Brad King <brad.king@kitware.com> | 2021-03-16 14:51:25 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2021-03-16 14:51:32 (GMT) |
commit | 3cea13c2f33c9ac46332ba1aa1d5a67042849c7a (patch) | |
tree | ec8fc6b10740100d79af8395c394148234242ebc /Source/cmSystemTools.cxx | |
parent | 84f94fb1964a7a8b09fb83e79f1ea6032add3b8d (diff) | |
parent | 0d497e159b5854ed050d9eb8c4e965976a03de11 (diff) | |
download | CMake-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
Diffstat (limited to 'Source/cmSystemTools.cxx')
-rw-r--r-- | Source/cmSystemTools.cxx | 47 |
1 files changed, 47 insertions, 0 deletions
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 +} |