cmGetTargetPropertyCommand.cxx 1.9 KB

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