cmGetTargetPropertyCommand.cxx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 << this->Makefile->GetPolicies()
  56. ->GetPolicyWarning(cmPolicies::CMP0045) << "\n";
  57. case cmPolicies::OLD:
  58. break;
  59. case cmPolicies::REQUIRED_IF_USED:
  60. case cmPolicies::REQUIRED_ALWAYS:
  61. case cmPolicies::NEW:
  62. issueMessage = true;
  63. messageType = cmake::FATAL_ERROR;
  64. }
  65. if (issueMessage)
  66. {
  67. e << "get_target_property() called with non-existent target \""
  68. << targetName << "\".";
  69. this->Makefile->IssueMessage(messageType, e.str());
  70. if (messageType == cmake::FATAL_ERROR)
  71. {
  72. return false;
  73. }
  74. }
  75. }
  76. if (prop_exists)
  77. {
  78. this->Makefile->AddDefinition(var, prop.c_str());
  79. return true;
  80. }
  81. this->Makefile->AddDefinition(var, (var+"-NOTFOUND").c_str());
  82. return true;
  83. }