| 826 | } |
| 827 | |
| 828 | void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement( |
| 829 | std::string const& config, std::string const& fileConfig, |
| 830 | bool firstForConfig) |
| 831 | { |
| 832 | cmGlobalNinjaGenerator* globalGen = this->GetGlobalGenerator(); |
| 833 | if (!globalGen->GetLanguageEnabled("CUDA")) { |
| 834 | return; |
| 835 | } |
| 836 | |
| 837 | cmGeneratorTarget* genTarget = this->GetGeneratorTarget(); |
| 838 | |
| 839 | bool requiresDeviceLinking = requireDeviceLinking( |
| 840 | *this->GeneratorTarget, *this->GetLocalGenerator(), config); |
| 841 | if (!requiresDeviceLinking) { |
| 842 | return; |
| 843 | } |
| 844 | |
| 845 | // First and very important step is to make sure while inside this |
| 846 | // step our link language is set to CUDA |
| 847 | std::string const& objExt = |
| 848 | this->Makefile->GetSafeDefinition("CMAKE_CUDA_OUTPUT_EXTENSION"); |
| 849 | |
| 850 | std::string targetOutputDir = |
| 851 | this->GetLocalGenerator()->MaybeRelativeToTopBinDir( |
| 852 | cmStrCat(genTarget->GetSupportDirectory(), |
| 853 | globalGen->ConfigDirectory(config), '/')); |
| 854 | targetOutputDir = globalGen->ExpandCFGIntDir(targetOutputDir, config); |
| 855 | |
| 856 | std::string targetOutputReal = |
| 857 | this->ConvertToNinjaPath(targetOutputDir + "cmake_device_link" + objExt); |
| 858 | |
| 859 | if (firstForConfig) { |
| 860 | globalGen->GetByproductsForCleanTarget(config).push_back(targetOutputReal); |
| 861 | } |
| 862 | this->DeviceLinkObject = targetOutputReal; |
| 863 | |
| 864 | // Write comments. |
| 865 | cmGlobalNinjaGenerator::WriteDivider(this->GetCommonFileStream()); |
| 866 | this->GetCommonFileStream() |
| 867 | << "# Device Link build statements for " |
| 868 | << cmState::GetTargetTypeName(genTarget->GetType()) << " target " |
| 869 | << this->GetTargetName() << "\n\n"; |
| 870 | |
| 871 | if (this->Makefile->GetSafeDefinition("CMAKE_CUDA_COMPILER_ID") == "Clang") { |
| 872 | std::string architecturesStr = |
| 873 | this->GeneratorTarget->GetSafeProperty("CUDA_ARCHITECTURES"); |
| 874 | |
| 875 | if (cmIsOff(architecturesStr)) { |
| 876 | this->Makefile->IssueMessage(MessageType::FATAL_ERROR, |
| 877 | "CUDA_SEPARABLE_COMPILATION on Clang " |
| 878 | "requires CUDA_ARCHITECTURES to be set."); |
| 879 | return; |
| 880 | } |
| 881 | |
| 882 | this->WriteDeviceLinkRules(config); |
| 883 | this->WriteDeviceLinkStatements(config, cmList{ architecturesStr }, |
| 884 | targetOutputReal); |
| 885 | } else { |
no test coverage detected