From f75bea1071859a74f170f45beb7651dcba1ab18a Mon Sep 17 00:00:00 2001 From: Raul Tambre Date: Sun, 8 Mar 2020 16:34:10 +0200 Subject: CUDA: Abstract language flag to compiler modules Separate this detail out into compiler-specific modules. Required for Clang support, as it uses slightly different language flags. --- Modules/CMakeCUDAInformation.cmake | 10 +++++----- Modules/Compiler/NVIDIA-CUDA.cmake | 2 ++ Modules/Platform/Windows-NVIDIA-CUDA.cmake | 8 ++++---- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Modules/CMakeCUDAInformation.cmake b/Modules/CMakeCUDAInformation.cmake index 974f5fa..f31713e 100644 --- a/Modules/CMakeCUDAInformation.cmake +++ b/Modules/CMakeCUDAInformation.cmake @@ -138,24 +138,24 @@ endif() #Specify how to compile when ptx has been requested if(NOT CMAKE_CUDA_COMPILE_PTX_COMPILATION) set(CMAKE_CUDA_COMPILE_PTX_COMPILATION - " ${_CMAKE_CUDA_EXTRA_FLAGS} -x cu -ptx -o ") + " ${_CMAKE_CUDA_EXTRA_FLAGS} ${_CMAKE_COMPILE_AS_CUDA_FLAG} -ptx -o ") endif() #Specify how to compile when separable compilation has been requested if(NOT CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION) set(CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION - " ${_CMAKE_CUDA_EXTRA_FLAGS} -x cu -dc -o ") + " ${_CMAKE_CUDA_EXTRA_FLAGS} ${_CMAKE_COMPILE_AS_CUDA_FLAG} -dc -o ") endif() #Specify how to compile when whole compilation has been requested if(NOT CMAKE_CUDA_COMPILE_WHOLE_COMPILATION) set(CMAKE_CUDA_COMPILE_WHOLE_COMPILATION - " ${_CMAKE_CUDA_EXTRA_FLAGS} -x cu -c -o ") + " ${_CMAKE_CUDA_EXTRA_FLAGS} ${_CMAKE_COMPILE_AS_CUDA_FLAG} -c -o ") endif() -if(CMAKE_GENERATOR STREQUAL "Ninja" AND NOT CMAKE_DEPFILE_FLAGS_CUDA ) +if(CMAKE_GENERATOR STREQUAL "Ninja" AND NOT CMAKE_DEPFILE_FLAGS_CUDA) set(CMAKE_CUDA_COMPILE_DEPENDENCY_DETECTION - " ${_CMAKE_CUDA_EXTRA_FLAGS} -x cu -M -MT -o $DEP_FILE") + " ${_CMAKE_CUDA_EXTRA_FLAGS} ${_CMAKE_COMPILE_AS_CUDA_FLAG} -M -MT -o $DEP_FILE") #The Ninja generator uses the make file dependency files to determine what #files need to be recompiled. Unfortunately, nvcc < 10.2 doesn't support building #a source file and generating the dependencies of said file in a single diff --git a/Modules/Compiler/NVIDIA-CUDA.cmake b/Modules/Compiler/NVIDIA-CUDA.cmake index 1f4d54d..2a2564e 100644 --- a/Modules/Compiler/NVIDIA-CUDA.cmake +++ b/Modules/Compiler/NVIDIA-CUDA.cmake @@ -4,6 +4,8 @@ set(CMAKE_CUDA_COMPILER_HAS_DEVICE_LINK_PHASE True) set(CMAKE_CUDA_VERBOSE_FLAG "-v") set(CMAKE_CUDA_VERBOSE_COMPILE_FLAG "-Xcompiler=-v") +set(_CMAKE_COMPILE_AS_CUDA_FLAG "-x cu") + if (CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL 10.2.89) # The -forward-unknown-to-host-compiler flag was only # added to nvcc in 10.2 so before that we had no good diff --git a/Modules/Platform/Windows-NVIDIA-CUDA.cmake b/Modules/Platform/Windows-NVIDIA-CUDA.cmake index af43f46..2f50280 100644 --- a/Modules/Platform/Windows-NVIDIA-CUDA.cmake +++ b/Modules/Platform/Windows-NVIDIA-CUDA.cmake @@ -1,11 +1,11 @@ include(Platform/Windows-MSVC) set(CMAKE_CUDA_COMPILE_PTX_COMPILATION - " ${_CMAKE_CUDA_EXTRA_FLAGS} -x cu -ptx -o -Xcompiler=-Fd,-FS") + " ${_CMAKE_CUDA_EXTRA_FLAGS} ${_CMAKE_COMPILE_AS_CUDA_FLAG} -ptx -o -Xcompiler=-Fd,-FS") set(CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION - " ${_CMAKE_CUDA_EXTRA_FLAGS} -x cu -dc -o -Xcompiler=-Fd,-FS") + " ${_CMAKE_CUDA_EXTRA_FLAGS} ${_CMAKE_COMPILE_AS_CUDA_FLAG} -dc -o -Xcompiler=-Fd,-FS") set(CMAKE_CUDA_COMPILE_WHOLE_COMPILATION - " ${_CMAKE_CUDA_EXTRA_FLAGS} -x cu -c -o -Xcompiler=-Fd,-FS") + " ${_CMAKE_CUDA_EXTRA_FLAGS} ${_CMAKE_COMPILE_AS_CUDA_FLAG} -c -o -Xcompiler=-Fd,-FS") set(__IMPLICT_LINKS ) foreach(dir ${CMAKE_CUDA_HOST_IMPLICIT_LINK_DIRECTORIES}) @@ -48,7 +48,7 @@ unset(__IMPLICT_DLINK_DIRS) set(CMAKE_CUDA_DEVICE_LINK_LIBRARY " ${_CMAKE_CUDA_EXTRA_FLAGS} ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink -o -Xcompiler=-Fd,-FS${__IMPLICT_DLINK_FLAGS}") set(CMAKE_CUDA_DEVICE_LINK_EXECUTABLE - " ${_CMAKE_CUDA_EXTRA_FLAGS} ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink -o -Xcompiler=-Fd,-FS${__IMPLICT_DLINK_FLAGS}") + " ${_CMAKE_CUDA_EXTRA_FLAGS} ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink -o -Xcompiler=-Fd,-FS${__IMPLICT_DLINK_FLAGS}") unset(__IMPLICT_DLINK_FLAGS) string(REPLACE "/D" "-D" _PLATFORM_DEFINES_CUDA "${_PLATFORM_DEFINES}${_PLATFORM_DEFINES_CXX}") -- cgit v0.12