Search code examples
c++cmakecudaclangnvcc

How to make CMake use clang for CUDA to support c++17


According to this question, it is possible to use c++17 with cuda by using clang. However, I couldn't find how to setup CMakeLists.txt to accomplish this.

I enable c++17 with

add_compile_options(-std=c++17)

Out of the box with the following

    enable_language(CUDA)

nvcc complains

nvcc fatal   : Value 'c++17' is not defined for option 'std'

Adding the following as suggested here

    set(CUDA_HOST_COMPILER clang++)
    set(CMAKE_CUDA_COMPILER /usr/bin/clang++)

clang to complain

clang: error: language not recognized: 'cu'

Solution

  • Try

    set(CMAKE_CXX_STANDARD 17)