I’m trying to use CUDA with clang-cl (or just plain cl.exe) on Windows, using Mark Schofield’s Windows toolchain. The toolchain finds cl.exe, but then when CMake tries to find CUDA it fails, because nvcc can’t find compiler cl.exe in $PATH.
I think the same thing happens at build time, because cmake doesn’t set $PATH before invoking ninja.
How can I set my project up so cl.exe is on $PATH both while reading the CMakefiles and when running the build?
There’s no mechanism to do so (unless cmake --build $dir is the way to run the build).
Note that CMake expects the environment to support running the compiler as needed. MSVC has this as a persistent requirement and other platforms work because the default environment “works”. However, when using module load on Unix machines or DEVELOPER_DIR= to choose an Xcode toolchain on macOS, the environment needs to be consistent between compiler detection and use. CMake cannot know what all matters from the environment nor how to persist it to the build in a local way (e.g., xcode-select can change default toolchain behaviors on macOS behind CMake’s back).
Hey, @garyo, thanks for taking a look at my WindowsToolchain project.
I guess the best way on Windows is to open a developer prompt and work from there.
Yes. If you want an ‘off the shelf’ solution then your best bet is either:
Use CMake with a Visual Studio Generator.
Use CMake with a Ninja generator, running from a Visual Studio command-prompt.
The WindowsToolchain project is an attempt at getting the best of both worlds - Ninja builds are (from my experience) faster than MSBuild builds, and the WindowsToolchain avoids having to configure/change environment variables to configure builds.
That being said, WindowsToolchain just added some basic support for CUDA compilation - with the help of a contributor to the project, we worked to make it easier to use the Toolchain with CUDA. Take a look at #106 from the project for more details.