cmIncludeDirectoryCommand.cxx 3.5 KB

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