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 std::vector<std::string> beforeIncludes;
40 std::vector<std::string> afterIncludes;
41 std::set<cmStdString> systemIncludes;
43 for(; i != args.end(); ++i)
52 this->SetError("given empty-string as include directory.");
56 std::vector<std::string> includes;
58 GetIncludes(*i, includes);
62 beforeIncludes.insert(beforeIncludes.end(),
68 afterIncludes.insert(afterIncludes.end(),
74 for (std::vector<std::string>::const_iterator li = includes.begin();
75 li != includes.end(); ++li)
77 systemIncludes.insert(*li);
81 std::reverse(beforeIncludes.begin(), beforeIncludes.end());
83 this->Makefile->AddIncludeDirectories(afterIncludes);
84 this->Makefile->AddIncludeDirectories(beforeIncludes, before);
85 this->Makefile->AddSystemIncludeDirectories(systemIncludes);
90 static bool StartsWithGeneratorExpression(const std::string &input)
92 return input[0] == '$' && input[1] == '<';
95 // do a lot of cleanup on the arguments because this is one place where folks
96 // sometimes take the output of a program and pass it directly into this
97 // command not thinking that a single argument could be filled with spaces
98 // and newlines etc liek below:
101 // /boo/hoo /dingle/berry "
103 // ideally that should be three separate arguments but when sucking the
104 // output from a program and passing it into a command the cleanup doesn't
107 void cmIncludeDirectoryCommand::GetIncludes(const std::string &arg,
108 std::vector<std::string> &incs)
110 // break apart any line feed arguments
111 std::string::size_type pos = 0;
112 std::string::size_type lastPos = 0;
113 while((pos = arg.find('\n', lastPos)) != std::string::npos)
117 std::string inc = arg.substr(lastPos,pos);
118 this->NormalizeInclude(inc);
126 std::string inc = arg.substr(lastPos);
127 this->NormalizeInclude(inc);
134 void cmIncludeDirectoryCommand::NormalizeInclude(std::string &inc)
136 std::string::size_type b = inc.find_first_not_of(" \r");
137 std::string::size_type e = inc.find_last_not_of(" \r");
138 if ((b!=inc.npos) && (e!=inc.npos))
140 inc.assign(inc, b, 1+e-b); // copy the remaining substring
148 if (!cmSystemTools::IsOff(inc.c_str()))
150 cmSystemTools::ConvertToUnixSlashes(inc);
152 if(!cmSystemTools::FileIsFullPath(inc.c_str()))
154 if(!StartsWithGeneratorExpression(inc))
156 std::string tmp = this->Makefile->GetStartDirectory();