0

When using CMake 3.26.4 with CUDA v12.1 and Visual 16.11.25 and compiling a .cu file, I get the following error:

1>nvcc fatal   : A single input file is required for a non-link phase when an outputfile is specified

Here are some relevant CMake parts:

enable_language(CUDA)

add_library(${project} SHARED)

set_target_properties(${project} PROPERTIES CXX_STANDARD 17)

if (MSVC)
  target_compile_definitions(${project} PUBLIC -DBOOST_ASIO_DISABLE_CONCEPTS)
  target_compile_options(${project} PRIVATE /std:c++latest /await:strict /bigobj "/Zc:__cplusplus")
endif()

find_package(CUDAToolkit)

set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -arch=sm_60")

target_link_libraries(${project} PRIVATE CUDA::cuda_driver)

set_property(TARGET ${project} PROPERTY CUDA_SEPARABLE_COMPILATION ON)

It looks like NVCC doesn't like any of the / flags that are passed from the CXX compiler.

  • Tried: set(CUDA_PROPAGATE_HOST_FLAGS FALSE). Probably deprecated

  • Tried: Removing the target_compile_options and use add_compile_options with $<$<COMPILE_LANGUAGE:CXX> ...

Any hint? Thanks!

paleonix
  • 2,293
  • 1
  • 13
  • 29
SebK
  • 499
  • 4
  • 2
  • 1
    Hardcoding the architecture into the `CMakeLists.txt` is discouraged, at least if your code is compatible with more than one architecture. When configuring, you can set it using [`CMAKE_CUDA_ARCHITECTURES`](https://cmake.org/cmake/help/latest/variable/CMAKE_CUDA_ARCHITECTURES.html). The linked site also shows a nice example of setting a default architecture and also which property to use if you really want to hard-code it. – paleonix May 26 '23 at 15:36
  • I'm not sure if there is a better way to do this in CMake, but you could just use something like `target_compile_options(${project} PRIVATE "$<$:--compiler-options=/std:c++latest>")`. See [Confusing flags passed to MSVC through NVCC with CMake](https://stackoverflow.com/q/59564886/10107454). – paleonix May 26 '23 at 18:02

1 Answers1

1

So by removing:

if (MSVC)
  target_compile_definitions(${project} PUBLIC -DBOOST_ASIO_DISABLE_CONCEPTS)
  target_compile_options(${project} PRIVATE /std:c++latest /await:strict /bigobj "/Zc:__cplusplus")
endif()

And replacing it with:

set(my_cxx_flags -DBOOST_ASIO_DISABLE_CONCEPTS /std:c++latest /await:strict /bigobj "/Zc:__cplusplus")

target_compile_options(${project} PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${my_cxx_flags}> )

That seems to solve the issue.

talonmies
  • 70,661
  • 34
  • 192
  • 269
SebK
  • 499
  • 4
  • 2