mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-07 22:30:13 -06:00
target_*: Fix cross-directory call backtraces
Record the call-site backtrace, not the current backtrace of the target's directory. Fixes: #23873
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,25 +13,13 @@
|
||||
"compileGroupLanguage": "C",
|
||||
"backtrace": [
|
||||
{
|
||||
"file": "^codemodel-v2\\.cmake$",
|
||||
"line": 18,
|
||||
"command": "add_subdirectory",
|
||||
"file": "^subdir/CMakeLists\\.txt$",
|
||||
"line": 4,
|
||||
"command": "target_sources",
|
||||
"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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user