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