cmRemoveCommand.cxx 1.4 KB

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