From 20807a188299b5f070cf145e40539a30761975ff Mon Sep 17 00:00:00 2001 From: Raul Tambre Date: Tue, 24 Nov 2020 18:50:32 +0200 Subject: CUDA: Fix user-set architectures during detection with Visual Studio If the user specifies CMAKE_CUDA_ARCHITECTURES we use those during detection and error out if they don't work. For Visual Studio a dummy project file is used instead of invoking the compiler directly. NVCC would thus use its default and we'd fail if CMAKE_CUDA_ARCHITECTURES was anything other than NVCC's default. Use the necessary project file variable in CMakeDetermineCompilerId.cmake to match other generators. Fixes #21492. --- Modules/CMakeDetermineCompilerId.cmake | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index 44332a6..1feaf91 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -368,7 +368,14 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS} endif() set(cuda_tools "CUDA ${CMAKE_VS_PLATFORM_TOOLSET_CUDA}") set(id_compile "CudaCompile") - set(id_ItemDefinitionGroup_entry "%(AdditionalOptions)-v") + if(CMAKE_VS_PLATFORM_NAME STREQUAL x64) + set(cuda_target "64") + endif() + foreach(arch ${CMAKE_CUDA_ARCHITECTURES}) + string(REGEX MATCH "[0-9]+" arch_name "${arch}") + string(APPEND cuda_codegen "compute_${arch_name},sm_${arch_name};") + endforeach() + set(id_ItemDefinitionGroup_entry "${cuda_target}%(AdditionalOptions)-v${cuda_codegen}") set(id_PostBuildEvent_Command [[echo CMAKE_CUDA_COMPILER=$(CudaToolkitBinDir)\nvcc.exe]]) if(CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR) set(id_CudaToolkitCustomDir "${CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR}nvcc") @@ -378,9 +385,6 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS} string(CONCAT id_Import_props [[]]) string(CONCAT id_Import_targets [[]]) endif() - if(CMAKE_VS_PLATFORM_NAME STREQUAL x64) - set(id_ItemDefinitionGroup_entry "64%(AdditionalOptions)-v") - endif() if(CMAKE_CUDA_FLAGS MATCHES "(^| )-cudart +shared( |$)") set(id_Link_AdditionalDependencies "cudart.lib") else() -- cgit v0.12