Compiler detection not running in toolchain modified environment?
So I am trying a hack where I want nvcc to use a different llvm then installed by visual studio. After fiddling around I found a setup which works from the command line but the same approach does not work in CMake.
The CMake setup is in my toolchain is:
### CUDA section nvcc
include(CheckLanguage)
check_language(CXX)
set(CUDA_C_COMPILER "${CMAKE_CXX_COMPILER}")
if(NOT CMAKE_CXX_COMPILER MATCHES "/VC/")
# NVCC tries to look for vcvarsall.bat within a parent folder of the compiler within VC/Auxiliary/Build
# So the compiler needs to be within the folder /VC/, so we need to do a little folder dance to achieve that
# Additionally the compiler needs to be the first to be found on PATH
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/llvm-toolchain/VC/Auxiliary/Build")
file(WRITE "${CMAKE_BINARY_DIR}/llvm-toolchain/VC/Auxiliary/Build/vcvarsall.bat" "")
set(cuda_cxx_compiler_path "${CMAKE_BINARY_DIR}/llvm-toolchain/VC/bin")
cmake_path(GET CMAKE_CXX_COMPILER FILENAME cxx_compiler_filename)
cmake_path(GET CMAKE_CXX_COMPILER PARENT_PATH cxx_compiler_filepath)
set(CUDA_C_COMPILER "${cuda_cxx_compiler_path}/${cxx_compiler_filename}")
set(ENV{PATH} "${cuda_cxx_compiler_path};$ENV{PATH}")
execute_process(COMMAND mklink /J "${cuda_cxx_compiler_path}" "${cxx_compiler_filepath}")
#file(CREATE_LINK "${cxx_compiler_filepath}" "${cuda_cxx_compiler_path}" SYMBOLIC)
unset(cxx_compiler_filename)
unset(cxx_compiler_filepath)
unset(cuda_cxx_compiler_path)
string(APPEND CMAKE_CUDA_FLAGS " --use-local-env --allow-unsupported-compiler -ccbin \"${CUDA_C_COMPILER}\"")
endif()
string(APPEND CMAKE_CUDA_FLAGS " -Xcompiler -fuse-ld=lld-link -Xcompiler -std=c++17")
CMAKE_CXX_COMPILER points to clang-cl within the normal installation directory of the LLVM installer.
However compiler detection fails with:
FAILED: CMakeFiles/cmTC_c4cdf.dir/main.cu.obj
E:\all\vcpkg\installed\x64-win-llvm-release\tools\cuda\bin\nvcc.exe -forward-unknown-to-host-compiler --use-local-env --allow-unsupported-compiler -ccbin "E:/all/vcpkg/buildtrees/magma/x64-win-llvm-release-rel/llvm-toolchain/VC/bin/clang-cl.exe" -Xcompiler -fuse-ld=lld-link -Xcompiler -std=c++17 -Xcompiler="-O2 -Ob2" -DNDEBUG "--generate-code=arch=compute_52,code=[compute_52,sm_52]" -Xcompiler=-MD -MD -MT CMakeFiles\cmTC_c4cdf.dir\main.cu.obj -MF CMakeFiles\cmTC_c4cdf.dir\main.cu.obj.d -x cu -c E:\all\vcpkg\buildtrees\magma\x64-win-llvm-release-rel\CMakeFiles\CMakeScratch\TryCompile-8d3a93\main.cu -o CMakeFiles\cmTC_c4cdf.dir\main.cu.obj -Xcompiler=-FdCMakeFiles\cmTC_c4cdf.dir\,-FS
nvcc fatal : cl.exe in PATH (C:/Program Files/LLVM/bin) is different than one specified with -ccbin (E:/all/vcpkg/buildtrees/magma/x64-win-llvm-release-rel/llvm-toolchain/VC/bin)
ninja: build stopped: subcommand failed.
Which basically means that nvcc does not the the environment modification of PATH done in the toolchain via set(ENV{PATH} "${cuda_cxx_compiler_path};$ENV{PATH}")