cmGetTargetPropertyCommand.cxx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmGetTargetPropertyCommand.h"
  11. // cmSetTargetPropertyCommand
  12. bool cmGetTargetPropertyCommand
  13. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  14. {
  15. if(args.size() != 3 )
  16. {
  17. this->SetError("called with incorrect number of arguments");
  18. return false;
  19. }
  20. std::string var = args[0];
  21. const std::string& targetName = args[1];
  22. std::string prop;
  23. bool prop_exists = false;
  24. if(args[2] == "ALIASED_TARGET")
  25. {
  26. if(this->Makefile->IsAlias(targetName))
  27. {
  28. if(cmTarget* target =
  29. this->Makefile->FindTargetToUse(targetName))
  30. {
  31. prop = target->GetName();
  32. prop_exists = true;
  33. }
  34. }
  35. }
  36. else if(cmTarget* tgt = this->Makefile->FindTargetToUse(targetName))
  37. {
  38. cmTarget& target = *tgt;
  39. const char* prop_cstr = target.GetProperty(args[2], this->Makefile);
  40. if(prop_cstr)
  41. {
  42. prop = prop_cstr;
  43. prop_exists = true;
  44. }
  45. }
  46. else
  47. {
  48. bool issueMessage = false;
  49. std::ostringstream e;
  50. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  51. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0045))
  52. {
  53. case cmPolicies::WARN:
  54. issueMessage = true;
  55. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0045) << "\n";
  56. case cmPolicies::OLD:
  57. break;
  58. case cmPolicies::REQUIRED_IF_USED:
  59. case cmPolicies::REQUIRED_ALWAYS:
  60. case cmPolicies::NEW:
  61. issueMessage = true;
  62. messageType = cmake::FATAL_ERROR;
  63. }
  64. if (issueMessage)
  65. {
  66. e << "get_target_property() called with non-existent target \""
  67. << targetName << "\".";
  68. this->Makefile->IssueMessage(messageType, e.str());
  69. if (messageType == cmake::FATAL_ERROR)
  70. {
  71. return false;
  72. }
  73. }
  74. }
  75. if (prop_exists)
  76. {
  77. this->Makefile->AddDefinition(var, prop.c_str());
  78. return true;
  79. }
  80. this->Makefile->AddDefinition(var, (var+"-NOTFOUND").c_str());
  81. return true;
  82. }