Clarify documentation for if.
[cmake.git] / Source / cmBuildNameCommand.cxx
blob08a9e2a21366a3da4804b13172a0d721306a20dd
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmBuildNameCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2008-01-23 15:27:59 $
7 Version: $Revision: 1.19 $
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 "cmBuildNameCommand.h"
19 #include <cmsys/RegularExpression.hxx>
21 // cmBuildNameCommand
22 bool cmBuildNameCommand
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 const char* cacheValue = this->Makefile->GetDefinition(args[0].c_str());
31 if(cacheValue)
33 // do we need to correct the value?
34 cmsys::RegularExpression reg("[()/]");
35 if (reg.find(cacheValue))
37 std::string cv = cacheValue;
38 cmSystemTools::ReplaceString(cv,"/", "_");
39 cmSystemTools::ReplaceString(cv,"(", "_");
40 cmSystemTools::ReplaceString(cv,")", "_");
41 this->Makefile->AddCacheDefinition(args[0].c_str(),
42 cv.c_str(),
43 "Name of build.",
44 cmCacheManager::STRING);
46 return true;
50 std::string buildname = "WinNT";
51 if(this->Makefile->GetDefinition("UNIX"))
53 buildname = "";
54 cmSystemTools::RunSingleCommand("uname -a", &buildname);
55 if(buildname.length())
57 std::string RegExp = "([^ ]*) [^ ]* ([^ ]*) ";
58 cmsys::RegularExpression reg( RegExp.c_str() );
59 if(reg.find(buildname.c_str()))
61 buildname = reg.match(1) + "-" + reg.match(2);
65 std::string compiler = "${CMAKE_CXX_COMPILER}";
66 this->Makefile->ExpandVariablesInString ( compiler );
67 buildname += "-";
68 buildname += cmSystemTools::GetFilenameName(compiler);
69 cmSystemTools::ReplaceString(buildname,
70 "/", "_");
71 cmSystemTools::ReplaceString(buildname,
72 "(", "_");
73 cmSystemTools::ReplaceString(buildname,
74 ")", "_");
76 this->Makefile->AddCacheDefinition(args[0].c_str(),
77 buildname.c_str(),
78 "Name of build.",
79 cmCacheManager::STRING);
80 return true;