Do I still need FindCUDA ?

Hello CMake Community !

I just had the opportunity to update one of our Ubuntu 20.04 host at work with the last stable CMake snap (actually version 3.18.1) and have been surprised with an error during the build of our project, using Nvidia CUDA, saying that the property CUDA_ARCHITECTURES was not properly set.
Okay :slightly_smiling_face:, than I looked in the documentation and saw that a new FindCUDAToolkit exists and decided to use it. :tada:
Except that CMake 3.18.1 doesn’t agree with me and gives me the following error :

By not providing "FindFindCUDAToolkit.cmake" in CMAKE_MODULE_PATH this   
project has asked CMake to find a package configuration file provided by 
"FindCUDAToolkit", but CMake did not find one.                           
                                                                         
Could not find a package configuration file provided by "FindCUDAToolkit"
with any of the following names:                                         
                                                                         
  FindCUDAToolkitConfig.cmake                                            
  findcudatoolkit-config.cmake                                           

Finding this unbelievable, I searched for this .cmake file on the host and found it there :
/snap/cmake/513/share/cmake-3.18/Modules/FindCUDAToolkit.cmake

So, the file exists, but I don’t understand why CMake doesn’t find it. :thinking:
Does it only search for CMake Modules in the project’s root folder and /usr/lib/x86_64-linux-gnu/cmake/?
Do I really need to add the path manually to CMAKE_MODULE_PATH or is there a better/proper way to deal with this issue ?

Thanks in advance for your information !
Best Regards !

You seem to have an additional “Find” prefix in your code

Thanks for the quick answer @hsattler !
You are incredibly right :
I declare the following
find_package(FindCUDAToolkit REQUIRED)
instead of
find_package(CUDAToolkit REQUIRED)
I did not remember that CMake puts the Find prefix himself for searching for Modules… stupid me :expressionless:
Thanks a lot !

But, I would point out that it is obsolete. CUDA is a first-class language now.

project( foo
...
         LANGUAGES CXX CUDA
)

Thank you for this precision @jwm !
I didn’t know that and you’re right :
I removed find_package(CUDAToolkit REQUIRED) and replaced

target_link_libraries(mylib
    CUDA::cudart
    CUDA::cudart_static
)
target_include_directories(mylib
    PUBLIC
        ${CUDAToolkit_INCLUDE_DIRS}
        include
)

with

target_link_libraries(mylib
    cudart
    cudart_static
)
target_include_directories(mylib
    PUBLIC
        ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}
        include
)

and everything works just fine !
Thanks for the info, my CMakeLists is much easier now :+1:

Regards

1 Like

thank you for your info