CMake:有没有办法将选项传递给g ++而不是nvcc

时间:2017-05-24 09:45:01

标签: c++ c++11 cuda cmake nvcc

在CMakeList.txt中,我想将-std=g++0x添加到g ++选项中,如下所示: set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x)

然而,所有CMAKE_CXX_FLAGS也通过-Xcompiler标志(自动完成)传递给nvcc。但是,nvcc不适用于gnu++0x标准。

有没有办法将标志传递给g ++而不是传递给nvcc

编译器由

指定
if(CUDA_NVCC_HOST_COMPILER)
    list(APPEND CUDA_NVCC_FLAGS "--compiler-bindir=${CUDA_NVCC_HOST_COMPILER}")
endif(CUDA_NVCC_HOST_COMPILER)

1 个答案:

答案 0 :(得分:2)

来自FindCUDA documentation

CUDA_PROPAGATE_HOST_FLAGS (Default ON)
-- Set to ON to propagate CMAKE_{C,CXX}_FLAGS and their configuration
   dependent counterparts (e.g. CMAKE_C_FLAGS_DEBUG) automatically to the
   host compiler through nvcc's -Xcompiler flag.  This helps make the
   generated host code match the rest of the system better.  Sometimes
   certain flags give nvcc problems, and this will help you turn the flag
   propagation off.  This does not affect the flags supplied directly to nvcc
   via CUDA_NVCC_FLAGS or through the OPTION flags specified through
   CUDA_ADD_LIBRARY, CUDA_ADD_EXECUTABLE, or CUDA_WRAP_SRCS.  Flags used for
   shared library compilation are not affected by this flag.

所以,要解决你的问题,只需输入

即可
set(CUDA_PROPAGATE_HOST_FLAGS FALSE)

靠近CMake脚本的开头。