CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS function in FindCUDA.cmake

I am building Visual Studio 2017 project with CMake 3.13.1. I am using CUDA 9.2.

When separable compilation is activated, function (inside FindCUDA.cmake)

function(CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS

sets up host flags ( ${flags} ) that are passed to NVCC when performing device link (-dlink) of relocatable device code (line 1911).

Build configuration specific flags are setup in the following fashion (line 1875):

foreach(f ${important_host_flags})
    list(APPEND flags $<$<CONFIG:${config}>:-Xcompiler> $<$<CONFIG:${config}>:${f}>)
endforeach()

The flags are then passed on to nvcc, that is invoked in a custom build step like so (line 1906):

add_custom_command(
        OUTPUT ${output_file}
        DEPENDS ${object_files}
        COMMAND ${CUDA_NVCC_EXECUTABLE} ${nvcc_flags} -dlink ${object_files} -o ${output_file}
        ${flags}
        COMMENT "Building NVCC intermediate link file ${output_file_relative_path}"
        ${_verbatim}
        )

The following snippet from the above code invokes nvcc with the aforementioned flags ( ${flags} ):

COMMAND ${CUDA_NVCC_EXECUTABLE} ${nvcc_flags} -dlink ${object_files} -o ${output_file} ${flags}

As far as I am concerned, the idea was for ${flags} to expand into one particular flag depending on the built configuration (given that flags are populated with generator expressions), i.e., if we are building Debug:

COMMAND ${CUDA_NVCC_EXECUTABLE} ${nvcc_flags} -dlink ${object_files} -o ${output_file} -Xcompiler /MDd

However, what happens is that generator expressions in ${flags} that do not comply with the currently built configuration are simply set to an empty string. So if we are building Debug configuration, we get the following:

COMMAND ${CUDA_NVCC_EXECUTABLE} ${nvcc_flags} -dlink ${object_files} -o ${output_file} -Xcompiler /MDd 
 "" "" "" "" "" ""

Which results in

nvcc fatal   : Don't know what to do with ''

Removing the loop that populates the ${flags} and manually setting flags to, say,

-Xcompiler /MDd

fixes the problem, lets the project build and the code is successfully run.

I was wondering if I am missing something in the script, or is it a bug? I apologize in advance if I overlooked something fundamental.

If you wish to file a bug report, do so by following the process here:
https://devtalk.nvidia.com/default/topic/1044668/cuda-programming-and-performance/-how-to-report-a-bug/

It’s useful if you can also provide a self-contained reproducer and the steps you run into issue.