Add a way to print the origins of used include directories.
This commit is contained in:
parent
18a3195ad5
commit
0941d6232a
|
@ -896,6 +896,15 @@ void cmDocumentVariables::DefineVariables(cmake* cm)
|
||||||
" script, it may get fatal error messages from the script.",false,
|
" script, it may get fatal error messages from the script.",false,
|
||||||
"Variables That Change Behavior");
|
"Variables That Change Behavior");
|
||||||
|
|
||||||
|
cm->DefineProperty
|
||||||
|
("CMAKE_DEBUG_TARGET_PROPERTIES", cmProperty::VARIABLE,
|
||||||
|
"Enables tracing output for target properties.",
|
||||||
|
"This variable can be populated with a list of properties to generate "
|
||||||
|
"debug output for when evaluating target properties. Currently it can "
|
||||||
|
"only be used when evaluating the INCLUDE_DIRECTORIES target property. "
|
||||||
|
"In that case, it outputs a backtrace for each include directory in "
|
||||||
|
"the build. Default is unset.",false,"Variables That Change Behavior");
|
||||||
|
|
||||||
// Variables defined by CMake that describe the system
|
// Variables defined by CMake that describe the system
|
||||||
|
|
||||||
cm->DefineProperty
|
cm->DefineProperty
|
||||||
|
|
|
@ -83,6 +83,11 @@ public:
|
||||||
return this->Input;
|
return this->Input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmListFileBacktrace GetBacktrace() const
|
||||||
|
{
|
||||||
|
return this->Backtrace;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
cmCompiledGeneratorExpression(cmListFileBacktrace const& backtrace,
|
cmCompiledGeneratorExpression(cmListFileBacktrace const& backtrace,
|
||||||
const char *input);
|
const char *input);
|
||||||
|
|
|
@ -2485,6 +2485,7 @@ void cmTarget::SetProperty(const char* prop, const char* value)
|
||||||
if(strcmp(prop,"INCLUDE_DIRECTORIES") == 0)
|
if(strcmp(prop,"INCLUDE_DIRECTORIES") == 0)
|
||||||
{
|
{
|
||||||
cmListFileBacktrace lfbt;
|
cmListFileBacktrace lfbt;
|
||||||
|
this->Makefile->GetBacktrace(lfbt);
|
||||||
cmGeneratorExpression ge(lfbt);
|
cmGeneratorExpression ge(lfbt);
|
||||||
deleteAndClear(this->Internal->IncludeDirectoriesEntries);
|
deleteAndClear(this->Internal->IncludeDirectoriesEntries);
|
||||||
cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
|
cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
|
||||||
|
@ -2507,6 +2508,7 @@ void cmTarget::AppendProperty(const char* prop, const char* value,
|
||||||
if(strcmp(prop,"INCLUDE_DIRECTORIES") == 0)
|
if(strcmp(prop,"INCLUDE_DIRECTORIES") == 0)
|
||||||
{
|
{
|
||||||
cmListFileBacktrace lfbt;
|
cmListFileBacktrace lfbt;
|
||||||
|
this->Makefile->GetBacktrace(lfbt);
|
||||||
cmGeneratorExpression ge(lfbt);
|
cmGeneratorExpression ge(lfbt);
|
||||||
this->Internal->IncludeDirectoriesEntries.push_back(
|
this->Internal->IncludeDirectoriesEntries.push_back(
|
||||||
new cmTargetInternals::IncludeDirectoriesEntry(ge.Parse(value)));
|
new cmTargetInternals::IncludeDirectoriesEntry(ge.Parse(value)));
|
||||||
|
@ -2541,6 +2543,20 @@ std::vector<std::string> cmTarget::GetIncludeDirectories(const char *config)
|
||||||
this->GetName(),
|
this->GetName(),
|
||||||
"INCLUDE_DIRECTORIES", 0, 0);
|
"INCLUDE_DIRECTORIES", 0, 0);
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<std::string> debugProperties;
|
||||||
|
const char *debugProp =
|
||||||
|
this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
|
||||||
|
if (debugProp)
|
||||||
|
{
|
||||||
|
cmSystemTools::ExpandListArgument(debugProp, debugProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool debugIncludes = std::find(debugProperties.begin(),
|
||||||
|
debugProperties.end(),
|
||||||
|
"INCLUDE_DIRECTORIES")
|
||||||
|
!= debugProperties.end();
|
||||||
|
|
||||||
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();
|
||||||
|
@ -2553,6 +2569,7 @@ std::vector<std::string> cmTarget::GetIncludeDirectories(const char *config)
|
||||||
this,
|
this,
|
||||||
&dagChecker),
|
&dagChecker),
|
||||||
entryIncludes);
|
entryIncludes);
|
||||||
|
std::string usedIncludes;
|
||||||
for(std::vector<std::string>::const_iterator
|
for(std::vector<std::string>::const_iterator
|
||||||
li = entryIncludes.begin(); li != entryIncludes.end(); ++li)
|
li = entryIncludes.begin(); li != entryIncludes.end(); ++li)
|
||||||
{
|
{
|
||||||
|
@ -2565,8 +2582,18 @@ std::vector<std::string> cmTarget::GetIncludeDirectories(const char *config)
|
||||||
if(uniqueIncludes.insert(inc).second)
|
if(uniqueIncludes.insert(inc).second)
|
||||||
{
|
{
|
||||||
includes.push_back(*li);
|
includes.push_back(*li);
|
||||||
|
if (debugIncludes)
|
||||||
|
{
|
||||||
|
usedIncludes += " * " + *li + "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!usedIncludes.empty())
|
||||||
|
{
|
||||||
|
this->Makefile->GetCMakeInstance()->IssueMessage(cmake::LOG,
|
||||||
|
"Used includes:\n" + usedIncludes,
|
||||||
|
(*it)->ge->GetBacktrace());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return includes;
|
return includes;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
0
|
|
@ -0,0 +1,42 @@
|
||||||
|
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\):
|
||||||
|
CMakeLists.txt:3 \(include\)
|
||||||
|
+
|
||||||
|
CMake Warning at DebugIncludes.cmake:13 \(set_property\):
|
||||||
|
Used includes:
|
||||||
|
|
||||||
|
\* .*/Tests/RunCMake/include_directories/three
|
||||||
|
|
||||||
|
Call Stack \(most recent call first\):
|
||||||
|
CMakeLists.txt:3 \(include\)
|
||||||
|
+
|
||||||
|
CMake Warning at DebugIncludes.cmake:18 \(include_directories\):
|
||||||
|
Used includes:
|
||||||
|
|
||||||
|
\* .*/Tests/RunCMake/include_directories/four
|
||||||
|
|
||||||
|
Call Stack \(most recent call first\):
|
||||||
|
CMakeLists.txt:3 \(include\)
|
||||||
|
+
|
||||||
|
CMake Warning at DebugIncludes.cmake:25 \(set_property\):
|
||||||
|
Used includes:
|
||||||
|
|
||||||
|
\* .*/Tests/RunCMake/include_directories/five
|
||||||
|
\* .*/Tests/RunCMake/include_directories/six
|
||||||
|
|
||||||
|
Call Stack \(most recent call first\):
|
||||||
|
DebugIncludes.cmake:35 \(some_macro\)
|
||||||
|
DebugIncludes.cmake:38 \(some_function\)
|
||||||
|
CMakeLists.txt:3 \(include\)
|
|
@ -0,0 +1,38 @@
|
||||||
|
|
||||||
|
project(DebugIncludes)
|
||||||
|
|
||||||
|
set(CMAKE_DEBUG_TARGET_PROPERTIES INCLUDE_DIRECTORIES)
|
||||||
|
|
||||||
|
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/DebugIncludes.cpp" "enum { dummy };\n")
|
||||||
|
|
||||||
|
include_directories(
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/one"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/two"
|
||||||
|
)
|
||||||
|
|
||||||
|
set_property(DIRECTORY APPEND PROPERTY INCLUDE_DIRECTORIES
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/three")
|
||||||
|
|
||||||
|
add_library(lll "${CMAKE_CURRENT_BINARY_DIR}/DebugIncludes.cpp")
|
||||||
|
|
||||||
|
include_directories(
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/two"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/three"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/four"
|
||||||
|
)
|
||||||
|
|
||||||
|
macro(some_macro)
|
||||||
|
set_property(TARGET lll APPEND PROPERTY
|
||||||
|
INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/one"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/three"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/four"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/five"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/six"
|
||||||
|
)
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
function(some_function)
|
||||||
|
some_macro()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
some_function()
|
|
@ -1,3 +1,4 @@
|
||||||
include(RunCMake)
|
include(RunCMake)
|
||||||
|
|
||||||
run_cmake(NotFoundContent)
|
run_cmake(NotFoundContent)
|
||||||
|
run_cmake(DebugIncludes)
|
||||||
|
|
Loading…
Reference in New Issue