2009-09-28 11:43:28 -04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2001-05-04 11:34:59 -04:00
|
|
|
|
2009-09-28 11:43:28 -04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2001-05-04 11:34:59 -04:00
|
|
|
|
2009-09-28 11:43:28 -04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2001-05-04 11:34:59 -04:00
|
|
|
#include "cmBuildNameCommand.h"
|
|
|
|
|
2003-06-23 14:10:12 -04:00
|
|
|
#include <cmsys/RegularExpression.hxx>
|
|
|
|
|
2001-05-04 11:34:59 -04:00
|
|
|
// cmBuildNameCommand
|
2016-05-16 10:34:04 -04:00
|
|
|
bool cmBuildNameCommand::InitialPass(std::vector<std::string> const& args,
|
|
|
|
cmExecutionStatus&)
|
2001-05-04 11:34:59 -04:00
|
|
|
{
|
2016-05-16 10:34:04 -04:00
|
|
|
if (this->Disallowed(
|
|
|
|
cmPolicies::CMP0036,
|
|
|
|
"The build_name command should not be called; see CMP0036.")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (args.size() < 1) {
|
2001-05-04 11:34:59 -04:00
|
|
|
this->SetError("called with incorrect number of arguments");
|
|
|
|
return false;
|
2016-05-16 10:34:04 -04:00
|
|
|
}
|
2014-03-11 00:04:11 +01:00
|
|
|
const char* cacheValue = this->Makefile->GetDefinition(args[0]);
|
2016-05-16 10:34:04 -04:00
|
|
|
if (cacheValue) {
|
2012-08-13 13:42:58 -04:00
|
|
|
// do we need to correct the value?
|
2003-06-23 14:10:12 -04:00
|
|
|
cmsys::RegularExpression reg("[()/]");
|
2016-05-16 10:34:04 -04:00
|
|
|
if (reg.find(cacheValue)) {
|
2001-07-10 09:23:34 -04:00
|
|
|
std::string cv = cacheValue;
|
Use std::replace for replacing chars in strings.
Find uses of `cmSystemTools::ReplaceString` where both `replace` and
`with` are string literals with a size of one.
Automate with:
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\2', '\3');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\\\\\\\\\");|std::replace(\1.begin(), \1.end(), '\2', '\\\\\\\\');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\\\\\\\\\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\\\\\\\\', '\2');|g"
2016-05-24 22:58:11 +02:00
|
|
|
std::replace(cv.begin(), cv.end(), '/', '_');
|
|
|
|
std::replace(cv.begin(), cv.end(), '(', '_');
|
|
|
|
std::replace(cv.begin(), cv.end(), ')', '_');
|
2016-05-16 10:34:04 -04:00
|
|
|
this->Makefile->AddCacheDefinition(args[0], cv.c_str(), "Name of build.",
|
|
|
|
cmState::STRING);
|
2001-05-04 11:34:59 -04:00
|
|
|
}
|
2016-05-16 10:34:04 -04:00
|
|
|
return true;
|
|
|
|
}
|
2012-08-13 13:42:58 -04:00
|
|
|
|
2001-05-16 15:15:21 -04:00
|
|
|
std::string buildname = "WinNT";
|
2016-05-16 10:34:04 -04:00
|
|
|
if (this->Makefile->GetDefinition("UNIX")) {
|
2001-05-04 11:34:59 -04:00
|
|
|
buildname = "";
|
2015-04-20 15:36:57 -04:00
|
|
|
cmSystemTools::RunSingleCommand("uname -a", &buildname, &buildname);
|
2016-05-16 10:34:04 -04:00
|
|
|
if (!buildname.empty()) {
|
2001-05-04 16:44:24 -04:00
|
|
|
std::string RegExp = "([^ ]*) [^ ]* ([^ ]*) ";
|
2016-05-16 10:34:04 -04:00
|
|
|
cmsys::RegularExpression reg(RegExp.c_str());
|
|
|
|
if (reg.find(buildname.c_str())) {
|
2002-10-23 18:03:27 -04:00
|
|
|
buildname = reg.match(1) + "-" + reg.match(2);
|
2001-05-04 16:44:24 -04:00
|
|
|
}
|
2001-05-04 11:34:59 -04:00
|
|
|
}
|
2016-05-16 10:34:04 -04:00
|
|
|
}
|
2002-04-26 09:55:32 -04:00
|
|
|
std::string compiler = "${CMAKE_CXX_COMPILER}";
|
2016-05-16 10:34:04 -04:00
|
|
|
this->Makefile->ExpandVariablesInString(compiler);
|
2002-04-26 09:55:32 -04:00
|
|
|
buildname += "-";
|
2001-07-02 16:30:40 -04:00
|
|
|
buildname += cmSystemTools::GetFilenameName(compiler);
|
Use std::replace for replacing chars in strings.
Find uses of `cmSystemTools::ReplaceString` where both `replace` and
`with` are string literals with a size of one.
Automate with:
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\2', '\3');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\\\\\\\\\");|std::replace(\1.begin(), \1.end(), '\2', '\\\\\\\\');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\\\\\\\\\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\\\\\\\\', '\2');|g"
2016-05-24 22:58:11 +02:00
|
|
|
std::replace(buildname.begin(), buildname.end(), '/', '_');
|
|
|
|
std::replace(buildname.begin(), buildname.end(), '(', '_');
|
|
|
|
std::replace(buildname.begin(), buildname.end(), ')', '_');
|
2012-08-13 13:42:58 -04:00
|
|
|
|
2016-05-16 10:34:04 -04:00
|
|
|
this->Makefile->AddCacheDefinition(args[0], buildname.c_str(),
|
|
|
|
"Name of build.", cmState::STRING);
|
2001-05-04 11:34:59 -04:00
|
|
|
return true;
|
|
|
|
}
|