cmSetDirectoryPropertiesCommand.cxx 1.6 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 "cmSetDirectoryPropertiesCommand.h"
  4. #include "cmExecutionStatus.h"
  5. #include "cmMakefile.h"
  6. namespace {
  7. bool RunCommand(cmMakefile& mf, std::vector<std::string>::const_iterator ait,
  8. std::vector<std::string>::const_iterator aitend,
  9. std::string& errors);
  10. }
  11. // cmSetDirectoryPropertiesCommand
  12. bool cmSetDirectoryPropertiesCommand(std::vector<std::string> const& args,
  13. cmExecutionStatus& status)
  14. {
  15. if (args.empty()) {
  16. status.SetError("called with incorrect number of arguments");
  17. return false;
  18. }
  19. std::string errors;
  20. bool ret =
  21. RunCommand(status.GetMakefile(), args.begin() + 1, args.end(), errors);
  22. if (!ret) {
  23. status.SetError(errors);
  24. }
  25. return ret;
  26. }
  27. namespace {
  28. bool RunCommand(cmMakefile& mf, std::vector<std::string>::const_iterator ait,
  29. std::vector<std::string>::const_iterator aitend,
  30. std::string& errors)
  31. {
  32. for (; ait != aitend; ait += 2) {
  33. if (ait + 1 == aitend) {
  34. errors = "Wrong number of arguments";
  35. return false;
  36. }
  37. const std::string& prop = *ait;
  38. const std::string& value = *(ait + 1);
  39. if (prop == "VARIABLES") {
  40. errors = "Variables and cache variables should be set using SET command";
  41. return false;
  42. }
  43. if (prop == "MACROS") {
  44. errors = "Commands and macros cannot be set using SET_CMAKE_PROPERTIES";
  45. return false;
  46. }
  47. mf.SetProperty(prop, value.c_str());
  48. }
  49. return true;
  50. }
  51. }