Best practices when providing CMake functions in a library

My library has CMake functions which add build steps of a code generator to a target. I would like users of my library to be able to use these functions. However I’m unsure how I should provide them. The most simple solution is a CMake include. A library user however must know the path or the CMAKE_MODULE_PATH has to be set accordingly.

Question 1: Is it possible/best practice to provide CMAKE_MODULE_PATH which points to the includes of the library in the CMake package, so that users of the library can include my files after find_package()?

Question 2: Is it possible/best practice to make the functions directly available with find_package()?

The classical way to proceed is to deliver directly the functions when find_package() is evaluated.
To avoid any potential clash names, it is strongly recommended prefixing the functions with the name of the package:

find_package(MyPackage ...)

# use function created by the package
MyPackage_MyFunction(...)

my apologies for reviving an old thread, but could someone explain (or point me to a resource that explains) how one would “deliver directly the functions when find_package() is evaluated”?My assumption is that the .cmake files with the functions definitions would be loaded (viainclude()? ) into the scope of the find_package()` caller. If so, I’m still unclear how that would be implemented.

The functions are always global, so any function defined in a file evaluated through find_package() will be available globally.

Moreover, the module file loaded through find_package() is evaluated in the scope of the caller. So, any variable set or updated as part of this evaluation will be visible by the caller.

thank you that was very helpful.

I was also avoiding having to create a config.cmake.in file and the include(CMakePackageConfigHelpers) boilerplate. Unfortunately, without the config.cmake.in file, it wasn’t obvious how I could include() the .cmake files in questions. Adding the .config file as shown in CMake tutorial, step 11 helped.