compile definitions from CL got propagated to NVCC despite COMPILE_LANGUAGES guard
I am on Windows 10, Visual studio 2017, CUDA 9.1, latest cmake nightly build. This is a follow up to #17435 (closed) and I was quite excited with the !1657 (merged) merge, but I am still running into problems. See below minimal code to reproduce the problem.
CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(Example LANGUAGES CXX CUDA)
set(PROJECT_SRCS ${PROJECT_SOURCE_DIR}/mycu.cu)
add_executable(${PROJECT_NAME} ${PROJECT_SRCS})
if(MSVC)
set(CUDA_DISABLE "__pragma(warning(push\\,0))")
set(DISABLE "__pragma(warning(push,0))")
set(ENABLE "__pragma(warning(pop))")
endif()
target_compile_definitions(${PROJECT_NAME} PUBLIC
$<$<COMPILE_LANGUAGE:CXX>:WINDOWS_DISABLE_ALL_WARNING=${DISABLE}>
$<$<COMPILE_LANGUAGE:CUDA>:WINDOWS_DISABLE_ALL_WARNING=${CUDA_DISABLE}>
WINDOWS_ENABLE_ALL_WARNING=${ENABLE})
mycu.cu can be as simple as
WINDOWS_DISABLE_ALL_WARNING
#include <iostream>
WINDOWS_ENABLE_ALL_WARNING
int main(){
return 0;
}
After I build it the error message is
C:/Users/jasju/Desktop/test/mycu.cu(15): fatal error C1001: An internal error has occurred in the compiler. [C:\Users
\jasju\Desktop\test\build\Example.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\BuildCustomizations\CUDA 9.1.t
argets(707,9): error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\bin\nvcc.exe" -genc
ode=arch=compute_30,code=\"sm_30,compute_30\" --use-local-env --cl-version 2017 -ccbin "C:\Program Files (x86)\Microsof
t Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\bin\HostX86\x64" -x cu -I"C:\Program Files\NVIDIA GPU Computi
ng Toolkit\CUDA\v9.1\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\include" --keep-dir x64\De
bug -maxrregcount=0 --machine 64 --compile -cudart static -Xcompiler="/EHsc -Zi -Ob0" -g -D_WINDOWS -D"WINDOWS_DISAB
LE_ALL_WARNING=__pragma(warning(push\,0))" -D"WINDOWS_ENABLE_ALL_WARNING=__pragma(warning(pop))" -D"CMAKE_INTDIR=\"Debu
g\"" -DWIN32 -D_WINDOWS -D"WINDOWS_DISABLE_ALL_WARNING=__pragma(warning(push,0))" -D"WINDOWS_ENABLE_ALL_WARNING=__pragm
a(warning(pop))" -D"CMAKE_INTDIR=\"Debug\"" -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /FS /Zi /RTC1 /MDd /GR" -o Exampl
e.dir\Debug\mycu.cu.obj "C:\Users\jasju\Desktop\test\mycu.cu"" exited with code 2. [C:\Users\jasju\Desktop\test\build\E
xample.vcxproj]
judging from the error message, the compile definitions that is intended for CXX only got passed on to CUDA. Is this a bug in the newly implemented generator expression COMPILE_LANGUAGE
?
Another note is, if I rename mycu.cu
to mycpp.cpp
and run it with the same CMakeLists it is able to get the correct compile definitions and not being affected by the ones intended for CUDA.