1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-20 21:40:15 +08:00

cmBuildNameCommand: Implement as free function

This commit is contained in:
Regina Pfeifer
2019-08-13 13:43:47 +02:00
parent 86bf1eef75
commit c55fb044a9
4 changed files with 16 additions and 28 deletions

View File

@@ -5,21 +5,20 @@
#include "cmsys/RegularExpression.hxx" #include "cmsys/RegularExpression.hxx"
#include <algorithm> #include <algorithm>
#include "cmExecutionStatus.h"
#include "cmMakefile.h" #include "cmMakefile.h"
#include "cmStateTypes.h" #include "cmStateTypes.h"
#include "cmSystemTools.h" #include "cmSystemTools.h"
class cmExecutionStatus; bool cmBuildNameCommand(std::vector<std::string> const& args,
cmExecutionStatus& status)
// cmBuildNameCommand
bool cmBuildNameCommand::InitialPass(std::vector<std::string> const& args,
cmExecutionStatus&)
{ {
if (args.empty()) { if (args.empty()) {
this->SetError("called with incorrect number of arguments"); status.SetError("called with incorrect number of arguments");
return false; return false;
} }
const char* cacheValue = this->Makefile->GetDefinition(args[0]); cmMakefile& mf = status.GetMakefile();
const char* cacheValue = mf.GetDefinition(args[0]);
if (cacheValue) { if (cacheValue) {
// do we need to correct the value? // do we need to correct the value?
cmsys::RegularExpression reg("[()/]"); cmsys::RegularExpression reg("[()/]");
@@ -28,14 +27,14 @@ bool cmBuildNameCommand::InitialPass(std::vector<std::string> const& args,
std::replace(cv.begin(), cv.end(), '/', '_'); std::replace(cv.begin(), cv.end(), '/', '_');
std::replace(cv.begin(), cv.end(), '(', '_'); std::replace(cv.begin(), cv.end(), '(', '_');
std::replace(cv.begin(), cv.end(), ')', '_'); std::replace(cv.begin(), cv.end(), ')', '_');
this->Makefile->AddCacheDefinition(args[0], cv.c_str(), "Name of build.", mf.AddCacheDefinition(args[0], cv.c_str(), "Name of build.",
cmStateEnums::STRING); cmStateEnums::STRING);
} }
return true; return true;
} }
std::string buildname = "WinNT"; std::string buildname = "WinNT";
if (this->Makefile->GetDefinition("UNIX")) { if (mf.GetDefinition("UNIX")) {
buildname.clear(); buildname.clear();
cmSystemTools::RunSingleCommand("uname -a", &buildname, &buildname); cmSystemTools::RunSingleCommand("uname -a", &buildname, &buildname);
if (!buildname.empty()) { if (!buildname.empty()) {
@@ -47,14 +46,14 @@ bool cmBuildNameCommand::InitialPass(std::vector<std::string> const& args,
} }
} }
std::string compiler = "${CMAKE_CXX_COMPILER}"; std::string compiler = "${CMAKE_CXX_COMPILER}";
this->Makefile->ExpandVariablesInString(compiler); mf.ExpandVariablesInString(compiler);
buildname += "-"; buildname += "-";
buildname += cmSystemTools::GetFilenameName(compiler); buildname += cmSystemTools::GetFilenameName(compiler);
std::replace(buildname.begin(), buildname.end(), '/', '_'); std::replace(buildname.begin(), buildname.end(), '/', '_');
std::replace(buildname.begin(), buildname.end(), '(', '_'); std::replace(buildname.begin(), buildname.end(), '(', '_');
std::replace(buildname.begin(), buildname.end(), ')', '_'); std::replace(buildname.begin(), buildname.end(), ')', '_');
this->Makefile->AddCacheDefinition(args[0], buildname.c_str(), mf.AddCacheDefinition(args[0], buildname.c_str(), "Name of build.",
"Name of build.", cmStateEnums::STRING); cmStateEnums::STRING);
return true; return true;
} }

View File

@@ -8,21 +8,9 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "cm_memory.hxx"
#include "cmCommand.h"
class cmExecutionStatus; class cmExecutionStatus;
class cmBuildNameCommand : public cmCommand bool cmBuildNameCommand(std::vector<std::string> const& args,
{ cmExecutionStatus& status);
public:
std::unique_ptr<cmCommand> Clone() override
{
return cm::make_unique<cmBuildNameCommand>();
}
bool InitialPass(std::vector<std::string> const& args,
cmExecutionStatus& status) override;
};
#endif #endif

View File

@@ -221,7 +221,7 @@ void GetScriptingCommands(cmState* state)
cm::make_unique<cmWriteFileCommand>()); cm::make_unique<cmWriteFileCommand>());
state->AddDisallowedCommand( state->AddDisallowedCommand(
"build_name", cm::make_unique<cmBuildNameCommand>(), cmPolicies::CMP0036, "build_name", cmBuildNameCommand, cmPolicies::CMP0036,
"The build_name command should not be called; see CMP0036."); "The build_name command should not be called; see CMP0036.");
state->AddDisallowedCommand( state->AddDisallowedCommand(
"use_mangled_mesa", cm::make_unique<cmUseMangledMesaCommand>(), "use_mangled_mesa", cm::make_unique<cmUseMangledMesaCommand>(),

View File

@@ -19,6 +19,7 @@
#include "cmGlobVerificationManager.h" #include "cmGlobVerificationManager.h"
#include "cmListFileCache.h" #include "cmListFileCache.h"
#include "cmMakefile.h" #include "cmMakefile.h"
#include "cmMessageType.h"
#include "cmStatePrivate.h" #include "cmStatePrivate.h"
#include "cmStateSnapshot.h" #include "cmStateSnapshot.h"
#include "cmStringAlgorithms.h" #include "cmStringAlgorithms.h"