diff options
author | Cristian Adam <cristian.adam@gmail.com> | 2019-05-20 19:32:24 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-05-21 14:29:47 (GMT) |
commit | 26a99da206526efb203d0e448d7e095a07bec2fd (patch) | |
tree | 45d75b3710bdae0bc373993c2ad47788ce70cdb7 /Help | |
parent | c365243a3a282523062b5378898aa4fe6436f8fb (diff) | |
download | CMake-26a99da206526efb203d0e448d7e095a07bec2fd.zip CMake-26a99da206526efb203d0e448d7e095a07bec2fd.tar.gz CMake-26a99da206526efb203d0e448d7e095a07bec2fd.tar.bz2 |
find_package: Add option to prefer Config mode
Add a `CMAKE_FIND_PACKAGE_PREFER_CONFIG` variable to tell
`find_package` calls to look for a package configuration file
first even if a find module is available.
Fixes: #16805, #19236
Diffstat (limited to 'Help')
-rw-r--r-- | Help/command/find_package.rst | 7 | ||||
-rw-r--r-- | Help/manual/cmake-variables.7.rst | 1 | ||||
-rw-r--r-- | Help/release/dev/find-package-prefer-config.rst | 6 | ||||
-rw-r--r-- | Help/variable/CMAKE_FIND_PACKAGE_PREFER_CONFIG.rst | 27 | ||||
-rw-r--r-- | Help/variable/CMAKE_FIND_PACKAGE_WARN_NO_MODULE.rst | 3 |
5 files changed, 44 insertions, 0 deletions
diff --git a/Help/command/find_package.rst b/Help/command/find_package.rst index eb44eb2..e5e5b2c 100644 --- a/Help/command/find_package.rst +++ b/Help/command/find_package.rst @@ -59,6 +59,13 @@ for finding the package, checking the version, and producing any needed messages. Some find-modules provide limited or no support for versioning; check the module documentation. +If the ``MODULE`` option is not specfied in the above signature, +CMake first searches for the package using Module mode. Then, if the +package is not found, it searches again using Config mode. A user +may set the variable :variable:`CMAKE_FIND_PACKAGE_PREFER_CONFIG` to +``TRUE`` to direct CMake first search using Config mode before falling +back to Module mode. + Full Signature and Config Mode ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst index fd5e28f..1011ed2 100644 --- a/Help/manual/cmake-variables.7.rst +++ b/Help/manual/cmake-variables.7.rst @@ -172,6 +172,7 @@ Variables that Change Behavior /variable/CMAKE_FIND_NO_INSTALL_PREFIX /variable/CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY /variable/CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY + /variable/CMAKE_FIND_PACKAGE_PREFER_CONFIG /variable/CMAKE_FIND_PACKAGE_RESOLVE_SYMLINKS /variable/CMAKE_FIND_PACKAGE_WARN_NO_MODULE /variable/CMAKE_FIND_ROOT_PATH diff --git a/Help/release/dev/find-package-prefer-config.rst b/Help/release/dev/find-package-prefer-config.rst new file mode 100644 index 0000000..377e8c5 --- /dev/null +++ b/Help/release/dev/find-package-prefer-config.rst @@ -0,0 +1,6 @@ +find-package-prefer-config +-------------------------- + +* Variable :variable:`CMAKE_FIND_PACKAGE_PREFER_CONFIG` was added to tell + :command:`find_package` calls to look for a package configuration + file first even if a find module is available. diff --git a/Help/variable/CMAKE_FIND_PACKAGE_PREFER_CONFIG.rst b/Help/variable/CMAKE_FIND_PACKAGE_PREFER_CONFIG.rst new file mode 100644 index 0000000..db658a1 --- /dev/null +++ b/Help/variable/CMAKE_FIND_PACKAGE_PREFER_CONFIG.rst @@ -0,0 +1,27 @@ +CMAKE_FIND_PACKAGE_PREFER_CONFIG +--------------------------------- + +Tell :command:`find_package` to try "Config" mode before "Module" mode if no +mode was specified. + +The command :command:`find_package` operates without an explicit mode when +the reduced signature is used without the ``MODULE`` option. In this case, +by default, CMake first tries Module mode by searching for a +``Find<pkg>.cmake`` module. If it fails, CMake then searches for the package +using Config mode. + +Set ``CMAKE_FIND_PACKAGE_PREFER_CONFIG`` to ``TRUE`` to tell +:command:`find_package` to first search using Config mode before falling back +to Module mode. + +This variable may be useful when a developer has compiled a custom version of +a common library and wishes to link it to a dependent project. If this +variable is set to ``TRUE``, it would prevent a dependent project's call +to :command:`find_package` from selecting the default library located by the +system's ``Find<pkg>.cmake`` module before finding the developer's custom +built library. + +Once this variable is set, it is the responsibility of the exported +``<pkg>Config.cmake`` files to provide the same result variables as the +``Find<pkg>.cmake`` modules so that dependent projects can use them +interchangeably. diff --git a/Help/variable/CMAKE_FIND_PACKAGE_WARN_NO_MODULE.rst b/Help/variable/CMAKE_FIND_PACKAGE_WARN_NO_MODULE.rst index f1116bb..5c4f23a 100644 --- a/Help/variable/CMAKE_FIND_PACKAGE_WARN_NO_MODULE.rst +++ b/Help/variable/CMAKE_FIND_PACKAGE_WARN_NO_MODULE.rst @@ -17,3 +17,6 @@ Set ``CMAKE_FIND_PACKAGE_WARN_NO_MODULE`` to ``TRUE`` to tell :command:`find_package` to warn when it implicitly assumes Config mode. This helps developers enforce use of an explicit mode in all calls to :command:`find_package` within a project. + +This variable has no effect if :variable:`CMAKE_FIND_PACKAGE_PREFER_CONFIG` is +set to ``TRUE``. |