Hi all,
I am simultaneously learning CMake and how successfully compile a cuda project. As an exercise, I decided to take the cppIntegration project from the SDK, and figure out how to get it to compile with CMake, using the FindCuda.cmake utility downloaded from http://www.sci.utah.edu/~abe/FindCuda.html. I successfully got the example available in the download to work. Using that example as a template, I attempted to extract the relevant parts of the CMakeList.txt files and apply the same structure to the cppIntegration project. No Luck! I cannot get the cppIntegration project to successfully compile.
My directory structure is
“bin” (for the out-of-source build)
“CMake” (the provided code)
“src” (This contains the two *.cu files, the two *.cpp files of cppIntegration, and a CMakeLists.txt file)
CmakeLists.txt
The top directory CMakeLists.txt file looks like
[codebox]# The name of our project is “CPPINTEGRATION”. CMakeLists files in this project can
refer to the root source directory of the project as ${CPPINTEGRATION_SOURCE_DIR} and
to the root binary directory of the project as ${CPPINTEGRATION_BINARY_DIR}.
cmake_minimum_required (VERSION 2.6)
project (CPPINTEGRATION)
INCLUDE(${CMAKE_SOURCE_DIR}/CMake/cuda/FindCuda.cmake)
SUBDIRS(
src
)
[/codebox]
The CMakeList.txt in the “src” looks like
[codebox]# Add current directory to the nvcc include line.
CUDA_INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}
)
INCLUDE_DIRECTORIES( ${FOUND_CUDA_NVCC_INCLUDE} ${FOUND_CUT_INCLUDE})
##################################################
Use the CUDA_COMPILE macro.
CUDA_COMPILE(CUDA_FILES cppIntegration_kernel.cu cppIntegration.cu)
ADD_EXECUTABLE(cuda_compile_example
${CUDA_FILES}
main.cpp
cppIntegration_gold.cpp
)
[/codebox]
cmake appears to find all the right files, includes, libraries (with a little help)
But the verbose make generates the following error
/sw/bin/cmake -H/Users/phillicl/miniMD/IncrementalCUDATest -B/Users/phillicl/miniMD/IncrementalCUDATest/bin --check-build-system CMakeFiles/Makefile.cmake 0
/sw/bin/cmake -E cmake_progress_start /Users/phillicl/miniMD/IncrementalCUDATest/bin/CMakeFiles /Users/phillicl/miniMD/IncrementalCUDATest/bin/CMakeFiles/progress.make
make -f CMakeFiles/Makefile2 all
make -f src/CMakeFiles/cuda_compile_example.dir/build.make src/CMakeFiles/cuda_compile_example.dir/depend
cd /Users/phillicl/miniMD/IncrementalCUDATest/bin && /sw/bin/cmake -E cmake_depends “Unix Makefiles” /Users/phillicl/miniMD/IncrementalCUDATest /Users/phillicl/miniMD/IncrementalCUDATest/src /Users/phillicl/miniMD/IncrementalCUDATest/bin /Users/phillicl/miniMD/IncrementalCUDATest/bin/src /Users/phillicl/miniMD/IncrementalCUDATest/bin/src/CMakeFiles/cuda_compile_example.dir/DependInfo.cmake --color=
make -f src/CMakeFiles/cuda_compile_example.dir/build.make src/CMakeFiles/cuda_compile_example.dir/build
Linking CXX executable cuda_compile_example
cd /Users/phillicl/miniMD/IncrementalCUDATest/bin/src && /sw/bin/cmake -E cmake_link_script CMakeFiles/cuda_compile_example.dir/link.txt --verbose=1
/usr/bin/c++ -O3 -DNDEBUG -Wl,-search_paths_first -headerpad_max_install_names -fPIC CMakeFiles/cuda_compile_example.dir/main.o CMakeFiles/cuda_compile_example.dir/cppIntegration_gold.o -o cuda_compile_example /usr/local/cuda/lib/libcuda.dylib /usr/local/cuda/lib/libcudart.dylib
Undefined symbols:
“_runTest”, referenced from:
_main in main.o
“_cutCheckCmdLineFlag”, referenced from:
_main in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make[2]: *** [src/cuda_compile_example] Error 1
make[1]: *** [src/CMakeFiles/cuda_compile_example.dir/all] Error 2
make: *** [all] Error 2
As you can see, it does not appear to actually compile the *.cu files and thus has no object files! Its as if the macro is not working somehow. (I get an identical output if I “comment” out the “CUDA_COMPILE”)
What am I missing?