Commit Graph

369 Commits

Author SHA1 Message Date
Brad King
3c0dbb66f5 CMP0011: Remove support for OLD behavior 2025-01-17 09:28:36 -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
1c6cecdce9 cmFindPackageCommand: Fix searching a root path as a prefix
A root path like `/` or `c:/` needs to end in a slash.  Revise our
prefix search logic to maintain a trailing slash instead of removing one
just to add it again.
2024-12-19 09:56:24 -05:00
Matthew Woehlke
34828650d6 find_package: Add experimental gate for CPS support 2024-12-13 08:58:24 -05:00
Matthew Woehlke
25cc83428e find_package: Actually import .cps files
Implement logic (partly adapted from the 2023 proof-of-concept) to
actually parse CPS files and generate imported targets. Implement logic
to locate and load supplemental files. Adjust prefix handling to require
that the CPS file provides sufficient information to translate the
prefix placeholder into a meaningful path. (Note that this corresponds
to a change in the specification.)
2024-12-13 08:58:24 -05:00
Matthew Woehlke
91c31ada23 find_package: Actually find .cps files
Add a helper class to read CPS files. Use this to teach find_package how
to consider and accept .cps files in its search. (Note that no version
testing is performed at this time.) Add a simple test that we can find a
package from a .cps file and correctly extract the version information.

Note that this doesn't actually import anything from CPS yet.
2024-12-13 08:58:24 -05:00
Matthew Woehlke
b89e43b2bc find_package: Start implementing CPS search
Teach find_package to search CPS search paths, and to look for CPS file
names. Modify the set of file names to also include the file type (CPS
or CMake-script). Modify the search function to allow specifying which
file type(s) to consider.

During full path search, each possible path is searched for only one of
the two possible file types. However, subsequent runs, or when
considering a user-specified path (<name>_DIR), CMake will look for both
file types.

Note that this only adds the new path search logic as described above;
CMake does not yet know how to read CPS files, and there is a high
likelihood that Bad Things will happen if it tries. However, this seemed
like a good place to checkpoint.
2024-12-13 08:58:24 -05:00
Brad King
592e95bbea cmFindPackageCommand: Avoid temporarily saving non-existent result 2024-12-12 11:38:29 -05:00
Brad King
8d6b76771d find_package: Explicitly normalize CONFIG file path as it exists on disk
This was missed in commit 9d44a77454 (find_*: Explicitly normalize found
paths as they exist on disk, 2024-10-17).
2024-12-12 11:36:40 -05:00
Brad King
b66c010033 Merge topic 'refactor-find_package'
e2a6416622 find_package: Refactor in support of recursion
bd542748af find_package: Use map::emplace instead of make_pair

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !10054
2024-12-09 09:59:00 -05:00
Matthew Woehlke
3f450d2680 find_package: Fix sign-cast warning
Tweak a helper function to avoid an implicit cast from unsigned to
signed. This is hardly the only -Wsign-conversion we are tripping, but
cmFindPackage is now free of such.
2024-12-03 17:19:39 -05:00
Matthew Woehlke
e2a6416622 find_package: Refactor in support of recursion
Separate argument handling and actual operation of the find_package
command into separate methods. This is preparatory to adding improved
support for transitive dependencies and will allow nested calls to be
set up using structured data types, rather than having to perform all
communication via a constructed argument list.

As a consequence, the sets of required and optional components, as well
as the component list string, are now members rather than local
variables. This also allows us to drop some parameters and simplify how
we set the variables indicating which components are required.
2024-12-03 11:15:51 -05:00
Matthew Woehlke
bd542748af find_package: Use map::emplace instead of make_pair
Replace map::insert(make_pair(...) with map::emplace(...). This should
be slightly more efficient, but also removes one of only two uses of
std::pair. (Upcoming changes are going to remove the other, which will
let us drop use of <utility>.)
2024-11-29 16:15:59 -05:00
Alex Turbov
b48d5aeae7 find_*: Improve error message quoting consistency
Some error messages (Windows registry related) of the `find_xxx` and
`cmake_host_system_information` commands, reported keywords in quotes,
while most commands did not.
2024-11-27 08:30:15 -05:00
Alex Turbov
d6d7ac51c8 cmFindPackageCommand.cxx: Optimize cmStrCat() calls 2024-11-27 08:30:15 -05:00
Matthew Woehlke
ea28b30e04 find_package: Allow cmDirectoryListGenerator::Names to be nullptr
Change cmDirectoryListGenerator::Names to be a pointer rather than a
reference wrapper. This allows it to be a null pointer, which allows
cmAnyDirectoryListGenerator to pass a nullptr rather than needing to
construct and hold an empty list just to satisfy the reference being
non-null. Importantly, it also make it more obvious that anyone
constructing a cmDirectoryListGenerator or subcless thereof needs to
pass something that isn't going to immediately go out of scope.
2024-11-25 12:41:56 -05:00
Brad King
659d8bd430 cmPolicies: Remove now-unused REQUIRED_IF_USED and REQUIRED_ALWAYS states 2024-11-13 11:43:07 -05:00
Matthew Woehlke
230e5ec172 find_package: Don't test <name>_DIR against ignored paths
Tweak `find_package` to not compare an already-specified `<name>_DIR`
against the set of ignored paths. This is a minor behavior change in
that, if a previously found package is in a location that is NEWLY
ignored (i.e. because the user modified the ignored paths since the
previous run of CMake), we won't throw out the old result. However, it
also means that a user specifying `<name>_DIR` takes precedence over the
set of ignored paths, which seems like the desired behavior.

Note that the current behavior was introduced in commit 11f97d1968
(find_package: Refactor CMAKE_[SYSTEM_]IGNORE_PATH, 2022-01-28,
v3.23.0-rc1~31^2) and appears to have been unintentional.
2024-10-29 15:01:04 -04:00
Matthew Woehlke
6f3dc1161a find_package: Also sort Framework matches
Add cmAnyDirectoryListGenerator, which matches any directory but also
sorts matches in the same manner as cmProjectDirectoryListGenerator.
Modify SearchFrameworkPrefix to use this, in combination with a literal
path (cmAppendPathSegmentGenerator), instead of cmFileListGeneratorGlob
(which is removed, as it is no longer used). This improves the
consistency of when sorting is available.

This uses cmDirectoryListGenerator's new ability to match anything, as
mentioned in the previous commit.
2024-10-24 13:42:42 -04:00
Matthew Woehlke
e90f60f864 find_package: Don't glob certain macOS paths
Modify cmDirectoryListGenerator to support exact matching as well as
'starts-with' matching. The latter is used to implement '<name>*' search
paths, but cmDirectoryListGenerator is also used for '<name><suffix>'
matching (via cmMacProjectDirectoryListGenerator, mainly for macOS
paths), which resulted in the latter actually matching '<name><suffix>*'
even though that is not documented and unlikely to be useful.

This also adds the ability for cmDirectoryListGenerator to match
anything (by giving an empty list of names), which isn't in use yet, but
which we will use in the future.
2024-10-24 12:59:51 -04:00
Brad King
9d44a77454 find_*: Explicitly normalize found paths as they exist on disk 2024-10-22 13:26:19 -04:00
Brad King
2108f3507f cmSystemTools: Add SplitEnvPathNormalized to split paths from environment 2024-10-22 13:23:27 -04:00
Daniel Pfeifer
58c5f77837 clang-tidy: fix readability-redundant-* warnings 2024-10-11 15:37:21 +02:00
Vitaly Stakhovsky
58da4aa47d Source: Avoid comparing pointers to nullptr 2024-08-27 10:56:38 -04: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
8b3d48ab94 Merge topic 'save-restore-PACKAGE_PREFIX_DIR'
41f4e1c457 CMakePackageConfigHelpers: Document PACKAGE_PREFIX_DIR for public use
c5231ba29e find_package: Save/restore PACKAGE_PREFIX_DIR
8ac7958e3a generate_apple_*_selection_file: Save/restore PACKAGE_PREFIX_DIR
bf88879f1f generate_apple_architecture_selection_file: Avoid early returns
a4ac2c92f4 Help: Add missing section heading for apple architecture selection
b7fcc44be9 Help: Fix CMakePackageConfigHelpers typos, grammar and formatting
f1cacaa830 Tests/RunCMake/CMakePackage: Define variable closer to where it is used

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !9430
2024-04-22 08:42:13 -04:00
Craig Scott
c5231ba29e find_package: Save/restore PACKAGE_PREFIX_DIR
Package configuration files generated by `configure_package_config_file`
set this variable in `@PACKAGE_INIT@` and then use it later.  There may
be intervening calls to `find_package`, e.g., via `find_dependency`.
If the loaded package also used `configure_package_config_file`, it
may change the value of `PACKAGE_PREFIX_DIR`.  Explicitly save and
restore the value to avoid this.

Fixes: #25827
2024-04-19 11:44:09 -04:00
Vitaly Stakhovsky
1a49b439a5 Source: Use cmValue::IsOn and IsOff
Speed up a bit by calling members directly.
2024-03-17 19:05:37 -04:00
Kyle Edwards
c6e6861e63 install(EXPORT): Export find_dependency() calls
Issue: #20511
Co-Authored-by: Brad King <brad.king@kitware.com>
Co-Authored-by: Robert Maynard <rmaynard@nvidia.com>
2023-11-13 11:07:52 -05:00
Brad King
241ee252ce IWYU: Update for Debian 12 CI job
`include-what-you-use` diagnostics, in practice, are specific to
the environment's compiler and standard library.  Update includes
to satisfy IWYU for our CI job under Debian 12.
2023-07-28 09:14:08 -04:00
Marc Chevrier
4fc322bab4 AddCacheEntry: Suppress raw pointer usage 2023-05-30 16:41:59 +02:00
Marc Chevrier
aa5fed5052 SetProperty: suppress raw pointer usage 2023-05-26 14:48:22 +02:00
Marc Chevrier
241304190f CMake code rely on cmList class for CMake lists management (part. 2) 2023-04-29 09:54:31 +02:00
Marc Chevrier
e08ba229ee CMake code rely on cmList class for CMake lists management (part. 1) 2023-04-24 10:41:10 +02: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
Craig Scott
716ce4402a
find_package: Ensure root path stack and module vars are restored
Fixes: #24595
2023-03-17 21:35:30 +11:00
Brad King
d45992e633 Merge topic 'recursion-limit'
49167cf68f Source: Adjust stack sizes and recursion limits to work together
9504cef8c4 Tests: Allow RunCMake.MaxRecursionDepth to test public-facing default limit
60ef076bac find_package: Enforce maximum nesting depth below maximum recursion depth
89b69bf1ad Add CMAKE_MAXIMUM_RECURSION_DEPTH environment variable
395895bda7 cmMakefile: Factor out helper to get recursion depth limit
88bc8dfc14 cmMakefile: Store recursion depth limit as size_t
fcad8d0630 cmMakefile: Improve parsing of CMAKE_MAXIMUM_RECURSION_DEPTH variable
497f7d5c1a Tests: Simplify option passing to RunCMake.MaxRecursionDepth cases

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !8307
2023-03-14 09:35:45 -04:00
Brad King
60ef076bac find_package: Enforce maximum nesting depth below maximum recursion depth
The stack usage for nested `find_package` calls is much larger than for
other kinds of recursion, so enforce a lower limit to avoid stack
overflow.
2023-03-13 11:48:19 -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
Brad King
bfeb16bd5b cmFindPackageCommand: Refactor CMP0074 logic to de-duplicate lookups 2023-02-23 09:12:29 -05:00
Brad King
c0fcd07e6f cmFindPackageCommand: Factor out methods for package root stack management 2023-02-23 09:12:28 -05:00
Vitaly Stakhovsky
b3edfcf46e cmValue: Use operator* explicitly to convert to std::string; avoid extra call 2023-01-15 23:39:02 -05:00
makise-homura
b1577f7a6a LCC: Update -Wunused-variable warning number as of LCC 1.26.16 2022-12-08 20:34:58 +03:00
Brad King
0dfd939077 cmFindPackageCommand: Suppress LCC false-positive warning
Extend the LCC warning suppression from commit 08e7fb3cfa
(cmFindPackageCommand: Compile-time path generator expressions,
2022-07-05, v3.25.0-rc1~361^2~5) to cover a new number for the
same warning, now produced by LCC 1.26.15.
2022-10-13 10:40:23 -04:00
Alex Turbov
19366408fe cmFindPackageCommand: Protect overrides of cmDirectoryListGenerator
Move virtual function overrides into a protected section of class.
2022-08-04 09:41:59 -04:00
Alex Turbov
e55c154c5b cmFindPackageCommand: Add one more search path
The `PREFIX/(Foo|foo|FOO).*/(cmake|CMake)/(Foo|foo|FOO).*/` search
path is the similar to the one already exists
`PREFIX/(Foo|foo|FOO).*/(lib/ARCH|lib*|share)/cmake/(Foo|foo|FOO).*/`.
2022-08-04 09:41:59 -04:00
Alex Turbov
2f69c0233c cmFindPackageCommand: Optimize the last calls to TryGeneratedPaths 2022-08-02 09:46:52 -04:00