1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-16 14:08:35 +08:00

cmCommand refactor: cmSetPropertyCommand

This commit is contained in:
Gabor Bencze
2019-08-09 15:07:45 +02:00
committed by Brad King
parent 7c83c19205
commit 36f32d3604
3 changed files with 256 additions and 198 deletions

View File

@@ -156,8 +156,7 @@ void GetScriptingCommands(cmState* state)
state->AddBuiltinCommand("set", cmSetCommand); state->AddBuiltinCommand("set", cmSetCommand);
state->AddBuiltinCommand("set_directory_properties", state->AddBuiltinCommand("set_directory_properties",
cmSetDirectoryPropertiesCommand); cmSetDirectoryPropertiesCommand);
state->AddBuiltinCommand("set_property", state->AddBuiltinCommand("set_property", cmSetPropertyCommand);
cm::make_unique<cmSetPropertyCommand>());
state->AddBuiltinCommand("site_name", cmSiteNameCommand); state->AddBuiltinCommand("site_name", cmSiteNameCommand);
state->AddBuiltinCommand("string", cm::make_unique<cmStringCommand>()); state->AddBuiltinCommand("string", cm::make_unique<cmStringCommand>());
state->AddBuiltinCommand("unset", cmUnsetCommand); state->AddBuiltinCommand("unset", cmUnsetCommand);

View File

@@ -2,8 +2,10 @@
file Copyright.txt or https://cmake.org/licensing for details. */ file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmSetPropertyCommand.h" #include "cmSetPropertyCommand.h"
#include <set>
#include <sstream> #include <sstream>
#include "cmExecutionStatus.h"
#include "cmGlobalGenerator.h" #include "cmGlobalGenerator.h"
#include "cmInstalledFile.h" #include "cmInstalledFile.h"
#include "cmMakefile.h" #include "cmMakefile.h"
@@ -17,20 +19,66 @@
#include "cmTest.h" #include "cmTest.h"
#include "cmake.h" #include "cmake.h"
class cmExecutionStatus; namespace {
bool HandleGlobalMode(cmExecutionStatus& status,
cmSetPropertyCommand::cmSetPropertyCommand() const std::set<std::string>& names,
{ const std::string& propertyName,
this->AppendMode = false; const std::string& propertyValue, bool appendAsString,
this->AppendAsString = false; bool appendMode, bool remove);
this->Remove = true; bool HandleDirectoryMode(cmExecutionStatus& status,
const std::set<std::string>& names,
const std::string& propertyName,
const std::string& propertyValue, bool appendAsString,
bool appendMode, bool remove);
bool HandleTargetMode(cmExecutionStatus& status,
const std::set<std::string>& names,
const std::string& propertyName,
const std::string& propertyValue, bool appendAsString,
bool appendMode, bool remove);
bool HandleTarget(cmTarget* target, cmMakefile& makefile,
const std::string& propertyName,
const std::string& propertyValue, bool appendAsString,
bool appendMode, bool remove);
bool HandleSourceMode(cmExecutionStatus& status,
const std::set<std::string>& names,
const std::string& propertyName,
const std::string& propertyValue, bool appendAsString,
bool appendMode, bool remove);
bool HandleSource(cmSourceFile* sf, const std::string& propertyName,
const std::string& propertyValue, bool appendAsString,
bool appendMode, bool remove);
bool HandleTestMode(cmExecutionStatus& status, std::set<std::string>& names,
const std::string& propertyName,
const std::string& propertyValue, bool appendAsString,
bool appendMode, bool remove);
bool HandleTest(cmTest* test, const std::string& propertyName,
const std::string& propertyValue, bool appendAsString,
bool appendMode, bool remove);
bool HandleCacheMode(cmExecutionStatus& status,
const std::set<std::string>& names,
const std::string& propertyName,
const std::string& propertyValue, bool appendAsString,
bool appendMode, bool remove);
bool HandleCacheEntry(std::string const& cacheKey, const cmMakefile& makefile,
const std::string& propertyName,
const std::string& propertyValue, bool appendAsString,
bool appendMode, bool remove);
bool HandleInstallMode(cmExecutionStatus& status,
const std::set<std::string>& names,
const std::string& propertyName,
const std::string& propertyValue, bool appendAsString,
bool appendMode, bool remove);
bool HandleInstall(cmInstalledFile* file, cmMakefile& makefile,
const std::string& propertyName,
const std::string& propertyValue, bool appendAsString,
bool appendMode, bool remove);
} }
bool cmSetPropertyCommand::InitialPass(std::vector<std::string> const& args, bool cmSetPropertyCommand(std::vector<std::string> const& args,
cmExecutionStatus&) cmExecutionStatus& status)
{ {
if (args.size() < 2) { if (args.size() < 2) {
this->SetError("called with incorrect number of arguments"); status.SetError("called with incorrect number of arguments");
return false; return false;
} }
@@ -56,10 +104,17 @@ bool cmSetPropertyCommand::InitialPass(std::vector<std::string> const& args,
e << "given invalid scope " << scopeName << ". " e << "given invalid scope " << scopeName << ". "
<< "Valid scopes are GLOBAL, DIRECTORY, " << "Valid scopes are GLOBAL, DIRECTORY, "
"TARGET, SOURCE, TEST, CACHE, INSTALL."; "TARGET, SOURCE, TEST, CACHE, INSTALL.";
this->SetError(e.str()); status.SetError(e.str());
return false; return false;
} }
bool appendAsString = false;
bool appendMode = false;
bool remove = true;
std::set<std::string> names;
std::string propertyName;
std::string propertyValue;
// Parse the rest of the arguments up to the values. // Parse the rest of the arguments up to the values.
enum Doing enum Doing
{ {
@@ -75,54 +130,61 @@ bool cmSetPropertyCommand::InitialPass(std::vector<std::string> const& args,
doing = DoingProperty; doing = DoingProperty;
} else if (arg == "APPEND") { } else if (arg == "APPEND") {
doing = DoingNone; doing = DoingNone;
this->AppendMode = true; appendMode = true;
this->Remove = false; remove = false;
this->AppendAsString = false; appendAsString = false;
} else if (arg == "APPEND_STRING") { } else if (arg == "APPEND_STRING") {
doing = DoingNone; doing = DoingNone;
this->AppendMode = true; appendMode = true;
this->Remove = false; remove = false;
this->AppendAsString = true; appendAsString = true;
} else if (doing == DoingNames) { } else if (doing == DoingNames) {
this->Names.insert(arg); names.insert(arg);
} else if (doing == DoingProperty) { } else if (doing == DoingProperty) {
this->PropertyName = arg; propertyName = arg;
doing = DoingValues; doing = DoingValues;
} else if (doing == DoingValues) { } else if (doing == DoingValues) {
this->PropertyValue += sep; propertyValue += sep;
sep = ";"; sep = ";";
this->PropertyValue += arg; propertyValue += arg;
this->Remove = false; remove = false;
} else { } else {
std::ostringstream e; std::ostringstream e;
e << "given invalid argument \"" << arg << "\"."; e << "given invalid argument \"" << arg << "\".";
this->SetError(e.str()); status.SetError(e.str());
return false; return false;
} }
} }
// Make sure a property name was found. // Make sure a property name was found.
if (this->PropertyName.empty()) { if (propertyName.empty()) {
this->SetError("not given a PROPERTY <name> argument."); status.SetError("not given a PROPERTY <name> argument.");
return false; return false;
} }
// Dispatch property setting. // Dispatch property setting.
switch (scope) { switch (scope) {
case cmProperty::GLOBAL: case cmProperty::GLOBAL:
return this->HandleGlobalMode(); return HandleGlobalMode(status, names, propertyName, propertyValue,
appendAsString, appendMode, remove);
case cmProperty::DIRECTORY: case cmProperty::DIRECTORY:
return this->HandleDirectoryMode(); return HandleDirectoryMode(status, names, propertyName, propertyValue,
appendAsString, appendMode, remove);
case cmProperty::TARGET: case cmProperty::TARGET:
return this->HandleTargetMode(); return HandleTargetMode(status, names, propertyName, propertyValue,
appendAsString, appendMode, remove);
case cmProperty::SOURCE_FILE: case cmProperty::SOURCE_FILE:
return this->HandleSourceMode(); return HandleSourceMode(status, names, propertyName, propertyValue,
appendAsString, appendMode, remove);
case cmProperty::TEST: case cmProperty::TEST:
return this->HandleTestMode(); return HandleTestMode(status, names, propertyName, propertyValue,
appendAsString, appendMode, remove);
case cmProperty::CACHE: case cmProperty::CACHE:
return this->HandleCacheMode(); return HandleCacheMode(status, names, propertyName, propertyValue,
appendAsString, appendMode, remove);
case cmProperty::INSTALL: case cmProperty::INSTALL:
return this->HandleInstallMode(); return HandleInstallMode(status, names, propertyName, propertyValue,
appendAsString, appendMode, remove);
case cmProperty::VARIABLE: case cmProperty::VARIABLE:
case cmProperty::CACHED_VARIABLE: case cmProperty::CACHED_VARIABLE:
@@ -131,57 +193,67 @@ bool cmSetPropertyCommand::InitialPass(std::vector<std::string> const& args,
return true; return true;
} }
bool cmSetPropertyCommand::HandleGlobalMode() namespace {
bool HandleGlobalMode(cmExecutionStatus& status,
const std::set<std::string>& names,
const std::string& propertyName,
const std::string& propertyValue,
const bool appendAsString, const bool appendMode,
const bool remove)
{ {
if (!this->Names.empty()) { if (!names.empty()) {
this->SetError("given names for GLOBAL scope."); status.SetError("given names for GLOBAL scope.");
return false; return false;
} }
// Set or append the property. // Set or append the property.
cmake* cm = this->Makefile->GetCMakeInstance(); cmake* cm = status.GetMakefile().GetCMakeInstance();
std::string const& name = this->PropertyName; const char* value = propertyValue.c_str();
const char* value = this->PropertyValue.c_str(); if (remove) {
if (this->Remove) {
value = nullptr; value = nullptr;
} }
if (this->AppendMode) { if (appendMode) {
cm->AppendProperty(name, value ? value : "", this->AppendAsString); cm->AppendProperty(propertyName, value ? value : "", appendAsString);
} else { } else {
cm->SetProperty(name, value); cm->SetProperty(propertyName, value);
} }
return true; return true;
} }
bool cmSetPropertyCommand::HandleDirectoryMode() bool HandleDirectoryMode(cmExecutionStatus& status,
const std::set<std::string>& names,
const std::string& propertyName,
const std::string& propertyValue,
const bool appendAsString, const bool appendMode,
const bool remove)
{ {
if (this->Names.size() > 1) { if (names.size() > 1) {
this->SetError("allows at most one name for DIRECTORY scope."); status.SetError("allows at most one name for DIRECTORY scope.");
return false; return false;
} }
// Default to the current directory. // Default to the current directory.
cmMakefile* mf = this->Makefile; cmMakefile* mf = &status.GetMakefile();
// Lookup the directory if given. // Lookup the directory if given.
if (!this->Names.empty()) { if (!names.empty()) {
// Construct the directory name. Interpret relative paths with // Construct the directory name. Interpret relative paths with
// respect to the current directory. // respect to the current directory.
std::string dir = *this->Names.begin(); std::string dir = *names.begin();
if (!cmSystemTools::FileIsFullPath(dir)) { if (!cmSystemTools::FileIsFullPath(dir)) {
dir = this->Makefile->GetCurrentSourceDirectory(); dir = status.GetMakefile().GetCurrentSourceDirectory();
dir += "/"; dir += "/";
dir += *this->Names.begin(); dir += *names.begin();
} }
// The local generators are associated with collapsed paths. // The local generators are associated with collapsed paths.
dir = cmSystemTools::CollapseFullPath(dir); dir = cmSystemTools::CollapseFullPath(dir);
mf = this->Makefile->GetGlobalGenerator()->FindMakefile(dir); mf = status.GetMakefile().GetGlobalGenerator()->FindMakefile(dir);
if (!mf) { if (!mf) {
// Could not find the directory. // Could not find the directory.
this->SetError( status.SetError(
"DIRECTORY scope provided but requested directory was not found. " "DIRECTORY scope provided but requested directory was not found. "
"This could be because the directory argument was invalid or, " "This could be because the directory argument was invalid or, "
"it is valid but has not been processed yet."); "it is valid but has not been processed yet.");
@@ -190,109 +262,128 @@ bool cmSetPropertyCommand::HandleDirectoryMode()
} }
// Set or append the property. // Set or append the property.
std::string const& name = this->PropertyName; const char* value = propertyValue.c_str();
const char* value = this->PropertyValue.c_str(); if (remove) {
if (this->Remove) {
value = nullptr; value = nullptr;
} }
if (this->AppendMode) { if (appendMode) {
mf->AppendProperty(name, value ? value : "", this->AppendAsString); mf->AppendProperty(propertyName, value ? value : "", appendAsString);
} else { } else {
mf->SetProperty(name, value); mf->SetProperty(propertyName, value);
} }
return true; return true;
} }
bool cmSetPropertyCommand::HandleTargetMode() bool HandleTargetMode(cmExecutionStatus& status,
const std::set<std::string>& names,
const std::string& propertyName,
const std::string& propertyValue,
const bool appendAsString, const bool appendMode,
const bool remove)
{ {
for (std::string const& name : this->Names) { for (std::string const& name : names) {
if (this->Makefile->IsAlias(name)) { if (status.GetMakefile().IsAlias(name)) {
this->SetError("can not be used on an ALIAS target."); status.SetError("can not be used on an ALIAS target.");
return false; return false;
} }
if (cmTarget* target = this->Makefile->FindTargetToUse(name)) { if (cmTarget* target = status.GetMakefile().FindTargetToUse(name)) {
// Handle the current target. // Handle the current target.
if (!this->HandleTarget(target)) { if (!HandleTarget(target, status.GetMakefile(), propertyName,
propertyValue, appendAsString, appendMode, remove)) {
return false; return false;
} }
} else { } else {
std::ostringstream e; std::ostringstream e;
e << "could not find TARGET " << name e << "could not find TARGET " << name
<< ". Perhaps it has not yet been created."; << ". Perhaps it has not yet been created.";
this->SetError(e.str()); status.SetError(e.str());
return false; return false;
} }
} }
return true; return true;
} }
bool cmSetPropertyCommand::HandleTarget(cmTarget* target) bool HandleTarget(cmTarget* target, cmMakefile& makefile,
const std::string& propertyName,
const std::string& propertyValue, const bool appendAsString,
const bool appendMode, const bool remove)
{ {
// Set or append the property. // Set or append the property.
std::string const& name = this->PropertyName; const char* value = propertyValue.c_str();
const char* value = this->PropertyValue.c_str(); if (remove) {
if (this->Remove) {
value = nullptr; value = nullptr;
} }
if (this->AppendMode) { if (appendMode) {
target->AppendProperty(name, value, this->AppendAsString); target->AppendProperty(propertyName, value, appendAsString);
} else { } else {
target->SetProperty(name, value); target->SetProperty(propertyName, value);
} }
// Check the resulting value. // Check the resulting value.
target->CheckProperty(name, this->Makefile); target->CheckProperty(propertyName, &makefile);
return true; return true;
} }
bool cmSetPropertyCommand::HandleSourceMode() bool HandleSourceMode(cmExecutionStatus& status,
const std::set<std::string>& names,
const std::string& propertyName,
const std::string& propertyValue,
const bool appendAsString, const bool appendMode,
const bool remove)
{ {
for (std::string const& name : this->Names) { for (std::string const& name : names) {
// Get the source file. // Get the source file.
if (cmSourceFile* sf = this->Makefile->GetOrCreateSource(name)) { if (cmSourceFile* sf = status.GetMakefile().GetOrCreateSource(name)) {
if (!this->HandleSource(sf)) { if (!HandleSource(sf, propertyName, propertyValue, appendAsString,
appendMode, remove)) {
return false; return false;
} }
} else { } else {
std::ostringstream e; std::ostringstream e;
e << "given SOURCE name that could not be found or created: " << name; e << "given SOURCE name that could not be found or created: " << name;
this->SetError(e.str()); status.SetError(e.str());
return false; return false;
} }
} }
return true; return true;
} }
bool cmSetPropertyCommand::HandleSource(cmSourceFile* sf) bool HandleSource(cmSourceFile* sf, const std::string& propertyName,
const std::string& propertyValue, const bool appendAsString,
const bool appendMode, const bool remove)
{ {
// Set or append the property. // Set or append the property.
std::string const& name = this->PropertyName; const char* value = propertyValue.c_str();
const char* value = this->PropertyValue.c_str(); if (remove) {
if (this->Remove) {
value = nullptr; value = nullptr;
} }
if (this->AppendMode) { if (appendMode) {
sf->AppendProperty(name, value, this->AppendAsString); sf->AppendProperty(propertyName, value, appendAsString);
} else { } else {
sf->SetProperty(name, value); sf->SetProperty(propertyName, value);
} }
return true; return true;
} }
bool cmSetPropertyCommand::HandleTestMode() bool HandleTestMode(cmExecutionStatus& status, std::set<std::string>& names,
const std::string& propertyName,
const std::string& propertyValue,
const bool appendAsString, const bool appendMode,
const bool remove)
{ {
// Look for tests with all names given. // Look for tests with all names given.
std::set<std::string>::iterator next; std::set<std::string>::iterator next;
for (std::set<std::string>::iterator ni = this->Names.begin(); for (std::set<std::string>::iterator ni = names.begin(); ni != names.end();
ni != this->Names.end(); ni = next) { ni = next) {
next = ni; next = ni;
++next; ++next;
if (cmTest* test = this->Makefile->GetTest(*ni)) { if (cmTest* test = status.GetMakefile().GetTest(*ni)) {
if (this->HandleTest(test)) { if (HandleTest(test, propertyName, propertyValue, appendAsString,
this->Names.erase(ni); appendMode, remove)) {
names.erase(ni);
} else { } else {
return false; return false;
} }
@@ -300,137 +391,151 @@ bool cmSetPropertyCommand::HandleTestMode()
} }
// Names that are still left were not found. // Names that are still left were not found.
if (!this->Names.empty()) { if (!names.empty()) {
std::ostringstream e; std::ostringstream e;
e << "given TEST names that do not exist:\n"; e << "given TEST names that do not exist:\n";
for (std::string const& name : this->Names) { for (std::string const& name : names) {
e << " " << name << "\n"; e << " " << name << "\n";
} }
this->SetError(e.str()); status.SetError(e.str());
return false; return false;
} }
return true; return true;
} }
bool cmSetPropertyCommand::HandleTest(cmTest* test) bool HandleTest(cmTest* test, const std::string& propertyName,
const std::string& propertyValue, const bool appendAsString,
const bool appendMode, const bool remove)
{ {
// Set or append the property. // Set or append the property.
std::string const& name = this->PropertyName; const char* value = propertyValue.c_str();
const char* value = this->PropertyValue.c_str(); if (remove) {
if (this->Remove) {
value = nullptr; value = nullptr;
} }
if (this->AppendMode) { if (appendMode) {
test->AppendProperty(name, value, this->AppendAsString); test->AppendProperty(propertyName, value, appendAsString);
} else { } else {
test->SetProperty(name, value); test->SetProperty(propertyName, value);
} }
return true; return true;
} }
bool cmSetPropertyCommand::HandleCacheMode() bool HandleCacheMode(cmExecutionStatus& status,
const std::set<std::string>& names,
const std::string& propertyName,
const std::string& propertyValue,
const bool appendAsString, const bool appendMode,
const bool remove)
{ {
if (this->PropertyName == "ADVANCED") { if (propertyName == "ADVANCED") {
if (!this->Remove && !cmIsOn(this->PropertyValue) && if (!remove && !cmIsOn(propertyValue) && !cmIsOff(propertyValue)) {
!cmIsOff(this->PropertyValue)) {
std::ostringstream e; std::ostringstream e;
e << "given non-boolean value \"" << this->PropertyValue e << "given non-boolean value \"" << propertyValue
<< R"(" for CACHE property "ADVANCED". )"; << R"(" for CACHE property "ADVANCED". )";
this->SetError(e.str()); status.SetError(e.str());
return false; return false;
} }
} else if (this->PropertyName == "TYPE") { } else if (propertyName == "TYPE") {
if (!cmState::IsCacheEntryType(this->PropertyValue)) { if (!cmState::IsCacheEntryType(propertyValue)) {
std::ostringstream e; std::ostringstream e;
e << "given invalid CACHE entry TYPE \"" << this->PropertyValue << "\""; e << "given invalid CACHE entry TYPE \"" << propertyValue << "\"";
this->SetError(e.str()); status.SetError(e.str());
return false; return false;
} }
} else if (this->PropertyName != "HELPSTRING" && } else if (propertyName != "HELPSTRING" && propertyName != "STRINGS" &&
this->PropertyName != "STRINGS" && propertyName != "VALUE") {
this->PropertyName != "VALUE") {
std::ostringstream e; std::ostringstream e;
e << "given invalid CACHE property " << this->PropertyName << ". " e << "given invalid CACHE property " << propertyName << ". "
<< "Settable CACHE properties are: " << "Settable CACHE properties are: "
<< "ADVANCED, HELPSTRING, STRINGS, TYPE, and VALUE."; << "ADVANCED, HELPSTRING, STRINGS, TYPE, and VALUE.";
this->SetError(e.str()); status.SetError(e.str());
return false; return false;
} }
for (std::string const& name : this->Names) { for (std::string const& name : names) {
// Get the source file. // Get the source file.
cmMakefile* mf = this->GetMakefile(); cmake* cm = status.GetMakefile().GetCMakeInstance();
cmake* cm = mf->GetCMakeInstance();
const char* existingValue = cm->GetState()->GetCacheEntryValue(name); const char* existingValue = cm->GetState()->GetCacheEntryValue(name);
if (existingValue) { if (existingValue) {
if (!this->HandleCacheEntry(name)) { if (!HandleCacheEntry(name, status.GetMakefile(), propertyName,
propertyValue, appendAsString, appendMode,
remove)) {
return false; return false;
} }
} else { } else {
std::ostringstream e; std::ostringstream e;
e << "could not find CACHE variable " << name e << "could not find CACHE variable " << name
<< ". Perhaps it has not yet been created."; << ". Perhaps it has not yet been created.";
this->SetError(e.str()); status.SetError(e.str());
return false; return false;
} }
} }
return true; return true;
} }
bool cmSetPropertyCommand::HandleCacheEntry(std::string const& cacheKey) bool HandleCacheEntry(std::string const& cacheKey, const cmMakefile& makefile,
const std::string& propertyName,
const std::string& propertyValue,
const bool appendAsString, const bool appendMode,
const bool remove)
{ {
// Set or append the property. // Set or append the property.
std::string const& name = this->PropertyName; const char* value = propertyValue.c_str();
const char* value = this->PropertyValue.c_str(); cmState* state = makefile.GetState();
cmState* state = this->Makefile->GetState(); if (remove) {
if (this->Remove) { state->RemoveCacheEntryProperty(cacheKey, propertyName);
state->RemoveCacheEntryProperty(cacheKey, name);
} }
if (this->AppendMode) { if (appendMode) {
state->AppendCacheEntryProperty(cacheKey, name, value, state->AppendCacheEntryProperty(cacheKey, propertyName, value,
this->AppendAsString); appendAsString);
} else { } else {
state->SetCacheEntryProperty(cacheKey, name, value); state->SetCacheEntryProperty(cacheKey, propertyName, value);
} }
return true; return true;
} }
bool cmSetPropertyCommand::HandleInstallMode() bool HandleInstallMode(cmExecutionStatus& status,
const std::set<std::string>& names,
const std::string& propertyName,
const std::string& propertyValue,
const bool appendAsString, const bool appendMode,
const bool remove)
{ {
cmake* cm = this->Makefile->GetCMakeInstance(); cmake* cm = status.GetMakefile().GetCMakeInstance();
for (std::string const& name : this->Names) { for (std::string const& name : names) {
if (cmInstalledFile* file = if (cmInstalledFile* file =
cm->GetOrCreateInstalledFile(this->Makefile, name)) { cm->GetOrCreateInstalledFile(&status.GetMakefile(), name)) {
if (!this->HandleInstall(file)) { if (!HandleInstall(file, status.GetMakefile(), propertyName,
propertyValue, appendAsString, appendMode, remove)) {
return false; return false;
} }
} else { } else {
std::ostringstream e; std::ostringstream e;
e << "given INSTALL name that could not be found or created: " << name; e << "given INSTALL name that could not be found or created: " << name;
this->SetError(e.str()); status.SetError(e.str());
return false; return false;
} }
} }
return true; return true;
} }
bool cmSetPropertyCommand::HandleInstall(cmInstalledFile* file) bool HandleInstall(cmInstalledFile* file, cmMakefile& makefile,
const std::string& propertyName,
const std::string& propertyValue, const bool appendAsString,
const bool appendMode, const bool remove)
{ {
// Set or append the property. // Set or append the property.
std::string const& name = this->PropertyName; const char* value = propertyValue.c_str();
if (remove) {
cmMakefile* mf = this->Makefile; file->RemoveProperty(propertyName);
} else if (appendMode) {
const char* value = this->PropertyValue.c_str(); file->AppendProperty(&makefile, propertyName, value, appendAsString);
if (this->Remove) {
file->RemoveProperty(name);
} else if (this->AppendMode) {
file->AppendProperty(mf, name, value, this->AppendAsString);
} else { } else {
file->SetProperty(mf, name, value); file->SetProperty(&makefile, propertyName, value);
} }
return true; return true;
} }
}

View File

@@ -5,58 +5,12 @@
#include "cmConfigure.h" // IWYU pragma: keep #include "cmConfigure.h" // IWYU pragma: keep
#include <set>
#include <string> #include <string>
#include <vector> #include <vector>
#include "cm_memory.hxx"
#include "cmCommand.h"
class cmExecutionStatus; class cmExecutionStatus;
class cmInstalledFile;
class cmSourceFile;
class cmTarget;
class cmTest;
class cmSetPropertyCommand : public cmCommand bool cmSetPropertyCommand(std::vector<std::string> const& args,
{ cmExecutionStatus& status);
public:
cmSetPropertyCommand();
std::unique_ptr<cmCommand> Clone() override
{
return cm::make_unique<cmSetPropertyCommand>();
}
/**
* This is called when the command is first encountered in
* the input file.
*/
bool InitialPass(std::vector<std::string> const& args,
cmExecutionStatus& status) override;
private:
std::set<std::string> Names;
std::string PropertyName;
std::string PropertyValue;
bool Remove;
bool AppendMode;
bool AppendAsString;
// Implementation of each property type.
bool HandleGlobalMode();
bool HandleDirectoryMode();
bool HandleTargetMode();
bool HandleTarget(cmTarget* target);
bool HandleSourceMode();
bool HandleSource(cmSourceFile* sf);
bool HandleTestMode();
bool HandleTest(cmTest* test);
bool HandleCacheMode();
bool HandleCacheEntry(std::string const&);
bool HandleInstallMode();
bool HandleInstall(cmInstalledFile* file);
};
#endif #endif