[CMake] CUDA language support with host compiler flags

csiga.biga at aol.com csiga.biga at aol.com
Thu Feb 21 10:23:46 EST 2019


Hi All!
I am trying to compile CUDA code with controlling both host and device compiler flags.
Currently my CMakeLists.txt looks like:
```
cmake_minimum_required(VERSION 3.8) # CUDA language support

project(CUDA_test LANGUAGES CXX CUDA)

if (MSVC)
  string(REGEX REPLACE "/W[0-9]" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
endif (MSVC)

set(Hdrs)

set(Srcs Main.cu)

add_executable(${PROJECT_NAME} ${Hdrs} ${Srcs})

target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

target_compile_options(${PROJECT_NAME} PRIVATE $<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wall -Wextra -pedantic>
                                               $<$<CXX_COMPILER_ID:MSVC>:/W4>)

set_target_properties(${PROJECT_NAME} PROPERTIES CUDA_SEPARABLE_COMPILATION ON
                                                 CUDA_STANDARD 14
                                                 CUDA_STANDARD_REQUIRED ON
                                                 CUDA_EXTENSIONS OFF
                                                 CXX_STANDARD 14
                                                 CXX_STANDARD_REQUIRED ON
                                                 CXX_EXTENSIONS OFF)

source_group ("Headers" FILES ${Hdrs})
source_group ("Sources" FILES ${Srcs})```

However, when I compile the code I get the following error:
[1/3] Building CUDA object CMakeFiles/CUDA_test.dir/Main.cu.o
FAILED: 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 -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
nvcc fatal   : Unknown option 'Wall'
ninja: build stopped: subcommand failed.
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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20190221/47c42c27/attachment.html>


More information about the CMake mailing list