cmake/Source/cmRemoveCommand.cxx

65 lines
1.9 KiB
C++
Raw Normal View History

2009-10-04 10:30:41 +03:00
/*============================================================================
CMake - Cross Platform Makefile Generator
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
2009-10-04 10:30:41 +03:00
Distributed under the OSI-approved BSD License (the "License");
see accompanying file Copyright.txt for details.
2009-10-04 10:30:41 +03:00
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License for more information.
============================================================================*/
#include "cmRemoveCommand.h"
// cmRemoveCommand
2016-07-09 11:21:54 +02:00
bool cmRemoveCommand::InitialPass(std::vector<std::string> const& args,
cmExecutionStatus&)
{
2016-07-09 11:21:54 +02:00
if (args.size() < 1) {
return true;
2016-07-09 11:21:54 +02:00
}
const char* variable = args[0].c_str(); // 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;
}