cmake/Source/cmLinkLineDeviceComputer.cxx

101 lines
2.5 KiB
C++
Raw Normal View History

2017-04-14 19:02:05 +02:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmLinkLineDeviceComputer.h"
2017-07-20 19:35:53 +02:00
#include <set>
#include <sstream>
2017-04-14 19:02:05 +02:00
#include "cmComputeLinkInformation.h"
#include "cmGeneratorTarget.h"
#include "cmGlobalNinjaGenerator.h"
2017-07-20 19:35:53 +02:00
#include "cmStateTypes.h"
class cmOutputConverter;
2017-04-14 19:02:05 +02:00
cmLinkLineDeviceComputer::cmLinkLineDeviceComputer(
2017-07-20 19:35:53 +02:00
cmOutputConverter* outputConverter, cmStateDirectory const& stateDir)
2017-04-14 19:02:05 +02:00
: cmLinkLineComputer(outputConverter, stateDir)
{
}
cmLinkLineDeviceComputer::~cmLinkLineDeviceComputer()
{
}
std::string cmLinkLineDeviceComputer::ComputeLinkLibraries(
cmComputeLinkInformation& cli, std::string const& stdLibString)
{
// Write the library flags to the build rule.
std::ostringstream fout;
typedef cmComputeLinkInformation::ItemVector ItemVector;
ItemVector const& items = cli.GetItems();
std::string config = cli.GetConfig();
2018-01-26 17:06:56 +01:00
for (auto const& item : items) {
if (!item.Target) {
2017-04-14 19:02:05 +02:00
continue;
}
2017-07-20 19:35:53 +02:00
bool skippable = false;
2018-01-26 17:06:56 +01:00
switch (item.Target->GetType()) {
2017-07-20 19:35:53 +02:00
case cmStateEnums::SHARED_LIBRARY:
case cmStateEnums::MODULE_LIBRARY:
case cmStateEnums::INTERFACE_LIBRARY:
skippable = true;
break;
case cmStateEnums::STATIC_LIBRARY:
// If a static library is resolving its device linking, it should
// be removed for other device linking
skippable =
2018-01-26 17:06:56 +01:00
item.Target->GetPropertyAsBool("CUDA_RESOLVE_DEVICE_SYMBOLS");
2017-07-20 19:35:53 +02:00
break;
default:
break;
}
if (skippable) {
2017-04-14 19:02:05 +02:00
continue;
}
std::set<std::string> langs;
2018-01-26 17:06:56 +01:00
item.Target->GetLanguages(langs, config);
2017-04-14 19:02:05 +02:00
if (langs.count("CUDA") == 0) {
continue;
}
2018-01-26 17:06:56 +01:00
if (item.IsPath) {
2017-04-14 19:02:05 +02:00
fout << this->ConvertToOutputFormat(
2018-01-26 17:06:56 +01:00
this->ConvertToLinkReference(item.Value));
2017-04-14 19:02:05 +02:00
} else {
2018-01-26 17:06:56 +01:00
fout << item.Value;
2017-04-14 19:02:05 +02:00
}
fout << " ";
}
if (!stdLibString.empty()) {
fout << stdLibString << " ";
}
return fout.str();
}
std::string cmLinkLineDeviceComputer::GetLinkerLanguage(cmGeneratorTarget*,
std::string const&)
{
return "CUDA";
}
cmNinjaLinkLineDeviceComputer::cmNinjaLinkLineDeviceComputer(
2017-07-20 19:35:53 +02:00
cmOutputConverter* outputConverter, cmStateDirectory const& stateDir,
2017-04-14 19:02:05 +02:00
cmGlobalNinjaGenerator const* gg)
: cmLinkLineDeviceComputer(outputConverter, stateDir)
, GG(gg)
{
}
std::string cmNinjaLinkLineDeviceComputer::ConvertToLinkReference(
std::string const& lib) const
{
return GG->ConvertToNinjaPath(lib);
}