C ++ 11 support in NVCC with CMake

I am running Ubuntu 15.10 with CUDA 7.5. CMmake v3.2.2, NVCC - release 7.5, v7.5.17; GCC - Ubuntu 5.2.1-22ubuntu2 v5.2.1

Starting C ++ 11 in regular projects is easy:

project(foo CXX) set(TARGET foo CMAKE_CXX_STANDARD 11) 

I define my CUDA project with:

 find_package(CUDA REQUIRED) CUDA_ADD_EXECUTABLE(foo ${foo_src} ${foo_hdr} ${foo_cu}) 

But C ++ 11 support does not apply to NVCC. I have to add:

 list(APPEND CUDA_NVCC_FLAGS "-std=c++11") 

It looks like shreds. Obviously, this has been done recently for this task , but I could not find the results.

How do I get CMake to automatically set C ++ 11 flags when declaring a project as C ++ 11?

EDIT: I reinstalled this question using CUDA 8.0 and CMake 3.5.1.

From the documentation , set(CUDA_PROPAGATE_HOST_FLAGS ON) will distribute the contents of CMAKE_CXX_FLAGS , so the following C ++ 11 triggers for both cpp and NVCC:

 set (CMAKE_CXX_FLAGS "--std=c++11") set (CUDA_PROPAGATE_HOST_FLAGS ON) 

However, set(CMAKE_CXX_STANDARD 11) does not affect CMAKE_CXX_FLAGS , therefore, below are the compiler errors for C ++ 11 device code, since there is nothing to distribute:

 set (CMAKE_CXX_STANDARD 11) set (CUDA_PROPAGATE_HOST_FLAGS ON) 

I cannot find a CMake command combination that allows explicitly setting --std=c++11 in the CXX or CUDA flags.

+7
c ++ 11 cmake cuda
source share
1 answer

Since CMake 3.8 (since CMake supports CUDA as a language), a new target property, CUDA_STANDARD , appears. Although its name is rather confusing, it adds the -std=XXX command to the nvcc compilation command.

With a recent version of CMake, the correct way would be

 cmake_minimum_required(3.8.2) enable_language(CUDA) add_executable(foo ${foo_src} ${foo_cu}) set_property(TARGET foo PROPERTY CUDA_STANDARD 11) 
+1
source share

All Articles