1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
12 #include "cmIncludeDirectoryCommand.h"
14 // cmIncludeDirectoryCommand
15 bool cmIncludeDirectoryCommand
16 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
23 std::vector<std::string>::const_iterator i = args.begin();
25 bool before = this->Makefile->IsOn("CMAKE_INCLUDE_DIRECTORIES_BEFORE");
33 else if ((*i) == "AFTER")
39 for(; i != args.end(); ++i)
48 this->SetError("given empty-string as include directory.");
52 this->AddDirectory(i->c_str(),before,system);
58 // do a lot of cleanup on the arguments because this is one place where folks
59 // sometimes take the output of a program and pass it directly into this
60 // command not thinking that a single argument could be filled with spaces
61 // and newlines etc liek below:
64 // /boo/hoo /dingle/berry "
66 // ideally that should be three separate arguments but when sucking the
67 // output from a program and passing it into a command the cleanup doesn't
70 void cmIncludeDirectoryCommand::AddDirectory(const char *i,
74 // break apart any line feed arguments
76 std::string::size_type pos = 0;
77 if((pos = ret.find('\n', pos)) != std::string::npos)
81 this->AddDirectory(ret.substr(0,pos).c_str(), before, system);
85 this->AddDirectory(ret.substr(pos+1,ret.size()-pos-1).c_str(),
91 // remove any leading or trailing spaces and \r
92 std::string::size_type b = ret.find_first_not_of(" \r");
93 std::string::size_type e = ret.find_last_not_of(" \r");
94 if ((b!=ret.npos) && (e!=ret.npos))
96 ret.assign(ret, b, 1+e-b); // copy the remaining substring
100 return; // if we get here, we had only whitespace in the string
103 if (!cmSystemTools::IsOff(ret.c_str()))
105 cmSystemTools::ConvertToUnixSlashes(ret);
106 if(!cmSystemTools::FileIsFullPath(ret.c_str()))
108 std::string tmp = this->Makefile->GetStartDirectory();
114 this->Makefile->AddIncludeDirectory(ret.c_str(), before);
117 this->Makefile->AddSystemIncludeDirectory(ret.c_str());