Use specific CMAKE_CUDA_COMPILER instead of forcing CMake to use the same compiler for both CXX and CUDA #1710
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Kind of a niche feature, I think. The idea behind the change is that CUDA compiler should be separate from CXX compiler, simply because then the user will be able to use
-DCMAKE_CUDA_COMPILER=/specific/cuda/cc
.Made this change because
nvcc
doesn't like the latest GCC release in the package manager. However, conveniently there existsgcc13
package, that containsgcc-13.x
versions. The issue is that CMake will want to use latest GCC for CXX, but due to specifying the compiler for CUDA as the same as compiler for CXX, CUDA will not be able to properly compile on latest GCC releases.Solution? Simple! Just use the CMake's built-in
CMAKE_<LANG>_COMPILER
for handling the compiler specification for every language that is used in the CMake project.This way, CMake can decide what compiler to use for CUDA on its own, or users will be able to specify the host compiler for
nvcc
using the-DCMAKE_CUDA_COMPILER=/specific/cuda/cc
flag.Additional changes:
-std
have the same value as the project'sCMAKE_CXX_STANDARD
for consistency. (Could possibly useset(CMAKE_CUDA_STANDARD 17)
instead oflist(APPEND CUDA_NVCC_FLAGS "-std=c++${CMAKE_CXX_STANDARD}")
, but not sure if it would work as expected?)