Michael
Michael

Reputation: 1498

CMake: Is there a way of passing options to g++ but not to nvcc

In CMakeList.txt I do want to add the -std=g++0x to the g++ options like this: set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x)

However all the CMAKE_CXX_FLAGS are passed on to nvcc as well, via the -Xcompiler flag (which is done automatically). However nvcc doesn't work with the gnu++0x standard.

Is there a way of passing the flag to g++ but not to nvcc

The compiler is specified by

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

Upvotes: 2

Views: 1665

Answers (1)

MultipleMonomials
MultipleMonomials

Reputation: 429

From the 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.

So, to fix your problem, just put

set(CUDA_PROPAGATE_HOST_FLAGS FALSE)

near the start of your CMake script.

Upvotes: 2

Related Questions