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.