cmIncludeDirectoryCommand.cxx 3.3 KB

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