cmTargetPropCommandBase.cxx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2013 Stephen Kelly <[email protected]>
  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 "cmTargetPropCommandBase.h"
  11. #include "cmGlobalGenerator.h"
  12. //----------------------------------------------------------------------------
  13. bool cmTargetPropCommandBase
  14. ::HandleArguments(std::vector<std::string> const& args, const char *prop,
  15. ArgumentFlags flags)
  16. {
  17. if(args.size() < 3)
  18. {
  19. this->SetError("called with incorrect number of arguments");
  20. return false;
  21. }
  22. // Lookup the target for which libraries are specified.
  23. this->Target =
  24. this->Makefile->GetCMakeInstance()
  25. ->GetGlobalGenerator()->FindTarget(0, args[0].c_str());
  26. if(!this->Target)
  27. {
  28. this->Target = this->Makefile->FindTargetToUse(args[0].c_str());
  29. }
  30. if(!this->Target)
  31. {
  32. this->HandleMissingTarget(args[0]);
  33. return false;
  34. }
  35. unsigned int argIndex = 1;
  36. bool prepend = false;
  37. if ((flags & PROCESS_BEFORE) && args[argIndex] == "BEFORE")
  38. {
  39. if (args.size() < 4)
  40. {
  41. this->SetError("called with incorrect number of arguments");
  42. return false;
  43. }
  44. prepend = true;
  45. ++argIndex;
  46. }
  47. this->Property = prop;
  48. while (argIndex < args.size())
  49. {
  50. if (!this->ProcessContentArgs(args, argIndex, prepend))
  51. {
  52. return false;
  53. }
  54. }
  55. return true;
  56. }
  57. //----------------------------------------------------------------------------
  58. bool cmTargetPropCommandBase
  59. ::ProcessContentArgs(std::vector<std::string> const& args,
  60. unsigned int &argIndex, bool prepend)
  61. {
  62. const std::string scope = args[argIndex];
  63. if(scope != "PUBLIC"
  64. && scope != "PRIVATE"
  65. && scope != "INTERFACE" )
  66. {
  67. this->SetError("called with invalid arguments");
  68. return false;
  69. }
  70. if(this->Target->IsImported() && scope != "INTERFACE")
  71. {
  72. this->HandleImportedTargetInvalidScope(args[0], scope);
  73. return false;
  74. }
  75. ++argIndex;
  76. std::string content;
  77. std::string sep;
  78. for(unsigned int i=argIndex; i < args.size(); ++i, ++argIndex)
  79. {
  80. if(args[i] == "PUBLIC"
  81. || args[i] == "PRIVATE"
  82. || args[i] == "INTERFACE" )
  83. {
  84. this->PopulateTargetProperies(scope, content, prepend);
  85. return true;
  86. }
  87. if (this->Makefile->FindTargetToUse(args[i].c_str()))
  88. {
  89. content += sep + "$<TARGET_PROPERTY:" + args[i]
  90. + ",INTERFACE_" + this->Property + ">";
  91. }
  92. else if (!this->HandleNonTargetArg(content, sep, args[i], args[0]))
  93. {
  94. return false;
  95. }
  96. sep = ";";
  97. }
  98. this->PopulateTargetProperies(scope, content, prepend);
  99. return true;
  100. }
  101. //----------------------------------------------------------------------------
  102. void cmTargetPropCommandBase
  103. ::PopulateTargetProperies(const std::string &scope,
  104. const std::string &content, bool prepend)
  105. {
  106. if (scope == "PRIVATE" || scope == "PUBLIC")
  107. {
  108. this->HandleDirectContent(this->Target, content, prepend);
  109. }
  110. if (scope == "INTERFACE" || scope == "PUBLIC")
  111. {
  112. if (prepend)
  113. {
  114. const std::string propName = std::string("INTERFACE_") + this->Property;
  115. const char *propValue = this->Target->GetProperty(propName.c_str());
  116. const std::string totalContent = content + (propValue
  117. ? std::string(";") + propValue
  118. : std::string());
  119. this->Target->SetProperty(propName.c_str(), totalContent.c_str());
  120. }
  121. else
  122. {
  123. this->Target->AppendProperty(("INTERFACE_" + this->Property).c_str(),
  124. content.c_str());
  125. }
  126. }
  127. }