cmake/Source/cmRemoveCommand.cxx

61 lines
1.5 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"
2017-04-14 19:02:05 +02:00
#include "cmMakefile.h"
#include "cmSystemTools.h"
class cmExecutionStatus;
// cmRemoveCommand
2016-07-09 11:21:54 +02:00
bool cmRemoveCommand::InitialPass(std::vector<std::string> const& args,
cmExecutionStatus&)
{
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
2016-07-09 11:21:54 +02:00
const char* cacheValue = this->Makefile->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
std::vector<std::string> varArgsExpanded;
cmSystemTools::ExpandListArgument(cacheValue, varArgsExpanded);
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)
std::vector<std::string> argsExpanded;
std::vector<std::string> temp;
2015-04-27 22:25:09 +02:00
temp.insert(temp.end(), args.begin() + 1, args.end());
cmSystemTools::ExpandList(temp, argsExpanded);
2013-03-16 19:13:01 +02:00
// now create the new value
std::string value;
2016-07-09 11:21:54 +02:00
for (unsigned int j = 0; j < varArgsExpanded.size(); ++j) {
int found = 0;
2016-07-09 11:21:54 +02:00
for (unsigned int k = 0; k < argsExpanded.size(); ++k) {
if (varArgsExpanded[j] == argsExpanded[k]) {
found = 1;
break;
}
2016-07-09 11:21:54 +02:00
}
if (!found) {
if (!value.empty()) {
value += ";";
}
2016-07-09 11:21:54 +02:00
value += varArgsExpanded[j];
}
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
// add the definition
this->Makefile->AddDefinition(variable, value.c_str());
return true;
}