|  | @@ -3,6 +3,7 @@
 | 
	
		
			
				|  |  |  #include "cmNinjaTargetGenerator.h"
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  #include <algorithm>
 | 
	
		
			
				|  |  | +#include <array>
 | 
	
		
			
				|  |  |  #include <cassert>
 | 
	
		
			
				|  |  |  #include <functional>
 | 
	
		
			
				|  |  |  #include <iterator>
 | 
	
	
		
			
				|  | @@ -859,11 +860,22 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang,
 | 
	
		
			
				|  |  |          this->Makefile->GetRequiredDefinition("_CMAKE_CUDA_RDC_FLAG");
 | 
	
		
			
				|  |  |        cudaCompileMode = cmStrCat(cudaCompileMode, rdcFlag, " ");
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | -    if (this->GeneratorTarget->GetPropertyAsBool("CUDA_PTX_COMPILATION")) {
 | 
	
		
			
				|  |  | -      const std::string& ptxFlag =
 | 
	
		
			
				|  |  | -        this->Makefile->GetRequiredDefinition("_CMAKE_CUDA_PTX_FLAG");
 | 
	
		
			
				|  |  | -      cudaCompileMode = cmStrCat(cudaCompileMode, ptxFlag);
 | 
	
		
			
				|  |  | -    } else {
 | 
	
		
			
				|  |  | +    static std::array<cm::string_view, 4> const compileModes{
 | 
	
		
			
				|  |  | +      { "PTX"_s, "CUBIN"_s, "FATBIN"_s, "OPTIX"_s }
 | 
	
		
			
				|  |  | +    };
 | 
	
		
			
				|  |  | +    bool useNormalCompileMode = true;
 | 
	
		
			
				|  |  | +    for (cm::string_view mode : compileModes) {
 | 
	
		
			
				|  |  | +      auto propName = cmStrCat("CUDA_", mode, "_COMPILATION");
 | 
	
		
			
				|  |  | +      auto defName = cmStrCat("_CMAKE_CUDA_", mode, "_FLAG");
 | 
	
		
			
				|  |  | +      if (this->GeneratorTarget->GetPropertyAsBool(propName)) {
 | 
	
		
			
				|  |  | +        const std::string& flag =
 | 
	
		
			
				|  |  | +          this->Makefile->GetRequiredDefinition(defName);
 | 
	
		
			
				|  |  | +        cudaCompileMode = cmStrCat(cudaCompileMode, flag);
 | 
	
		
			
				|  |  | +        useNormalCompileMode = false;
 | 
	
		
			
				|  |  | +        break;
 | 
	
		
			
				|  |  | +      }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    if (useNormalCompileMode) {
 | 
	
		
			
				|  |  |        const std::string& wholeFlag =
 | 
	
		
			
				|  |  |          this->Makefile->GetRequiredDefinition("_CMAKE_CUDA_WHOLE_FLAG");
 | 
	
		
			
				|  |  |        cudaCompileMode = cmStrCat(cudaCompileMode, wholeFlag);
 | 
	
	
		
			
				|  | @@ -1789,11 +1801,22 @@ void cmNinjaTargetGenerator::ExportObjectCompileCommand(
 | 
	
		
			
				|  |  |          this->Makefile->GetRequiredDefinition("_CMAKE_CUDA_RDC_FLAG");
 | 
	
		
			
				|  |  |        cudaCompileMode = cmStrCat(cudaCompileMode, rdcFlag, " ");
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | -    if (this->GeneratorTarget->GetPropertyAsBool("CUDA_PTX_COMPILATION")) {
 | 
	
		
			
				|  |  | -      const std::string& ptxFlag =
 | 
	
		
			
				|  |  | -        this->Makefile->GetRequiredDefinition("_CMAKE_CUDA_PTX_FLAG");
 | 
	
		
			
				|  |  | -      cudaCompileMode = cmStrCat(cudaCompileMode, ptxFlag);
 | 
	
		
			
				|  |  | -    } else {
 | 
	
		
			
				|  |  | +    static std::array<cm::string_view, 4> const compileModes{
 | 
	
		
			
				|  |  | +      { "PTX"_s, "CUBIN"_s, "FATBIN"_s, "OPTIX"_s }
 | 
	
		
			
				|  |  | +    };
 | 
	
		
			
				|  |  | +    bool useNormalCompileMode = true;
 | 
	
		
			
				|  |  | +    for (cm::string_view mode : compileModes) {
 | 
	
		
			
				|  |  | +      auto propName = cmStrCat("CUDA_", mode, "_COMPILATION");
 | 
	
		
			
				|  |  | +      auto defName = cmStrCat("_CMAKE_CUDA_", mode, "_FLAG");
 | 
	
		
			
				|  |  | +      if (this->GeneratorTarget->GetPropertyAsBool(propName)) {
 | 
	
		
			
				|  |  | +        const std::string& flag =
 | 
	
		
			
				|  |  | +          this->Makefile->GetRequiredDefinition(defName);
 | 
	
		
			
				|  |  | +        cudaCompileMode = cmStrCat(cudaCompileMode, flag);
 | 
	
		
			
				|  |  | +        useNormalCompileMode = false;
 | 
	
		
			
				|  |  | +        break;
 | 
	
		
			
				|  |  | +      }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    if (useNormalCompileMode) {
 | 
	
		
			
				|  |  |        const std::string& wholeFlag =
 | 
	
		
			
				|  |  |          this->Makefile->GetRequiredDefinition("_CMAKE_CUDA_WHOLE_FLAG");
 | 
	
		
			
				|  |  |        cudaCompileMode = cmStrCat(cudaCompileMode, wholeFlag);
 |