packaging: Initial packaging
[platform/upstream/cmake.git] / Source / cmBuildNameCommand.cxx
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
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 "cmBuildNameCommand.h"
13
14 #include <cmsys/RegularExpression.hxx>
15
16 // cmBuildNameCommand
17 bool cmBuildNameCommand
18 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
19 {
20   if(args.size() < 1 )
21     {
22     this->SetError("called with incorrect number of arguments");
23     return false;
24     }
25   const char* cacheValue = this->Makefile->GetDefinition(args[0].c_str());
26   if(cacheValue)
27     {
28     // do we need to correct the value?
29     cmsys::RegularExpression reg("[()/]");
30     if (reg.find(cacheValue))
31       {
32       std::string cv = cacheValue;
33       cmSystemTools::ReplaceString(cv,"/", "_");
34       cmSystemTools::ReplaceString(cv,"(", "_");
35       cmSystemTools::ReplaceString(cv,")", "_");
36       this->Makefile->AddCacheDefinition(args[0].c_str(),
37                                      cv.c_str(),
38                                      "Name of build.",
39                                      cmCacheManager::STRING);
40       }
41     return true;
42     }
43
44
45   std::string buildname = "WinNT";
46   if(this->Makefile->GetDefinition("UNIX"))
47     {
48     buildname = "";
49     cmSystemTools::RunSingleCommand("uname -a", &buildname);
50     if(buildname.length())
51       {
52       std::string RegExp = "([^ ]*) [^ ]* ([^ ]*) ";
53       cmsys::RegularExpression reg( RegExp.c_str() );
54       if(reg.find(buildname.c_str()))
55         {
56         buildname = reg.match(1) + "-" + reg.match(2);
57         }
58       }
59     }
60   std::string compiler = "${CMAKE_CXX_COMPILER}";
61   this->Makefile->ExpandVariablesInString ( compiler );
62   buildname += "-";
63   buildname += cmSystemTools::GetFilenameName(compiler);
64   cmSystemTools::ReplaceString(buildname,
65                                "/", "_");
66   cmSystemTools::ReplaceString(buildname,
67                                "(", "_");
68   cmSystemTools::ReplaceString(buildname,
69                                ")", "_");
70
71   this->Makefile->AddCacheDefinition(args[0].c_str(),
72                                  buildname.c_str(),
73                                  "Name of build.",
74                                  cmCacheManager::STRING);
75   return true;
76 }
77