KWSys Nightly Date Stamp
[cmake.git] / Source / cmSiteNameCommand.cxx
blob27e67487bf5ac90749480b804f47f4463add0128
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmSiteNameCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2008-01-23 15:27:59 $
7 Version: $Revision: 1.24 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmSiteNameCommand.h"
19 #include <cmsys/RegularExpression.hxx>
21 // cmSiteNameCommand
22 bool cmSiteNameCommand
23 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
25 if(args.size() != 1 )
27 this->SetError("called with incorrect number of arguments");
28 return false;
30 std::vector<std::string> paths;
31 paths.push_back("/usr/bsd");
32 paths.push_back("/usr/sbin");
33 paths.push_back("/usr/bin");
34 paths.push_back("/bin");
35 paths.push_back("/sbin");
36 paths.push_back("/usr/local/bin");
38 const char* cacheValue
39 = this->Makefile->GetDefinition(args[0].c_str());
40 if(cacheValue)
42 return true;
45 const char *temp = this->Makefile->GetDefinition("HOSTNAME");
46 std::string hostname_cmd;
47 if(temp)
49 hostname_cmd = temp;
51 else
53 hostname_cmd = cmSystemTools::FindProgram("hostname", paths);
56 std::string siteName = "unknown";
57 #if defined(_WIN32) && !defined(__CYGWIN__)
58 std::string host;
59 if(cmSystemTools::ReadRegistryValue
60 ("HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\"
61 "Control\\ComputerName\\ComputerName;ComputerName", host))
63 siteName = host;
65 #else
66 // try to find the hostname for this computer
67 if (!cmSystemTools::IsOff(hostname_cmd.c_str()))
69 std::string host;
70 cmSystemTools::RunSingleCommand(hostname_cmd.c_str(),
71 &host, 0, 0, false);
73 // got the hostname
74 if (host.length())
76 // remove any white space from the host name
77 std::string hostRegExp = "[ \t\n\r]*([^\t\n\r ]*)[ \t\n\r]*";
78 cmsys::RegularExpression hostReg (hostRegExp.c_str());
79 if (hostReg.find(host.c_str()))
81 // strip whitespace
82 host = hostReg.match(1);
85 if(host.length())
87 siteName = host;
91 #endif
92 this->Makefile->
93 AddCacheDefinition(args[0].c_str(),
94 siteName.c_str(),
95 "Name of the computer/site where compile is being run",
96 cmCacheManager::STRING);
98 return true;