1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmSiteNameCommand.cxx,v $
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>
22 bool cmSiteNameCommand
23 ::InitialPass(std::vector
<std::string
> const& args
, cmExecutionStatus
&)
27 this->SetError("called with incorrect number of arguments");
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());
45 const char *temp
= this->Makefile
->GetDefinition("HOSTNAME");
46 std::string hostname_cmd
;
53 hostname_cmd
= cmSystemTools::FindProgram("hostname", paths
);
56 std::string siteName
= "unknown";
57 #if defined(_WIN32) && !defined(__CYGWIN__)
59 if(cmSystemTools::ReadRegistryValue
60 ("HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\"
61 "Control\\ComputerName\\ComputerName;ComputerName", host
))
66 // try to find the hostname for this computer
67 if (!cmSystemTools::IsOff(hostname_cmd
.c_str()))
70 cmSystemTools::RunSingleCommand(hostname_cmd
.c_str(),
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()))
82 host
= hostReg
.match(1);
93 AddCacheDefinition(args
[0].c_str(),
95 "Name of the computer/site where compile is being run",
96 cmCacheManager::STRING
);