2016-09-27 19:01:08 +00:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2008-01-17 20:54:49 +00:00
|
|
|
#include "cmSetPropertyCommand.h"
|
2016-04-29 13:40:20 +00:00
|
|
|
|
2019-08-09 13:07:45 +00:00
|
|
|
#include <set>
|
2016-10-25 18:35:04 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
2019-08-09 13:07:45 +00:00
|
|
|
#include "cmExecutionStatus.h"
|
2016-10-19 20:30:58 +00:00
|
|
|
#include "cmGlobalGenerator.h"
|
2016-10-25 18:35:04 +00:00
|
|
|
#include "cmInstalledFile.h"
|
|
|
|
#include "cmMakefile.h"
|
|
|
|
#include "cmProperty.h"
|
2019-02-15 20:34:44 +00:00
|
|
|
#include "cmRange.h"
|
2016-10-19 20:30:58 +00:00
|
|
|
#include "cmSourceFile.h"
|
|
|
|
#include "cmState.h"
|
2019-08-17 09:04:11 +00:00
|
|
|
#include "cmStringAlgorithms.h"
|
2016-10-25 18:35:04 +00:00
|
|
|
#include "cmSystemTools.h"
|
|
|
|
#include "cmTarget.h"
|
2016-10-19 20:30:58 +00:00
|
|
|
#include "cmTest.h"
|
2016-10-25 18:35:04 +00:00
|
|
|
#include "cmake.h"
|
|
|
|
|
2019-08-09 13:07:45 +00:00
|
|
|
namespace {
|
|
|
|
bool HandleGlobalMode(cmExecutionStatus& status,
|
|
|
|
const std::set<std::string>& names,
|
|
|
|
const std::string& propertyName,
|
|
|
|
const std::string& propertyValue, bool appendAsString,
|
|
|
|
bool appendMode, bool remove);
|
|
|
|
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);
|
2008-01-17 20:54:49 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 13:07:45 +00:00
|
|
|
bool cmSetPropertyCommand(std::vector<std::string> const& args,
|
|
|
|
cmExecutionStatus& status)
|
2008-01-17 20:54:49 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
if (args.size() < 2) {
|
2019-08-09 13:07:45 +00:00
|
|
|
status.SetError("called with incorrect number of arguments");
|
2008-01-17 20:54:49 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-01-17 20:54:49 +00:00
|
|
|
|
|
|
|
// Get the scope on which to set the property.
|
2019-02-07 21:39:05 +00:00
|
|
|
std::string const& scopeName = args.front();
|
2008-01-17 20:54:49 +00:00
|
|
|
cmProperty::ScopeType scope;
|
2019-02-07 21:39:05 +00:00
|
|
|
if (scopeName == "GLOBAL") {
|
2008-01-17 20:54:49 +00:00
|
|
|
scope = cmProperty::GLOBAL;
|
2019-02-07 21:39:05 +00:00
|
|
|
} else if (scopeName == "DIRECTORY") {
|
2008-01-17 20:54:49 +00:00
|
|
|
scope = cmProperty::DIRECTORY;
|
2019-02-07 21:39:05 +00:00
|
|
|
} else if (scopeName == "TARGET") {
|
2008-01-17 20:54:49 +00:00
|
|
|
scope = cmProperty::TARGET;
|
2019-02-07 21:39:05 +00:00
|
|
|
} else if (scopeName == "SOURCE") {
|
2008-01-17 20:54:49 +00:00
|
|
|
scope = cmProperty::SOURCE_FILE;
|
2019-02-07 21:39:05 +00:00
|
|
|
} else if (scopeName == "TEST") {
|
2008-01-17 20:54:49 +00:00
|
|
|
scope = cmProperty::TEST;
|
2019-02-07 21:39:05 +00:00
|
|
|
} else if (scopeName == "CACHE") {
|
2009-03-10 15:10:59 +00:00
|
|
|
scope = cmProperty::CACHE;
|
2019-02-07 21:39:05 +00:00
|
|
|
} else if (scopeName == "INSTALL") {
|
2014-05-15 17:12:40 +00:00
|
|
|
scope = cmProperty::INSTALL;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2019-09-15 17:11:02 +00:00
|
|
|
status.SetError(cmStrCat("given invalid scope ", scopeName,
|
|
|
|
". "
|
|
|
|
"Valid scopes are GLOBAL, DIRECTORY, "
|
|
|
|
"TARGET, SOURCE, TEST, CACHE, INSTALL."));
|
2008-01-17 20:54:49 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-01-17 20:54:49 +00:00
|
|
|
|
2019-08-09 13:07:45 +00:00
|
|
|
bool appendAsString = false;
|
|
|
|
bool appendMode = false;
|
|
|
|
bool remove = true;
|
|
|
|
std::set<std::string> names;
|
|
|
|
std::string propertyName;
|
|
|
|
std::string propertyValue;
|
|
|
|
|
2008-01-17 20:54:49 +00:00
|
|
|
// Parse the rest of the arguments up to the values.
|
2016-05-16 14:34:04 +00:00
|
|
|
enum Doing
|
|
|
|
{
|
|
|
|
DoingNone,
|
|
|
|
DoingNames,
|
|
|
|
DoingProperty,
|
|
|
|
DoingValues
|
|
|
|
};
|
2008-01-17 20:54:49 +00:00
|
|
|
Doing doing = DoingNames;
|
|
|
|
const char* sep = "";
|
2019-02-07 21:39:05 +00:00
|
|
|
for (std::string const& arg : cmMakeRange(args).advance(1)) {
|
|
|
|
if (arg == "PROPERTY") {
|
2008-01-17 20:54:49 +00:00
|
|
|
doing = DoingProperty;
|
2019-02-07 21:39:05 +00:00
|
|
|
} else if (arg == "APPEND") {
|
2008-01-17 20:54:49 +00:00
|
|
|
doing = DoingNone;
|
2019-08-09 13:07:45 +00:00
|
|
|
appendMode = true;
|
|
|
|
remove = false;
|
|
|
|
appendAsString = false;
|
2019-02-07 21:39:05 +00:00
|
|
|
} else if (arg == "APPEND_STRING") {
|
2011-07-13 21:14:41 +00:00
|
|
|
doing = DoingNone;
|
2019-08-09 13:07:45 +00:00
|
|
|
appendMode = true;
|
|
|
|
remove = false;
|
|
|
|
appendAsString = true;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (doing == DoingNames) {
|
2019-08-09 13:07:45 +00:00
|
|
|
names.insert(arg);
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (doing == DoingProperty) {
|
2019-08-09 13:07:45 +00:00
|
|
|
propertyName = arg;
|
2008-01-17 20:54:49 +00:00
|
|
|
doing = DoingValues;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (doing == DoingValues) {
|
2019-08-09 13:07:45 +00:00
|
|
|
propertyValue += sep;
|
2008-01-17 20:54:49 +00:00
|
|
|
sep = ";";
|
2019-08-09 13:07:45 +00:00
|
|
|
propertyValue += arg;
|
|
|
|
remove = false;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2019-09-15 17:11:02 +00:00
|
|
|
status.SetError(cmStrCat("given invalid argument \"", arg, "\"."));
|
2008-01-17 20:54:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-01-17 20:54:49 +00:00
|
|
|
|
|
|
|
// Make sure a property name was found.
|
2019-08-09 13:07:45 +00:00
|
|
|
if (propertyName.empty()) {
|
|
|
|
status.SetError("not given a PROPERTY <name> argument.");
|
2008-01-17 20:54:49 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-01-17 20:54:49 +00:00
|
|
|
|
|
|
|
// Dispatch property setting.
|
2016-05-16 14:34:04 +00:00
|
|
|
switch (scope) {
|
|
|
|
case cmProperty::GLOBAL:
|
2019-08-09 13:07:45 +00:00
|
|
|
return HandleGlobalMode(status, names, propertyName, propertyValue,
|
|
|
|
appendAsString, appendMode, remove);
|
2016-05-16 14:34:04 +00:00
|
|
|
case cmProperty::DIRECTORY:
|
2019-08-09 13:07:45 +00:00
|
|
|
return HandleDirectoryMode(status, names, propertyName, propertyValue,
|
|
|
|
appendAsString, appendMode, remove);
|
2016-05-16 14:34:04 +00:00
|
|
|
case cmProperty::TARGET:
|
2019-08-09 13:07:45 +00:00
|
|
|
return HandleTargetMode(status, names, propertyName, propertyValue,
|
|
|
|
appendAsString, appendMode, remove);
|
2016-05-16 14:34:04 +00:00
|
|
|
case cmProperty::SOURCE_FILE:
|
2019-08-09 13:07:45 +00:00
|
|
|
return HandleSourceMode(status, names, propertyName, propertyValue,
|
|
|
|
appendAsString, appendMode, remove);
|
2016-05-16 14:34:04 +00:00
|
|
|
case cmProperty::TEST:
|
2019-08-09 13:07:45 +00:00
|
|
|
return HandleTestMode(status, names, propertyName, propertyValue,
|
|
|
|
appendAsString, appendMode, remove);
|
2016-05-16 14:34:04 +00:00
|
|
|
case cmProperty::CACHE:
|
2019-08-09 13:07:45 +00:00
|
|
|
return HandleCacheMode(status, names, propertyName, propertyValue,
|
|
|
|
appendAsString, appendMode, remove);
|
2016-05-16 14:34:04 +00:00
|
|
|
case cmProperty::INSTALL:
|
2019-08-09 13:07:45 +00:00
|
|
|
return HandleInstallMode(status, names, propertyName, propertyValue,
|
|
|
|
appendAsString, appendMode, remove);
|
2008-01-17 20:54:49 +00:00
|
|
|
|
|
|
|
case cmProperty::VARIABLE:
|
|
|
|
case cmProperty::CACHED_VARIABLE:
|
|
|
|
break; // should never happen
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-01-17 20:54:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-09 13:07:45 +00:00
|
|
|
namespace {
|
|
|
|
bool HandleGlobalMode(cmExecutionStatus& status,
|
|
|
|
const std::set<std::string>& names,
|
|
|
|
const std::string& propertyName,
|
2020-01-25 15:37:00 +00:00
|
|
|
const std::string& propertyValue, bool appendAsString,
|
|
|
|
bool appendMode, bool remove)
|
2008-01-17 20:54:49 +00:00
|
|
|
{
|
2019-08-09 13:07:45 +00:00
|
|
|
if (!names.empty()) {
|
|
|
|
status.SetError("given names for GLOBAL scope.");
|
2008-01-17 20:54:49 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-01-17 20:54:49 +00:00
|
|
|
|
|
|
|
// Set or append the property.
|
2019-08-09 13:07:45 +00:00
|
|
|
cmake* cm = status.GetMakefile().GetCMakeInstance();
|
|
|
|
if (appendMode) {
|
2020-01-25 15:37:00 +00:00
|
|
|
cm->AppendProperty(propertyName, propertyValue, appendAsString);
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2020-01-25 15:37:00 +00:00
|
|
|
if (remove) {
|
|
|
|
cm->SetProperty(propertyName, nullptr);
|
|
|
|
} else {
|
|
|
|
cm->SetProperty(propertyName, propertyValue.c_str());
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-01-17 20:54:49 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-09 13:07:45 +00:00
|
|
|
bool HandleDirectoryMode(cmExecutionStatus& status,
|
|
|
|
const std::set<std::string>& names,
|
|
|
|
const std::string& propertyName,
|
2020-01-25 15:37:00 +00:00
|
|
|
const std::string& propertyValue, bool appendAsString,
|
|
|
|
bool appendMode, bool remove)
|
2008-01-17 20:54:49 +00:00
|
|
|
{
|
2019-08-09 13:07:45 +00:00
|
|
|
if (names.size() > 1) {
|
|
|
|
status.SetError("allows at most one name for DIRECTORY scope.");
|
2008-01-17 20:54:49 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-01-17 20:54:49 +00:00
|
|
|
|
|
|
|
// Default to the current directory.
|
2019-08-09 13:07:45 +00:00
|
|
|
cmMakefile* mf = &status.GetMakefile();
|
2008-01-17 20:54:49 +00:00
|
|
|
|
|
|
|
// Lookup the directory if given.
|
2019-08-09 13:07:45 +00:00
|
|
|
if (!names.empty()) {
|
2008-01-17 20:54:49 +00:00
|
|
|
// Construct the directory name. Interpret relative paths with
|
|
|
|
// respect to the current directory.
|
2019-08-09 13:07:45 +00:00
|
|
|
std::string dir = *names.begin();
|
2018-01-31 15:20:02 +00:00
|
|
|
if (!cmSystemTools::FileIsFullPath(dir)) {
|
2019-08-22 14:34:40 +00:00
|
|
|
dir = cmStrCat(status.GetMakefile().GetCurrentSourceDirectory(), '/',
|
|
|
|
*names.begin());
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-01-17 20:54:49 +00:00
|
|
|
|
|
|
|
// The local generators are associated with collapsed paths.
|
2014-10-15 12:54:05 +00:00
|
|
|
dir = cmSystemTools::CollapseFullPath(dir);
|
2008-01-17 20:54:49 +00:00
|
|
|
|
2019-08-09 13:07:45 +00:00
|
|
|
mf = status.GetMakefile().GetGlobalGenerator()->FindMakefile(dir);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!mf) {
|
2008-01-17 20:54:49 +00:00
|
|
|
// Could not find the directory.
|
2019-08-09 13:07:45 +00:00
|
|
|
status.SetError(
|
2016-05-16 14:34:04 +00:00
|
|
|
"DIRECTORY scope provided but requested directory was not found. "
|
|
|
|
"This could be because the directory argument was invalid or, "
|
|
|
|
"it is valid but has not been processed yet.");
|
2008-01-17 20:54:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-01-17 20:54:49 +00:00
|
|
|
|
|
|
|
// Set or append the property.
|
2019-08-09 13:07:45 +00:00
|
|
|
if (appendMode) {
|
2020-01-25 15:37:00 +00:00
|
|
|
mf->AppendProperty(propertyName, propertyValue, appendAsString);
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2020-01-25 15:37:00 +00:00
|
|
|
if (remove) {
|
|
|
|
mf->SetProperty(propertyName, nullptr);
|
|
|
|
} else {
|
|
|
|
mf->SetProperty(propertyName, propertyValue.c_str());
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-01-17 20:54:49 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-09 13:07:45 +00:00
|
|
|
bool HandleTargetMode(cmExecutionStatus& status,
|
|
|
|
const std::set<std::string>& names,
|
|
|
|
const std::string& propertyName,
|
2020-01-25 15:37:00 +00:00
|
|
|
const std::string& propertyValue, bool appendAsString,
|
|
|
|
bool appendMode, bool remove)
|
2008-01-17 20:54:49 +00:00
|
|
|
{
|
2019-08-09 13:07:45 +00:00
|
|
|
for (std::string const& name : names) {
|
|
|
|
if (status.GetMakefile().IsAlias(name)) {
|
|
|
|
status.SetError("can not be used on an ALIAS target.");
|
2013-07-12 07:14:31 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2019-08-09 13:07:45 +00:00
|
|
|
if (cmTarget* target = status.GetMakefile().FindTargetToUse(name)) {
|
2008-01-17 20:54:49 +00:00
|
|
|
// Handle the current target.
|
2019-08-09 13:07:45 +00:00
|
|
|
if (!HandleTarget(target, status.GetMakefile(), propertyName,
|
|
|
|
propertyValue, appendAsString, appendMode, remove)) {
|
2008-01-17 20:54:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2019-09-15 17:11:02 +00:00
|
|
|
status.SetError(cmStrCat("could not find TARGET ", name,
|
|
|
|
". Perhaps it has not yet been created."));
|
2008-01-17 20:54:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-01-17 20:54:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-09 13:07:45 +00:00
|
|
|
bool HandleTarget(cmTarget* target, cmMakefile& makefile,
|
|
|
|
const std::string& propertyName,
|
2020-01-25 15:37:00 +00:00
|
|
|
const std::string& propertyValue, bool appendAsString,
|
|
|
|
bool appendMode, bool remove)
|
2008-01-17 20:54:49 +00:00
|
|
|
{
|
|
|
|
// Set or append the property.
|
2019-08-09 13:07:45 +00:00
|
|
|
if (appendMode) {
|
2020-01-25 15:37:00 +00:00
|
|
|
target->AppendProperty(propertyName, propertyValue, appendAsString);
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2020-01-25 15:37:00 +00:00
|
|
|
if (remove) {
|
|
|
|
target->SetProperty(propertyName, nullptr);
|
|
|
|
} else {
|
|
|
|
target->SetProperty(propertyName, propertyValue.c_str());
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-01-17 20:54:49 +00:00
|
|
|
|
2008-08-19 15:43:51 +00:00
|
|
|
// Check the resulting value.
|
2019-08-09 13:07:45 +00:00
|
|
|
target->CheckProperty(propertyName, &makefile);
|
2008-08-19 15:43:51 +00:00
|
|
|
|
2008-01-17 20:54:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-09 13:07:45 +00:00
|
|
|
bool HandleSourceMode(cmExecutionStatus& status,
|
|
|
|
const std::set<std::string>& names,
|
|
|
|
const std::string& propertyName,
|
2020-01-25 15:37:00 +00:00
|
|
|
const std::string& propertyValue, bool appendAsString,
|
|
|
|
bool appendMode, bool remove)
|
2008-01-17 20:54:49 +00:00
|
|
|
{
|
2019-08-09 13:07:45 +00:00
|
|
|
for (std::string const& name : names) {
|
2008-01-17 20:54:49 +00:00
|
|
|
// Get the source file.
|
2019-08-09 13:07:45 +00:00
|
|
|
if (cmSourceFile* sf = status.GetMakefile().GetOrCreateSource(name)) {
|
|
|
|
if (!HandleSource(sf, propertyName, propertyValue, appendAsString,
|
|
|
|
appendMode, remove)) {
|
2008-01-17 20:54:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2019-09-15 17:11:02 +00:00
|
|
|
status.SetError(cmStrCat(
|
|
|
|
"given SOURCE name that could not be found or created: ", name));
|
2008-01-17 20:54:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-01-17 20:54:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-09 13:07:45 +00:00
|
|
|
bool HandleSource(cmSourceFile* sf, const std::string& propertyName,
|
2020-01-25 15:37:00 +00:00
|
|
|
const std::string& propertyValue, bool appendAsString,
|
|
|
|
bool appendMode, bool remove)
|
2008-01-17 20:54:49 +00:00
|
|
|
{
|
|
|
|
// Set or append the property.
|
2019-08-09 13:07:45 +00:00
|
|
|
if (appendMode) {
|
2020-01-25 15:37:00 +00:00
|
|
|
sf->AppendProperty(propertyName, propertyValue, appendAsString);
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2020-01-25 15:37:00 +00:00
|
|
|
if (remove) {
|
|
|
|
sf->SetProperty(propertyName, nullptr);
|
|
|
|
} else {
|
|
|
|
sf->SetProperty(propertyName, propertyValue.c_str());
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-01-17 20:54:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-09 13:07:45 +00:00
|
|
|
bool HandleTestMode(cmExecutionStatus& status, std::set<std::string>& names,
|
|
|
|
const std::string& propertyName,
|
2020-01-25 15:37:00 +00:00
|
|
|
const std::string& propertyValue, bool appendAsString,
|
|
|
|
bool appendMode, bool remove)
|
2008-01-17 20:54:49 +00:00
|
|
|
{
|
2009-01-05 20:00:57 +00:00
|
|
|
// Look for tests with all names given.
|
2014-02-10 05:21:34 +00:00
|
|
|
std::set<std::string>::iterator next;
|
2019-09-04 20:17:22 +00:00
|
|
|
for (auto ni = names.begin(); ni != names.end(); ni = next) {
|
2009-01-05 20:00:57 +00:00
|
|
|
next = ni;
|
|
|
|
++next;
|
2019-08-09 13:07:45 +00:00
|
|
|
if (cmTest* test = status.GetMakefile().GetTest(*ni)) {
|
|
|
|
if (HandleTest(test, propertyName, propertyValue, appendAsString,
|
|
|
|
appendMode, remove)) {
|
|
|
|
names.erase(ni);
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2008-01-17 20:54:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-01-17 20:54:49 +00:00
|
|
|
|
|
|
|
// Names that are still left were not found.
|
2019-08-09 13:07:45 +00:00
|
|
|
if (!names.empty()) {
|
2015-01-05 19:31:31 +00:00
|
|
|
std::ostringstream e;
|
2008-01-17 20:54:49 +00:00
|
|
|
e << "given TEST names that do not exist:\n";
|
2019-08-09 13:07:45 +00:00
|
|
|
for (std::string const& name : names) {
|
2017-09-11 10:40:26 +00:00
|
|
|
e << " " << name << "\n";
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2019-08-09 13:07:45 +00:00
|
|
|
status.SetError(e.str());
|
2008-01-17 20:54:49 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-01-17 20:54:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-09 13:07:45 +00:00
|
|
|
bool HandleTest(cmTest* test, const std::string& propertyName,
|
2020-01-25 15:37:00 +00:00
|
|
|
const std::string& propertyValue, bool appendAsString,
|
|
|
|
bool appendMode, bool remove)
|
2008-01-17 20:54:49 +00:00
|
|
|
{
|
|
|
|
// Set or append the property.
|
2019-08-09 13:07:45 +00:00
|
|
|
if (appendMode) {
|
2020-01-25 15:37:00 +00:00
|
|
|
test->AppendProperty(propertyName, propertyValue, appendAsString);
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2020-01-25 15:37:00 +00:00
|
|
|
if (remove) {
|
|
|
|
test->SetProperty(propertyName, nullptr);
|
|
|
|
} else {
|
|
|
|
test->SetProperty(propertyName, propertyValue.c_str());
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-01-17 20:54:49 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2009-03-10 15:10:59 +00:00
|
|
|
|
2019-08-09 13:07:45 +00:00
|
|
|
bool HandleCacheMode(cmExecutionStatus& status,
|
|
|
|
const std::set<std::string>& names,
|
|
|
|
const std::string& propertyName,
|
2020-01-25 15:37:00 +00:00
|
|
|
const std::string& propertyValue, bool appendAsString,
|
|
|
|
bool appendMode, bool remove)
|
2009-03-10 15:10:59 +00:00
|
|
|
{
|
2019-08-09 13:07:45 +00:00
|
|
|
if (propertyName == "ADVANCED") {
|
|
|
|
if (!remove && !cmIsOn(propertyValue) && !cmIsOff(propertyValue)) {
|
2019-09-15 17:11:02 +00:00
|
|
|
status.SetError(cmStrCat("given non-boolean value \"", propertyValue,
|
|
|
|
R"(" for CACHE property "ADVANCED". )"));
|
2009-03-10 15:10:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-08-09 13:07:45 +00:00
|
|
|
} else if (propertyName == "TYPE") {
|
|
|
|
if (!cmState::IsCacheEntryType(propertyValue)) {
|
2019-09-15 17:11:02 +00:00
|
|
|
status.SetError(
|
|
|
|
cmStrCat("given invalid CACHE entry TYPE \"", propertyValue, "\""));
|
2009-03-10 15:10:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-08-09 13:07:45 +00:00
|
|
|
} else if (propertyName != "HELPSTRING" && propertyName != "STRINGS" &&
|
|
|
|
propertyName != "VALUE") {
|
2019-09-15 17:11:02 +00:00
|
|
|
status.SetError(
|
|
|
|
cmStrCat("given invalid CACHE property ", propertyName,
|
|
|
|
". "
|
|
|
|
"Settable CACHE properties are: "
|
|
|
|
"ADVANCED, HELPSTRING, STRINGS, TYPE, and VALUE."));
|
2009-03-10 15:10:59 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-03-10 15:10:59 +00:00
|
|
|
|
2019-08-09 13:07:45 +00:00
|
|
|
for (std::string const& name : names) {
|
2009-03-10 15:10:59 +00:00
|
|
|
// Get the source file.
|
2019-08-09 13:07:45 +00:00
|
|
|
cmake* cm = status.GetMakefile().GetCMakeInstance();
|
2017-09-11 10:40:26 +00:00
|
|
|
const char* existingValue = cm->GetState()->GetCacheEntryValue(name);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (existingValue) {
|
2019-08-09 13:07:45 +00:00
|
|
|
if (!HandleCacheEntry(name, status.GetMakefile(), propertyName,
|
|
|
|
propertyValue, appendAsString, appendMode,
|
|
|
|
remove)) {
|
2009-03-10 15:10:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2019-09-15 17:11:02 +00:00
|
|
|
status.SetError(cmStrCat("could not find CACHE variable ", name,
|
|
|
|
". Perhaps it has not yet been created."));
|
2009-03-10 15:10:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-03-10 15:10:59 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-09 13:07:45 +00:00
|
|
|
bool HandleCacheEntry(std::string const& cacheKey, const cmMakefile& makefile,
|
|
|
|
const std::string& propertyName,
|
2020-01-25 15:37:00 +00:00
|
|
|
const std::string& propertyValue, bool appendAsString,
|
|
|
|
bool appendMode, bool remove)
|
2009-03-10 15:10:59 +00:00
|
|
|
{
|
|
|
|
// Set or append the property.
|
2019-08-09 13:07:45 +00:00
|
|
|
const char* value = propertyValue.c_str();
|
|
|
|
cmState* state = makefile.GetState();
|
|
|
|
if (remove) {
|
|
|
|
state->RemoveCacheEntryProperty(cacheKey, propertyName);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2019-08-09 13:07:45 +00:00
|
|
|
if (appendMode) {
|
|
|
|
state->AppendCacheEntryProperty(cacheKey, propertyName, value,
|
|
|
|
appendAsString);
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2019-08-09 13:07:45 +00:00
|
|
|
state->SetCacheEntryProperty(cacheKey, propertyName, value);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-03-10 15:10:59 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2014-05-15 17:12:40 +00:00
|
|
|
|
2019-08-09 13:07:45 +00:00
|
|
|
bool HandleInstallMode(cmExecutionStatus& status,
|
|
|
|
const std::set<std::string>& names,
|
|
|
|
const std::string& propertyName,
|
2020-01-25 15:37:00 +00:00
|
|
|
const std::string& propertyValue, bool appendAsString,
|
|
|
|
bool appendMode, bool remove)
|
2014-05-15 17:12:40 +00:00
|
|
|
{
|
2019-08-09 13:07:45 +00:00
|
|
|
cmake* cm = status.GetMakefile().GetCMakeInstance();
|
2014-05-15 17:12:40 +00:00
|
|
|
|
2019-08-09 13:07:45 +00:00
|
|
|
for (std::string const& name : names) {
|
2016-05-16 14:34:04 +00:00
|
|
|
if (cmInstalledFile* file =
|
2019-08-09 13:07:45 +00:00
|
|
|
cm->GetOrCreateInstalledFile(&status.GetMakefile(), name)) {
|
|
|
|
if (!HandleInstall(file, status.GetMakefile(), propertyName,
|
|
|
|
propertyValue, appendAsString, appendMode, remove)) {
|
2014-05-15 17:12:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2019-09-15 17:11:02 +00:00
|
|
|
status.SetError(cmStrCat(
|
|
|
|
"given INSTALL name that could not be found or created: ", name));
|
2014-05-15 17:12:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-05-15 17:12:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-09 13:07:45 +00:00
|
|
|
bool HandleInstall(cmInstalledFile* file, cmMakefile& makefile,
|
|
|
|
const std::string& propertyName,
|
2020-01-25 15:37:00 +00:00
|
|
|
const std::string& propertyValue, bool appendAsString,
|
|
|
|
bool appendMode, bool remove)
|
2014-05-15 17:12:40 +00:00
|
|
|
{
|
|
|
|
// Set or append the property.
|
2019-08-09 13:07:45 +00:00
|
|
|
const char* value = propertyValue.c_str();
|
|
|
|
if (remove) {
|
|
|
|
file->RemoveProperty(propertyName);
|
|
|
|
} else if (appendMode) {
|
|
|
|
file->AppendProperty(&makefile, propertyName, value, appendAsString);
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2019-08-09 13:07:45 +00:00
|
|
|
file->SetProperty(&makefile, propertyName, value);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-05-15 17:12:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-08-09 13:07:45 +00:00
|
|
|
}
|