1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #include "cmSiteNameCommand.h"
5 #include "cmsys/RegularExpression.hxx"
7 #include "cmExecutionStatus.h"
8 #include "cmMakefile.h"
9 #include "cmStateTypes.h"
10 #include "cmSystemTools.h"
14 bool cmSiteNameCommand(std::vector<std::string> const& args,
15 cmExecutionStatus& status)
17 if (args.size() != 1) {
18 status.SetError("called with incorrect number of arguments");
21 std::vector<std::string> paths;
22 paths.emplace_back("/usr/bsd");
23 paths.emplace_back("/usr/sbin");
24 paths.emplace_back("/usr/bin");
25 paths.emplace_back("/bin");
26 paths.emplace_back("/sbin");
27 paths.emplace_back("/usr/local/bin");
29 cmValue cacheValue = status.GetMakefile().GetDefinition(args[0]);
34 cmValue temp = status.GetMakefile().GetDefinition("HOSTNAME");
35 std::string hostname_cmd;
39 hostname_cmd = cmSystemTools::FindProgram("hostname", paths);
42 std::string siteName = "unknown";
43 #if defined(_WIN32) && !defined(__CYGWIN__)
45 if (cmSystemTools::ReadRegistryValue(
46 "HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\"
47 "Control\\ComputerName\\ComputerName;ComputerName",
52 // try to find the hostname for this computer
53 if (!cmIsOff(hostname_cmd)) {
55 cmSystemTools::RunSingleCommand(hostname_cmd, &host, nullptr, nullptr,
56 nullptr, cmSystemTools::OUTPUT_NONE);
60 // remove any white space from the host name
61 std::string hostRegExp = "[ \t\n\r]*([^\t\n\r ]*)[ \t\n\r]*";
62 cmsys::RegularExpression hostReg(hostRegExp.c_str());
63 if (hostReg.find(host.c_str())) {
65 host = hostReg.match(1);
74 status.GetMakefile().AddCacheDefinition(
75 args[0], siteName, "Name of the computer/site where compile is being run",
76 cmStateEnums::STRING);