Build: Fix finding nvcc (if not in $PATH) with older versions of CMake #3682
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.
In #3444 we've added a mechanism that helps CMake find
nvcc
when it's missing in$PATH
, but the CUDA toolkit can still be found at a typical location. It has now been observed that this does not work as intended on older versions of CMake like 3.13 or 3.16 (#3545).CMake would go into an infinite loop with messages like
NOTFOUND
is the initial value assigned toCMAKE_CUDA_COMPILER
bycheck_language
, which is written to CMake's build cache then. We override it to a proper valueset(CMAKE_CUDA_COMPILER "${CUDAToolkit_BIN_DIR}/nvcc")
, but this change only appears to be effective with more recent versions of cmake (I was using 3.23).In my tests with CMake 3.13 and 3.16 the problem is resolved by clearing the
CMAKE_CUDA_COMPILER
variable from the cache before setting it to a new value.Similar infinite loops have been reported earlier (https://public.kitware.com/Bug/view.php?id=14841) and it has been discouraged to override
CMAKE_<LANG>_COMPILER
insideCMakeLists.txt
, but I'd still prefer to contain this logic inside the CMake script.Fixes #3545