cmRemoveCommand.cxx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmRemoveCommand.h"
  4. #include "cmMakefile.h"
  5. #include "cmSystemTools.h"
  6. class cmExecutionStatus;
  7. // cmRemoveCommand
  8. bool cmRemoveCommand::InitialPass(std::vector<std::string> const& args,
  9. cmExecutionStatus&)
  10. {
  11. if (args.empty()) {
  12. return true;
  13. }
  14. std::string const& variable = args[0]; // VAR is always first
  15. // get the old value
  16. const char* cacheValue = this->Makefile->GetDefinition(variable);
  17. // if there is no old value then return
  18. if (!cacheValue) {
  19. return true;
  20. }
  21. // expand the variable
  22. std::vector<std::string> varArgsExpanded;
  23. cmSystemTools::ExpandListArgument(cacheValue, varArgsExpanded);
  24. // expand the args
  25. // check for REMOVE(VAR v1 v2 ... vn)
  26. std::vector<std::string> argsExpanded;
  27. std::vector<std::string> temp;
  28. temp.insert(temp.end(), args.begin() + 1, args.end());
  29. cmSystemTools::ExpandList(temp, argsExpanded);
  30. // now create the new value
  31. std::string value;
  32. for (std::string const& varArgExpanded : varArgsExpanded) {
  33. int found = 0;
  34. for (std::string const& argExpanded : argsExpanded) {
  35. if (varArgExpanded == argExpanded) {
  36. found = 1;
  37. break;
  38. }
  39. }
  40. if (!found) {
  41. if (!value.empty()) {
  42. value += ";";
  43. }
  44. value += varArgExpanded;
  45. }
  46. }
  47. // add the definition
  48. this->Makefile->AddDefinition(variable, value.c_str());
  49. return true;
  50. }