Merge topic 'clean-include-dirs-debugging'

6063fef Output include directories as LOG messages, not warnings.
aa66748 Specify the target whose includes are being listed.
d70204a Only output includes once after the start of 'generate-time' when debugging.
0d46e9a Store includes from the same include_directories call together.
This commit is contained in:
Brad King 2013-01-23 15:11:36 -05:00 committed by CMake Topic Stage
commit 7db963a017
10 changed files with 124 additions and 65 deletions

View File

@ -37,9 +37,13 @@ bool cmFLTKWrapUICommand
// get the list of GUI files from which .cxx and .h will be generated // get the list of GUI files from which .cxx and .h will be generated
std::string outputDirectory = this->Makefile->GetCurrentOutputDirectory(); std::string outputDirectory = this->Makefile->GetCurrentOutputDirectory();
{
// Some of the generated files are *.h so the directory "GUI" // Some of the generated files are *.h so the directory "GUI"
// where they are created have to be added to the include path // where they are created have to be added to the include path
this->Makefile->AddIncludeDirectory( outputDirectory.c_str() ); std::vector<std::string> outputDirectories;
outputDirectories.push_back(outputDirectory);
this->Makefile->AddIncludeDirectories( outputDirectories );
}
for(std::vector<std::string>::iterator i = (newArgs.begin() + 1); for(std::vector<std::string>::iterator i = (newArgs.begin() + 1);
i != newArgs.end(); i++) i != newArgs.end(); i++)

View File

@ -980,6 +980,7 @@ void cmGlobalGenerator::Generate()
// Generate project files // Generate project files
for (i = 0; i < this->LocalGenerators.size(); ++i) for (i = 0; i < this->LocalGenerators.size(); ++i)
{ {
this->LocalGenerators[i]->GetMakefile()->SetGeneratingBuildSystem();
this->SetCurrentLocalGenerator(this->LocalGenerators[i]); this->SetCurrentLocalGenerator(this->LocalGenerators[i]);
this->LocalGenerators[i]->Generate(); this->LocalGenerators[i]->Generate();
this->LocalGenerators[i]->GenerateInstallRules(); this->LocalGenerators[i]->GenerateInstallRules();

View File

@ -36,6 +36,10 @@ bool cmIncludeDirectoryCommand
++i; ++i;
} }
std::vector<std::string> beforeIncludes;
std::vector<std::string> afterIncludes;
std::set<cmStdString> systemIncludes;
for(; i != args.end(); ++i) for(; i != args.end(); ++i)
{ {
if(*i == "SYSTEM") if(*i == "SYSTEM")
@ -49,9 +53,37 @@ bool cmIncludeDirectoryCommand
return false; return false;
} }
this->AddDirectory(i->c_str(),before,system); std::vector<std::string> 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<std::string>::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; 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 // output from a program and passing it into a command the cleanup doesn't
// always happen // always happen
// //
void cmIncludeDirectoryCommand::AddDirectory(const char *i, void cmIncludeDirectoryCommand::GetIncludes(const std::string &arg,
bool before, std::vector<std::string> &incs)
bool system)
{ {
// break apart any line feed arguments // break apart any line feed arguments
std::string ret = i;
std::string::size_type pos = 0; 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) if (pos)
{ {
this->AddDirectory(ret.substr(0,pos).c_str(), before, system); std::string inc = arg.substr(lastPos,pos);
NormalizeInclude(inc);
incs.push_back(inc);
} }
if (ret.size()-pos-1) lastPos = pos + 1;
{
this->AddDirectory(ret.substr(pos+1,ret.size()-pos-1).c_str(),
before, system);
} }
return; std::string inc = arg.substr(lastPos);
NormalizeInclude(inc);
incs.push_back(inc);
} }
// remove any leading or trailing spaces and \r void cmIncludeDirectoryCommand::NormalizeInclude(std::string &inc)
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 std::string::size_type b = inc.find_first_not_of(" \r");
} std::string::size_type e = inc.find_last_not_of(" \r");
else 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); cmSystemTools::ConvertToUnixSlashes(inc);
if(!cmSystemTools::FileIsFullPath(ret.c_str()))
if(!cmSystemTools::FileIsFullPath(inc.c_str()))
{ {
if(!StartsWithGeneratorExpression(ret)) if(!StartsWithGeneratorExpression(inc))
{ {
std::string tmp = this->Makefile->GetStartDirectory(); std::string tmp = this->Makefile->GetStartDirectory();
tmp += "/"; tmp += "/";
tmp += ret; tmp += inc;
ret = tmp; inc = tmp;
} }
} }
} }
this->Makefile->AddIncludeDirectory(ret.c_str(), before);
if(system)
{
this->Makefile->AddSystemIncludeDirectory(ret.c_str());
} }
}

View File

@ -84,7 +84,8 @@ public:
protected: protected:
// used internally // used internally
void AddDirectory(const char *arg, bool before, bool system); void GetIncludes(const std::string &arg, std::vector<std::string> &incs);
void NormalizeInclude(std::string &inc);
}; };

View File

@ -99,6 +99,7 @@ cmMakefile::cmMakefile(): Internal(new Internals)
this->AddDefaultDefinitions(); this->AddDefaultDefinitions();
this->Initialize(); this->Initialize();
this->PreOrder = false; this->PreOrder = false;
this->GeneratingBuildSystem = false;
} }
cmMakefile::cmMakefile(const cmMakefile& mf): Internal(new Internals) cmMakefile::cmMakefile(const cmMakefile& mf): Internal(new Internals)
@ -1616,20 +1617,31 @@ void cmMakefile::AddSubDirectory(const char* srcPath, const char *binPath,
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmMakefile::AddIncludeDirectory(const char* inc, bool before) void cmMakefile::AddIncludeDirectories(const std::vector<std::string> &incs,
bool before)
{ {
if (!inc) if (incs.empty())
{ {
return; return;
} }
std::string incString;
std::string sep;
for(std::vector<std::string>::const_iterator li = incs.begin();
li != incs.end(); ++li)
{
incString += sep + *li;
sep = ";";
}
std::vector<IncludeDirectoriesEntry>::iterator position = std::vector<IncludeDirectoriesEntry>::iterator position =
before ? this->IncludeDirectoriesEntries.begin() before ? this->IncludeDirectoriesEntries.begin()
: this->IncludeDirectoriesEntries.end(); : this->IncludeDirectoriesEntries.end();
cmListFileBacktrace lfbt; cmListFileBacktrace lfbt;
this->GetBacktrace(lfbt); this->GetBacktrace(lfbt);
IncludeDirectoriesEntry entry(inc, lfbt); IncludeDirectoriesEntry entry(incString, lfbt);
this->IncludeDirectoriesEntries.insert(position, entry); this->IncludeDirectoriesEntries.insert(position, entry);
// Property on each target: // Property on each target:
@ -1642,9 +1654,14 @@ void cmMakefile::AddIncludeDirectory(const char* inc, bool before)
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmMakefile::AddSystemIncludeDirectory(const char* dir) void
cmMakefile::AddSystemIncludeDirectories(const std::set<cmStdString> &incs)
{ {
this->SystemIncludeDirectories.insert(dir); for(std::set<cmStdString>::const_iterator li = incs.begin();
li != incs.end(); ++li)
{
this->SystemIncludeDirectories.insert(*li);
}
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -287,7 +287,8 @@ public:
/** /**
* Add an include directory to the build. * Add an include directory to the build.
*/ */
void AddIncludeDirectory(const char*, bool before = false); void AddIncludeDirectories(const std::vector<std::string> &incs,
bool before = false);
/** /**
* Add a variable definition to the build. This variable * Add a variable definition to the build. This variable
@ -545,7 +546,7 @@ public:
/** /**
* Mark include directories as system directories. * Mark include directories as system directories.
*/ */
void AddSystemIncludeDirectory(const char* dir); void AddSystemIncludeDirectories(const std::set<cmStdString> &incs);
bool IsSystemIncludeDirectory(const char* dir); bool IsSystemIncludeDirectory(const char* dir);
/** Expand out any arguements in the vector that have ; separated /** Expand out any arguements in the vector that have ; separated
@ -869,6 +870,9 @@ public:
return this->IncludeDirectoriesEntries; return this->IncludeDirectoriesEntries;
} }
bool IsGeneratingBuildSystem(){ return this->GeneratingBuildSystem; }
void SetGeneratingBuildSystem(){ this->GeneratingBuildSystem = true; }
protected: protected:
// add link libraries and directories to the target // add link libraries and directories to the target
void AddGlobalLinkInformation(const char* name, cmTarget& target); void AddGlobalLinkInformation(const char* name, cmTarget& target);
@ -1018,6 +1022,9 @@ private:
// Enforce rules about CMakeLists.txt files. // Enforce rules about CMakeLists.txt files.
void EnforceDirectoryLevelRules(); void EnforceDirectoryLevelRules();
bool GeneratingBuildSystem;
}; };
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -152,6 +152,7 @@ cmTarget::cmTarget()
this->IsApple = false; this->IsApple = false;
this->IsImportedTarget = false; this->IsImportedTarget = false;
this->BuildInterfaceIncludesAppended = false; this->BuildInterfaceIncludesAppended = false;
this->DebugIncludesDone = false;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -2750,11 +2751,17 @@ std::vector<std::string> cmTarget::GetIncludeDirectories(const char *config)
cmSystemTools::ExpandListArgument(debugProp, debugProperties); cmSystemTools::ExpandListArgument(debugProp, debugProperties);
} }
bool debugIncludes = std::find(debugProperties.begin(), bool debugIncludes = !this->DebugIncludesDone
&& std::find(debugProperties.begin(),
debugProperties.end(), debugProperties.end(),
"INCLUDE_DIRECTORIES") "INCLUDE_DIRECTORIES")
!= debugProperties.end(); != debugProperties.end();
if (this->Makefile->IsGeneratingBuildSystem())
{
this->DebugIncludesDone = true;
}
for (std::vector<cmTargetInternals::IncludeDirectoriesEntry*>::const_iterator for (std::vector<cmTargetInternals::IncludeDirectoriesEntry*>::const_iterator
it = this->Internal->IncludeDirectoriesEntries.begin(), it = this->Internal->IncludeDirectoriesEntries.begin(),
end = this->Internal->IncludeDirectoriesEntries.end(); end = this->Internal->IncludeDirectoriesEntries.end();
@ -2789,8 +2796,8 @@ std::vector<std::string> cmTarget::GetIncludeDirectories(const char *config)
if (!usedIncludes.empty()) if (!usedIncludes.empty())
{ {
this->Makefile->GetCMakeInstance()->IssueMessage(cmake::LOG, this->Makefile->GetCMakeInstance()->IssueMessage(cmake::LOG,
"Used includes:\n" + usedIncludes, "Used includes for target " + this->Name + ":\n"
(*it)->ge->GetBacktrace()); + usedIncludes, (*it)->ge->GetBacktrace());
} }
} }
return includes; return includes;

View File

@ -616,6 +616,7 @@ private:
bool DLLPlatform; bool DLLPlatform;
bool IsApple; bool IsApple;
bool IsImportedTarget; bool IsImportedTarget;
bool DebugIncludesDone;
mutable std::map<cmStdString, std::set<std::string> > mutable std::map<cmStdString, std::set<std::string> >
LinkDependentProperties; LinkDependentProperties;
mutable std::set<std::string> LinkImplicitNullProperties; mutable std::set<std::string> LinkImplicitNullProperties;

View File

@ -4394,6 +4394,10 @@ void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
isError = true; isError = true;
msg << "CMake Internal Error (please report a bug)"; msg << "CMake Internal Error (please report a bug)";
} }
else if(t == cmake::LOG)
{
msg << "CMake Debug Log";
}
else else
{ {
msg << "CMake Warning"; msg << "CMake Warning";

View File

@ -1,37 +1,30 @@
CMake Warning at DebugIncludes.cmake:8 \(include_directories\): CMake Debug Log at DebugIncludes.cmake:8 \(include_directories\):
Used includes: Used includes for target lll:
\* .*/Tests/RunCMake/include_directories/one \* .*/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 \* .*/Tests/RunCMake/include_directories/two
Call Stack \(most recent call first\): Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\) CMakeLists.txt:3 \(include\)
+ +
CMake Warning at DebugIncludes.cmake:13 \(set_property\): CMake Debug Log at DebugIncludes.cmake:13 \(set_property\):
Used includes: Used includes for target lll:
\* .*/Tests/RunCMake/include_directories/three \* .*/Tests/RunCMake/include_directories/three
Call Stack \(most recent call first\): Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\) CMakeLists.txt:3 \(include\)
+ +
CMake Warning at DebugIncludes.cmake:18 \(include_directories\): CMake Debug Log at DebugIncludes.cmake:18 \(include_directories\):
Used includes: Used includes for target lll:
\* .*/Tests/RunCMake/include_directories/four \* .*/Tests/RunCMake/include_directories/four
Call Stack \(most recent call first\): Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\) CMakeLists.txt:3 \(include\)
+ +
CMake Warning at DebugIncludes.cmake:25 \(set_property\): CMake Debug Log at DebugIncludes.cmake:25 \(set_property\):
Used includes: Used includes for target lll:
\* .*/Tests/RunCMake/include_directories/five \* .*/Tests/RunCMake/include_directories/five
\* .*/Tests/RunCMake/include_directories/six \* .*/Tests/RunCMake/include_directories/six