cmIncludeDirectoryCommand.cxx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. const char* errorMessage
  45. = "Empty Include Directory Passed into INCLUDE_DIRECTORIES command.";
  46. if(this->Makefile->NeedBackwardsCompatibility(2,4))
  47. {
  48. cmSystemTools::Error(errorMessage);
  49. }
  50. else
  51. {
  52. this->SetError(errorMessage);
  53. return false;
  54. }
  55. }
  56. this->AddDirectory(i->c_str(),before,system);
  57. }
  58. return true;
  59. }
  60. // do a lot of cleanup on the arguments because this is one place where folks
  61. // sometimes take the output of a program and pass it directly into this
  62. // command not thinking that a single argument could be filled with spaces
  63. // and newlines etc liek below:
  64. //
  65. // " /foo/bar
  66. // /boo/hoo /dingle/berry "
  67. //
  68. // ideally that should be three seperate arguments but when sucking the
  69. // output from a program and passing it into a command the cleanup doesn't
  70. // always happen
  71. //
  72. void cmIncludeDirectoryCommand::AddDirectory(const char *i,
  73. bool before,
  74. bool system)
  75. {
  76. // break apart any line feed arguments
  77. std::string ret = i;
  78. std::string::size_type pos = 0;
  79. if((pos = ret.find('\n', pos)) != std::string::npos)
  80. {
  81. if (pos)
  82. {
  83. this->AddDirectory(ret.substr(0,pos).c_str(), before, system);
  84. }
  85. if (ret.size()-pos-1)
  86. {
  87. this->AddDirectory(ret.substr(pos+1,ret.size()-pos-1).c_str(),
  88. before, system);
  89. }
  90. return;
  91. }
  92. // remove any leading or trailing spaces and \r
  93. pos = ret.size()-1;
  94. while(ret[pos] == ' ' || ret[pos] == '\r')
  95. {
  96. ret.erase(pos);
  97. pos--;
  98. }
  99. pos = 0;
  100. while(ret.size() && ret[pos] == ' ' || ret[pos] == '\r')
  101. {
  102. ret.erase(pos,1);
  103. }
  104. if (!ret.size())
  105. {
  106. return;
  107. }
  108. if (!cmSystemTools::IsOff(ret.c_str()))
  109. {
  110. cmSystemTools::ConvertToUnixSlashes(ret);
  111. if(!cmSystemTools::FileIsFullPath(ret.c_str()))
  112. {
  113. std::string tmp = this->Makefile->GetStartDirectory();
  114. tmp += "/";
  115. tmp += ret;
  116. ret = tmp;
  117. }
  118. }
  119. this->Makefile->AddIncludeDirectory(ret.c_str(), before);
  120. if(system)
  121. {
  122. this->Makefile->AddSystemIncludeDirectory(ret.c_str());
  123. }
  124. }