cmTargetPropCommandBase.cxx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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())
  71. {
  72. this->HandleImportedTarget(args[0]);
  73. return false;
  74. }
  75. ++argIndex;
  76. std::vector<std::string> content;
  77. for(unsigned int i=argIndex; i < args.size(); ++i, ++argIndex)
  78. {
  79. if(args[i] == "PUBLIC"
  80. || args[i] == "PRIVATE"
  81. || args[i] == "INTERFACE" )
  82. {
  83. this->PopulateTargetProperies(scope, content, prepend);
  84. return true;
  85. }
  86. content.push_back(args[i]);
  87. }
  88. this->PopulateTargetProperies(scope, content, prepend);
  89. return true;
  90. }
  91. //----------------------------------------------------------------------------
  92. void cmTargetPropCommandBase
  93. ::PopulateTargetProperies(const std::string &scope,
  94. const std::vector<std::string> &content,
  95. bool prepend)
  96. {
  97. if (scope == "PRIVATE" || scope == "PUBLIC")
  98. {
  99. this->HandleDirectContent(this->Target, content, prepend);
  100. }
  101. if (scope == "INTERFACE" || scope == "PUBLIC")
  102. {
  103. if (prepend)
  104. {
  105. const std::string propName = std::string("INTERFACE_") + this->Property;
  106. const char *propValue = this->Target->GetProperty(propName.c_str());
  107. const std::string totalContent = this->Join(content) + (propValue
  108. ? std::string(";") + propValue
  109. : std::string());
  110. this->Target->SetProperty(propName.c_str(), totalContent.c_str());
  111. }
  112. else
  113. {
  114. this->Target->AppendProperty(("INTERFACE_" + this->Property).c_str(),
  115. this->Join(content).c_str());
  116. }
  117. }
  118. }