Bladeren bron

Merge topic 'cuda_vs_skip_computation' into release-3.19

dd77dec18d VS: Don't compute CUDA options unless necessary
e9109dec36 Merge branch 'ninja-multi-per-config-sources' into release-3.18
7c0de4175b Merge branch 'cmake-E-cat-binary' into release-3.18

Acked-by: Kitware Robot <[email protected]>
Merge-request: !5422
Brad King 5 jaren geleden
bovenliggende
commit
8d6a0b9364

+ 8 - 0
Source/cmGeneratorTarget.cxx

@@ -7240,6 +7240,14 @@ void cmGeneratorTarget::GetLanguages(std::set<std::string>& languages,
   }
 }
 
+bool cmGeneratorTarget::IsLanguageUsed(std::string const& language,
+                                       std::string const& config) const
+{
+  std::set<std::string> languages;
+  this->GetLanguages(languages, config);
+  return languages.count(language);
+}
+
 bool cmGeneratorTarget::IsCSharpOnly() const
 {
   // Only certain target types may compile CSharp.

+ 2 - 0
Source/cmGeneratorTarget.h

@@ -417,6 +417,8 @@ public:
   // until we have per-target object file properties.
   void GetLanguages(std::set<std::string>& languages,
                     std::string const& config) const;
+  bool IsLanguageUsed(std::string const& language,
+                      std::string const& config) const;
 
   bool IsCSharpOnly() const;
 

+ 4 - 2
Source/cmVisualStudio10TargetGenerator.cxx

@@ -3078,7 +3078,8 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions()
     return true;
   }
   for (std::string const& c : this->Configurations) {
-    if (!this->ComputeCudaOptions(c)) {
+    if (this->GeneratorTarget->IsLanguageUsed("CUDA", c) &&
+        !this->ComputeCudaOptions(c)) {
       return false;
     }
   }
@@ -3218,7 +3219,8 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions(
 void cmVisualStudio10TargetGenerator::WriteCudaOptions(
   Elem& e1, std::string const& configName)
 {
-  if (!this->MSTools || !this->GlobalGenerator->IsCudaEnabled()) {
+  if (!this->MSTools || !this->GlobalGenerator->IsCudaEnabled() ||
+      !this->GeneratorTarget->IsLanguageUsed("CUDA", configName)) {
     return;
   }
   Elem e2(e1, "CudaCompile");

+ 4 - 0
Tests/RunCMake/CMP0104/CMP0104-Common.cmake

@@ -1,2 +1,6 @@
+# Make sure CMP0104 isn't issued for CXX targets created prior to enabling CUDA. See #21341.
+enable_language(CXX)
+add_library(cxx main.cxx)
+
 enable_language(CUDA)
 add_library(cuda main.cu)

+ 3 - 0
Tests/RunCMake/CMP0104/main.cxx

@@ -0,0 +1,3 @@
+int main()
+{
+}