diff options
author | Brad King <brad.king@kitware.com> | 2022-08-22 14:58:46 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-08-22 19:29:43 (GMT) |
commit | 52c95540b722926ba833ead05a575189bdabf84e (patch) | |
tree | b620d3dfeaabb69d61a9e3c2413a0d73692d6968 | |
parent | 0d64c3abd13a0b14f1a14b7717dbac8988d12256 (diff) | |
download | CMake-52c95540b722926ba833ead05a575189bdabf84e.zip CMake-52c95540b722926ba833ead05a575189bdabf84e.tar.gz CMake-52c95540b722926ba833ead05a575189bdabf84e.tar.bz2 |
target_*: Fix cross-directory call backtraces
Record the call-site backtrace, not the current backtrace of the
target's directory.
Fixes: #23873
-rw-r--r-- | Source/cmLocalGenerator.cxx | 3 | ||||
-rw-r--r-- | Source/cmSetPropertyCommand.cxx | 4 | ||||
-rw-r--r-- | Source/cmStandardLevelResolver.cxx | 7 | ||||
-rw-r--r-- | Source/cmTarget.cxx | 37 | ||||
-rw-r--r-- | Source/cmTarget.h | 6 | ||||
-rw-r--r-- | Source/cmTargetCompileDefinitionsCommand.cxx | 4 | ||||
-rw-r--r-- | Source/cmTargetIncludeDirectoriesCommand.cxx | 3 | ||||
-rw-r--r-- | Source/cmTargetLinkLibrariesCommand.cxx | 8 | ||||
-rw-r--r-- | Source/cmTargetPrecompileHeadersCommand.cxx | 4 | ||||
-rw-r--r-- | Source/cmTargetSourcesCommand.cxx | 9 | ||||
-rw-r--r-- | Tests/RunCMake/FileAPI/codemodel-v2-data/targets/c_subdir.json | 58 |
11 files changed, 67 insertions, 76 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 64f8996..b44d2a0 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -15,6 +15,7 @@ #include <vector> #include <cm/memory> +#include <cm/optional> #include <cm/string_view> #include <cmext/algorithm> #include <cmext/string_view> @@ -2686,7 +2687,7 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target) cmStrCat(linkerProperty, configUpper), cmStrCat(" ", this->ConvertToOutputFormat(pchSourceObj, SHELL)), - true); + cm::nullopt, true); } else if (reuseTarget->GetType() == cmStateEnums::OBJECT_LIBRARY) { // FIXME: This can propagate more than one level, unlike diff --git a/Source/cmSetPropertyCommand.cxx b/Source/cmSetPropertyCommand.cxx index db10cd4..521cf63 100644 --- a/Source/cmSetPropertyCommand.cxx +++ b/Source/cmSetPropertyCommand.cxx @@ -9,6 +9,7 @@ #include "cmExecutionStatus.h" #include "cmGlobalGenerator.h" #include "cmInstalledFile.h" +#include "cmListFileCache.h" #include "cmMakefile.h" #include "cmMessageType.h" #include "cmPolicies.h" @@ -561,7 +562,8 @@ bool HandleTarget(cmTarget* target, cmMakefile& makefile, { // Set or append the property. if (appendMode) { - target->AppendProperty(propertyName, propertyValue, appendAsString); + target->AppendProperty(propertyName, propertyValue, + makefile.GetBacktrace(), appendAsString); } else { if (remove) { target->SetProperty(propertyName, nullptr); diff --git a/Source/cmStandardLevelResolver.cxx b/Source/cmStandardLevelResolver.cxx index 785f356..be15288 100644 --- a/Source/cmStandardLevelResolver.cxx +++ b/Source/cmStandardLevelResolver.cxx @@ -18,6 +18,7 @@ #include "cmGeneratorExpression.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" +#include "cmListFileCache.h" #include "cmMakefile.h" #include "cmMessageType.h" #include "cmPolicies.h" @@ -416,7 +417,8 @@ bool cmStandardLevelResolver::AddRequiredTargetFeature( cmTarget* target, const std::string& feature, std::string* error) const { if (cmGeneratorExpression::Find(feature) != std::string::npos) { - target->AppendProperty("COMPILE_FEATURES", feature); + target->AppendProperty("COMPILE_FEATURES", feature, + this->Makefile->GetBacktrace()); return true; } @@ -426,7 +428,8 @@ bool cmStandardLevelResolver::AddRequiredTargetFeature( return false; } - target->AppendProperty("COMPILE_FEATURES", feature); + target->AppendProperty("COMPILE_FEATURES", feature, + this->Makefile->GetBacktrace()); // FIXME: Add a policy to avoid updating the <LANG>_STANDARD target // property due to COMPILE_FEATURES. The language standard selection diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index eafea05..050206a 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -295,6 +295,12 @@ public: cm::string_view fileSetType) const; cmValue GetFileSetPaths(cmTarget const* self, std::string const& fileSetName, cm::string_view fileSetType) const; + + cmListFileBacktrace GetBacktrace( + cm::optional<cmListFileBacktrace> const& bt) const + { + return bt ? *bt : this->Makefile->GetBacktrace(); + } }; cmTargetInternals::cmTargetInternals() @@ -1243,7 +1249,8 @@ void cmTarget::AddLinkLibrary(cmMakefile& mf, std::string const& lib, ? targetNameGenex(lib) : lib; this->AppendProperty("LINK_LIBRARIES", - this->GetDebugGeneratorExpressions(libName, llt)); + this->GetDebugGeneratorExpressions(libName, llt), + mf.GetBacktrace()); } if (cmGeneratorExpression::Find(lib) != std::string::npos || @@ -1684,7 +1691,9 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) } void cmTarget::AppendProperty(const std::string& prop, - const std::string& value, bool asString) + const std::string& value, + cm::optional<cmListFileBacktrace> const& bt, + bool asString) { if (prop == "NAME") { this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, @@ -1715,32 +1724,32 @@ void cmTarget::AppendProperty(const std::string& prop, } if (prop == "INCLUDE_DIRECTORIES") { if (!value.empty()) { - cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); + cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); this->impl->IncludeDirectoriesEntries.emplace_back(value, lfbt); } } else if (prop == "COMPILE_OPTIONS") { if (!value.empty()) { - cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); + cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); this->impl->CompileOptionsEntries.emplace_back(value, lfbt); } } else if (prop == "COMPILE_FEATURES") { if (!value.empty()) { - cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); + cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); this->impl->CompileFeaturesEntries.emplace_back(value, lfbt); } } else if (prop == "COMPILE_DEFINITIONS") { if (!value.empty()) { - cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); + cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); this->impl->CompileDefinitionsEntries.emplace_back(value, lfbt); } } else if (prop == "LINK_OPTIONS") { if (!value.empty()) { - cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); + cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); this->impl->LinkOptionsEntries.emplace_back(value, lfbt); } } else if (prop == "LINK_DIRECTORIES") { if (!value.empty()) { - cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); + cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); this->impl->LinkDirectoriesEntries.emplace_back(value, lfbt); } } else if (prop == "PRECOMPILE_HEADERS") { @@ -1753,32 +1762,32 @@ void cmTarget::AppendProperty(const std::string& prop, return; } if (!value.empty()) { - cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); + cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); this->impl->PrecompileHeadersEntries.emplace_back(value, lfbt); } } else if (prop == "LINK_LIBRARIES") { if (!value.empty()) { - cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); + cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); this->impl->LinkImplementationPropertyEntries.emplace_back(value, lfbt); } } else if (prop == propINTERFACE_LINK_LIBRARIES) { if (!value.empty()) { - cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); + cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); this->impl->LinkInterfacePropertyEntries.emplace_back(value, lfbt); } } else if (prop == propINTERFACE_LINK_LIBRARIES_DIRECT) { if (!value.empty()) { - cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); + cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); this->impl->LinkInterfaceDirectPropertyEntries.emplace_back(value, lfbt); } } else if (prop == propINTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE) { if (!value.empty()) { - cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); + cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); this->impl->LinkInterfaceDirectExcludePropertyEntries.emplace_back(value, lfbt); } } else if (prop == "SOURCES") { - cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); + cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); this->impl->SourceEntries.emplace_back(value, lfbt); } else if (cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME")) { this->impl->Makefile->IssueMessage( diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 3d0a06b..1550f5b 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -185,8 +185,10 @@ public: { this->SetProperty(prop, cmValue(value)); } - void AppendProperty(const std::string& prop, const std::string& value, - bool asString = false); + void AppendProperty( + const std::string& prop, const std::string& value, + cm::optional<cmListFileBacktrace> const& bt = cm::nullopt, + bool asString = false); //! Might return a nullptr if the property is not set or invalid cmValue GetProperty(const std::string& prop) const; //! Always returns a valid pointer diff --git a/Source/cmTargetCompileDefinitionsCommand.cxx b/Source/cmTargetCompileDefinitionsCommand.cxx index b56b245..268bfac 100644 --- a/Source/cmTargetCompileDefinitionsCommand.cxx +++ b/Source/cmTargetCompileDefinitionsCommand.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmTargetCompileDefinitionsCommand.h" +#include "cmListFileCache.h" #include "cmMakefile.h" #include "cmMessageType.h" #include "cmStringAlgorithms.h" @@ -28,7 +29,8 @@ private: const std::vector<std::string>& content, bool /*prepend*/, bool /*system*/) override { - tgt->AppendProperty("COMPILE_DEFINITIONS", this->Join(content)); + tgt->AppendProperty("COMPILE_DEFINITIONS", this->Join(content), + this->Makefile->GetBacktrace()); return true; // Successfully handled. } diff --git a/Source/cmTargetIncludeDirectoriesCommand.cxx b/Source/cmTargetIncludeDirectoriesCommand.cxx index b4b4319..cb83873 100644 --- a/Source/cmTargetIncludeDirectoriesCommand.cxx +++ b/Source/cmTargetIncludeDirectoriesCommand.cxx @@ -88,7 +88,8 @@ void TargetIncludeDirectoriesImpl::HandleInterfaceContent( system); if (system) { std::string joined = this->Join(content); - tgt->AppendProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES", joined); + tgt->AppendProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES", joined, + this->Makefile->GetBacktrace()); } } diff --git a/Source/cmTargetLinkLibrariesCommand.cxx b/Source/cmTargetLinkLibrariesCommand.cxx index ba901d0..fb03b62 100644 --- a/Source/cmTargetLinkLibrariesCommand.cxx +++ b/Source/cmTargetLinkLibrariesCommand.cxx @@ -625,7 +625,7 @@ bool TLL::HandleLibrary(ProcessingState currentProcessingState, void TLL::AppendProperty(std::string const& prop, std::string const& value) { this->AffectsProperty(prop); - this->Target->AppendProperty(prop, value); + this->Target->AppendProperty(prop, value, this->Makefile.GetBacktrace()); } void TLL::AffectsProperty(std::string const& prop) @@ -636,14 +636,16 @@ void TLL::AffectsProperty(std::string const& prop) // Add a wrapper to the expression to tell LookupLinkItem to look up // names in the caller's directory. if (this->Props.insert(prop).second) { - this->Target->AppendProperty(prop, this->DirectoryId); + this->Target->AppendProperty(prop, this->DirectoryId, + this->Makefile.GetBacktrace()); } } TLL::~TLL() { for (std::string const& prop : this->Props) { - this->Target->AppendProperty(prop, CMAKE_DIRECTORY_ID_SEP); + this->Target->AppendProperty(prop, CMAKE_DIRECTORY_ID_SEP, + this->Makefile.GetBacktrace()); } } diff --git a/Source/cmTargetPrecompileHeadersCommand.cxx b/Source/cmTargetPrecompileHeadersCommand.cxx index a5066cc..4dd158d 100644 --- a/Source/cmTargetPrecompileHeadersCommand.cxx +++ b/Source/cmTargetPrecompileHeadersCommand.cxx @@ -5,6 +5,7 @@ #include <utility> #include "cmGeneratorExpression.h" +#include "cmListFileCache.h" #include "cmMakefile.h" #include "cmMessageType.h" #include "cmStringAlgorithms.h" @@ -48,7 +49,8 @@ private: { std::string const& base = this->Makefile->GetCurrentSourceDirectory(); tgt->AppendProperty("PRECOMPILE_HEADERS", - this->Join(ConvertToAbsoluteContent(content, base))); + this->Join(ConvertToAbsoluteContent(content, base)), + this->Makefile->GetBacktrace()); return true; } diff --git a/Source/cmTargetSourcesCommand.cxx b/Source/cmTargetSourcesCommand.cxx index e2b0213..53e25b5 100644 --- a/Source/cmTargetSourcesCommand.cxx +++ b/Source/cmTargetSourcesCommand.cxx @@ -79,7 +79,8 @@ private: { tgt->AppendProperty("SOURCES", this->Join(this->ConvertToAbsoluteContent( - tgt, content, IsInterface::No, CheckCMP0076::Yes))); + tgt, content, IsInterface::No, CheckCMP0076::Yes)), + this->Makefile->GetBacktrace()); return true; // Successfully handled. } @@ -324,11 +325,13 @@ bool TargetSourcesImpl::HandleOneFileSet( cmStrCat("$<BUILD_INTERFACE:", dir, ">"); if (cmFileSetVisibilityIsForSelf(visibility)) { this->Target->AppendProperty("INCLUDE_DIRECTORIES", - interfaceDirectoriesGenex); + interfaceDirectoriesGenex, + this->Makefile->GetBacktrace()); } if (cmFileSetVisibilityIsForInterface(visibility)) { this->Target->AppendProperty("INTERFACE_INCLUDE_DIRECTORIES", - interfaceDirectoriesGenex); + interfaceDirectoriesGenex, + this->Makefile->GetBacktrace()); } } } diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/c_subdir.json b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/c_subdir.json index 799c21e..12ec917 100644 --- a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/c_subdir.json +++ b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/c_subdir.json @@ -13,25 +13,13 @@ "compileGroupLanguage": "C", "backtrace": [ { - "file": "^codemodel-v2\\.cmake$", - "line": 18, - "command": "add_subdirectory", - "hasParent": true - }, - { - "file": "^codemodel-v2\\.cmake$", - "line": null, - "command": null, - "hasParent": true - }, - { - "file": "^CMakeLists\\.txt$", - "line": 3, - "command": "include", + "file": "^subdir/CMakeLists\\.txt$", + "line": 4, + "command": "target_sources", "hasParent": true }, { - "file": "^CMakeLists\\.txt$", + "file": "^subdir/CMakeLists\\.txt$", "line": null, "command": null, "hasParent": false @@ -78,25 +66,13 @@ "define": "SUBDIR", "backtrace": [ { - "file": "^codemodel-v2\\.cmake$", - "line": 18, - "command": "add_subdirectory", + "file": "^subdir/CMakeLists\\.txt$", + "line": 1, + "command": "target_compile_definitions", "hasParent": true }, { - "file": "^codemodel-v2\\.cmake$", - "line": null, - "command": null, - "hasParent": true - }, - { - "file": "^CMakeLists\\.txt$", - "line": 3, - "command": "include", - "hasParent": true - }, - { - "file": "^CMakeLists\\.txt$", + "file": "^subdir/CMakeLists\\.txt$", "line": null, "command": null, "hasParent": false @@ -153,25 +129,13 @@ "id": "^c_lib::@6890427a1f51a3e7e1df$", "backtrace": [ { - "file": "^codemodel-v2\\.cmake$", - "line": 18, - "command": "add_subdirectory", - "hasParent": true - }, - { - "file": "^codemodel-v2\\.cmake$", - "line": null, - "command": null, - "hasParent": true - }, - { - "file": "^CMakeLists\\.txt$", + "file": "^subdir/CMakeLists\\.txt$", "line": 3, - "command": "include", + "command": "target_link_libraries", "hasParent": true }, { - "file": "^CMakeLists\\.txt$", + "file": "^subdir/CMakeLists\\.txt$", "line": null, "command": null, "hasParent": false |