From 6e636f2ebaf78141f4d0a36c96804b9a1bc89857 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 27 Mar 2014 13:16:59 +0100 Subject: [PATCH] cmTarget: Make the SOURCES origin tracable. --- .../CMAKE_DEBUG_TARGET_PROPERTIES.rst | 3 +- Source/cmTarget.cxx | 39 +++++++++++++++++-- Source/cmTarget.h | 1 + .../TargetSources/OriginDebug-result.txt | 1 + .../TargetSources/OriginDebug-stderr.txt | 15 +++++++ .../RunCMake/TargetSources/OriginDebug.cmake | 14 +++++++ .../TargetSources/OriginDebugIDE-result.txt | 1 + .../TargetSources/OriginDebugIDE-stderr.txt | 22 +++++++++++ .../TargetSources/OriginDebugIDE.cmake | 4 ++ .../RunCMake/TargetSources/RunCMakeTest.cmake | 3 ++ 10 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 Tests/RunCMake/TargetSources/OriginDebug-result.txt create mode 100644 Tests/RunCMake/TargetSources/OriginDebug-stderr.txt create mode 100644 Tests/RunCMake/TargetSources/OriginDebug.cmake create mode 100644 Tests/RunCMake/TargetSources/OriginDebugIDE-result.txt create mode 100644 Tests/RunCMake/TargetSources/OriginDebugIDE-stderr.txt create mode 100644 Tests/RunCMake/TargetSources/OriginDebugIDE.cmake diff --git a/Help/variable/CMAKE_DEBUG_TARGET_PROPERTIES.rst b/Help/variable/CMAKE_DEBUG_TARGET_PROPERTIES.rst index 11aed0c0b..edd8fa1fc 100644 --- a/Help/variable/CMAKE_DEBUG_TARGET_PROPERTIES.rst +++ b/Help/variable/CMAKE_DEBUG_TARGET_PROPERTIES.rst @@ -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. diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 0b5734de5..10ecbfa43 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -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 &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::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 &files, { assert(this->GetType() != INTERFACE_LIBRARY); + std::vector 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 &files, uniqueSrcs, &dagChecker, head, - config); + config, + debugSources); if (!this->Internal->CacheLinkInterfaceSourcesDone[config]) { @@ -686,7 +718,8 @@ void cmTarget::GetSourceFiles(std::vector &files, uniqueSrcs, &dagChecker, head, - config); + config, + debugSources); if (!this->Makefile->IsGeneratingBuildSystem()) { diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 15c49ea02..055e029a2 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -710,6 +710,7 @@ private: mutable std::map DebugCompatiblePropertiesDone; mutable bool DebugCompileOptionsDone; mutable bool DebugCompileDefinitionsDone; + mutable bool DebugSourcesDone; mutable std::set LinkImplicitNullProperties; bool BuildInterfaceIncludesAppended; diff --git a/Tests/RunCMake/TargetSources/OriginDebug-result.txt b/Tests/RunCMake/TargetSources/OriginDebug-result.txt new file mode 100644 index 000000000..573541ac9 --- /dev/null +++ b/Tests/RunCMake/TargetSources/OriginDebug-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/TargetSources/OriginDebug-stderr.txt b/Tests/RunCMake/TargetSources/OriginDebug-stderr.txt new file mode 100644 index 000000000..dad9fee84 --- /dev/null +++ b/Tests/RunCMake/TargetSources/OriginDebug-stderr.txt @@ -0,0 +1,15 @@ +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\) diff --git a/Tests/RunCMake/TargetSources/OriginDebug.cmake b/Tests/RunCMake/TargetSources/OriginDebug.cmake new file mode 100644 index 000000000..911a7d4f8 --- /dev/null +++ b/Tests/RunCMake/TargetSources/OriginDebug.cmake @@ -0,0 +1,14 @@ + +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) diff --git a/Tests/RunCMake/TargetSources/OriginDebugIDE-result.txt b/Tests/RunCMake/TargetSources/OriginDebugIDE-result.txt new file mode 100644 index 000000000..573541ac9 --- /dev/null +++ b/Tests/RunCMake/TargetSources/OriginDebugIDE-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/TargetSources/OriginDebugIDE-stderr.txt b/Tests/RunCMake/TargetSources/OriginDebugIDE-stderr.txt new file mode 100644 index 000000000..9797870ac --- /dev/null +++ b/Tests/RunCMake/TargetSources/OriginDebugIDE-stderr.txt @@ -0,0 +1,22 @@ +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\) diff --git a/Tests/RunCMake/TargetSources/OriginDebugIDE.cmake b/Tests/RunCMake/TargetSources/OriginDebugIDE.cmake new file mode 100644 index 000000000..a3cc3a8ed --- /dev/null +++ b/Tests/RunCMake/TargetSources/OriginDebugIDE.cmake @@ -0,0 +1,4 @@ + +# Separate test for the IDEs, because they show the CMakeLists.txt file +# as a source file. +include(${CMAKE_CURRENT_LIST_DIR}/OriginDebug.cmake) diff --git a/Tests/RunCMake/TargetSources/RunCMakeTest.cmake b/Tests/RunCMake/TargetSources/RunCMakeTest.cmake index 1a3a7fa36..b9095f9b5 100644 --- a/Tests/RunCMake/TargetSources/RunCMakeTest.cmake +++ b/Tests/RunCMake/TargetSources/RunCMakeTest.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()