1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
12 #include "cmSiteNameCommand.h"
14 #include <cmsys/RegularExpression.hxx>
17 bool cmSiteNameCommand
18 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
22 this->SetError("called with incorrect number of arguments");
25 std::vector<std::string> paths;
26 paths.push_back("/usr/bsd");
27 paths.push_back("/usr/sbin");
28 paths.push_back("/usr/bin");
29 paths.push_back("/bin");
30 paths.push_back("/sbin");
31 paths.push_back("/usr/local/bin");
33 const char* cacheValue
34 = this->Makefile->GetDefinition(args[0].c_str());
40 const char *temp = this->Makefile->GetDefinition("HOSTNAME");
41 std::string hostname_cmd;
48 hostname_cmd = cmSystemTools::FindProgram("hostname", paths);
51 std::string siteName = "unknown";
52 #if defined(_WIN32) && !defined(__CYGWIN__)
54 if(cmSystemTools::ReadRegistryValue
55 ("HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\"
56 "Control\\ComputerName\\ComputerName;ComputerName", host))
61 // try to find the hostname for this computer
62 if (!cmSystemTools::IsOff(hostname_cmd.c_str()))
65 cmSystemTools::RunSingleCommand(hostname_cmd.c_str(),
66 &host, 0, 0, cmSystemTools::OUTPUT_NONE);
71 // remove any white space from the host name
72 std::string hostRegExp = "[ \t\n\r]*([^\t\n\r ]*)[ \t\n\r]*";
73 cmsys::RegularExpression hostReg (hostRegExp.c_str());
74 if (hostReg.find(host.c_str()))
77 host = hostReg.match(1);
88 AddCacheDefinition(args[0].c_str(),
90 "Name of the computer/site where compile is being run",
91 cmCacheManager::STRING);