nvcc fatal : Compiler 'cl.exe' in PATH different than the one specified with -ccbin

I have been trying to use CUDA in my CMake project, but I had no luck.
I have used the -ccbin flag to specify my host compiler but nvcc looks for the compiler in the PATH variable.
Plus I have added my host compiler to my PATH variable.
I am using CUDA 9.0 with Windows 10 + NVidia GeForce 740M.

CMakeLists.txt :

cmake_minimum_required(VERSION 3.14)

set(CMAKE_CUDA_HOST_COMPILER  "F:/Visual Studio Program Files/Microsoft Visual Studio/2017/VC/Tools/MSVC/14.11.25503/bin/HostX86/x86")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --use-local-env --cl-version 2017")

project(hybridzip LANGUAGES CXX CUDA)
set(CMAKE_CXX_STANDARD 14)

include_directories("C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.0/include/")

add_executable(hybridzip main.cpp)
set_target_properties(hybridzip PROPERTIES CUDA_SEPARABLE_COMPILATION ON)

This is the full CMake log:

"C:\Program Files\CMake\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug "-DCMAKE_MAKE_PROGRAM=F:/Visual Studio Program Files/Microsoft Visual Studio/2017/VC/Tools/MSVC/14.11.25503/bin/HostX86/x86/nmake.exe" "-DCMAKE_C_COMPILER=F:/Visual Studio Program Files/Microsoft Visual Studio/2017/VC/Tools/MSVC/14.11.25503/bin/HostX86/x86/cl.exe" "-DCMAKE_CXX_COMPILER=F:/Visual Studio Program Files/Microsoft Visual Studio/2017/VC/Tools/MSVC/14.11.25503/bin/HostX86/x86/cl.exe" -G "CodeBlocks - NMake Makefiles" F:\hybridzip
-- The CXX compiler identification is MSVC 19.11.25548.2
-- The CUDA compiler identification is unknown
-- Check for working CXX compiler: F:/Visual Studio Program Files/Microsoft Visual Studio/2017/VC/Tools/MSVC/14.11.25503/bin/HostX86/x86/cl.exe
-- Check for working CXX compiler: F:/Visual Studio Program Files/Microsoft Visual Studio/2017/VC/Tools/MSVC/14.11.25503/bin/HostX86/x86/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.0/bin/nvcc.exe
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.0/bin/nvcc.exe -- broken
CMake Error at C:/Program Files/CMake/share/cmake-3.15/Modules/CMakeTestCUDACompiler.cmake:46 (message):
  The CUDA compiler

    "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.0/bin/nvcc.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: F:/hybridzip/cmake-build-debug/CMakeFiles/CMakeTmp
    
    Run Build Command(s):F:/Visual Studio Program Files/Microsoft Visual Studio/2017/VC/Tools/MSVC/14.11.25503/bin/HostX86/x86/nmake.exe /nologo cmTC_2cb71\fast && 	"F:\Visual Studio Program Files\Microsoft Visual Studio017\VC\Tools\MSVC4.11.25503\bin\HostX86\x86\nmake.exe" -f CMakeFiles\cmTC_2cb71.dir\build.make /nologo -L                  CMakeFiles\cmTC_2cb71.dir\build
    Building CUDA object CMakeFiles/cmTC_2cb71.dir/main.cu.obj
    	C:\PROGRA~1\NVIDIA~2\CUDA\v9.0\bin\nvcc.exe -ccbin="F:\Visual Studio Program Files\Microsoft Visual Studio017\VC\Tools\MSVC4.11.25503\bin\HostX86\x86"   --use-local-env --cl-version 2017 -x cu -c F:\hybridzip\cmake-build-debug\CMakeFiles\CMakeTmp\main.cu -o CMakeFiles\cmTC_2cb71.dir\main.cu.obj
    nvcc fatal   : Compiler 'cl.exe' in PATH different than the one specified with -ccbin
    NMAKE : fatal error U1077: 'C:\PROGRA~1\NVIDIA~2\CUDA\v9.0\bin\nvcc.exe' : return code '0x1'
    Stop.
    NMAKE : fatal error U1077: '"F:\Visual Studio Program Files\Microsoft Visual Studio017\VC\Tools\MSVC4.11.25503\bin\HostX86\x86\nmake.exe"' : return code '0x2'
    Stop.
    
    

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:6 (project)


-- Configuring incomplete, errors occurred!
See also "F:/hybridzip/cmake-build-debug/CMakeFiles/CMakeOutput.log".
See also "F:/hybridzip/cmake-build-debug/CMakeFiles/CMakeError.log".

[Finished]

I have been trying to crack this for two days now, but I had no luck.
Any help is appreciated.

You need to make sure the cl.exe found by traversing the path provided by -ccbin matches the cl.exe found by traversing your PATH variable.

What do you mean by that?
i have a similar error in cmake

The CUDA compiler identification is unknown

Detecting CUDA compiler ABI info
Detecting CUDA compiler ABI info - failed
Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2/bin/nvcc.exe
Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2/bin/nvcc.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-3.18/Modules/CMakeTestCUDACompiler.cmake:52 (message):
The CUDA compiler

"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2/bin/nvcc.exe"

is not able to compile a simple test program.

It fails with the following output:

Change Dir: C:/Users/Panagiotis/PycharmProjects/darknet-master/build/CMakeFiles/CMakeTmp

Run Build Command(s):C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/MSBuild/15.0/Bin/MSBuild.exe cmTC_be208.vcxproj /p:Configuration=Debug /p:Platform=Win32 /p:VisualStudioVersion=15.0 /v:m && Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework

Copyright (C) Microsoft Corporation. All rights reserved.



  Compiling CUDA source file main.cu...

  

  C:\Users\Panagiotis\PycharmProjects\darknet-master\build\CMakeFiles\CMakeTmp>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\bin\nvcc.exe" -gencode=arch=compute_30,code=\"sm_30,compute_30\" --use-local-env -ccbin "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86" -x cu   -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\include"     --keep-dir Debug -maxrregcount=0  --machine 32 --compile -cudart none set(CMAKE_CUDA_FLAGS ""$"{CMAKE_CUDA_FLAGS} --ptxas-options=-v)" CUDA_NVCC_FLAGS_DEBUG -g   -D"CMAKE_INTDIR=\"Debug\"" -D"CMAKE_INTDIR=\"Debug\"" -D_MBCS -Xcompiler "/EHsc /W1 /nologo /O2 /FdcmTC_be208.dir\Debug\vc141.pdb /FS /Zi  /MD " -o cmTC_be208.dir\Debug\main.obj "C:\Users\Panagiotis\PycharmProjects\darknet-master\build\CMakeFiles\CMakeTmp\main.cu" 

  nvcc fatal   : A single input file is required for a non-link phase when an outputfile is specified

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\BuildCustomizations\CUDA 10.2.targets(764,9): error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\bin\nvcc.exe" -gencode=arch=compute_30,code=\"sm_30,compute_30\" --use-local-env -ccbin "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86" -x cu   -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\include"     --keep-dir Debug -maxrregcount=0  --machine 32 --compile -cudart none set(CMAKE_CUDA_FLAGS ""$"{CMAKE_CUDA_FLAGS} --ptxas-options=-v)" CUDA_NVCC_FLAGS_DEBUG -g   -D"CMAKE_INTDIR=\"Debug\"" -D"CMAKE_INTDIR=\"Debug\"" -D_MBCS -Xcompiler "/EHsc /W1 /nologo /O2 /FdcmTC_be208.dir\Debug\vc141.pdb /FS /Zi  /MD " -o cmTC_be208.dir\Debug\main.obj "C:\Users\Panagiotis\PycharmProjects\darknet-master\build\CMakeFiles\CMakeTmp\main.cu"" exited with code 1. [C:\Users\Panagiotis\PycharmProjects\darknet-master\build\CMakeFiles\CMakeTmp\cmTC_be208.vcxproj]

CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:66 (enable_language)

I’ve found few machines where NVCC fails to compile CUDA examples with
nvcc fatal : Compiler ‘cl.exe’ in PATH different than the one specified with -ccbin
or simply errorlevel 1

Reason was in anaconda setting
HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun

see

for explanation