Advice for maintaining module-mode FindPackage.cmake files

CMake Gurus,

I have a question about maintaining module-mode FindPackage.cmake files. To wit, the documentation for find_package says:

The Find<PackageName>.cmake file is not typically provided by the package itself. Rather, it is normally provided by something external to the package, such as the operating system, CMake itself, or even the project from which the find_package() command was called. Being externally provided, Find Modules tend to be heuristic in nature and are susceptible to becoming out-of-date. They typically search for certain libraries, files and other package artifacts.

So, my question involves a package (ESMF) that does nicely provide a FindESMF.cmake file in its source code for its users, but does not install it. (It is a large and established enough library that converting to CMake would be a daunting task, so Config mode is probably a long-term dream/goal.)

Recently, I realized that this file does indeed change at times, and I’d missed that and moved to update the version I carried in my code. But then I had a thought: "Well, the library itself could install the file when you install the library into, say, prefix/lib/cmake/esmf" or whatever. Luckily I build ESMF in a way where I can–“outside” of their make system–do a simple “copy this file to directory foo” and then have my code know to set CMAKE_MODULE_PATH to that directory to find it. This way, I get any updates for free and if at some point FindESMF.cmake changes in such a way that it isn’t backwardsly compatible, I’m guaranteed to have the right file for that version of the library. (Might never happen…but it’s not impossible.)

Now the official advice does say it’s not really up to the package itself to provide it, but is there any “unofficial” advice for packages like this with a FindPackage.cmake file provided as a courtesy by the package? I had thought of making a PR to the package saying they could install it for us…but then the question is where? Should a module-mode FindPackage.cmake file go in prefix/lib/cmake/package/? prefix/share/package/?

Thanks for any help,
Matt

Note: Obviously the “dream scenario” for me is FindESMF.cmake is built into CMake itself, but ESMF is niche enough that it probably doesn’t warrant that…though FindNetCDF.cmake isn’t built in either…)

I think the way to go is rather convince ESMF to provide config files instead of find module and install that. One does not need CMake build system to generate those (as, for example, boost proves)

1 Like

@fenrir Interesting, thanks. Though I do wish boost were a simple example. I decided to clone it and…oof, that’s a complex beast! Still, I do deal with some simple libraries that do make Config files, and it might be as simple as starting from what CMake generates there and figuring out how to get GNU Make to fill out a template.

For “simple” libraries, you can just replace some code in a file just like .pc files. Once you have the skeleton of targets and such, filling in where the install puts them shouldn’t be too bad.

1 Like

Hm, pkgconfig… That’s a good point!
If it is looks too complex to brew good cmake module, you can brew .pc instead, which is much much simpler for ‘.lib + .h + flags’. Yes, it is not relocatable. Yes, it requires pkgconfig available on the build system. But that is really simple format suitable for ‘rapid start’.

Actually, .pc files can be relocatable.