Proper way for a package to propagate CMAKE_MODULE_PATH

Is there a proper way for a CMake package to propagate variables (in particular, CMAKE_MODULE_PATH) to any consuming projects? I’ve got a package that provides some find modules, and in its CMakeLists.txt, it adds the appropriate path to CMAKE_MODULE_PATH and everything works as expected. However, if I add this package to a consuming project using FetchContent, and then try to use one of its find modules from the superproject, I get errors that the requested find module isn’t in CMAKE_MODULE_PATH.

Is the only answer to have the project containing the find modules set an internal cache variable, and to do


from the consuming project? This works, but seems ugly.

Rather than forcing CMAKE_MODULE_PATH changes on the consumer, I’d just offer the variable for them to use as needed. The way I do it in VTK and ParaView is to modify CMAKE_MODULE_PATH locally in the -config.cmake and reset it at the end.

Note that things like API modules are best just included unconditionally. What kind of include() API are you trying to provide?

They’re find modules. I can just provide a MY_PKG_MODULE_PATH variable for the user, but I would rather have it “just work” after the user calls find_package(MyPkg).