<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<font size="2" face="arial" color="black">
<div><font size="2">Hi All!</font></div>
<div><font size="2"><br>
</font></div>
<div><font size="2">I am trying to compile CUDA code with
controlling both host and device compiler flags.</font></div>
<div><font size="2"><br>
</font></div>
<div><font size="2">Currently my CMakeLists.txt looks like:</font></div>
<div><font size="2"><br>
</font></div>
<div><font size="2">```<br>
</font></div>
<div><font size="2">cmake_minimum_required(VERSION 3.8) # CUDA
language support<br>
<br>
project(CUDA_test LANGUAGES CXX CUDA)<br>
<br>
if (MSVC)<br>
string(REGEX REPLACE "/W[0-9]" "" CMAKE_CXX_FLAGS
${CMAKE_CXX_FLAGS})<br>
endif (MSVC)<br>
<br>
set(Hdrs)<br>
<br>
set(Srcs Main.cu)<br>
<br>
add_executable(${PROJECT_NAME} ${Hdrs} ${Srcs})<br>
<br>
target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR})<br>
<br>
target_compile_options(${PROJECT_NAME} PRIVATE
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wall
-Wextra -pedantic><br>
$<$<CXX_COMPILER_ID:MSVC>:/W4>)<br>
<br>
set_target_properties(${PROJECT_NAME} PROPERTIES
CUDA_SEPARABLE_COMPILATION ON<br>
CUDA_STANDARD
14<br>
CUDA_STANDARD_REQUIRED ON<br>
CUDA_EXTENSIONS OFF<br>
CXX_STANDARD
14<br>
CXX_STANDARD_REQUIRED ON<br>
CXX_EXTENSIONS OFF)<br>
<br>
source_group ("Headers" FILES ${Hdrs})<br>
source_group ("Sources" FILES ${Srcs})</font></div>
<div><font size="2">```<br>
</font></div>
<div><font size="2"><br>
</font></div>
<div><font size="2">However, when I compile the code I get the
following error:</font></div>
<div><font size="2"><br>
</font></div>
<div><font size="2">[1/3] Building CUDA object
CMakeFiles/CUDA_test.dir/Main.cu.o<br>
FAILED: CMakeFiles/CUDA_test.dir/Main.cu.o <br>
/usr/bin/nvcc
-I/var/tmp/src/e75971a9-7e91-6137-abfa-df34048cc171/GCC-Debug-WSL
-g -Wall -Wextra -pedantic -std=c++14 -x cu -dc
/var/tmp/src/e75971a9-7e91-6137-abfa-df34048cc171/GCC-Debug-WSL/Main.cu
-o CMakeFiles/CUDA_test.dir/Main.cu.o &&
/usr/bin/nvcc
-I/var/tmp/src/e75971a9-7e91-6137-abfa-df34048cc171/GCC-Debug-WSL
-g -Wall -Wextra -pedantic -std=c++14 -x cu -M
/var/tmp/src/e75971a9-7e91-6137-abfa-df34048cc171/GCC-Debug-WSL/Main.cu
-MT CMakeFiles/CUDA_test.dir/Main.cu.o -o
CMakeFiles/CUDA_test.dir/Main.cu.o.d<br>
nvcc fatal : Unknown option 'Wall'<br>
ninja: build stopped: subcommand failed.</font></div>
<div><font size="2"><br>
</font></div>
<div><font size="2">CMake seems to pass -Wall -Wextra -pedantic to
the device compiler as well, even though it is neither GNU nor
Clang, but CUDA. How can I specify warning and similar flags
separatly for the host and device compilers?<br>
</font></div>
</font>
</body>
</html>