enable_language(CUDA) ignores NVCC Compiler flags

Hello everybody,

I am trying to include some CUDA-Code in an existing project. It seems that the CMAKE option enable_language(CUDA) leads to some troubles in setting NVCC compiler flags.

With this CMAKE script everything compiles well:

project(projectName)
set(CUDA_SEPARABLE_COMPILATION ON)
#enable_language(CUDA)
get_filename_component(CUDA_LIB_PATH ${CUDA_CUDART_LIBRARY} DIRECTORY)
find_library(CUDA_cudadevrt_LIBRARY cudadevrt PATHS ${CUDA_LIB_PATH})

include_directories("C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0/include")




cuda_add_executable(
    ${PROJECT_NAME}
    main.cpp
    cuda_functions.cu
    cuda_functions.hu
    helpers.hpp
    cHeader.hpp
    foobar.cu
    structs.hpp
)

target_link_libraries(${PROJECT_NAME} ${CUDA_cudadevrt_LIBRARY})

But if i enable the language support I get the error " calling a global function from a global function is only allowed on the compute_35 architecture or above"

project(projectName)
set(CUDA_SEPARABLE_COMPILATION ON)
enable_language(CUDA)
get_filename_component(CUDA_LIB_PATH ${CUDA_CUDART_LIBRARY} DIRECTORY)
find_library(CUDA_cudadevrt_LIBRARY cudadevrt PATHS ${CUDA_LIB_PATH})

include_directories("C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0/include")




add_executable(
    ${PROJECT_NAME}
    main.cpp
    cuda_functions.cu
    cuda_functions.hu
    helpers.hpp
    cHeader.hpp
    foobar.cu
    structs.hpp
)

target_link_libraries(${PROJECT_NAME} ${CUDA_cudadevrt_LIBRARY})

The NVCC flags are set in an extra file:

set(CUDA_NVCC_FLAGS "-o3")
set(CUDA_NVCC_FLAGS "-arch=sm_52")

The project is build for Visual Studio 14 2015 Win64.
The project is build for Nvidia Quadro M2000.
My CMake Version is 3.10.2
I am using Nvidia GPU Computing Toolkit V8.0.

I think to extend CUDA_NVCC_FLAGS you have to do something like

set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -O3")
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -arch=sm_52")

In your example the arch=sm_52 option would overwrite (erase) the previous o3 flag.

Also note that the o3 from your posting is not a valid option, as it has to be an upper case O3.

And what’s that “extra file” and how do you make sure it’s being considered?

Christian