1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-14 02:08:27 +08:00
Commit Graph

411 Commits

Author SHA1 Message Date
Taylor Sasser
ae373e93fb install(PACKAGE_INFO): Add version and location to package dependencies
Refactor `cmFindPackageStack` to track additional metadata
about <package> found. This includes two new fields,
`Version` and `Location` which correspond to package version and path.
The remaining package information will be implemented in a later commit
2025-08-12 11:07:09 -04:00
Matthew Woehlke
b3873b8272 cmFindPackageStack: Allow controlled mutation
As mentioned in the previous commit, we would like to record additional
information in the find-package stack, but we don't have the information
at the point a stack entry is created. This necessitates making the
stack mutable. However, in order to restrict mutation, do not directly
expose the mutable value, and instead arrange for it to be accessible
only via cmFindPackageStackRAII (renamed and extracted from cmMakefile).
This ensures that mutation can only happen while the stack is being
built.
2025-07-30 11:01:14 -04:00
Vito Gamberini
f61768107e find_package: Implement UNWIND_INCLUDE
This implements a limited exception mechanism for find_package() via
the UNWIND_INCLUDE keyword.

When package discovery via find_package(UNWIND_INCLUDE) fails the
StateSnapshot is updated to an UNWINDING state. In this state further
calls to find_package() and include() are forbidden. While in the
UNWINDING state, the include() command immediately calls
SetReturnInvoked() whenever it is reached.

The UNWINDING state is reset when a parent call to find_package() is
reached.

Fixes: #26897
2025-07-13 16:08:19 -04:00
Ben Boeckel
c42d82d569 find_*: support suppressing implicit transition events
When projects explicitly unset variables, the transition detection can
end up reporting events when they are not desired.

See: #24833
2025-06-11 20:09:32 +02:00
Ben Boeckel
0e53a67a7b cmFindPackage: fix over-reporting
Both track when a `_DIR` variable is already defined and suppress
implicit event reporting when a mode that has no reliable method for
such detection.
2025-06-10 20:01:12 +02:00
Ben Boeckel
8b3fc9578a cmFindPackageCommand: report found files to debugging infra 2025-06-09 12:24:32 -04:00
Ben Boeckel
928a74f684 cmFindCommon: always track configure log information
This does mean that debug state is always around, so instead gate the
non-configure log information behind a dedicated variable.
2025-06-09 12:24:31 -04:00
Brad King
6be0c6d26a Merge topic 'astgrep-cmstrcat'
557c44b93e cmStrCat: use character literals where possible
23779057fd cmStrCat: combine neighboring arguments where possible
483d13daf4 ast-grep: add a rule to turn strings into characters
61743471d9 ast-grep: add a rule to find adjacent string literals in cmStrCat calls

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !10790
2025-05-22 08:47:15 -04:00
Brad King
edb80c068b Merge topic 'find-package-event-providers'
3d60b0ba1d configure-log: fill in dependency provider information

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !10785
2025-05-20 09:13:36 -04:00
Ben Boeckel
557c44b93e cmStrCat: use character literals where possible
Found and replaced using the `cmstrcat-to-char-literal` rule for
`ast-grep`.
2025-05-15 19:12:04 +02:00
Ben Boeckel
3ac505f79d cmFindCommon: log search path variables
No pruning of variables which are not relevant is performed as it would
involve duplication of determining which paths to manage.
2025-05-15 12:24:58 +02:00
Ben Boeckel
3d60b0ba1d configure-log: fill in dependency provider information
This uses the special "path" of `dependency_provider::…` to indicate the
provider in use.
2025-05-14 22:12:46 +02:00
Ben Boeckel
8df9819839 find_package: generate find_package-v1 configure log events
Since `find_package` is far more complex than other `find_*` commands,
it gets its own event.

Closes: #24833
2025-05-09 16:46:43 +02:00
Brad King
52903a0ae4 Merge topic 'find-event-refactor'
fdccb8846c cmFindCommonDebugState: adopt event writing logic
716dfd3b1e cmFindCommon: track debug state as an object
c6d097135d cmFindBaseDebugState: factor out a base class
bd5cb1f8e6 cmFindCommon: use `DebugModeEnabled` to query for debug mode
76ea613f4c cmFindBaseDebugState: get the command name directly from the object

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !10713
2025-05-02 11:07:02 -04:00
Brad King
0556c1b455 Merge topic 'fix-find-performane-regression'
bb3a348def find_package: Fix performance regression in 4.0.0 release

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !10731
2025-05-01 15:50:28 -04:00
Matthew Woehlke
bb3a348def find_package: Fix performance regression in 4.0.0 release
In commit e90f60f864 (find_package: Don't glob certain macOS paths,
2024-10-23, v4.0.0-rc1~579^2~1) we changed the name matching logic of
`find_package` to check if a possible match is a directory before
checking whether the name is a match.  In some situations, this results
in unnecessarily calling `stat` for a very large number of files, which
can be extremely slow on some systems (especially Windows).  Fix this by
making the check the last thing we do before accepting a possible match.

Fixes: #26817
2025-05-01 14:48:33 -04:00
Ben Boeckel
fdccb8846c cmFindCommonDebugState: adopt event writing logic
This lays the groundwork for `find_package` also using the same
triggering logic.
2025-05-01 12:47:24 +02:00
Ben Boeckel
716dfd3b1e cmFindCommon: track debug state as an object
This also means that the `DebugState` instances do not need to ask if
debug mode is enabled: if they exist, it is enabled.
2025-04-29 20:10:43 +02:00
Ben Boeckel
bd5cb1f8e6 cmFindCommon: use DebugModeEnabled to query for debug mode
This simplifies changing how debug mode is represented.
2025-04-29 20:10:43 +02:00
Matthew Woehlke
de5fa2ae53 find_package: Improve support for CPS multiple inclusion
Keep track of CPS files we have imported in CMake's state, and use this
(instead of the prior, temporary work-around that used `<name>_CONFIG`)
as a guard for trying to import more than once from the same file. This
has two advantages; first, it is robust against finding the same package
name in different locations in alternating searches, and second, it
allows us to load additional appendices associated with a root package
that has already been loaded.

Fixes: #26731
2025-04-03 14:40:39 -04:00
Brad King
be1f4dde2e Merge topic 'find_package-cps-multiple-inclusion'
b498611902 find_package: Add minimal support for CPS multiple inclusion

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !10581
2025-04-03 14:06:53 -04:00
Matthew Woehlke
b498611902 find_package: Add minimal support for CPS multiple inclusion
Do not try to load a CPS file if we've already loaded the same file.
This only works if the current `find_package` call selects the same file
as the previous most recent call, and if the user has not meddled with
the `<name>_CONFIG` variable.

Issue: #26731
2025-04-02 13:45:36 -04:00
Brad King
ff5712fbfc Merge topic 'find_package-fix-nested-calls'
37823b366f find_package: Restore component requirements in nested calls

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !10576
2025-04-02 10:23:28 -04:00
Matthew Woehlke
37823b366f find_package: Restore component requirements in nested calls
Fix logic to populate required and optional components from CMake
variables when `find_package` is called in a nested context.

This was broken in commit e2a6416622 (find_package: Refactor in support
of recursion, 2024-11-29, v4.0.0-rc1~356^2), which promoted the
component sets from locals (in cmFindPackageCommand::InitialPass) to
member variables. Previously, in a nested context, these sets were
simply not filled, and we relied on the variables indicating component
requirement to already be set. When logic was added to properly fill the
sets (which is needed for CPS), it blindly dumped all components into
the required set, without actually checking whether the context had
marked the components as required or optional.

Fixes: #26824
2025-04-02 10:16:40 -04:00
Brad King
2b8b17106c FindCABLE: Add policy to remove this module
CABLE has not been maintained in a long time.
2025-03-27 09:48:49 -04:00
Brad King
d84881dce6 Merge topic 'fix-cps-cmake-deps'
c3d279841b find_package: CPS component requirements != CMake components

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !10427
2025-03-06 07:53:27 -05:00
Matthew Woehlke
c3d279841b find_package: CPS component requirements != CMake components
Modify how CMake handles required components of a CPS transitive
dependency to not pass them as COMPONENTS if a CMake-script package is
found as the resolved dependency. This is necessary as many CMake-script
package description files do not treat component requests as target
requests (which, in CPS-land, they effectively are), but do implement
logic to mark themselves 'not found' if requested components are
missing. As a result, passing in the required targets as required
components is likely to cause the dependency to be spuriously not found
if it is only available via a CMake-script package configuration file.

Fix this by introducing a new 'required targets' concept, and by passing
CPS component requirements as both required targets and optional
components. The latter serves as a hint for packages that might provide
only a subset of themselves. The former is used to post-validate a
CMake-script package, or is folded on-the-fly into required components
when considering CPS packages.

Note that this functionality is not exposed to the user at this time,
and is only used when resolving transitive dependencies for a CPS
package.
2025-03-05 14:47:49 -05:00
Kitware Robot
1772622772 LICENSE: Replace references to Copyright.txt with LICENSE.rst
```
git grep -lz 'Copyright.txt or https://cmake.org/licensing ' |
  while IFS= read -r -d $'\0' f ; do
    sed -i '/Copyright.txt or https:\/\/cmake.org\/licensing / {
              s/Copyright.txt/LICENSE.rst/
            }' "$f" ; done
```
2025-03-03 10:43:35 -05:00
Kitware Robot
de273b2e11 LICENSE: Replace references to Copyright.txt with LICENSE.rst
```
git grep -lz 'Copyright.txt or https://cmake.org/licensing ' |
  while IFS= read -r -d $'\0' f ; do
    sed -i '/Copyright.txt or https:\/\/cmake.org\/licensing / {
              s/Copyright.txt/LICENSE.rst/
            }' "$f" ; done
```
2025-03-03 09:56:07 -05:00
Brad King
75da788360 Merge topic 'find-package-required'
857a039d66 find_*: Add variable to default calls to REQUIRED

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !10364
2025-02-28 11:15:23 -05:00
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
Hongxu Xu
0e2b87244c find_package: Fix CMAKE_FIND_PACKAGE_SORT_DIRECTION documented default
Previously the documentation said the default was `DEC`,
but the implementation has always defaulted to `ASC`.

Fixes: #22728
2025-02-24 15:03:34 -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
Brad King
a0aa37180c Merge topic 'find-cps-version'
3e6466eb16 find_package: Honor version requests when finding CPS packages
7a0e698384 find_package: Fix CPS version parsing
35a7ed125b find_package: Fix reporting of rejected CPS files' version

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !10297
2025-02-13 09:33:06 -05:00
Brad King
3f2386db2b Merge topic 'find-cps-version' into release-4.0
3e6466eb16 find_package: Honor version requests when finding CPS packages
7a0e698384 find_package: Fix CPS version parsing
35a7ed125b find_package: Fix reporting of rejected CPS files' version

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !10297
2025-02-13 09:33:04 -05:00
Matthew Woehlke
3e6466eb16 find_package: Honor version requests when finding CPS packages
Teach find_package to check a CPS package's version (when provided)
against a version request given to the find_package invocation.
2025-02-12 11:36:41 -05:00
Matthew Woehlke
7a0e698384 find_package: Fix CPS version parsing
Update cmPackageInfoReader's version parsing to more fully conform to
the specification and to reject non-conforming version strings. Start
adding framework to support version schemas other than "simple". Fix how
cmFindPackageCommand extracts version parts to not fail if more than
four parts are present.
2025-02-12 11:35:54 -05:00
Matthew Woehlke
caff0d62c6 cmFindPackageCommand: Simplify cmStrCat
Replace an unnecessary single-character string_view in cmStrCat with a
literal character.
2025-02-11 12:29:06 -05:00
Matthew Woehlke
35a7ed125b find_package: Fix reporting of rejected CPS files' version
The logic to extract the version of a CPS file into the location used to
record files that were considered but rejected was happening too late,
resulting in rejected files unnecessarily reporting their version as
"unknown". Fix this by filling the variable sooner.
2025-02-07 11:57:54 -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
ac20cd43c0 find_package: Fix reporting of transitive dependency errors
Fix find_package to set an error message when trying to find
dependencies of a CPS package fails. This fixes the command previously
reporting "find_package unknown error" for such failures.
2025-02-01 06:20:14 -05:00
Kitware Robot
0b96ae1f6a Revise C++ coding style using clang-format with "east const"
Run the `clang-format.bash` script to update all our C and C++ code to a
new style defined by `.clang-format`, now with "east const" enforcement.
Use `clang-format` version 18.

* If you reached this commit for a line in `git blame`, re-run the blame
  operation starting at the parent of this commit to see older history
  for the content.

* See the parent commit for instructions to rebase a change across this
  style transition commit.

Issue: #26123
2025-01-23 13:09:50 -05:00
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