A problem with documentation of find_package

I couldn’t find a documentation page specifying how to arrive from a module name, e.g. FindCUDAToolkit to the proper syntax of calling find_package, i.e. find_package(CUDAToolkit) in this case. I’m I missing something? If not, can it be added to documentation?

Initially, I asked that question on stackoverflow https://stackoverflow.com/questions/65713975

Quoting https://cmake.org/cmake/help/latest/manual/cmake-developer.7.html

A “find module” is a Find<PackageName>.cmake file to be loaded by the find_package() command when invoked for <PackageName>.

and

A FindFoo.cmake module will typically be loaded by the command:

find_package(Foo [major[.minor[.patch[.tweak]]]]
             [EXACT] [QUIET] [REQUIRED]
             [[COMPONENTS] [components...]]
             [OPTIONAL_COMPONENTS components...]
             [NO_POLICY_SCOPE]) 

Does that cover it?

1 Like

Yes, it does, but you have to know where to look for it. For a newbie like me, it would help to have this repeated or linked to on find_package() page: https://cmake.org/cmake/help/latest/command/find_package.html

On second reading, technically this information is on find_package() page, but it’s not straightforward to uncover for a beginner. I think the main problem for me was that page https://cmake.org/cmake/help/latest/module/FindCUDAToolkit.html calls FindCUDAToolkit a script and has no reference to CUDAToolkit package.

I think enhancing the find_package docs would be the way to go here. Wanting to use module FindX via find_package, one could expect that the find_package docs would be of interest. Adding "use via find_package(X)" feels like adding "use via include(X)" to other module documentation.

Cc: @kyle.edwards @betsy.mcphail

1 Like