Initial commit.
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmIncludeDirectoryCommand.cxx
blob465ba614ddd3885bd5ad9cbfcf1a9df56c85fe67
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmIncludeDirectoryCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2008/01/23 15:27:59 $
7 Version: $Revision: 1.27 $
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 const char* versionValue =
54 this->Makefile->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY");
55 const char* errorMessage
56 = "Empty Include Directory Passed into INCLUDE_DIRECTORIES command.";
57 if(atof(versionValue) < 2.5)
59 cmSystemTools::Error(errorMessage);
61 else
63 this->SetError(errorMessage);
64 return 0;
68 this->AddDirectory(i->c_str(),before,system);
71 return true;
74 // do a lot of cleanup on the arguments because this is one place where folks
75 // sometimes take the output of a program and pass it directly into this
76 // command not thinking that a single argument could be filled with spaces
77 // and newlines etc liek below:
79 // " /foo/bar
80 // /boo/hoo /dingle/berry "
82 // ideally that should be three seperate arguments but when sucking the
83 // output from a program and passing it into a command the cleanup doesn't
84 // always happen
86 void cmIncludeDirectoryCommand::AddDirectory(const char *i,
87 bool before,
88 bool system)
90 // break apart any line feed arguments
91 std::string ret = i;
92 std::string::size_type pos = 0;
93 if((pos = ret.find('\n', pos)) != std::string::npos)
95 if (pos)
97 this->AddDirectory(ret.substr(0,pos).c_str(), before, system);
99 if (ret.size()-pos-1)
101 this->AddDirectory(ret.substr(pos+1,ret.size()-pos-1).c_str(),
102 before, system);
104 return;
107 // remove any leading or trailing spaces and \r
108 pos = ret.size()-1;
109 while(ret[pos] == ' ' || ret[pos] == '\r')
111 ret.erase(pos);
112 pos--;
114 pos = 0;
115 while(ret.size() && ret[pos] == ' ' || ret[pos] == '\r')
117 ret.erase(pos,1);
119 if (!ret.size())
121 return;
124 if (!cmSystemTools::IsOff(ret.c_str()))
126 cmSystemTools::ConvertToUnixSlashes(ret);
127 if(!cmSystemTools::FileIsFullPath(ret.c_str()))
129 std::string tmp = this->Makefile->GetStartDirectory();
130 tmp += "/";
131 tmp += ret;
132 ret = tmp;
135 this->Makefile->AddIncludeDirectory(ret.c_str(), before);
136 if(system)
138 this->Makefile->AddSystemIncludeDirectory(ret.c_str());