cmGetTargetPropertyCommand.cxx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 "cmGetTargetPropertyCommand.h"
  4. #include "cmTargetPropertyComputer.h"
  5. // cmSetTargetPropertyCommand
  6. bool cmGetTargetPropertyCommand::InitialPass(
  7. std::vector<std::string> const& args, cmExecutionStatus&)
  8. {
  9. if (args.size() != 3) {
  10. this->SetError("called with incorrect number of arguments");
  11. return false;
  12. }
  13. std::string var = args[0];
  14. const std::string& targetName = args[1];
  15. std::string prop;
  16. bool prop_exists = false;
  17. if (cmTarget* tgt = this->Makefile->FindTargetToUse(targetName)) {
  18. if (args[2] == "ALIASED_TARGET") {
  19. if (this->Makefile->IsAlias(targetName)) {
  20. prop = tgt->GetName();
  21. prop_exists = true;
  22. }
  23. } else if (!args[2].empty()) {
  24. const char* prop_cstr = CM_NULLPTR;
  25. cmListFileBacktrace bt = this->Makefile->GetBacktrace();
  26. cmMessenger* messenger = this->Makefile->GetMessenger();
  27. if (cmTargetPropertyComputer::PassesWhitelist(tgt->GetType(), args[2],
  28. messenger, bt)) {
  29. prop_cstr = tgt->GetComputedProperty(args[2], messenger, bt);
  30. if (!prop_cstr) {
  31. prop_cstr = tgt->GetProperty(args[2]);
  32. }
  33. }
  34. if (prop_cstr) {
  35. prop = prop_cstr;
  36. prop_exists = true;
  37. }
  38. }
  39. } else {
  40. bool issueMessage = false;
  41. std::ostringstream e;
  42. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  43. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0045)) {
  44. case cmPolicies::WARN:
  45. issueMessage = true;
  46. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0045) << "\n";
  47. case cmPolicies::OLD:
  48. break;
  49. case cmPolicies::REQUIRED_IF_USED:
  50. case cmPolicies::REQUIRED_ALWAYS:
  51. case cmPolicies::NEW:
  52. issueMessage = true;
  53. messageType = cmake::FATAL_ERROR;
  54. }
  55. if (issueMessage) {
  56. e << "get_target_property() called with non-existent target \""
  57. << targetName << "\".";
  58. this->Makefile->IssueMessage(messageType, e.str());
  59. if (messageType == cmake::FATAL_ERROR) {
  60. return false;
  61. }
  62. }
  63. }
  64. if (prop_exists) {
  65. this->Makefile->AddDefinition(var, prop.c_str());
  66. return true;
  67. }
  68. this->Makefile->AddDefinition(var, (var + "-NOTFOUND").c_str());
  69. return true;
  70. }