Commit Graph

41 Commits

Author SHA1 Message Date
Martin Duffy
857a039d66 find_*: Add variable to default calls to REQUIRED
This adds a `CMAKE_FIND_REQUIRED` variable which causes `find_package`,
`find_path`, `find_file`, `find_library` and `find_program` to be
considered `REQUIRED` by default.

It also introduces an `OPTIONAL` keyword to those commands, allowing
them to ignore the value of this variable.

Issue: #26576
2025-02-27 10:51:07 -05:00
Brad King
2123244746 FindGCCXML: Add policy to remove this module
GCC-XML has been superseded by CastXML for a long time.

Closes: #26687
2025-02-17 11:35:25 -05:00
Matthew Woehlke
619c1bacfd Tests: Separate out CPS RunCMake/find_package tests
The set of RunCMake/find_package tests is quite large, which makes
development and management less efficient. While this could probably
stand additional refactoring, split out just the CPS tests for now, as
those are currently under active development.
2025-02-06 15:23:09 -05:00
Matthew Woehlke
894f256a12 find_package: Find CPS components
Implement finding components of CPS packages. Specifically, reject any
candidate packages that don't provide all required components, and
ignore appendices that don't provide requested (required or optional)
components. This applies to both top-level searches and also searching
for package dependencies.
2025-02-01 06:44:43 -05:00
Matthew Woehlke
42de87cbae find_package: Find CPS dependencies
Implement finding dependencies of CPS packages. This is done by setting
up additional `cmFindPackageCommand` instances which are used to look
for a parent package's dependencies.
2025-01-13 08:43:14 -05:00
Brad King
adfb0623cb find_package: Fix assertion failure on empty sysroots
Previously we crashed if at least one root variable was set to empty and
at least one to non-empty.

Fixes: #26538
2024-12-19 09:58:02 -05:00
Kyle Edwards
f8264cf2ff
find_package(): Debug re-rooting behavior
find_package()'s debug mode provides information about which
prefixes are searched, but not which roots are prepended to each
prefix. Display this information if debugging is enabled.
2024-08-02 16:18:44 -04:00
Brad King
e0355c4ea9 FindBoost: Add policy to remove this module
Upstream Boost 1.70 and above provide a proper `BoostConfig.cmake`
package configuration file.  Packages for all major distros now
provide it in at least one LTS release.  Add a policy to pretend
that the `FindBoost` module does not exist so that projects calling
`find_package(Boost)` use the upstream package directly.

Closes: #19402
2024-05-03 10:30:23 -04:00
Brad King
5e5132e1b1 MinGW: Search for packages in standard MSYSTEM environment prefixes
MSYS2 and similar MinGW/MSYS distributions define development
environments with a `MSYSTEM` environment variable.  Each such
environment has a documented installation prefix for its packages,
often provided by a `MSYSTEM_PREFIX` environment variable.
Since commit 84a25fc263 (cmake_host_system_information: Add
MSYSTEM_PREFIX query, 2023-09-08) we can look up this prefix.

Add `$MSYSTEM_PREFIX/local` and `$MSYSTEM_PREFIX` to our system search
prefixes when targeting MinGW under `MSYSTEM` environments.  This is
their equivalent to `/usr/local` and `/usr`, which we search by default
on UNIX systems.

Issue: #24216
2023-09-13 08:35:59 -04:00
Brad King
a4c5b91f80 FindPython{Interp,Libs}: Add policy to remove these modules
The `FindPythonInterp` and `FindPythonLibs` modules have been deprecated
since CMake 3.12.  Add a policy to pretend they do not exist in order to
encourage projects to port to `FindPython` or `FindPython{2,3}`.
2023-03-30 12:05:09 -04:00
Brad King
7a7793e6d7 FindCUDA: Disallow with CMP0147 under Visual Studio
FindCUDA's custom commands invoke `nvcc`, which invokes `cl`.  Under VS
this is done without a `/FS` flag, so `.pdb` generation races if we
use `BuildInParallel`.  The FindCUDA module has already been removed by
policy CMP0146 after being deprecated since CMake 3.10, so it is
simplest to just disallow this combination of features.

Issue: #24576
2023-03-12 07:52:15 -04:00
Brad King
2c146a7fc5 FindCUDA: Add policy to remove this module
The `FindCUDA` module has been deprecated since CMake 3.10.
Add a policy to pretend it doesn't exist in order to encourage
projects to port away from it.
2023-03-09 07:39:36 -05:00
Brad King
2e469212c8 Dart,FindDart: Add policy to remove these modules
These modules and the "DART" tool they support have long been replaced
by CTest.
2023-02-28 08:43:45 -05:00
Brad King
df9c4b1872 find_package: Use <PACKAGENAME>_ROOT variables as search prefixes
Extend commit eb35d8884b (find_package: Use PackageName_ROOT variables
as search prefixes, 2018-03-15, v3.12.0-rc1~349^2) to also check
upper-case `<PACKAGENAME>_ROOT` variables.  Add policy `CMP0144` to
enable the behavior in a compatible way.

Fixes: #24403
2023-02-23 09:15:14 -05:00
Alex Turbov
a081606855 Tests: Add more find_package search path cases 2022-07-11 17:14:01 +04:00
Marc Chevrier
8d7e80cf3d find_* commands: add control over Windows registry views
Fixes: #22775
2022-04-29 22:00:02 +02:00
Robert Maynard
42f7e39789 Find: Support per call disabling of CMAKE_INSTALL_PREFIX
Fixes #23359
2022-04-15 09:33:55 -04:00
John Parent
2f1ffa003c find_package: Add support for default GLOBAL imported targets
Allow find package to promote scope of imported targets by specifying
an argument to `find_package` or by specifying a CMake variable.
    * Add support for CMAKE_GLOBAL_IMPORT_SCOPE variable
    * Add support for GLOBAL argument to find_package

Additionally add testing for above features.
2022-03-10 12:44:36 -05:00
Brad King
38de1bef2d find_package: Improve --debug-find-pkg= when using a find module
Extend the feature added by commit d7b18895bc (cmake: Add filtered
debug-find options, 2021-12-07, v3.23.0-rc1~217^2) to enable debug
output for `find_*` calls within a find module or cmake package
configuration file.

Fixes: #23211
2022-02-10 16:30:10 -05:00
Brad King
2f43527574 Tests: Improve order of RunCMake.find_package cases
Sort recently added cases among similar-named cases.
2022-02-10 15:25:05 -05:00
Kyle Edwards
201d8c4298 find_*(): Add CMAKE_IGNORE_PREFIX_PATH variable
Fixes: #20878
2022-02-02 11:09:00 -05:00
Kyle Edwards
30e5c1d92b find_package(): Add tests for CMAKE_IGNORE_PATH 2022-01-31 10:33:54 -05:00
John Parent
d7b18895bc cmake: Add filtered debug-find options
Add a `--debug-find-pkg=` option to debug find calls for specific
packages.

Add a `--debug-find-var=` option to debug find calls for specific
return variables.

Fixes: #21880
2021-12-17 08:55:21 -05:00
Alexandru Croitor
91ec6eee58 find_package: Don't reroot prefix that is equal to a root path
When both CMAKE_FIND_ROOT_PATH and CMAKE_PREFIX_PATH are set to
/opt/my_device_sysroot, cmFindCommon::RerootPaths would only look
for packages in /opt/my_device_sysroot/opt/my_device_sysroot
but would not try to look in /opt/my_device_sysroot.

Make sure to not reroot the prefix path in such a case.

Fixes: #21937
2021-10-20 18:50:41 +02:00
Eugene Shalygin
a2e9fe38e4 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.
2021-07-08 08:03:38 -04:00
Robert Maynard
e609afeb5f WriteBasicConfigVersion supports version strings such as 21.07.04
Fixes #22207
2021-05-27 15:18:37 -04:00
Orgad Shaneh
ddcd1469e8 MSYS: Add support for running under MSYS runtime environment
Detect MSYS as CYGWIN, with the required adaptations.
2021-04-26 14:27:34 -04:00
Marc Chevrier
212b0afb66 find_package: raise error on empty version range 2020-09-29 13:06:09 +02:00
Marc Chevier
d7df81067b find_package: Add support of version range
This enhancement is the first step for solving issue #21107
2020-09-23 12:52:25 +02:00
Robert Maynard
204b8d9f4e find_*: Use debug logging infrastructure
Teach the find_package, find_library, find_program, find_path, and
find_file commands to print debug log messages when enabled by the
`--debug-find` command-line option or `CMAKE_FIND_DEBUG_MODE` variable.
2019-12-19 08:09:49 -05:00
Robert Maynard
609fe39043 FindPackage: Support NO_[]_PATH global call options 2019-07-22 17:17:02 -04:00
David Aguilar
b773e58099 find_package: add test coverage for CMAKE_FIND_PACKAGE_RESOLVE_SYMLINKS 2019-01-16 09:59:46 -05:00
Kyle Edwards
0f5c1b404b find_package(): Add policy to remove the FindQt module
Removing FindQt.cmake gives Qt upstream a path forward to export its
own QtConfig.cmake files which can be found by find_package()
without having to explicitly specify CONFIG. Projects that still
want to use Qt3/4 can call find_package(Qt[34]), include(FindQt),
or add FindQt.cmake to their CMAKE_MODULE_PATH.
2018-11-14 15:05:06 -05:00
Brad King
eb35d8884b find_package: Use PackageName_ROOT variables as search prefixes
This feature was originally added by commit v3.9.0-rc1~71^2~2 (find_*:
Add a new PackageRoot search path group, 2017-05-03) and documented by
commit v3.9.0-rc1~71^2 (find_*: Add docs for PackageRoot search path
group, 2017-05-03).  However, we had to disable the feature and remove
the documentation in commit v3.9.1~2^2 (find_*: Disable the PACKAGE_ROOT
search path group for CMake 3.9, 2017-08-08) due to breaking projects
that used `PackageName_ROOT` variables themselves.

Add policy `CMP0074` to restore the `PackageName_ROOT` variable behavior
in a compatible way.  Also revise the stack of root paths to store the
paths themselves rather than the package names.  This way the policy can
be considered at the `find_package` call site instead of individual
`find_` calls inside a find module.

Co-Author: Chuck Atkins <chuck.atkins@kitware.com>
Issue: #17144
2018-03-16 09:19:28 -04:00
Chuck Atkins
4a20711690 find_package: Split PACKAGE_ROOT tests to work with smaller regex 2017-08-02 12:03:52 -04:00
Brad King
e7730d78b4 find_package: Restore longer message when config files were considered
Since commit v3.9.0-rc1~58^2 (find_package: shorten output for missing
package in config mode, 2017-05-09) we print only the one line

    - Could NOT find Foo (missing: Foo_DIR)

when package Foo cannot be found in CONFIG mode and it is not REQUIRED.
However, in the case that package configuration files were found but not
used, this one line message leaves out important information.  This can
happen when a package configuration file sets `Foo_FOUND` to `FALSE` or
when its package version file does not match the requested version.
Restore the longer message in these cases.  Otherwise a seemingly valid
explicit `Foo_DIR` setting appears to be silently ignored even if it was
considered.

Fixes: #17029
2017-07-07 11:43:59 -04:00
Chuck Atkins
57744ca9c0 find_*: Add tests for PackageRoot search path group 2017-05-16 15:19:45 -04:00
Brad King
b219ff94ac Tests: Add case for package version file unmatched policy scope 2015-11-24 14:01:21 -05:00
Brad King
6d100f9f46 find_package: Test rejection of required+optional components 2012-03-19 10:53:36 -04:00
Alex Neundorf
0cf84472d7 find_package: additional test for checking the error message
This patch adds a test which checks the error message, which is
produced in the case that a Config file has set Foo_FOUND to FALSE
by itself.

Alex
2012-03-13 16:56:52 -04:00
Brad King
eb33000d75 Use generalized RunCMake test infrastrucure for find_package test 2012-03-12 09:33:21 -04:00