c++ - CMake:有没有办法将选项传递给 g++ 但不传递给 nvcc

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

在 CMakeList.txt 中,我确实想将 -std=g++0x 添加到 g++ 选项,如下所示: 设置(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)

最佳答案

来自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 脚本的开头。

关于c++ - CMake:有没有办法将选项传递给 g++ 但不传递给 nvcc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44154731/

相关文章:

c++ - 在一个 QTableWidget 单元格中显示不同颜色的字符串

c++ - 删除一个 char* 崩溃程序

c++ - clang 使用了错误的系统包含目录

c++ - 1/sqrt(x) 和 std::exp(-0.5 * std::log(x)) 之间的数值权衡

c - 我们应该使用 __device__ 和 __host__ 的例子

c++ - 类中的引用对象和其他引用对象

c++ - 将接口(interface)和实现与普通功能分离

c++ - 理解 std::thread 语义,工作函数作为类成员

memory-management - 参数超过 256 字节的 CUDA 内核调用思路

c++ - Thrust 中的虚方法调用