cmRemoveCommand.cxx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 "cmStringAlgorithms.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> const varArgsExpanded = cmExpandedList(cacheValue);
  23. // expand the args
  24. // check for REMOVE(VAR v1 v2 ... vn)
  25. std::vector<std::string> const argsExpanded =
  26. cmExpandedLists(args.begin() + 1, args.end());
  27. // now create the new value
  28. std::string value;
  29. for (std::string const& varArgExpanded : varArgsExpanded) {
  30. int found = 0;
  31. for (std::string const& argExpanded : argsExpanded) {
  32. if (varArgExpanded == argExpanded) {
  33. found = 1;
  34. break;
  35. }
  36. }
  37. if (!found) {
  38. if (!value.empty()) {
  39. value += ";";
  40. }
  41. value += varArgExpanded;
  42. }
  43. }
  44. // add the definition
  45. this->Makefile->AddDefinition(variable, value);
  46. return true;
  47. }