From 0d46e9a0297d78dabc9988604a15c0096c702855 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 20 Jan 2013 12:28:59 +0100 Subject: Store includes from the same include_directories call together. Otherwise, we get a separate IncludeDirectoriesEntry for each include, and that causes unnecessary and confusing splitting in the output when debugging the INCLUDE_DIRECTORIES property. --- Source/cmFLTKWrapUICommand.cxx | 6 +- Source/cmIncludeDirectoryCommand.cxx | 92 ++++++++++++++-------- Source/cmIncludeDirectoryCommand.h | 3 +- Source/cmMakefile.cxx | 30 +++++-- Source/cmMakefile.h | 5 +- .../include_directories/DebugIncludes-stderr.txt | 7 -- 6 files changed, 91 insertions(+), 52 deletions(-) diff --git a/Source/cmFLTKWrapUICommand.cxx b/Source/cmFLTKWrapUICommand.cxx index a4aa75a..b08c335 100644 --- a/Source/cmFLTKWrapUICommand.cxx +++ b/Source/cmFLTKWrapUICommand.cxx @@ -37,9 +37,13 @@ bool cmFLTKWrapUICommand // get the list of GUI files from which .cxx and .h will be generated std::string outputDirectory = this->Makefile->GetCurrentOutputDirectory(); + { // Some of the generated files are *.h so the directory "GUI" // where they are created have to be added to the include path - this->Makefile->AddIncludeDirectory( outputDirectory.c_str() ); + std::vector outputDirectories; + outputDirectories.push_back(outputDirectory); + this->Makefile->AddIncludeDirectories( outputDirectories ); + } for(std::vector::iterator i = (newArgs.begin() + 1); i != newArgs.end(); i++) diff --git a/Source/cmIncludeDirectoryCommand.cxx b/Source/cmIncludeDirectoryCommand.cxx index ba81849..671e09f 100644 --- a/Source/cmIncludeDirectoryCommand.cxx +++ b/Source/cmIncludeDirectoryCommand.cxx @@ -36,6 +36,10 @@ bool cmIncludeDirectoryCommand ++i; } + std::vector beforeIncludes; + std::vector afterIncludes; + std::set systemIncludes; + for(; i != args.end(); ++i) { if(*i == "SYSTEM") @@ -49,9 +53,37 @@ bool cmIncludeDirectoryCommand return false; } - this->AddDirectory(i->c_str(),before,system); + std::vector includes; + + GetIncludes(*i, includes); + if (before) + { + beforeIncludes.insert(beforeIncludes.end(), + includes.begin(), + includes.end()); + } + else + { + afterIncludes.insert(afterIncludes.end(), + includes.begin(), + includes.end()); + } + if (system) + { + for (std::vector::const_iterator li = includes.begin(); + li != includes.end(); ++li) + { + systemIncludes.insert(*li); + } + } } + std::reverse(beforeIncludes.begin(), beforeIncludes.end()); + + this->Makefile->AddIncludeDirectories(afterIncludes); + this->Makefile->AddIncludeDirectories(beforeIncludes, before); + this->Makefile->AddSystemIncludeDirectories(systemIncludes); + return true; } @@ -72,57 +104,49 @@ 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::AddDirectory(const char *i, - bool before, - bool system) +void cmIncludeDirectoryCommand::GetIncludes(const std::string &arg, + std::vector &incs) { // break apart any line feed arguments - std::string ret = i; std::string::size_type pos = 0; - if((pos = ret.find('\n', pos)) != std::string::npos) + std::string::size_type lastPos = 0; + while((pos = arg.find('\n', lastPos)) != std::string::npos) { if (pos) { - this->AddDirectory(ret.substr(0,pos).c_str(), before, system); - } - if (ret.size()-pos-1) - { - this->AddDirectory(ret.substr(pos+1,ret.size()-pos-1).c_str(), - before, system); + std::string inc = arg.substr(lastPos,pos); + NormalizeInclude(inc); + incs.push_back(inc); } - return; + lastPos = pos + 1; } + std::string inc = arg.substr(lastPos); + NormalizeInclude(inc); + incs.push_back(inc); +} - // remove any leading or trailing spaces and \r - std::string::size_type b = ret.find_first_not_of(" \r"); - std::string::size_type e = ret.find_last_not_of(" \r"); - if ((b!=ret.npos) && (e!=ret.npos)) - { - ret.assign(ret, b, 1+e-b); // copy the remaining substring - } - else +void cmIncludeDirectoryCommand::NormalizeInclude(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!=inc.npos) && (e!=inc.npos)) { - return; // if we get here, we had only whitespace in the string + inc.assign(inc, b, 1+e-b); // copy the remaining substring } - if (!cmSystemTools::IsOff(ret.c_str())) + if (!cmSystemTools::IsOff(inc.c_str())) { - cmSystemTools::ConvertToUnixSlashes(ret); - if(!cmSystemTools::FileIsFullPath(ret.c_str())) + cmSystemTools::ConvertToUnixSlashes(inc); + + if(!cmSystemTools::FileIsFullPath(inc.c_str())) { - if(!StartsWithGeneratorExpression(ret)) + if(!StartsWithGeneratorExpression(inc)) { std::string tmp = this->Makefile->GetStartDirectory(); tmp += "/"; - tmp += ret; - ret = tmp; + tmp += inc; + inc = tmp; } } } - this->Makefile->AddIncludeDirectory(ret.c_str(), before); - if(system) - { - this->Makefile->AddSystemIncludeDirectory(ret.c_str()); - } } - diff --git a/Source/cmIncludeDirectoryCommand.h b/Source/cmIncludeDirectoryCommand.h index dd37b82..a32fc77 100644 --- a/Source/cmIncludeDirectoryCommand.h +++ b/Source/cmIncludeDirectoryCommand.h @@ -84,7 +84,8 @@ public: protected: // used internally - void AddDirectory(const char *arg, bool before, bool system); + void GetIncludes(const std::string &arg, std::vector &incs); + void NormalizeInclude(std::string &inc); }; diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index b432986..7e77664 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1616,20 +1616,31 @@ void cmMakefile::AddSubDirectory(const char* srcPath, const char *binPath, } //---------------------------------------------------------------------------- -void cmMakefile::AddIncludeDirectory(const char* inc, bool before) +void cmMakefile::AddIncludeDirectories(const std::vector &incs, + bool before) { - if (!inc) + if (incs.empty()) { return; } + std::string incString; + std::string sep; + + for(std::vector::const_iterator li = incs.begin(); + li != incs.end(); ++li) + { + incString += sep + *li; + sep = ";"; + } + std::vector::iterator position = - before ? this->IncludeDirectoriesEntries.begin() - : this->IncludeDirectoriesEntries.end(); + before ? this->IncludeDirectoriesEntries.begin() + : this->IncludeDirectoriesEntries.end(); cmListFileBacktrace lfbt; this->GetBacktrace(lfbt); - IncludeDirectoriesEntry entry(inc, lfbt); + IncludeDirectoriesEntry entry(incString, lfbt); this->IncludeDirectoriesEntries.insert(position, entry); // Property on each target: @@ -1642,9 +1653,14 @@ void cmMakefile::AddIncludeDirectory(const char* inc, bool before) } //---------------------------------------------------------------------------- -void cmMakefile::AddSystemIncludeDirectory(const char* dir) +void +cmMakefile::AddSystemIncludeDirectories(const std::set &incs) { - this->SystemIncludeDirectories.insert(dir); + for(std::set::const_iterator li = incs.begin(); + li != incs.end(); ++li) + { + this->SystemIncludeDirectories.insert(*li); + } } //---------------------------------------------------------------------------- diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index a85015f..bb161b1 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -287,7 +287,8 @@ public: /** * Add an include directory to the build. */ - void AddIncludeDirectory(const char*, bool before = false); + void AddIncludeDirectories(const std::vector &incs, + bool before = false); /** * Add a variable definition to the build. This variable @@ -545,7 +546,7 @@ public: /** * Mark include directories as system directories. */ - void AddSystemIncludeDirectory(const char* dir); + void AddSystemIncludeDirectories(const std::set &incs); bool IsSystemIncludeDirectory(const char* dir); /** Expand out any arguements in the vector that have ; separated diff --git a/Tests/RunCMake/include_directories/DebugIncludes-stderr.txt b/Tests/RunCMake/include_directories/DebugIncludes-stderr.txt index 948def1..ab99784 100644 --- a/Tests/RunCMake/include_directories/DebugIncludes-stderr.txt +++ b/Tests/RunCMake/include_directories/DebugIncludes-stderr.txt @@ -2,13 +2,6 @@ CMake Warning at DebugIncludes.cmake:8 \(include_directories\): Used includes: \* .*/Tests/RunCMake/include_directories/one - -Call Stack \(most recent call first\): - CMakeLists.txt:3 \(include\) -+ -CMake Warning at DebugIncludes.cmake:8 \(include_directories\): - Used includes: - \* .*/Tests/RunCMake/include_directories/two Call Stack \(most recent call first\): -- cgit v0.12 From d70204a86aa3e454e73049efda3e1ccea8c60720 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 20 Jan 2013 12:50:53 +0100 Subject: Only output includes once after the start of 'generate-time' when debugging. During configure-time, GetIncludeDirectories may be called too, for example if using the export() command. As the content can be different, it should be output each time then. --- Source/cmGlobalGenerator.cxx | 1 + Source/cmMakefile.cxx | 1 + Source/cmMakefile.h | 6 ++++++ Source/cmTarget.cxx | 9 ++++++++- Source/cmTarget.h | 1 + 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index d2baf53..f28bd6c 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -980,6 +980,7 @@ void cmGlobalGenerator::Generate() // Generate project files for (i = 0; i < this->LocalGenerators.size(); ++i) { + this->LocalGenerators[i]->GetMakefile()->SetGeneratingBuildSystem(); this->SetCurrentLocalGenerator(this->LocalGenerators[i]); this->LocalGenerators[i]->Generate(); this->LocalGenerators[i]->GenerateInstallRules(); diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 7e77664..4721e4c 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -99,6 +99,7 @@ cmMakefile::cmMakefile(): Internal(new Internals) this->AddDefaultDefinitions(); this->Initialize(); this->PreOrder = false; + this->GeneratingBuildSystem = false; } cmMakefile::cmMakefile(const cmMakefile& mf): Internal(new Internals) diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index bb161b1..a2783f2 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -870,6 +870,9 @@ public: return this->IncludeDirectoriesEntries; } + bool IsGeneratingBuildSystem(){ return this->GeneratingBuildSystem; } + void SetGeneratingBuildSystem(){ this->GeneratingBuildSystem = true; } + protected: // add link libraries and directories to the target void AddGlobalLinkInformation(const char* name, cmTarget& target); @@ -1019,6 +1022,9 @@ private: // Enforce rules about CMakeLists.txt files. void EnforceDirectoryLevelRules(); + + bool GeneratingBuildSystem; + }; //---------------------------------------------------------------------------- diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 815da40..fb99b4a 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -151,6 +151,7 @@ cmTarget::cmTarget() this->IsApple = false; this->IsImportedTarget = false; this->BuildInterfaceIncludesAppended = false; + this->DebugIncludesDone = false; } //---------------------------------------------------------------------------- @@ -2739,11 +2740,17 @@ std::vector cmTarget::GetIncludeDirectories(const char *config) cmSystemTools::ExpandListArgument(debugProp, debugProperties); } - bool debugIncludes = std::find(debugProperties.begin(), + bool debugIncludes = !this->DebugIncludesDone + && std::find(debugProperties.begin(), debugProperties.end(), "INCLUDE_DIRECTORIES") != debugProperties.end(); + if (this->Makefile->IsGeneratingBuildSystem()) + { + this->DebugIncludesDone = true; + } + for (std::vector::const_iterator it = this->Internal->IncludeDirectoriesEntries.begin(), end = this->Internal->IncludeDirectoriesEntries.end(); diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 69a00c1..47ec528 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -610,6 +610,7 @@ private: bool DLLPlatform; bool IsApple; bool IsImportedTarget; + bool DebugIncludesDone; mutable std::map > LinkDependentProperties; mutable std::set LinkImplicitNullProperties; -- cgit v0.12 From aa6674831c3ea3bf3cca7c9f667d2e5c75873a3d Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 20 Jan 2013 12:57:25 +0100 Subject: Specify the target whose includes are being listed. --- Source/cmTarget.cxx | 4 ++-- Tests/RunCMake/include_directories/DebugIncludes-stderr.txt | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index fb99b4a..6c9ed1b 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -2785,8 +2785,8 @@ std::vector cmTarget::GetIncludeDirectories(const char *config) if (!usedIncludes.empty()) { this->Makefile->GetCMakeInstance()->IssueMessage(cmake::LOG, - "Used includes:\n" + usedIncludes, - (*it)->ge->GetBacktrace()); + "Used includes for target " + this->Name + ":\n" + + usedIncludes, (*it)->ge->GetBacktrace()); } } return includes; diff --git a/Tests/RunCMake/include_directories/DebugIncludes-stderr.txt b/Tests/RunCMake/include_directories/DebugIncludes-stderr.txt index ab99784..379174a 100644 --- a/Tests/RunCMake/include_directories/DebugIncludes-stderr.txt +++ b/Tests/RunCMake/include_directories/DebugIncludes-stderr.txt @@ -1,5 +1,5 @@ CMake Warning at DebugIncludes.cmake:8 \(include_directories\): - Used includes: + Used includes for target lll: \* .*/Tests/RunCMake/include_directories/one \* .*/Tests/RunCMake/include_directories/two @@ -8,7 +8,7 @@ Call Stack \(most recent call first\): CMakeLists.txt:3 \(include\) + CMake Warning at DebugIncludes.cmake:13 \(set_property\): - Used includes: + Used includes for target lll: \* .*/Tests/RunCMake/include_directories/three @@ -16,7 +16,7 @@ Call Stack \(most recent call first\): CMakeLists.txt:3 \(include\) + CMake Warning at DebugIncludes.cmake:18 \(include_directories\): - Used includes: + Used includes for target lll: \* .*/Tests/RunCMake/include_directories/four @@ -24,7 +24,7 @@ Call Stack \(most recent call first\): CMakeLists.txt:3 \(include\) + CMake Warning at DebugIncludes.cmake:25 \(set_property\): - Used includes: + Used includes for target lll: \* .*/Tests/RunCMake/include_directories/five \* .*/Tests/RunCMake/include_directories/six -- cgit v0.12 From 6063fef226d35aad0629d7098f72afa650e7a149 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 20 Jan 2013 13:07:31 +0100 Subject: Output include directories as LOG messages, not warnings. --- Source/cmake.cxx | 4 ++++ Tests/RunCMake/include_directories/DebugIncludes-stderr.txt | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 2eecfba..932c996 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -4394,6 +4394,10 @@ void cmake::IssueMessage(cmake::MessageType t, std::string const& text, isError = true; msg << "CMake Internal Error (please report a bug)"; } + else if(t == cmake::LOG) + { + msg << "CMake Debug Log"; + } else { msg << "CMake Warning"; diff --git a/Tests/RunCMake/include_directories/DebugIncludes-stderr.txt b/Tests/RunCMake/include_directories/DebugIncludes-stderr.txt index 379174a..736fe69 100644 --- a/Tests/RunCMake/include_directories/DebugIncludes-stderr.txt +++ b/Tests/RunCMake/include_directories/DebugIncludes-stderr.txt @@ -1,4 +1,4 @@ -CMake Warning at DebugIncludes.cmake:8 \(include_directories\): +CMake Debug Log at DebugIncludes.cmake:8 \(include_directories\): Used includes for target lll: \* .*/Tests/RunCMake/include_directories/one @@ -7,7 +7,7 @@ CMake Warning at DebugIncludes.cmake:8 \(include_directories\): Call Stack \(most recent call first\): CMakeLists.txt:3 \(include\) + -CMake Warning at DebugIncludes.cmake:13 \(set_property\): +CMake Debug Log at DebugIncludes.cmake:13 \(set_property\): Used includes for target lll: \* .*/Tests/RunCMake/include_directories/three @@ -15,7 +15,7 @@ CMake Warning at DebugIncludes.cmake:13 \(set_property\): Call Stack \(most recent call first\): CMakeLists.txt:3 \(include\) + -CMake Warning at DebugIncludes.cmake:18 \(include_directories\): +CMake Debug Log at DebugIncludes.cmake:18 \(include_directories\): Used includes for target lll: \* .*/Tests/RunCMake/include_directories/four @@ -23,7 +23,7 @@ CMake Warning at DebugIncludes.cmake:18 \(include_directories\): Call Stack \(most recent call first\): CMakeLists.txt:3 \(include\) + -CMake Warning at DebugIncludes.cmake:25 \(set_property\): +CMake Debug Log at DebugIncludes.cmake:25 \(set_property\): Used includes for target lll: \* .*/Tests/RunCMake/include_directories/five -- cgit v0.12