I have a CMake project which requires package foo
, with a certain version range.
Now, I don't want to force my own foo tarball into the project, nor always download a release from the Internet, i.e. I want to use find_package()
. I also like the aesthetics of always doing that.
At the same time, if find_package()
fails, I do want to fallback to something, let's say the equivalent of a FetchContent_declare with some parameters I provide (e.g. building from a tarball I've bundled or downloading it from the web).
What is the idiomatic way to set-up this "find_package with fallback"?
Notes:
- I've noticed that there is some sort of hooking in
find_package()
which allows us to useOVERRIDE_FIND_PACKAGE
inFetchContent_declare()
, so maybe that can be used to implement the fallback I'm after - Assume a CMake version as high as you like