summaryrefslogtreecommitdiff
path: root/Source/cmIncludeDirectoryCommand.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmIncludeDirectoryCommand.cxx')
-rw-r--r--Source/cmIncludeDirectoryCommand.cxx72
1 files changed, 34 insertions, 38 deletions
diff --git a/Source/cmIncludeDirectoryCommand.cxx b/Source/cmIncludeDirectoryCommand.cxx
index b81f7cb2d..170aea125 100644
--- a/Source/cmIncludeDirectoryCommand.cxx
+++ b/Source/cmIncludeDirectoryCommand.cxx
@@ -4,23 +4,31 @@
#include <algorithm>
#include <set>
+#include <utility>
+#include "cmAlgorithms.h"
+#include "cmExecutionStatus.h"
+#include "cmGeneratorExpression.h"
#include "cmMakefile.h"
+#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
-class cmExecutionStatus;
+static void GetIncludes(cmMakefile& mf, const std::string& arg,
+ std::vector<std::string>& incs);
+static void NormalizeInclude(cmMakefile& mf, std::string& inc);
-// cmIncludeDirectoryCommand
-bool cmIncludeDirectoryCommand::InitialPass(
- std::vector<std::string> const& args, cmExecutionStatus&)
+bool cmIncludeDirectoryCommand(std::vector<std::string> const& args,
+ cmExecutionStatus& status)
{
if (args.empty()) {
return true;
}
- std::vector<std::string>::const_iterator i = args.begin();
+ cmMakefile& mf = status.GetMakefile();
- bool before = this->Makefile->IsOn("CMAKE_INCLUDE_DIRECTORIES_BEFORE");
+ auto i = args.begin();
+
+ bool before = mf.IsOn("CMAKE_INCLUDE_DIRECTORIES_BEFORE");
bool system = false;
if ((*i) == "BEFORE") {
@@ -41,20 +49,18 @@ bool cmIncludeDirectoryCommand::InitialPass(
continue;
}
if (i->empty()) {
- this->SetError("given empty-string as include directory.");
+ status.SetError("given empty-string as include directory.");
return false;
}
std::vector<std::string> includes;
- this->GetIncludes(*i, includes);
+ GetIncludes(mf, *i, includes);
if (before) {
- beforeIncludes.insert(beforeIncludes.end(), includes.begin(),
- includes.end());
+ cmAppend(beforeIncludes, includes);
} else {
- afterIncludes.insert(afterIncludes.end(), includes.begin(),
- includes.end());
+ cmAppend(afterIncludes, includes);
}
if (system) {
systemIncludes.insert(includes.begin(), includes.end());
@@ -62,22 +68,17 @@ bool cmIncludeDirectoryCommand::InitialPass(
}
std::reverse(beforeIncludes.begin(), beforeIncludes.end());
- this->Makefile->AddIncludeDirectories(afterIncludes);
- this->Makefile->AddIncludeDirectories(beforeIncludes, before);
- this->Makefile->AddSystemIncludeDirectories(systemIncludes);
+ mf.AddIncludeDirectories(afterIncludes);
+ mf.AddIncludeDirectories(beforeIncludes, before);
+ mf.AddSystemIncludeDirectories(systemIncludes);
return true;
}
-static bool StartsWithGeneratorExpression(const std::string& input)
-{
- return input[0] == '$' && input[1] == '<';
-}
-
// do a lot of cleanup on the arguments because this is one place where folks
// sometimes take the output of a program and pass it directly into this
// command not thinking that a single argument could be filled with spaces
-// and newlines etc liek below:
+// and newlines etc like below:
//
// " /foo/bar
// /boo/hoo /dingle/berry "
@@ -86,8 +87,8 @@ static bool StartsWithGeneratorExpression(const std::string& input)
// output from a program and passing it into a command the cleanup doesn't
// always happen
//
-void cmIncludeDirectoryCommand::GetIncludes(const std::string& arg,
- std::vector<std::string>& incs)
+static void GetIncludes(cmMakefile& mf, const std::string& arg,
+ std::vector<std::string>& incs)
{
// break apart any line feed arguments
std::string::size_type pos = 0;
@@ -95,41 +96,36 @@ void cmIncludeDirectoryCommand::GetIncludes(const std::string& arg,
while ((pos = arg.find('\n', lastPos)) != std::string::npos) {
if (pos) {
std::string inc = arg.substr(lastPos, pos);
- this->NormalizeInclude(inc);
+ NormalizeInclude(mf, inc);
if (!inc.empty()) {
- incs.push_back(inc);
+ incs.push_back(std::move(inc));
}
}
lastPos = pos + 1;
}
std::string inc = arg.substr(lastPos);
- this->NormalizeInclude(inc);
+ NormalizeInclude(mf, inc);
if (!inc.empty()) {
- incs.push_back(inc);
+ incs.push_back(std::move(inc));
}
}
-void cmIncludeDirectoryCommand::NormalizeInclude(std::string& inc)
+static void NormalizeInclude(cmMakefile& mf, std::string& inc)
{
std::string::size_type b = inc.find_first_not_of(" \r");
std::string::size_type e = inc.find_last_not_of(" \r");
if ((b != std::string::npos) && (e != std::string::npos)) {
inc.assign(inc, b, 1 + e - b); // copy the remaining substring
} else {
- inc = "";
+ inc.clear();
return;
}
- if (!cmSystemTools::IsOff(inc.c_str())) {
+ if (!cmIsOff(inc)) {
cmSystemTools::ConvertToUnixSlashes(inc);
-
- if (!cmSystemTools::FileIsFullPath(inc.c_str())) {
- if (!StartsWithGeneratorExpression(inc)) {
- std::string tmp = this->Makefile->GetCurrentSourceDirectory();
- tmp += "/";
- tmp += inc;
- inc = tmp;
- }
+ if (!cmSystemTools::FileIsFullPath(inc) &&
+ !cmGeneratorExpression::StartsWithGeneratorExpression(inc)) {
+ inc = cmStrCat(mf.GetCurrentSourceDirectory(), '/', inc);
}
}
}