cmake/Source/cmRemoveCommand.cxx

57 lines
1.4 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 "cmRemoveCommand.h"
2020-02-01 23:06:01 +01:00
#include "cmExecutionStatus.h"
2017-04-14 19:02:05 +02:00
#include "cmMakefile.h"
2020-02-01 23:06:01 +01:00
#include "cmStringAlgorithms.h"
2017-04-14 19:02:05 +02:00
// cmRemoveCommand
2020-02-01 23:06:01 +01:00
bool cmRemoveCommand(std::vector<std::string> const& args,
cmExecutionStatus& status)
{
2016-10-30 18:24:19 +01:00
if (args.empty()) {
return true;
2016-07-09 11:21:54 +02:00
}
2017-07-20 19:35:53 +02:00
std::string const& variable = args[0]; // VAR is always first
// get the old value
2020-02-01 23:06:01 +01:00
const char* cacheValue = status.GetMakefile().GetDefinition(variable);
// if there is no old value then return
2016-07-09 11:21:54 +02:00
if (!cacheValue) {
return true;
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
// expand the variable
2020-02-01 23:06:01 +01:00
std::vector<std::string> const varArgsExpanded = cmExpandedList(cacheValue);
2013-03-16 19:13:01 +02:00
// expand the args
2013-03-16 19:13:01 +02:00
// check for REMOVE(VAR v1 v2 ... vn)
2019-11-11 23:01:05 +01:00
std::vector<std::string> const argsExpanded =
2020-02-01 23:06:01 +01:00
cmExpandedLists(args.begin() + 1, args.end());
2013-03-16 19:13:01 +02:00
// now create the new value
std::string value;
2018-01-26 17:06:56 +01:00
for (std::string const& varArgExpanded : varArgsExpanded) {
int found = 0;
2018-01-26 17:06:56 +01:00
for (std::string const& argExpanded : argsExpanded) {
if (varArgExpanded == argExpanded) {
found = 1;
break;
}
2016-07-09 11:21:54 +02:00
}
if (!found) {
if (!value.empty()) {
value += ";";
}
2018-01-26 17:06:56 +01:00
value += varArgExpanded;
}
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
// add the definition
2020-02-01 23:06:01 +01:00
status.GetMakefile().AddDefinition(variable, value);
return true;
}