mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-22 06:59:01 -06:00
cmLinkLineComputer: Add ComputeLinkLibraries overload with backtraces
This commit is contained in:
@@ -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<BT<std::string>> linkLibrariesList;
|
||||
this->ComputeLinkLibraries(cli, stdLibString, linkLibrariesList);
|
||||
cli.AppendValues(linkLibraries, linkLibrariesList);
|
||||
return linkLibraries;
|
||||
}
|
||||
|
||||
void cmLinkLineComputer::ComputeLinkLibraries(
|
||||
cmComputeLinkInformation& cli, std::string const& stdLibString,
|
||||
std::vector<BT<std::string>>& 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,
|
||||
|
||||
@@ -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<BT<std::string>>& linkLibraries);
|
||||
|
||||
virtual std::string GetLinkerLanguage(cmGeneratorTarget* target,
|
||||
std::string const& config);
|
||||
|
||||
@@ -4,13 +4,14 @@
|
||||
#include "cmLinkLineDeviceComputer.h"
|
||||
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
|
||||
#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<BT<std::string>>& 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<std::string> 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*,
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "cmConfigure.h" // IWYU pragma: keep
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "cmLinkLineComputer.h"
|
||||
|
||||
@@ -15,6 +16,8 @@ class cmGeneratorTarget;
|
||||
class cmLocalGenerator;
|
||||
class cmOutputConverter;
|
||||
class cmStateDirectory;
|
||||
template <typename T>
|
||||
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<BT<std::string>>& linkLibraries) override;
|
||||
|
||||
std::string GetLinkerLanguage(cmGeneratorTarget* target,
|
||||
std::string const& config) override;
|
||||
|
||||
Reference in New Issue
Block a user