2016-09-27 15:01:08 -04:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2001-05-04 11:34:59 -04:00
|
|
|
#include "cmBuildNameCommand.h"
|
|
|
|
|
2016-10-19 08:54:18 +02:00
|
|
|
#include <algorithm>
|
2003-06-23 14:10:12 -04:00
|
|
|
|
2019-09-30 10:46:28 -04:00
|
|
|
#include "cmsys/RegularExpression.hxx"
|
|
|
|
|
2019-08-13 13:43:47 +02:00
|
|
|
#include "cmExecutionStatus.h"
|
2016-10-19 08:54:18 +02:00
|
|
|
#include "cmMakefile.h"
|
2016-10-25 20:35:04 +02:00
|
|
|
#include "cmStateTypes.h"
|
2016-10-19 08:54:18 +02:00
|
|
|
#include "cmSystemTools.h"
|
|
|
|
|
2019-08-13 13:43:47 +02:00
|
|
|
bool cmBuildNameCommand(std::vector<std::string> const& args,
|
|
|
|
cmExecutionStatus& status)
|
2001-05-04 11:34:59 -04:00
|
|
|
{
|
2016-09-15 23:59:29 +02:00
|
|
|
if (args.empty()) {
|
2019-08-13 13:43:47 +02:00
|
|
|
status.SetError("called with incorrect number of arguments");
|
2001-05-04 11:34:59 -04:00
|
|
|
return false;
|
2016-05-16 10:34:04 -04:00
|
|
|
}
|
2019-08-13 13:43:47 +02:00
|
|
|
cmMakefile& mf = status.GetMakefile();
|
|
|
|
const char* cacheValue = mf.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(), ')', '_');
|
2019-08-13 13:43:47 +02:00
|
|
|
mf.AddCacheDefinition(args[0], cv.c_str(), "Name of build.",
|
|
|
|
cmStateEnums::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";
|
2019-08-13 13:43:47 +02:00
|
|
|
if (mf.GetDefinition("UNIX")) {
|
2017-09-16 02:26:49 +03:00
|
|
|
buildname.clear();
|
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 = "([^ ]*) [^ ]* ([^ ]*) ";
|
2018-08-07 11:27:20 -04:00
|
|
|
cmsys::RegularExpression reg(RegExp);
|
|
|
|
if (reg.find(buildname)) {
|
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}";
|
2019-08-13 13:43:47 +02:00
|
|
|
mf.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
|
|
|
|
2019-08-13 13:43:47 +02:00
|
|
|
mf.AddCacheDefinition(args[0], buildname.c_str(), "Name of build.",
|
|
|
|
cmStateEnums::STRING);
|
2001-05-04 11:34:59 -04:00
|
|
|
return true;
|
|
|
|
}
|