cmake/Source/cmBuildNameCommand.cxx

62 lines
2.0 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmBuildNameCommand.h"
2017-04-14 19:02:05 +02:00
#include <algorithm>
2020-02-01 23:06:01 +01:00
#include "cmsys/RegularExpression.hxx"
#include "cmExecutionStatus.h"
2017-04-14 19:02:05 +02:00
#include "cmMakefile.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
2021-11-20 13:41:27 +01:00
#include "cmValue.h"
2017-04-14 19:02:05 +02:00
2020-02-01 23:06:01 +01:00
bool cmBuildNameCommand(std::vector<std::string> const& args,
cmExecutionStatus& status)
{
2016-10-30 18:24:19 +01:00
if (args.empty()) {
2020-02-01 23:06:01 +01:00
status.SetError("called with incorrect number of arguments");
return false;
2016-07-09 11:21:54 +02:00
}
2020-02-01 23:06:01 +01:00
cmMakefile& mf = status.GetMakefile();
2021-11-20 13:41:27 +01:00
cmValue cacheValue = mf.GetDefinition(args[0]);
2016-07-09 11:21:54 +02:00
if (cacheValue) {
2013-03-16 19:13:01 +02:00
// do we need to correct the value?
cmsys::RegularExpression reg("[()/]");
2021-09-14 00:13:48 +02:00
std::string cv = *cacheValue;
if (reg.find(cv)) {
2016-07-09 11:21:54 +02:00
std::replace(cv.begin(), cv.end(), '/', '_');
std::replace(cv.begin(), cv.end(), '(', '_');
std::replace(cv.begin(), cv.end(), ')', '_');
2020-08-30 11:54:41 +02:00
mf.AddCacheDefinition(args[0], cv, "Name of build.",
2020-02-01 23:06:01 +01:00
cmStateEnums::STRING);
}
2016-07-09 11:21:54 +02:00
return true;
}
2013-03-16 19:13:01 +02:00
std::string buildname = "WinNT";
2020-02-01 23:06:01 +01:00
if (mf.GetDefinition("UNIX")) {
2018-01-26 17:06:56 +01:00
buildname.clear();
2015-08-17 11:37:30 +02:00
cmSystemTools::RunSingleCommand("uname -a", &buildname, &buildname);
2016-07-09 11:21:54 +02:00
if (!buildname.empty()) {
std::string RegExp = "([^ ]*) [^ ]* ([^ ]*) ";
2018-10-28 12:09:07 +01:00
cmsys::RegularExpression reg(RegExp);
if (reg.find(buildname)) {
buildname = reg.match(1) + "-" + reg.match(2);
}
}
2016-07-09 11:21:54 +02:00
}
std::string compiler = "${CMAKE_CXX_COMPILER}";
2020-02-01 23:06:01 +01:00
mf.ExpandVariablesInString(compiler);
buildname += "-";
buildname += cmSystemTools::GetFilenameName(compiler);
2016-07-09 11:21:54 +02:00
std::replace(buildname.begin(), buildname.end(), '/', '_');
std::replace(buildname.begin(), buildname.end(), '(', '_');
std::replace(buildname.begin(), buildname.end(), ')', '_');
2013-03-16 19:13:01 +02:00
2020-08-30 11:54:41 +02:00
mf.AddCacheDefinition(args[0], buildname, "Name of build.",
2020-02-01 23:06:01 +01:00
cmStateEnums::STRING);
return true;
}