From a209b31d0d088de40ba5bebdc6c9650f0583b2a6 Mon Sep 17 00:00:00 2001 From: Justin Goshi Date: Wed, 11 Sep 2019 10:28:38 -0700 Subject: cmComputeLinkInformation: Add AppendValues with backtraces --- Source/cmComputeLinkInformation.cxx | 13 +++++++++++++ Source/cmComputeLinkInformation.h | 3 +++ 2 files changed, 16 insertions(+) diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx index dd8d246..ed0bb85 100644 --- a/Source/cmComputeLinkInformation.cxx +++ b/Source/cmComputeLinkInformation.cxx @@ -6,6 +6,7 @@ #include "cmComputeLinkDepends.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" +#include "cmListFileCache.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" #include "cmMessageType.h" @@ -406,6 +407,18 @@ cmComputeLinkInformation::~cmComputeLinkInformation() delete this->OrderDependentRPath; } +void cmComputeLinkInformation::AppendValues( + std::string& result, std::vector>& values) +{ + for (BT& p : values) { + if (result.empty()) { + result.append(" "); + } + + result.append(p.Value); + } +} + cmComputeLinkInformation::ItemVector const& cmComputeLinkInformation::GetItems() const { diff --git a/Source/cmComputeLinkInformation.h b/Source/cmComputeLinkInformation.h index 0f71381..ee36a71 100644 --- a/Source/cmComputeLinkInformation.h +++ b/Source/cmComputeLinkInformation.h @@ -17,6 +17,8 @@ class cmGlobalGenerator; class cmMakefile; class cmOrderDirectories; class cmake; +template +class BT; /** \class cmComputeLinkInformation * \brief Compute link information for a target in one configuration. @@ -43,6 +45,7 @@ public: cmGeneratorTarget const* Target = nullptr; }; using ItemVector = std::vector; + void AppendValues(std::string& result, std::vector>& values); ItemVector const& GetItems() const; std::vector const& GetDirectories() const; std::vector const& GetDepends() const; -- cgit v0.12 From 0c6468178a76b6a2a11791b010ab01c97855affa Mon Sep 17 00:00:00 2001 From: Justin Goshi Date: Wed, 11 Sep 2019 10:31:05 -0700 Subject: cmComputeLinkInformation: Add GetDirectoriesWithBacktraces --- Source/cmComputeLinkInformation.cxx | 22 ++++++++++++++++++++++ Source/cmComputeLinkInformation.h | 1 + 2 files changed, 23 insertions(+) diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx index ed0bb85..6ee6455 100644 --- a/Source/cmComputeLinkInformation.cxx +++ b/Source/cmComputeLinkInformation.cxx @@ -431,6 +431,28 @@ std::vector const& cmComputeLinkInformation::GetDirectories() return this->OrderLinkerSearchPath->GetOrderedDirectories(); } +std::vector> +cmComputeLinkInformation::GetDirectoriesWithBacktraces() +{ + std::vector> directoriesWithBacktraces; + + std::vector> targetLinkDirectores = + this->Target->GetLinkDirectories(this->Config, this->LinkLanguage); + + const std::vector& orderedDirectories = this->GetDirectories(); + for (const std::string& dir : orderedDirectories) { + auto result = + std::find(targetLinkDirectores.begin(), targetLinkDirectores.end(), dir); + if (result != targetLinkDirectores.end()) { + directoriesWithBacktraces.emplace_back(std::move(*result)); + } else { + directoriesWithBacktraces.emplace_back(dir); + } + } + + return directoriesWithBacktraces; +} + std::string cmComputeLinkInformation::GetRPathLinkString() const { // If there is no separate linker runtime search flag (-rpath-link) diff --git a/Source/cmComputeLinkInformation.h b/Source/cmComputeLinkInformation.h index ee36a71..71af43f 100644 --- a/Source/cmComputeLinkInformation.h +++ b/Source/cmComputeLinkInformation.h @@ -48,6 +48,7 @@ public: void AppendValues(std::string& result, std::vector>& values); ItemVector const& GetItems() const; std::vector const& GetDirectories() const; + std::vector> GetDirectoriesWithBacktraces(); std::vector const& GetDepends() const; std::vector const& GetFrameworkPaths() const; std::string GetLinkLanguage() const { return this->LinkLanguage; } -- cgit v0.12 From 0ac9dcb807d6e7b1f905bc9685f8ae217dfce38b Mon Sep 17 00:00:00 2001 From: Justin Goshi Date: Wed, 11 Sep 2019 10:37:03 -0700 Subject: cmLinkLineComputer: Add ComputeLinkPath overload with backtraces --- Source/cmLinkLineComputer.cxx | 36 +++++++++++++++++++++++++++--------- Source/cmLinkLineComputer.h | 8 ++++++++ 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/Source/cmLinkLineComputer.cxx b/Source/cmLinkLineComputer.cxx index 91c551f..d5225db 100644 --- a/Source/cmLinkLineComputer.cxx +++ b/Source/cmLinkLineComputer.cxx @@ -4,10 +4,12 @@ #include "cmLinkLineComputer.h" #include +#include #include #include "cmComputeLinkInformation.h" #include "cmGeneratorTarget.h" +#include "cmListFileCache.h" #include "cmOutputConverter.h" #include "cmStateDirectory.h" #include "cmStateTypes.h" @@ -63,6 +65,7 @@ std::string cmLinkLineComputer::ComputeLinkLibs(cmComputeLinkInformation& cli) item.Target->GetType() == cmStateEnums::INTERFACE_LIBRARY) { continue; } + if (item.IsPath) { linkLibs += cli.GetLibLinkFileFlag(); linkLibs += @@ -72,6 +75,7 @@ std::string cmLinkLineComputer::ComputeLinkLibs(cmComputeLinkInformation& cli) } linkLibs += " "; } + return linkLibs; } @@ -101,8 +105,19 @@ std::string cmLinkLineComputer::ComputeLinkPath( std::string const& libPathTerminator) { std::string linkPath; + std::vector> linkPathList; + this->ComputeLinkPath(cli, libPathFlag, libPathTerminator, linkPathList); + cli.AppendValues(linkPath, linkPathList); + return linkPath; +} +void cmLinkLineComputer::ComputeLinkPath( + cmComputeLinkInformation& cli, std::string const& libPathFlag, + std::string const& libPathTerminator, std::vector>& linkPath) +{ if (cli.GetLinkLanguage() == "Swift") { + std::string linkPathNoBT; + for (const cmComputeLinkInformation::Item& item : cli.GetItems()) { const cmGeneratorTarget* target = item.Target; if (!target) { @@ -116,20 +131,23 @@ std::string cmLinkLineComputer::ComputeLinkPath( type = cmStateEnums::ImportLibraryArtifact; } - linkPath += cmStrCat(" ", libPathFlag, - item.Target->GetDirectory(cli.GetConfig(), type), - libPathTerminator, " "); + linkPathNoBT += cmStrCat( + " ", libPathFlag, item.Target->GetDirectory(cli.GetConfig(), type), + libPathTerminator, " "); } } - } - for (std::string const& libDir : cli.GetDirectories()) { - linkPath += - cmStrCat(" ", libPathFlag, this->ConvertToOutputForExisting(libDir), - libPathTerminator, " "); + if (!linkPathNoBT.empty()) { + linkPath.emplace_back(std::move(linkPathNoBT)); + } } - return linkPath; + for (BT libDir : cli.GetDirectoriesWithBacktraces()) { + libDir.Value = cmStrCat(" ", libPathFlag, + this->ConvertToOutputForExisting(libDir.Value), + libPathTerminator, " "); + linkPath.emplace_back(libDir); + } } std::string cmLinkLineComputer::ComputeRPath(cmComputeLinkInformation& cli) diff --git a/Source/cmLinkLineComputer.h b/Source/cmLinkLineComputer.h index 2355c32..5e0f795 100644 --- a/Source/cmLinkLineComputer.h +++ b/Source/cmLinkLineComputer.h @@ -7,12 +7,15 @@ #include "cmConfigure.h" // IWYU pragma: keep #include +#include #include "cmStateDirectory.h" class cmComputeLinkInformation; class cmGeneratorTarget; class cmOutputConverter; +template +class BT; class cmLinkLineComputer { @@ -34,6 +37,11 @@ public: std::string const& libPathFlag, std::string const& libPathTerminator); + void ComputeLinkPath(cmComputeLinkInformation& cli, + std::string const& libPathFlag, + std::string const& libPathTerminator, + std::vector>& linkPath); + std::string ComputeFrameworkPath(cmComputeLinkInformation& cli, std::string const& fwSearchFlag); -- cgit v0.12 From d4d0dd0f6a0f2287fd0fbdfad8c7210515af5eaa Mon Sep 17 00:00:00 2001 From: Justin Goshi Date: Fri, 13 Sep 2019 10:59:53 -0700 Subject: cmLinkLineComputer: Add ComputeLinkLibs overload with backtraces --- Source/cmComputeLinkInformation.h | 2 ++ Source/cmLinkLineComputer.cxx | 37 +++++++++++++++++++++++++++++++------ Source/cmLinkLineComputer.h | 2 ++ 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/Source/cmComputeLinkInformation.h b/Source/cmComputeLinkInformation.h index 71af43f..d3345d9 100644 --- a/Source/cmComputeLinkInformation.h +++ b/Source/cmComputeLinkInformation.h @@ -70,6 +70,8 @@ public: std::string GetConfig() const { return this->Config; } + const cmGeneratorTarget* GetTarget() { return this->Target; } + private: void AddItem(std::string const& item, const cmGeneratorTarget* tgt); void AddSharedDepItem(std::string const& item, cmGeneratorTarget const* tgt); diff --git a/Source/cmLinkLineComputer.cxx b/Source/cmLinkLineComputer.cxx index d5225db..dec25ff 100644 --- a/Source/cmLinkLineComputer.cxx +++ b/Source/cmLinkLineComputer.cxx @@ -9,6 +9,7 @@ #include "cmComputeLinkInformation.h" #include "cmGeneratorTarget.h" +#include "cmLinkItem.h" #include "cmListFileCache.h" #include "cmOutputConverter.h" #include "cmStateDirectory.h" @@ -58,6 +59,15 @@ std::string cmLinkLineComputer::ConvertToLinkReference( std::string cmLinkLineComputer::ComputeLinkLibs(cmComputeLinkInformation& cli) { std::string linkLibs; + std::vector> linkLibsList; + this->ComputeLinkLibs(cli, linkLibsList); + cli.AppendValues(linkLibs, linkLibsList); + return linkLibs; +} + +void cmLinkLineComputer::ComputeLinkLibs( + cmComputeLinkInformation& cli, std::vector>& linkLibraries) +{ using ItemVector = cmComputeLinkInformation::ItemVector; ItemVector const& items = cli.GetItems(); for (auto const& item : items) { @@ -66,17 +76,32 @@ std::string cmLinkLineComputer::ComputeLinkLibs(cmComputeLinkInformation& cli) continue; } + BT linkLib; if (item.IsPath) { - linkLibs += cli.GetLibLinkFileFlag(); - linkLibs += + linkLib.Value += cli.GetLibLinkFileFlag(); + linkLib.Value += this->ConvertToOutputFormat(this->ConvertToLinkReference(item.Value)); } else { - linkLibs += item.Value; + linkLib.Value += item.Value; + } + linkLib.Value += " "; + + const cmLinkImplementation* linkImpl = + cli.GetTarget()->GetLinkImplementation(cli.GetConfig()); + + for (const cmLinkImplItem& iter : linkImpl->Libraries) { + if (iter.Target != nullptr && + iter.Target->GetType() != cmStateEnums::INTERFACE_LIBRARY) { + std::string libPath = iter.Target->GetLocation(cli.GetConfig()); + if (item.Value == libPath) { + linkLib.Backtrace = iter.Backtrace; + break; + } + } } - linkLibs += " "; - } - return linkLibs; + linkLibraries.emplace_back(linkLib); + } } std::string cmLinkLineComputer::ConvertToOutputFormat(std::string const& input) diff --git a/Source/cmLinkLineComputer.h b/Source/cmLinkLineComputer.h index 5e0f795..a6e0ebf 100644 --- a/Source/cmLinkLineComputer.h +++ b/Source/cmLinkLineComputer.h @@ -53,6 +53,8 @@ public: protected: std::string ComputeLinkLibs(cmComputeLinkInformation& cli); + void ComputeLinkLibs(cmComputeLinkInformation& cli, + std::vector>& linkLibraries); std::string ComputeRPath(cmComputeLinkInformation& cli); std::string ConvertToOutputFormat(std::string const& input); -- cgit v0.12 From 7da17ef7973294a5207f879c0c5a3ed7ab727029 Mon Sep 17 00:00:00 2001 From: Justin Goshi Date: Wed, 11 Sep 2019 11:04:36 -0700 Subject: cmLinkLineComputer: Add ComputeLinkLibraries overload with backtraces --- Source/cmLinkLineComputer.cxx | 28 +++++++++++++++++++++---- Source/cmLinkLineComputer.h | 8 ++++++-- Source/cmLinkLineDeviceComputer.cxx | 41 ++++++++++++++++++++++++------------- Source/cmLinkLineDeviceComputer.h | 8 ++++++-- 4 files changed, 63 insertions(+), 22 deletions(-) diff --git a/Source/cmLinkLineComputer.cxx b/Source/cmLinkLineComputer.cxx index dec25ff..0dc6236 100644 --- a/Source/cmLinkLineComputer.cxx +++ b/Source/cmLinkLineComputer.cxx @@ -222,13 +222,30 @@ std::string cmLinkLineComputer::ComputeFrameworkPath( std::string cmLinkLineComputer::ComputeLinkLibraries( cmComputeLinkInformation& cli, std::string const& stdLibString) { - std::ostringstream fout; - fout << this->ComputeRPath(cli); + std::string linkLibraries; + std::vector> linkLibrariesList; + this->ComputeLinkLibraries(cli, stdLibString, linkLibrariesList); + cli.AppendValues(linkLibraries, linkLibrariesList); + return linkLibraries; +} + +void cmLinkLineComputer::ComputeLinkLibraries( + cmComputeLinkInformation& cli, std::string const& stdLibString, + std::vector>& linkLibraries) +{ + std::ostringstream rpathOut; + rpathOut << this->ComputeRPath(cli); + + std::string rpath = rpathOut.str(); + if (!rpath.empty()) { + linkLibraries.emplace_back(std::move(rpath)); + } // Write the library flags to the build rule. - fout << this->ComputeLinkLibs(cli); + this->ComputeLinkLibs(cli, linkLibraries); // Add the linker runtime search path if any. + std::ostringstream fout; std::string rpath_link = cli.GetRPathLinkString(); if (!cli.GetRPathLinkFlag().empty() && !rpath_link.empty()) { fout << cli.GetRPathLinkFlag(); @@ -241,7 +258,10 @@ std::string cmLinkLineComputer::ComputeLinkLibraries( fout << stdLibString << " "; } - return fout.str(); + std::string remainingLibs = fout.str(); + if (!remainingLibs.empty()) { + linkLibraries.emplace_back(remainingLibs); + } } std::string cmLinkLineComputer::GetLinkerLanguage(cmGeneratorTarget* target, diff --git a/Source/cmLinkLineComputer.h b/Source/cmLinkLineComputer.h index a6e0ebf..f426976 100644 --- a/Source/cmLinkLineComputer.h +++ b/Source/cmLinkLineComputer.h @@ -45,8 +45,12 @@ public: std::string ComputeFrameworkPath(cmComputeLinkInformation& cli, std::string const& fwSearchFlag); - virtual std::string ComputeLinkLibraries(cmComputeLinkInformation& cli, - std::string const& stdLibString); + std::string ComputeLinkLibraries(cmComputeLinkInformation& cli, + std::string const& stdLibString); + + virtual void ComputeLinkLibraries( + cmComputeLinkInformation& cli, std::string const& stdLibString, + std::vector>& linkLibraries); virtual std::string GetLinkerLanguage(cmGeneratorTarget* target, std::string const& config); diff --git a/Source/cmLinkLineDeviceComputer.cxx b/Source/cmLinkLineDeviceComputer.cxx index 1a602ca..d845652 100644 --- a/Source/cmLinkLineDeviceComputer.cxx +++ b/Source/cmLinkLineDeviceComputer.cxx @@ -4,13 +4,14 @@ #include "cmLinkLineDeviceComputer.h" #include -#include #include #include "cmAlgorithms.h" #include "cmComputeLinkInformation.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" +#include "cmLinkItem.h" +#include "cmListFileCache.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" #include "cmStateDirectory.h" @@ -67,12 +68,10 @@ bool cmLinkLineDeviceComputer::ComputeRequiresDeviceLinking( return false; } -std::string cmLinkLineDeviceComputer::ComputeLinkLibraries( - cmComputeLinkInformation& cli, std::string const& stdLibString) +void cmLinkLineDeviceComputer::ComputeLinkLibraries( + cmComputeLinkInformation& cli, std::string const& stdLibString, + std::vector>& linkLibraries) { - // Write the library flags to the build rule. - std::ostringstream fout; - // Generate the unique set of link items when device linking. // The nvcc device linker is designed so that each static library // with device symbols only needs to be listed once as it doesn't @@ -110,7 +109,7 @@ std::string cmLinkLineDeviceComputer::ComputeLinkLibraries( } } - std::string out; + BT linkLib; if (item.IsPath) { // nvcc understands absolute paths to libraries ending in '.a' or '.lib'. // These should be passed to nvlink. Other extensions need to be left @@ -118,7 +117,7 @@ std::string cmLinkLineDeviceComputer::ComputeLinkLibraries( // can tolerate '.so' or '.dylib' it cannot tolerate '.so.1'. if (cmHasLiteralSuffix(item.Value, ".a") || cmHasLiteralSuffix(item.Value, ".lib")) { - out += this->ConvertToOutputFormat( + linkLib.Value += this->ConvertToOutputFormat( this->ConvertToLinkReference(item.Value)); } } else if (item.Value == "-framework") { @@ -127,19 +126,33 @@ std::string cmLinkLineDeviceComputer::ComputeLinkLibraries( skipItemAfterFramework = true; continue; } else if (cmLinkItemValidForDevice(item.Value)) { - out += item.Value; + linkLib.Value += item.Value; } - if (emitted.insert(out).second) { - fout << out << " "; + if (emitted.insert(linkLib.Value).second) { + linkLib.Value += " "; + + const cmLinkImplementation* linkImpl = + cli.GetTarget()->GetLinkImplementation(cli.GetConfig()); + + for (const cmLinkImplItem& iter : linkImpl->Libraries) { + if (iter.Target != nullptr && + iter.Target->GetType() != cmStateEnums::INTERFACE_LIBRARY) { + std::string libPath = iter.Target->GetLocation(cli.GetConfig()); + if (item.Value == libPath) { + linkLib.Backtrace = iter.Backtrace; + break; + } + } + } + + linkLibraries.emplace_back(linkLib); } } if (!stdLibString.empty()) { - fout << stdLibString << " "; + linkLibraries.emplace_back(cmStrCat(stdLibString, ' ')); } - - return fout.str(); } std::string cmLinkLineDeviceComputer::GetLinkerLanguage(cmGeneratorTarget*, diff --git a/Source/cmLinkLineDeviceComputer.h b/Source/cmLinkLineDeviceComputer.h index 0ea5f69..a9b01cd 100644 --- a/Source/cmLinkLineDeviceComputer.h +++ b/Source/cmLinkLineDeviceComputer.h @@ -7,6 +7,7 @@ #include "cmConfigure.h" // IWYU pragma: keep #include +#include #include "cmLinkLineComputer.h" @@ -15,6 +16,8 @@ class cmGeneratorTarget; class cmLocalGenerator; class cmOutputConverter; class cmStateDirectory; +template +class BT; class cmLinkLineDeviceComputer : public cmLinkLineComputer { @@ -29,8 +32,9 @@ public: bool ComputeRequiresDeviceLinking(cmComputeLinkInformation& cli); - std::string ComputeLinkLibraries(cmComputeLinkInformation& cli, - std::string const& stdLibString) override; + void ComputeLinkLibraries( + cmComputeLinkInformation& cli, std::string const& stdLibString, + std::vector>& linkLibraries) override; std::string GetLinkerLanguage(cmGeneratorTarget* target, std::string const& config) override; -- cgit v0.12 From 5d39e792ae769025866ab42d58d3363719eec5c1 Mon Sep 17 00:00:00 2001 From: Justin Goshi Date: Wed, 11 Sep 2019 11:07:43 -0700 Subject: cmGeneratorTarget: Store backtrace for target LINK_DIRECTORIES property --- Source/cmGeneratorTarget.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index e4659b7..76b72b5 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -3692,7 +3692,7 @@ void processLinkDirectories(cmGeneratorTarget const* tgt, // in case projects set the LINK_DIRECTORIES property directly. cmSystemTools::ConvertToUnixSlashes(entryDirectory); if (uniqueDirectories.insert(entryDirectory).second) { - directories.emplace_back(entryDirectory); + directories.emplace_back(entryDirectory, entry.Backtrace); if (debugDirectories) { usedDirectories += " * " + entryDirectory + "\n"; } -- cgit v0.12 From 5bd65dff7a8198279b1e592b7e48b91119dfc794 Mon Sep 17 00:00:00 2001 From: Justin Goshi Date: Wed, 11 Sep 2019 11:15:08 -0700 Subject: cmLocalGenerator: Add OutputLinkLibraries overload with backtraces --- Source/cmLocalGenerator.cxx | 20 ++++++++++++++++---- Source/cmLocalGenerator.h | 5 +++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 9f22277..a4b482c 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1526,6 +1526,19 @@ void cmLocalGenerator::OutputLinkLibraries( std::string& linkLibraries, std::string& frameworkPath, std::string& linkPath) { + std::vector> linkLibrariesList; + std::vector> linkPathList; + this->OutputLinkLibraries(pcli, linkLineComputer, linkLibrariesList, + frameworkPath, linkPathList); + pcli->AppendValues(linkLibraries, linkLibrariesList); + pcli->AppendValues(linkPath, linkPathList); +} + +void cmLocalGenerator::OutputLinkLibraries( + cmComputeLinkInformation* pcli, cmLinkLineComputer* linkLineComputer, + std::vector>& linkLibraries, std::string& frameworkPath, + std::vector>& linkPath) +{ cmComputeLinkInformation& cli = *pcli; std::string linkLanguage = cli.GetLinkLanguage(); @@ -1557,10 +1570,9 @@ void cmLocalGenerator::OutputLinkLibraries( cmStrCat("CMAKE_", linkLanguage, "_FRAMEWORK_SEARCH_FLAG")); frameworkPath = linkLineComputer->ComputeFrameworkPath(cli, fwSearchFlag); - linkPath = - linkLineComputer->ComputeLinkPath(cli, libPathFlag, libPathTerminator); - - linkLibraries = linkLineComputer->ComputeLinkLibraries(cli, stdLibString); + linkLineComputer->ComputeLinkPath(cli, libPathFlag, libPathTerminator, + linkPath); + linkLineComputer->ComputeLinkLibraries(cli, stdLibString, linkLibraries); } std::string cmLocalGenerator::GetLinkLibsCMP0065( diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 34f58bd..f04f391 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -430,6 +430,11 @@ protected: cmLinkLineComputer* linkLineComputer, std::string& linkLibraries, std::string& frameworkPath, std::string& linkPath); + void OutputLinkLibraries(cmComputeLinkInformation* pcli, + cmLinkLineComputer* linkLineComputer, + std::vector>& linkLibraries, + std::string& frameworkPath, + std::vector>& linkPath); // Handle old-style install rules stored in the targets. void GenerateTargetInstallRules( -- cgit v0.12 From 4d6334824d81086af205fe06b6fc4c4fda5224b4 Mon Sep 17 00:00:00 2001 From: Justin Goshi Date: Wed, 11 Sep 2019 11:37:48 -0700 Subject: fileapi: add backtraces for LINK_PATH and LINK_DIRECTORIES --- Source/cmFileAPICodemodel.cxx | 20 ++++++++------ Source/cmLocalGenerator.cxx | 16 ++++++----- Source/cmLocalGenerator.h | 11 ++++---- Tests/RunCMake/FileAPI/codemodel-v2-check.py | 40 ++++++++++++++++++++++++++-- Tests/RunCMake/FileAPI/cxx/CMakeLists.txt | 1 + 5 files changed, 66 insertions(+), 22 deletions(-) diff --git a/Source/cmFileAPICodemodel.cxx b/Source/cmFileAPICodemodel.cxx index 805da81..3cf929f 100644 --- a/Source/cmFileAPICodemodel.cxx +++ b/Source/cmFileAPICodemodel.cxx @@ -1270,8 +1270,8 @@ Json::Value Target::DumpLinkCommandFragments() std::string linkLanguageFlags; std::vector> linkFlags; std::string frameworkPath; - std::string linkPath; - std::string linkLibs; + std::vector> linkPath; + std::vector> linkLibs; cmLocalGenerator* lg = this->GT->GetLocalGenerator(); cmLinkLineComputer linkLineComputer(lg, lg->GetStateSnapshot().GetDirectory()); @@ -1280,8 +1280,6 @@ Json::Value Target::DumpLinkCommandFragments() this->GT); linkLanguageFlags = cmTrimWhitespace(linkLanguageFlags); frameworkPath = cmTrimWhitespace(frameworkPath); - linkPath = cmTrimWhitespace(linkPath); - linkLibs = cmTrimWhitespace(linkLibs); if (!linkLanguageFlags.empty()) { linkFragments.append( @@ -1302,13 +1300,19 @@ Json::Value Target::DumpLinkCommandFragments() } if (!linkPath.empty()) { - linkFragments.append( - this->DumpCommandFragment(std::move(linkPath), "libraryPath")); + for (BT frag : linkPath) { + frag.Value = cmTrimWhitespace(frag.Value); + linkFragments.append( + this->DumpCommandFragment(this->ToJBT(frag), "libraryPath")); + } } if (!linkLibs.empty()) { - linkFragments.append( - this->DumpCommandFragment(std::move(linkLibs), "libraries")); + for (BT frag : linkLibs) { + frag.Value = cmTrimWhitespace(frag.Value); + linkFragments.append( + this->DumpCommandFragment(this->ToJBT(frag), "libraries")); + } } return linkFragments; diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index a4b482c..214e92c 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1198,17 +1198,21 @@ void cmLocalGenerator::GetTargetFlags( std::string& linkLibs, std::string& flags, std::string& linkFlags, std::string& frameworkPath, std::string& linkPath, cmGeneratorTarget* target) { - std::vector> tmpLinkFlags; - this->GetTargetFlags(linkLineComputer, config, linkLibs, flags, tmpLinkFlags, - frameworkPath, linkPath, target); - this->AppendFlags(linkFlags, tmpLinkFlags); + std::vector> linkFlagsList; + std::vector> linkPathList; + std::vector> linkLibsList; + this->GetTargetFlags(linkLineComputer, config, linkLibsList, flags, + linkFlagsList, frameworkPath, linkPathList, target); + this->AppendFlags(linkFlags, linkFlagsList); + this->AppendFlags(linkPath, linkPathList); + this->AppendFlags(linkLibs, linkLibsList); } void cmLocalGenerator::GetTargetFlags( cmLinkLineComputer* linkLineComputer, const std::string& config, - std::string& linkLibs, std::string& flags, + std::vector>& linkLibs, std::string& flags, std::vector>& linkFlags, std::string& frameworkPath, - std::string& linkPath, cmGeneratorTarget* target) + std::vector>& linkPath, cmGeneratorTarget* target) { const std::string buildType = cmSystemTools::UpperCase(config); cmComputeLinkInformation* pcli = target->GetLinkInformation(config); diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index f04f391..512df26 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -382,12 +382,11 @@ public: std::string& flags, std::string& linkFlags, std::string& frameworkPath, std::string& linkPath, cmGeneratorTarget* target); - void GetTargetFlags(cmLinkLineComputer* linkLineComputer, - const std::string& config, std::string& linkLibs, - std::string& flags, - std::vector>& linkFlags, - std::string& frameworkPath, std::string& linkPath, - cmGeneratorTarget* target); + void GetTargetFlags( + cmLinkLineComputer* linkLineComputer, const std::string& config, + std::vector>& linkLibs, std::string& flags, + std::vector>& linkFlags, std::string& frameworkPath, + std::vector>& linkPath, cmGeneratorTarget* target); void GetTargetDefines(cmGeneratorTarget const* target, std::string const& config, std::string const& lang, std::set& defines) const; diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-check.py b/Tests/RunCMake/FileAPI/codemodel-v2-check.py index 2a24421..52934f2 100644 --- a/Tests/RunCMake/FileAPI/codemodel-v2-check.py +++ b/Tests/RunCMake/FileAPI/codemodel-v2-check.py @@ -249,13 +249,13 @@ def check_target(c): if expected["backtrace"] is not None: expected_keys.append("backtrace") - assert actual["fragment"] == expected["fragment"] + assert matches(actual["fragment"], expected["fragment"]) assert actual["role"] == expected["role"] check_backtrace(obj, actual["backtrace"], expected["backtrace"]) assert sorted(actual.keys()) == sorted(expected_keys) - check_list_match(lambda a, e: is_string(a["fragment"], e["fragment"]), + check_list_match(lambda a, e: matches(a["fragment"], e["fragment"]), obj["link"]["commandFragments"], expected["link"]["commandFragments"], check=check_link_command_fragments, check_exception=lambda a, e: "Link fragment: %s" % a["fragment"], @@ -2218,6 +2218,42 @@ def gen_check_targets(c, g, inSource): }, ], }, + { + "fragment" : ".*TargetLinkDir\\\"?$", + "role" : "libraryPath", + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": 19, + "command": "target_link_directories", + "hasParent": True, + }, + { + "file" : "^cxx/CMakeLists\\.txt$", + "line": None, + "command": None, + "hasParent": False, + }, + ], + }, + { + "fragment" : ".*cxx_lib.*", + "role" : "libraries", + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": 6, + "command": "target_link_libraries", + "hasParent": True, + }, + { + "file" : "^cxx/CMakeLists\\.txt$", + "line": None, + "command": None, + "hasParent": False, + }, + ], + }, ], }, "archive": None, diff --git a/Tests/RunCMake/FileAPI/cxx/CMakeLists.txt b/Tests/RunCMake/FileAPI/cxx/CMakeLists.txt index 17ff455..b0564f5 100644 --- a/Tests/RunCMake/FileAPI/cxx/CMakeLists.txt +++ b/Tests/RunCMake/FileAPI/cxx/CMakeLists.txt @@ -16,3 +16,4 @@ target_link_libraries(cxx_static_exe PRIVATE cxx_static_lib) target_compile_options(cxx_exe PUBLIC TargetCompileOptions) target_link_options(cxx_exe PUBLIC TargetLinkOptions) +target_link_directories(cxx_exe PUBLIC "${CMAKE_BINARY_DIR}/TargetLinkDir") -- cgit v0.12