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