CUDA: Fallback to cxx_std_17 conflics with cuda_std_14
Inconsistent work of target_compile_features(cuda_std_17) and set(CMAKE_CXX_STANDARD).
Consider an example:
cmake_minimum_required(VERSION 3.18)
project(cmake_and_cuda LANGUAGES CXX CUDA)
add_library(test STATIC test.cpp test.cu)
option(SET_COMPILE_FEATURES "Sets the CUDA Standard via target_compile_features" OFF)
if(SET_COMPILE_FEATURES)
message("set compile features")
target_compile_features(test PUBLIC cxx_std_17 cuda_std_14)
else()
message("set cxx/cuda_standard")
set_target_properties(test PROPERTIES CXX_STANDARD 17 CUDA_STANDARD 14)
endif()
with empty test.cpp/test.cu.
and build it with cmake -S . -B build-feat -DSET_COMPILE_FEATURES=1 -DCMAKE_VERBOSE_MAKEFILE=1
and cmake -S . -B build-prop -DCMAKE_VERBOSE_MAKEFILE=1
The part of build log for compile_features:
33%] Building CXX object CMakeFiles/test.dir/test.cpp.o
/usr/lib64/ccache/c++ -std=gnu++17 -o CMakeFiles/test.dir/test.cpp.o -c /home/user/proj/cmake-compile-feature-and-property-fails/test.cpp
[ 66%] Building CUDA object CMakeFiles/test.dir/test.cu.o
/usr/local/cuda/bin/nvcc -forward-unknown-to-host-compiler --generate-code=arch=compute_52,code=[compute_52,sm_52] -std=c++17 -x cu -c /home/user/proj/cmake-compile-feature-and-property-fails/test.cu -o CMakeFiles/test.dir/test.cu.o
The both test.cpp and test.cu compiles with c++17 standard.
The part of build log for compile properties:
[ 33%] Building CXX object CMakeFiles/test.dir/test.cpp.o
/usr/lib64/ccache/c++ -std=gnu++17 -o CMakeFiles/test.dir/test.cpp.o -c /home/user/proj/cmake-compile-feature-and-property-fails/test.cpp
[ 66%] Building CUDA object CMakeFiles/test.dir/test.cu.o
/usr/local/cuda/bin/nvcc -forward-unknown-to-host-compiler --generate-code=arch=compute_52,code=[compute_52,sm_52] -std=c++14 -x cu -c /home/user/proj/cmake-compile-feature-and-property-fails/test.cu -o CMakeFiles/test.dir/test.cu.o
At this time test.cpp will build using c++17 standard and test.cu compiles with c++14 standard.
Edited by Brad King