cmIncludeDirectoryCommand.cxx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  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 "cmIncludeDirectoryCommand.h"
  11. // cmIncludeDirectoryCommand
  12. bool cmIncludeDirectoryCommand
  13. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  14. {
  15. if(args.size() < 1 )
  16. {
  17. return true;
  18. }
  19. std::vector<std::string>::const_iterator i = args.begin();
  20. bool before = this->Makefile->IsOn("CMAKE_INCLUDE_DIRECTORIES_BEFORE");
  21. bool system = false;
  22. if ((*i) == "BEFORE")
  23. {
  24. before = true;
  25. ++i;
  26. }
  27. else if ((*i) == "AFTER")
  28. {
  29. before = false;
  30. ++i;
  31. }
  32. for(; i != args.end(); ++i)
  33. {
  34. if(*i == "SYSTEM")
  35. {
  36. system = true;
  37. continue;
  38. }
  39. if(i->size() == 0)
  40. {
  41. this->SetError("given empty-string as include directory.");
  42. return false;
  43. }
  44. this->AddDirectory(i->c_str(),before,system);
  45. }
  46. return true;
  47. }
  48. // do a lot of cleanup on the arguments because this is one place where folks
  49. // sometimes take the output of a program and pass it directly into this
  50. // command not thinking that a single argument could be filled with spaces
  51. // and newlines etc liek below:
  52. //
  53. // " /foo/bar
  54. // /boo/hoo /dingle/berry "
  55. //
  56. // ideally that should be three seperate arguments but when sucking the
  57. // output from a program and passing it into a command the cleanup doesn't
  58. // always happen
  59. //
  60. void cmIncludeDirectoryCommand::AddDirectory(const char *i,
  61. bool before,
  62. bool system)
  63. {
  64. // break apart any line feed arguments
  65. std::string ret = i;
  66. std::string::size_type pos = 0;
  67. if((pos = ret.find('\n', pos)) != std::string::npos)
  68. {
  69. if (pos)
  70. {
  71. this->AddDirectory(ret.substr(0,pos).c_str(), before, system);
  72. }
  73. if (ret.size()-pos-1)
  74. {
  75. this->AddDirectory(ret.substr(pos+1,ret.size()-pos-1).c_str(),
  76. before, system);
  77. }
  78. return;
  79. }
  80. // remove any leading or trailing spaces and \r
  81. std::string::size_type b = ret.find_first_not_of(" \r");
  82. std::string::size_type e = ret.find_last_not_of(" \r");
  83. if ((b!=ret.npos) && (e!=ret.npos))
  84. {
  85. ret.assign(ret, b, 1+e-b); // copy the remaining substring
  86. }
  87. else
  88. {
  89. return; // if we get here, we had only whitespace in the string
  90. }
  91. if (!cmSystemTools::IsOff(ret.c_str()))
  92. {
  93. cmSystemTools::ConvertToUnixSlashes(ret);
  94. if(!cmSystemTools::FileIsFullPath(ret.c_str()))
  95. {
  96. std::string tmp = this->Makefile->GetStartDirectory();
  97. tmp += "/";
  98. tmp += ret;
  99. ret = tmp;
  100. }
  101. }
  102. this->Makefile->AddIncludeDirectory(ret.c_str(), before);
  103. if(system)
  104. {
  105. this->Makefile->AddSystemIncludeDirectory(ret.c_str());
  106. }
  107. }