1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmIncludeDirectoryCommand.cxx,v $
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
&)
28 std::vector
<std::string
>::const_iterator i
= args
.begin();
30 bool before
= this->Makefile
->IsOn("CMAKE_INCLUDE_DIRECTORIES_BEFORE");
38 else if ((*i
) == "AFTER")
44 for(; i
!= args
.end(); ++i
)
53 this->SetError("given empty-string as include directory.");
57 this->AddDirectory(i
->c_str(),before
,system
);
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:
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
75 void cmIncludeDirectoryCommand::AddDirectory(const char *i
,
79 // break apart any line feed arguments
81 std::string::size_type pos
= 0;
82 if((pos
= ret
.find('\n', pos
)) != std::string::npos
)
86 this->AddDirectory(ret
.substr(0,pos
).c_str(), before
, system
);
90 this->AddDirectory(ret
.substr(pos
+1,ret
.size()-pos
-1).c_str(),
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
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();
119 this->Makefile
->AddIncludeDirectory(ret
.c_str(), before
);
122 this->Makefile
->AddSystemIncludeDirectory(ret
.c_str());