find_package: Add variable to make package REQUIRED

Add a `CMAKE_REQUIRE_FIND_PACKAGE_<PackageName>` variable is complement
to `CMAKE_DISABLE_FIND_PACKAGE_<PackageName>` with just the opposite
behaviour: it turns non-required find_package call into the required one.

While optional package dependencies usually result in simple and clean
build logic, sometimes people want to be sure those optional
dependencies will be found and used. Examples are reproducible builds
and build instructions for 3rd parties. People choose to make
find_package calls REQUIRED and put them behind an option(). Such
workarounds blend build logic with build environment management and do
not look elegant.
This commit is contained in:
Eugene Shalygin
2021-07-07 14:41:34 +02:00
committed by Brad King
parent d49b507bb6
commit a2e9fe38e4
15 changed files with 99 additions and 6 deletions

View File

@@ -14,3 +14,5 @@ the package has already been found in a previous CMake run, the
variables which have been stored in the cache will still be there. In
that case it is recommended to remove the cache variables for this
package from the cache using the cache editor or :manual:`cmake(1)` ``-U``
See also the :variable:`CMAKE_REQUIRE_FIND_PACKAGE_<PackageName>` variable.

View File

@@ -0,0 +1,14 @@
CMAKE_REQUIRE_FIND_PACKAGE_<PackageName>
----------------------------------------
.. versionadded:: 3.22
Variable for making :command:`find_package` call ``REQUIRED``.
Every non-``REQUIRED`` :command:`find_package` call in a project can be
turned into ``REQUIRED`` by setting the variable
``CMAKE_REQUIRE_FIND_PACKAGE_<PackageName>`` to ``TRUE``.
This can be used to assert assumptions about build environment and to
ensure the build will fail early if they do not hold.
See also the :variable:`CMAKE_DISABLE_FIND_PACKAGE_<PackageName>` variable.