cmTargetPropCommandBase.cxx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. if ((this->Target->GetType() != cmTarget::SHARED_LIBRARY)
  36. && (this->Target->GetType() != cmTarget::STATIC_LIBRARY)
  37. && (this->Target->GetType() != cmTarget::OBJECT_LIBRARY)
  38. && (this->Target->GetType() != cmTarget::MODULE_LIBRARY)
  39. && (this->Target->GetType() != cmTarget::EXECUTABLE))
  40. {
  41. this->SetError("called with non-compilable target type");
  42. return false;
  43. }
  44. bool system = false;
  45. unsigned int argIndex = 1;
  46. if ((flags & PROCESS_SYSTEM) && args[argIndex] == "SYSTEM")
  47. {
  48. if (args.size() < 4)
  49. {
  50. this->SetError("called with incorrect number of arguments");
  51. return false;
  52. }
  53. system = true;
  54. ++argIndex;
  55. }
  56. bool prepend = false;
  57. if ((flags & PROCESS_BEFORE) && args[argIndex] == "BEFORE")
  58. {
  59. if (args.size() < 4)
  60. {
  61. this->SetError("called with incorrect number of arguments");
  62. return false;
  63. }
  64. prepend = true;
  65. ++argIndex;
  66. }
  67. this->Property = prop;
  68. while (argIndex < args.size())
  69. {
  70. if (!this->ProcessContentArgs(args, argIndex, prepend, system))
  71. {
  72. return false;
  73. }
  74. }
  75. return true;
  76. }
  77. //----------------------------------------------------------------------------
  78. bool cmTargetPropCommandBase
  79. ::ProcessContentArgs(std::vector<std::string> const& args,
  80. unsigned int &argIndex, bool prepend, bool system)
  81. {
  82. const std::string scope = args[argIndex];
  83. if(scope != "PUBLIC"
  84. && scope != "PRIVATE"
  85. && scope != "INTERFACE" )
  86. {
  87. this->SetError("called with invalid arguments");
  88. return false;
  89. }
  90. if(this->Target->IsImported())
  91. {
  92. this->HandleImportedTarget(args[0]);
  93. return false;
  94. }
  95. ++argIndex;
  96. std::vector<std::string> content;
  97. for(unsigned int i=argIndex; i < args.size(); ++i, ++argIndex)
  98. {
  99. if(args[i] == "PUBLIC"
  100. || args[i] == "PRIVATE"
  101. || args[i] == "INTERFACE" )
  102. {
  103. this->PopulateTargetProperies(scope, content, prepend, system);
  104. return true;
  105. }
  106. content.push_back(args[i]);
  107. }
  108. this->PopulateTargetProperies(scope, content, prepend, system);
  109. return true;
  110. }
  111. //----------------------------------------------------------------------------
  112. void cmTargetPropCommandBase
  113. ::PopulateTargetProperies(const std::string &scope,
  114. const std::vector<std::string> &content,
  115. bool prepend, bool system)
  116. {
  117. if (scope == "PRIVATE" || scope == "PUBLIC")
  118. {
  119. this->HandleDirectContent(this->Target, content, prepend, system);
  120. }
  121. if (scope == "INTERFACE" || scope == "PUBLIC")
  122. {
  123. this->HandleInterfaceContent(this->Target, content, prepend, system);
  124. }
  125. }
  126. //----------------------------------------------------------------------------
  127. void cmTargetPropCommandBase::HandleInterfaceContent(cmTarget *tgt,
  128. const std::vector<std::string> &content,
  129. bool prepend, bool)
  130. {
  131. if (prepend)
  132. {
  133. const std::string propName = std::string("INTERFACE_") + this->Property;
  134. const char *propValue = tgt->GetProperty(propName.c_str());
  135. const std::string totalContent = this->Join(content) + (propValue
  136. ? std::string(";") + propValue
  137. : std::string());
  138. tgt->SetProperty(propName.c_str(), totalContent.c_str());
  139. }
  140. else
  141. {
  142. tgt->AppendProperty(("INTERFACE_" + this->Property).c_str(),
  143. this->Join(content).c_str());
  144. }
  145. }