Adhere to the rules stipulated in 'cmake-developer' or those in 'find_package' for Find modules?

Hello, CMake Team.

Recently, while writing my own Find module, I encountered a point of confusion:

Should I adhere to the rules stipulated in cmake-developer or those in find_package for Find modules?

In the cmake-developer manual (Standard Variable Names), it is specified that we should provide certain variables in Find modules. For example:

  • Xxx_INCLUDE_DIRS
  • Xxx_LIBRARIES
  • Xxx_EXECUTABLE
  • …etc

However, at the same time, I saw in the find_package manual (Package File Interface Variables) that we are required to provide another format of variables. For example:

  • CMAKE_FIND_PACKAGE_NAME
  • <PackageName>_FIND_REQUIRED
  • <PackageName>_FIND_QUIETLY
  • …etc

Or is it that our Find modules should provide variables in both formats?

This Variables are set from find_package and are used in exported cmake config packages.

@ClausKlein

This Variables are set from find_package

So these interface variables mentioned in find_package manual (Package File Interface Variables) are set “automatically” when calling find_package in config mode.

and are used in exported cmake config packages .

And after find_package sets these interface variables, those config files (<PackageName>Config.cmake, <PackageName>ConfigVersion.cmake…etc) will do something based these interface variables.

Is that what you mean?

Then, what about module mode? If we call find_package in module mode, which means using Find modules, will these interface variables work in Find modules as well?

It may help to inspect a simple example like FindZLIB.cmke

These are inputs to your Find module code to know what variables were passed by the calling find_package.

These are variables your Find module sets to communicate what was found.

1 Like