CUDA: Detection fails on Windows with Ninja even if CUDA_PATH is available
When building a CUDA-enabled project under Windows using the Ninja generator, CMake requires nvcc
to be in the Path
environment variable even if we could determine its location based on the CUDA_PATH
environment variable instead.
As far as I can tell, _cmake_find_compiler
doesn't allow for custom search paths, so fixing this would require at least a small amount of refactoring. Before I open up an MR, I wanted to discuss how to approach this first.
For some context, I am building a package using vcpkg
, where the Path
variable gets overwritten by default, so I need to rely on other variables instead.
I confirmed that this is the issue by the following hacky modification, after which the package built correctly.
diff --git a/Modules/CMakeDetermineCompiler.cmake b/Modules/CMakeDetermineCompiler.cmake
index 2780399dcc..2181089ff7 100644
--- a/Modules/CMakeDetermineCompiler.cmake
+++ b/Modules/CMakeDetermineCompiler.cmake
@@ -61,6 +61,7 @@ macro(_cmake_find_compiler lang)
NAMES ${CMAKE_${lang}_COMPILER_LIST}
NAMES_PER_DIR
DOC "${lang} compiler"
+ PATHS "$ENV{CUDA_PATH}/bin"
NO_PACKAGE_ROOT_PATH
NO_CMAKE_PATH
NO_CMAKE_ENVIRONMENT_PATH