I am trying to add CUDA functions in existing C++ project which uses CMake.
For example, main.cpp looks like this:
#include <stdio.h>
#include "kernels/test.cuh"
int main() {
wrap_test_print();
return 0;
}
And kernels/test.cu looks like:
#include "test.cuh"
__global__ void test_print(){
printf("Hello World!\n");
}
void wrap_test_print() {
test_print<<<1, 1>>>();
return;
}
And kernels/test.cuh looks like:
#ifndef TEST_CUH__
#define TEST_CUH__
#include <stdio.h>
void wrap_test_print();
#endif
And I use following codes for CMakeLists.txt:
===============
CMakeLists.txt
===============
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
enable_language(CUDA)
project(cmake_and_cuda)
add_executable(main main.cpp)
add_subdirectory(kernels)
# set_property(TARGET main
# PROPERTY CUDA_SEPARABLE_COMPILATION ON)
target_link_libraries(main kernels)
===============
kernels/CMakeLists.txt
===============
enable_language(CUDA)
add_library(kernels
test.cu
test.cuh
)
target_compile_features(kernels PUBLIC cxx_std_11)
set_target_properties(kernels
PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
target_link_libraries(kernels)
However, when I use cmake .. in the build folder in the project, the following error message are printed:
CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
Missing variable is:
CMAKE_CUDA_DEVICE_LINK_LIBRARY
CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
Missing variable is:
CMAKE_CUDA_DEVICE_LINK_LIBRARY
I guess this is due to a cudart problem, so I added set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lcudart") but I could not resolve this issue. How can I solve this issue?