Introduction
I've been trying to compile my c++
program by using cmake + visual studio 2022 (msvc)
and I have some problems with the cmakefile
setup.
The problem
The program compiles when I don't have .cu
files and it does not compile when I use .cu
files.
Btw, in the c++
files I can use the cuda libraries.
This is the error I get in visual studio:
nvcc fatal : A single input file is required for a non-link phase when an outputfile is specified
Cmake file
Here's the simplified version of my cmake file:
cmake_minimum_required(VERSION 3.16)
project(collisions LANGUAGES CXX CUDA)
# Add the CUDA libraries
find_package(CUDA REQUIRED)
enable_language(CUDA)
# Source code
file(GLOB PROJECT_SOURCES_CPP "src/*/*.cpp" "src/*/*/*.cpp")
file(GLOB PROJECT_SOURCES_CU "src/*/*.cu")
# Include OpenMP
find_package(OpenMP)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
add_executable(${PROJECT_NAME} ${PROJECT_SOURCES_CPP} ${PROJECT_SOURCES_CU})
add_dependencies(${PROJECT_NAME} glfw glad glm)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/)
if (MSVC)
set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "/openmp:llvm")
endif()
set_target_properties(${PROJECT_NAME} PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
target_link_libraries(${PROJECT_NAME} PRIVATE glfw glad glm OpenMP::OpenMP_CXX ${CUDA_LIBRARIES})
I tried a lot of things with ChatGPT but we could not find the problem. I would like to fix this cmake file so that I can compile my program.