cmGetTargetPropertyCommand.cxx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. if(args[2] == "ALIASED_TARGET")
  24. {
  25. if(this->Makefile->IsAlias(targetName))
  26. {
  27. if(cmTarget* target =
  28. this->Makefile->FindTargetToUse(targetName))
  29. {
  30. prop = target->GetName();
  31. }
  32. }
  33. }
  34. else if(cmTarget* tgt = this->Makefile->FindTargetToUse(targetName))
  35. {
  36. cmTarget& target = *tgt;
  37. const char* prop_cstr = target.GetProperty(args[2]);
  38. if(prop_cstr)
  39. {
  40. prop = prop_cstr;
  41. }
  42. }
  43. else
  44. {
  45. bool issueMessage = false;
  46. cmOStringStream e;
  47. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  48. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0045))
  49. {
  50. case cmPolicies::WARN:
  51. issueMessage = true;
  52. e << this->Makefile->GetPolicies()
  53. ->GetPolicyWarning(cmPolicies::CMP0045) << "\n";
  54. case cmPolicies::OLD:
  55. break;
  56. case cmPolicies::REQUIRED_IF_USED:
  57. case cmPolicies::REQUIRED_ALWAYS:
  58. case cmPolicies::NEW:
  59. issueMessage = true;
  60. messageType = cmake::FATAL_ERROR;
  61. }
  62. if (issueMessage)
  63. {
  64. e << "get_target_property() called with non-existent target \""
  65. << targetName << "\".";
  66. this->Makefile->IssueMessage(messageType, e.str());
  67. if (messageType == cmake::FATAL_ERROR)
  68. {
  69. return false;
  70. }
  71. }
  72. }
  73. if (!prop.empty())
  74. {
  75. this->Makefile->AddDefinition(var, prop.c_str());
  76. return true;
  77. }
  78. this->Makefile->AddDefinition(var, (var+"-NOTFOUND").c_str());
  79. return true;
  80. }