Idiomatic way to do "find_package and download & build a fallback if not found"

39 views Asked by At

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 use OVERRIDE_FIND_PACKAGE in FetchContent_declare(), so maybe that can be used to implement the fallback I'm after
  • Assume a CMake version as high as you like
0

There are 0 answers