I am trying to build a program with some CUDA files using C++20 language standard on Ubuntu 20.04 LTS (Focal Fossa) with nvidia/cuda:12.1.0-devel-ubuntu20.04:
The CUDA compiler identification is NVIDIA 12.1.105
First, I tried to add in CMakeLists.txt the lines
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
but it seems to have no effect. The compiler rejected even C++17 features, e.g.
warning #3033-D: inline variables are a C++17 feature
The second attempt was to add compiler flag directly:
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --std c++20")
and I got
nvcc warning : The -std=c++20 flag is not supported with the configured host compiler. Flag will be ignored.
Which is very surprising considering that I tried both GCC 10 and Clang 11 as CMAKE_CXX_COMPILER.
The advice from the comments to write
set(CMAKE_CUDA_STANDARD 20)
does not work unfortunately on Ubuntu 20 with its default Cmake 3.16:
CUDA_STANDARD is set to invalid value '20'
I would prefer manually passing command-option to the compiler to forcing Cmake update.
The CMake documentation says that the first version to really support 20 for CUDA is 3.18.
https://cmake.org/cmake/help/latest/prop_tgt/CUDA_STANDARD.html
Try updating your version of CMake. For docker images, like the ones you are using, I sometimes have to download the binary and install it:
https://gitlab.com/correaa/boost-multi/-/blob/master/.gitlab-ci.yml?ref_type=heads#L402-403