Commit 6e636f2e authored by Stephen Kelly's avatar Stephen Kelly
Browse files

cmTarget: Make the SOURCES origin tracable.

parent 3676fb49
......@@ -6,7 +6,8 @@ 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 :prop_tgt:`INCLUDE_DIRECTORIES`,
:prop_tgt:`COMPILE_DEFINITIONS`, :prop_tgt:`COMPILE_OPTIONS`, :prop_tgt:`AUTOUIC_OPTIONS`,
:prop_tgt:`COMPILE_DEFINITIONS`, :prop_tgt:`COMPILE_OPTIONS`,
:prop_tgt:`AUTOUIC_OPTIONS`, :prop_tgt:`SOURCES`,
:prop_tgt:`POSITION_INDEPENDENT_CODE` target properties and any other property
listed in :prop_tgt:`COMPATIBLE_INTERFACE_STRING` and other ``COMPATIBLE_INTERFACE_``
properties. It outputs an origin for each entry in the target property.
......
......@@ -224,6 +224,7 @@ cmTarget::cmTarget()
this->DebugIncludesDone = false;
this->DebugCompileOptionsDone = false;
this->DebugCompileDefinitionsDone = false;
this->DebugSourcesDone = false;
}
//----------------------------------------------------------------------------
......@@ -553,7 +554,7 @@ static void processSources(cmTarget const* tgt,
std::set<std::string> &uniqueSrcs,
cmGeneratorExpressionDAGChecker *dagChecker,
cmTarget const* head,
std::string const& config)
std::string const& config, bool debugSources)
{
cmMakefile *mf = tgt->GetMakefile();
......@@ -601,6 +602,7 @@ static void processSources(cmTarget const* tgt,
(*it)->CachedEntries = entrySources;
}
}
std::string usedSources;
for(std::vector<std::string>::iterator
li = entrySources.begin(); li != entrySources.end(); ++li)
{
......@@ -609,8 +611,19 @@ static void processSources(cmTarget const* tgt,
if(uniqueSrcs.insert(src).second)
{
srcs.push_back(src);
if (debugSources)
{
usedSources += " * " + src + "\n";
}
}
}
if (!usedSources.empty())
{
mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
std::string("Used sources for target ")
+ tgt->GetName() + ":\n"
+ usedSources, (*it)->ge->GetBacktrace());
}
}
}
......@@ -621,6 +634,24 @@ void cmTarget::GetSourceFiles(std::vector<std::string> &files,
{
assert(this->GetType() != INTERFACE_LIBRARY);
std::vector<std::string> debugProperties;
const char *debugProp =
this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
if (debugProp)
{
cmSystemTools::ExpandListArgument(debugProp, debugProperties);
}
bool debugSources = !this->DebugSourcesDone
&& std::find(debugProperties.begin(),
debugProperties.end(),
"SOURCES")
!= debugProperties.end();
if (this->Makefile->IsGeneratingBuildSystem())
{
this->DebugSourcesDone = true;
}
cmListFileBacktrace lfbt;
......@@ -635,7 +666,8 @@ void cmTarget::GetSourceFiles(std::vector<std::string> &files,
uniqueSrcs,
&dagChecker,
head,
config);
config,
debugSources);
if (!this->Internal->CacheLinkInterfaceSourcesDone[config])
{
......@@ -686,7 +718,8 @@ void cmTarget::GetSourceFiles(std::vector<std::string> &files,
uniqueSrcs,
&dagChecker,
head,
config);
config,
debugSources);
if (!this->Makefile->IsGeneratingBuildSystem())
{
......
......@@ -710,6 +710,7 @@ private:
mutable std::map<std::string, bool> DebugCompatiblePropertiesDone;
mutable bool DebugCompileOptionsDone;
mutable bool DebugCompileDefinitionsDone;
mutable bool DebugSourcesDone;
mutable std::set<std::string> LinkImplicitNullProperties;
bool BuildInterfaceIncludesAppended;
......
CMake Debug Log at OriginDebug.cmake:13 \(add_library\):
Used sources for target OriginDebug:
\* .*Tests/RunCMake/TargetSources/empty_2.cpp
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
+
CMake Debug Log at OriginDebug.cmake:14 \(target_link_libraries\):
Used sources for target OriginDebug:
\* .*Tests/RunCMake/TargetSources/empty_1.cpp
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
cmake_minimum_required(VERSION 3.0)
project(OriginDebug)
set(CMAKE_DEBUG_TARGET_PROPERTIES SOURCES)
add_library(iface INTERFACE)
set_property(TARGET iface PROPERTY INTERFACE_SOURCES
empty_1.cpp
)
add_library(OriginDebug empty_2.cpp)
target_link_libraries(OriginDebug iface)
CMake Debug Log at OriginDebug.cmake:13 \(add_library\):
Used sources for target OriginDebug:
\* .*Tests/RunCMake/TargetSources/empty_2.cpp
Call Stack \(most recent call first\):
OriginDebugIDE.cmake:4 \(include\)
CMakeLists.txt:3 \(include\)
+
CMake Debug Log:
Used sources for target OriginDebug:
* .*CMakeLists.txt
+
CMake Debug Log at OriginDebug.cmake:14 \(target_link_libraries\):
Used sources for target OriginDebug:
\* .*Tests/RunCMake/TargetSources/empty_1.cpp
Call Stack \(most recent call first\):
OriginDebugIDE.cmake:4 \(include\)
CMakeLists.txt:3 \(include\)
# Separate test for the IDEs, because they show the CMakeLists.txt file
# as a source file.
include(${CMAKE_CURRENT_LIST_DIR}/OriginDebug.cmake)
......@@ -3,4 +3,7 @@ include(RunCMake)
if(RunCMake_GENERATOR MATCHES Xcode
OR RunCMake_GENERATOR MATCHES "Visual Studio")
run_cmake(ConfigNotAllowed)
run_cmake(OriginDebugIDE)
else()
run_cmake(OriginDebug)
endif()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment