[CMake] simple find_package example
Johannes Zarl-Zierl
johannes at zarl-zierl.at
Tue Aug 7 17:23:09 EDT 2018
Am Dienstag, 7. August 2018, 14:48:26 CEST schrieb Randy Heiland:
> Hmm, well if that's the case, how does one generate the HelloConfig.cmake
> file?
The official documentation is here:
https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html
> Although, for my particular situation, my question about wanting to
> generate a "Find" file still remains, I think. I have a library which is,
> potentially, useful to several projects. I assume there's some sort of
> "Find" template for any such lib, i.e., a project needs to be able to
> locate a lib (static or dynamic) and headers, cross-platform.
Im almost positively sure that you don't want a FindXYZ.cmake, but a
XYZConfig.cmake file instead. These are the main differences between Find-
module packages and config-file packages:
Find-Module packages:
- are written and maintained independently of the "consumed" project
(usually because the project does not support CMake)
- are usually shipped by the consuming project
- are hard to get right (they have to deal with strange installations, or old
versions of the software, etc.)
Config-file packages:
- are generated by the "consumed" project
- are shipped by the consumed project
- have tooling to ensure correctness
For the consuming project, there's no visible difference between both (you
call "find_package(XYZ)" and cmake uses whatever it finds. In principle, it's
even possible to use both together (note: please don't).
That said, the official documentation can be a bit overwhelming at first.
You probably can write some kind of cmake-2.6-style Find-Module package in
less time, but the time to do it "right" is worth your effort.
Just start by reading the documentation and don't hesitate to ask when you hit
a problem…
Cheers,
Johannes
More information about the CMake
mailing list