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 thefind_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ā¦)