cmLinkLineDeviceComputer.cxx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmLinkLineDeviceComputer.h"
  4. #include <sstream>
  5. #include "cmAlgorithms.h"
  6. #include "cmComputeLinkInformation.h"
  7. #include "cmGeneratorTarget.h"
  8. #include "cmGlobalNinjaGenerator.h"
  9. #include "cmStateTypes.h"
  10. class cmOutputConverter;
  11. cmLinkLineDeviceComputer::cmLinkLineDeviceComputer(
  12. cmOutputConverter* outputConverter, cmStateDirectory const& stateDir)
  13. : cmLinkLineComputer(outputConverter, stateDir)
  14. {
  15. }
  16. cmLinkLineDeviceComputer::~cmLinkLineDeviceComputer()
  17. {
  18. }
  19. std::string cmLinkLineDeviceComputer::ComputeLinkLibraries(
  20. cmComputeLinkInformation& cli, std::string const& stdLibString)
  21. {
  22. // Write the library flags to the build rule.
  23. std::ostringstream fout;
  24. typedef cmComputeLinkInformation::ItemVector ItemVector;
  25. ItemVector const& items = cli.GetItems();
  26. std::string config = cli.GetConfig();
  27. for (auto const& item : items) {
  28. if (item.Target) {
  29. bool skip = false;
  30. switch (item.Target->GetType()) {
  31. case cmStateEnums::MODULE_LIBRARY:
  32. case cmStateEnums::INTERFACE_LIBRARY:
  33. skip = true;
  34. break;
  35. case cmStateEnums::STATIC_LIBRARY:
  36. skip = item.Target->GetPropertyAsBool("CUDA_RESOLVE_DEVICE_SYMBOLS");
  37. break;
  38. default:
  39. break;
  40. }
  41. if (skip) {
  42. continue;
  43. }
  44. }
  45. if (item.IsPath) {
  46. // nvcc understands absolute paths to libraries ending in '.a' should
  47. // be passed to nvlink. Other extensions like '.so' or '.dylib' are
  48. // rejected by the nvcc front-end even though nvlink knows to ignore
  49. // them. Bypass the front-end via '-Xnvlink'.
  50. if (!cmHasLiteralSuffix(item.Value, ".a")) {
  51. fout << "-Xnvlink ";
  52. }
  53. fout << this->ConvertToOutputFormat(
  54. this->ConvertToLinkReference(item.Value));
  55. } else {
  56. fout << item.Value;
  57. }
  58. fout << " ";
  59. }
  60. if (!stdLibString.empty()) {
  61. fout << stdLibString << " ";
  62. }
  63. return fout.str();
  64. }
  65. std::string cmLinkLineDeviceComputer::GetLinkerLanguage(cmGeneratorTarget*,
  66. std::string const&)
  67. {
  68. return "CUDA";
  69. }
  70. cmNinjaLinkLineDeviceComputer::cmNinjaLinkLineDeviceComputer(
  71. cmOutputConverter* outputConverter, cmStateDirectory const& stateDir,
  72. cmGlobalNinjaGenerator const* gg)
  73. : cmLinkLineDeviceComputer(outputConverter, stateDir)
  74. , GG(gg)
  75. {
  76. }
  77. std::string cmNinjaLinkLineDeviceComputer::ConvertToLinkReference(
  78. std::string const& lib) const
  79. {
  80. return GG->ConvertToNinjaPath(lib);
  81. }