cmTargetIncludeDirectoriesCommand.cxx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 "cmTargetIncludeDirectoriesCommand.h"
  11. #include "cmGeneratorExpression.h"
  12. //----------------------------------------------------------------------------
  13. bool cmTargetIncludeDirectoriesCommand
  14. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  15. {
  16. return this->HandleArguments(args, "INCLUDE_DIRECTORIES",
  17. ArgumentFlags(PROCESS_BEFORE | PROCESS_SYSTEM));
  18. }
  19. //----------------------------------------------------------------------------
  20. void cmTargetIncludeDirectoriesCommand
  21. ::HandleImportedTarget(const std::string &tgt)
  22. {
  23. std::ostringstream e;
  24. e << "Cannot specify include directories for imported target \""
  25. << tgt << "\".";
  26. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  27. }
  28. //----------------------------------------------------------------------------
  29. void cmTargetIncludeDirectoriesCommand
  30. ::HandleMissingTarget(const std::string &name)
  31. {
  32. std::ostringstream e;
  33. e << "Cannot specify include directories for target \"" << name << "\" "
  34. "which is not built by this project.";
  35. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  36. }
  37. //----------------------------------------------------------------------------
  38. std::string cmTargetIncludeDirectoriesCommand
  39. ::Join(const std::vector<std::string> &content)
  40. {
  41. std::string dirs;
  42. std::string sep;
  43. std::string prefix =
  44. this->Makefile->GetCurrentSourceDirectory() + std::string("/");
  45. for(std::vector<std::string>::const_iterator it = content.begin();
  46. it != content.end(); ++it)
  47. {
  48. if (cmSystemTools::FileIsFullPath(it->c_str())
  49. || cmGeneratorExpression::Find(*it) == 0)
  50. {
  51. dirs += sep + *it;
  52. }
  53. else
  54. {
  55. dirs += sep + prefix + *it;
  56. }
  57. sep = ";";
  58. }
  59. return dirs;
  60. }
  61. //----------------------------------------------------------------------------
  62. bool cmTargetIncludeDirectoriesCommand
  63. ::HandleDirectContent(cmTarget *tgt, const std::vector<std::string> &content,
  64. bool prepend, bool system)
  65. {
  66. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  67. tgt->InsertInclude(this->Join(content), lfbt, prepend);
  68. if (system)
  69. {
  70. std::string prefix =
  71. this->Makefile->GetCurrentSourceDirectory() + std::string("/");
  72. std::set<std::string> sdirs;
  73. for (std::vector<std::string>::const_iterator it = content.begin();
  74. it != content.end(); ++it)
  75. {
  76. if (cmSystemTools::FileIsFullPath(it->c_str())
  77. || cmGeneratorExpression::Find(*it) == 0)
  78. {
  79. sdirs.insert(*it);
  80. }
  81. else
  82. {
  83. sdirs.insert(prefix + *it);
  84. }
  85. }
  86. tgt->AddSystemIncludeDirectories(sdirs);
  87. }
  88. return true;
  89. }
  90. //----------------------------------------------------------------------------
  91. void cmTargetIncludeDirectoriesCommand
  92. ::HandleInterfaceContent(cmTarget *tgt,
  93. const std::vector<std::string> &content,
  94. bool prepend, bool system)
  95. {
  96. cmTargetPropCommandBase::HandleInterfaceContent(tgt, content,
  97. prepend, system);
  98. if (system)
  99. {
  100. std::string joined = this->Join(content);
  101. tgt->AppendProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES",
  102. joined.c_str());
  103. }
  104. }