From 8e38985db7cb2c66f7fe74919e03e3f3ae0d0c41 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 7 Apr 2021 09:50:10 -0400 Subject: Makefiles: Fix dependency extraction with CUDA < 10.2 and host compiler Since commit 2c71d051fa (Makefiles Generators: use compiler for dependencies generation, 2020-10-18, v3.20.0-rc1~392^2) we invoke `nvcc` for CUDA < 10.2 a second time in order to generate a depfile. When `CMAKE_CUDA_HOST_COMPILER` is set, the second invocation is missing its `-ccbin=` option, even after refactoring in commit 8981e3e7cc (NVIDIA-CUDA: rely on new capabilities for deps generation, 2020-12-02, v3.20.0-rc1~362^2). Ideally we should move the `-ccbin=` flag into `Compiler/NVIDIA-CUDA`, but that will add `CMAKE_CUDA_HOST_COMPILER` support on Windows in command-line generators but not the Visual Studio generators. For now, add the flag to the depfile command specifically. Fixes: #22037 --- Modules/CMakeCUDAInformation.cmake | 3 +++ Modules/Compiler/NVIDIA-CUDA.cmake | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Modules/CMakeCUDAInformation.cmake b/Modules/CMakeCUDAInformation.cmake index cb03ef4..5fd54c1 100644 --- a/Modules/CMakeCUDAInformation.cmake +++ b/Modules/CMakeCUDAInformation.cmake @@ -111,6 +111,9 @@ include(CMakeCommonLanguageInclude) # CMAKE_CUDA_LINK_EXECUTABLE if(CMAKE_CUDA_HOST_COMPILER AND CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA") + # FIXME: This is too late for the Platform/Windows-NVIDIA-CUDA module to + # see it, so we do not support CMAKE_CUDA_HOST_COMPILER on Windows. + # Move this to Compiler/NVIDIA-CUDA and update the VS generator too. string(APPEND _CMAKE_CUDA_EXTRA_FLAGS " -ccbin=") endif() diff --git a/Modules/Compiler/NVIDIA-CUDA.cmake b/Modules/Compiler/NVIDIA-CUDA.cmake index eb80675..a0f7c05 100644 --- a/Modules/Compiler/NVIDIA-CUDA.cmake +++ b/Modules/Compiler/NVIDIA-CUDA.cmake @@ -30,7 +30,15 @@ if (CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL 10.2.89) # to get header dependency information set(CMAKE_DEPFILE_FLAGS_CUDA "-MD -MT -MF ") else() - set(CMAKE_CUDA_DEPENDS_EXTRA_COMMANDS " ${_CMAKE_CUDA_EXTRA_FLAGS} ${_CMAKE_COMPILE_AS_CUDA_FLAG} -M -MT -o ") + if(CMAKE_CUDA_HOST_COMPILER AND NOT CMAKE_SYSTEM_NAME STREQUAL "Windows") + # FIXME: Move the main -ccbin= flag from CMakeCUDAInformation to + # a block above, remove this copy, and update the VS generator too. + set(_CMAKE_CUDA_EXTRA_FLAGS_LOCAL " -ccbin=") + else() + set(_CMAKE_CUDA_EXTRA_FLAGS_LOCAL "") + endif() + set(CMAKE_CUDA_DEPENDS_EXTRA_COMMANDS " ${_CMAKE_CUDA_EXTRA_FLAGS}${_CMAKE_CUDA_EXTRA_FLAGS_LOCAL} ${_CMAKE_COMPILE_AS_CUDA_FLAG} -M -MT -o ") + unset(_CMAKE_CUDA_EXTRA_FLAGS_LOCAL) endif() set(CMAKE_CUDA_DEPFILE_FORMAT gcc) if((NOT DEFINED CMAKE_DEPENDS_USE_COMPILER OR CMAKE_DEPENDS_USE_COMPILER) -- cgit v0.12