cmGetCMakePropertyCommand.cxx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 "cmGetCMakePropertyCommand.h"
  4. #include <set>
  5. #include "cmExecutionStatus.h"
  6. #include "cmGlobalGenerator.h"
  7. #include "cmMakefile.h"
  8. #include "cmProperty.h"
  9. #include "cmState.h"
  10. #include "cmStringAlgorithms.h"
  11. // cmGetCMakePropertyCommand
  12. bool cmGetCMakePropertyCommand(std::vector<std::string> const& args,
  13. cmExecutionStatus& status)
  14. {
  15. if (args.size() < 2) {
  16. status.SetError("called with incorrect number of arguments");
  17. return false;
  18. }
  19. std::string const& variable = args[0];
  20. std::string output = "NOTFOUND";
  21. if (args[1] == "VARIABLES") {
  22. if (cmProp varsProp = status.GetMakefile().GetProperty("VARIABLES")) {
  23. output = *varsProp;
  24. }
  25. } else if (args[1] == "MACROS") {
  26. output.clear();
  27. if (cmProp macrosProp = status.GetMakefile().GetProperty("MACROS")) {
  28. output = *macrosProp;
  29. }
  30. } else if (args[1] == "COMPONENTS") {
  31. const std::set<std::string>* components =
  32. status.GetMakefile().GetGlobalGenerator()->GetInstallComponents();
  33. output = cmJoin(*components, ";");
  34. } else {
  35. cmProp prop = nullptr;
  36. if (!args[1].empty()) {
  37. prop = status.GetMakefile().GetState()->GetGlobalProperty(args[1]);
  38. }
  39. if (prop) {
  40. output = *prop;
  41. }
  42. }
  43. status.GetMakefile().AddDefinition(variable, output);
  44. return true;
  45. }