cmTargetPropCommandBase.cxx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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,
  15. const std::string& prop,
  16. ArgumentFlags flags)
  17. {
  18. if(args.size() < 2)
  19. {
  20. this->SetError("called with incorrect number of arguments");
  21. return false;
  22. }
  23. // Lookup the target for which libraries are specified.
  24. if (this->Makefile->IsAlias(args[0]))
  25. {
  26. this->SetError("can not be used on an ALIAS target.");
  27. return false;
  28. }
  29. this->Target =
  30. this->Makefile->GetCMakeInstance()
  31. ->GetGlobalGenerator()->FindTarget(args[0]);
  32. if(!this->Target)
  33. {
  34. this->Target = this->Makefile->FindTargetToUse(args[0]);
  35. }
  36. if(!this->Target)
  37. {
  38. this->HandleMissingTarget(args[0]);
  39. return false;
  40. }
  41. if ((this->Target->GetType() != cmState::SHARED_LIBRARY)
  42. && (this->Target->GetType() != cmState::STATIC_LIBRARY)
  43. && (this->Target->GetType() != cmState::OBJECT_LIBRARY)
  44. && (this->Target->GetType() != cmState::MODULE_LIBRARY)
  45. && (this->Target->GetType() != cmState::INTERFACE_LIBRARY)
  46. && (this->Target->GetType() != cmState::EXECUTABLE))
  47. {
  48. this->SetError("called with non-compilable target type");
  49. return false;
  50. }
  51. bool system = false;
  52. unsigned int argIndex = 1;
  53. if ((flags & PROCESS_SYSTEM) && args[argIndex] == "SYSTEM")
  54. {
  55. if (args.size() < 3)
  56. {
  57. this->SetError("called with incorrect number of arguments");
  58. return false;
  59. }
  60. system = true;
  61. ++argIndex;
  62. }
  63. bool prepend = false;
  64. if ((flags & PROCESS_BEFORE) && args[argIndex] == "BEFORE")
  65. {
  66. if (args.size() < 3)
  67. {
  68. this->SetError("called with incorrect number of arguments");
  69. return false;
  70. }
  71. prepend = true;
  72. ++argIndex;
  73. }
  74. this->Property = prop;
  75. while (argIndex < args.size())
  76. {
  77. if (!this->ProcessContentArgs(args, argIndex, prepend, system))
  78. {
  79. return false;
  80. }
  81. }
  82. return true;
  83. }
  84. //----------------------------------------------------------------------------
  85. bool cmTargetPropCommandBase
  86. ::ProcessContentArgs(std::vector<std::string> const& args,
  87. unsigned int &argIndex, bool prepend, bool system)
  88. {
  89. const std::string scope = args[argIndex];
  90. if(scope != "PUBLIC"
  91. && scope != "PRIVATE"
  92. && scope != "INTERFACE" )
  93. {
  94. this->SetError("called with invalid arguments");
  95. return false;
  96. }
  97. if(this->Target->IsImported())
  98. {
  99. this->HandleImportedTarget(args[0]);
  100. return false;
  101. }
  102. if (this->Target->GetType() == cmState::INTERFACE_LIBRARY
  103. && scope != "INTERFACE")
  104. {
  105. this->SetError("may only be set INTERFACE properties on INTERFACE "
  106. "targets");
  107. return false;
  108. }
  109. ++argIndex;
  110. std::vector<std::string> content;
  111. for(unsigned int i=argIndex; i < args.size(); ++i, ++argIndex)
  112. {
  113. if(args[i] == "PUBLIC"
  114. || args[i] == "PRIVATE"
  115. || args[i] == "INTERFACE" )
  116. {
  117. return this->PopulateTargetProperies(scope, content, prepend, system);
  118. }
  119. content.push_back(args[i]);
  120. }
  121. return this->PopulateTargetProperies(scope, content, prepend, system);
  122. }
  123. //----------------------------------------------------------------------------
  124. bool cmTargetPropCommandBase
  125. ::PopulateTargetProperies(const std::string &scope,
  126. const std::vector<std::string> &content,
  127. bool prepend, bool system)
  128. {
  129. if (scope == "PRIVATE" || scope == "PUBLIC")
  130. {
  131. if (!this->HandleDirectContent(this->Target, content, prepend, system))
  132. {
  133. return false;
  134. }
  135. }
  136. if (scope == "INTERFACE" || scope == "PUBLIC")
  137. {
  138. this->HandleInterfaceContent(this->Target, content, prepend, system);
  139. }
  140. return true;
  141. }
  142. //----------------------------------------------------------------------------
  143. void cmTargetPropCommandBase::HandleInterfaceContent(cmTarget *tgt,
  144. const std::vector<std::string> &content,
  145. bool prepend, bool)
  146. {
  147. if (prepend)
  148. {
  149. const std::string propName = std::string("INTERFACE_") + this->Property;
  150. const char *propValue = tgt->GetProperty(propName);
  151. const std::string totalContent = this->Join(content) + (propValue
  152. ? std::string(";") + propValue
  153. : std::string());
  154. tgt->SetProperty(propName, totalContent.c_str());
  155. }
  156. else
  157. {
  158. tgt->AppendProperty("INTERFACE_" + this->Property,
  159. this->Join(content).c_str());
  160. }
  161. }