Commit Graph

30 Commits

Author SHA1 Message Date
Matthew Woehlke 2151e5f79d export, install: Improve argument parsing
Modify the `export(EXPORT)` and `install(PACKAGE_INFO)` commands to
actually enforce that certain arguments must be non-empty. With respect
to `export`, this is mainly targeted at CPS export, but ends up
affecting all flavors of `export(EXPORT)` because that is the level at
which argument parsing is performed.

Also, add unit tests to verify that the new rejection of arguments with
missing or empty values is working, update the existing tests due to
changes in error reporting, and remove no-longer-needed manual
validation of an empty `PACKAGE_INFO` argument.
2025-12-09 13:37:01 -05:00
Brad King d6b76cdc87 Merge topic 'cps-validate-version'
cc508826b4 CPS: Validate package version
fb66a14da2 cmExportFileGenerator: Allow other message types

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !11458
2025-12-02 15:43:42 -05:00
Brad King a294c9ac1a Merge topic 'fix-cps-arg-parsing'
41b6b07527 cmExportCommand: Fix PACKAGE_INFO argument parsing

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !11459
2025-12-02 15:20:14 -05:00
Matthew Woehlke 41b6b07527 cmExportCommand: Fix PACKAGE_INFO argument parsing
While I'm unsure about why `cmPackageInfoArguments` was originally
written the way it was, in its current form, the way command sub-parsers
work, the parser never considers arguments associated with a sub-parser
if the sub-parser keyword isn't present. This means that the arguments
associated with `cmPackageInfoArguments` are treated as unknown, and the
logic to reject them being set if `PACKAGE_INFO` is not present can
never actually execute. Therefore, remove it, and remove the associated
(and effectively useless) `enable` argument to its `Check` method.

Instead, ensure that the package name is actually specified. The only
case in which the parser will create the `optional` associated with the
sub-parser arguments is if the relevant keyword (i.e. `PACKAGE_INFO`) is
present. However, while the associated value is `NonEmpty`, the way we
are using the parser does not actually enforce this, and it looks like a
correct fix may be a breaking change. Therefore, enforce it manually for
now.
2025-12-01 11:22:58 -05:00
Matthew Woehlke cc508826b4 CPS: Validate package version
Add version validation to cmExportPackageInfoGenerator. Specifically, if
a package uses the "simple" version schema (which is the default if no
schema is specified), validate that the specified version actually
conforms to the schema and issue an error if it does not. Also, issue a
warning if the schema is not recognized.
2025-11-26 17:04:26 -05:00
Matthew Woehlke 37b15eda3b CPS: Fix exporting definitions
Export compile definitions to CPS using the correct attribute name.

Fixes: #27403
2025-11-21 15:32:41 -05:00
Brad King 9d7393a0b0 Merge topic 'improve-cps-project-error' into release-4.2
f2b7184b98 cmPackageInfoArguments: Improve error message

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Reviewed-by: Ben Boeckel <ben.boeckel@kitware.com>
Merge-request: !11363
2025-10-28 09:28:11 -04:00
Brad King 68e836d20b Merge branch 'backport-4.1-improve-cps-export-namespace-error' 2025-10-27 15:56:11 -04:00
Matthew Woehlke 86e647ef2a CPS: Improve invalid namespace error
When CPS export fails due to a dependency on an improperly named
external target, reiterate the "canonical namespace" in the error
message for clarity.
2025-10-27 14:40:34 -04:00
Matthew Woehlke f2b7184b98 cmPackageInfoArguments: Improve error message
When given the name of a project that doesn't exist, report it as an
"unknown project" rather than an "invalid project". This is more
consistent with other, similar reporting.
2025-10-27 12:29:40 -04:00
AJIOB 5de7a09e77 Tests/RunCMake: Match dots more precisely, part 3 2025-10-20 14:45:24 -04:00
AJIOB 62b112ee25 Tests/RunCMake: Match CMakeLists.txt file name more precisely 2025-10-16 17:42:12 +03:00
AJIOB 06ccd15457 Tests/RunCMake: Match xxx.cmake file name more precisely 2025-10-16 17:42:12 +03:00
Taylor Sasser d92b6c3e20 CPS: Add Symbolic Components
Adds support for "symbolic" components, which represent feature-level
capabilities of a package that do not correspond to actual build targets.
These are modeled as pseudo-targets, using the INTERFACE type as a base,
and can be queried via:

  get_target_property(... <tgt> "SYMBOLIC")

This enables consumers to declare requirements on optional features
(e.g., SSL support) even when they do not map to concrete targets.

Fixes: #27187
2025-10-02 10:46:02 -04:00
F. Pichot a20e9569f1 install(PACKAGE_INFO): Record COMPONENT in global COMPONENTS list
Fixes: #27249
2025-09-23 10:23:37 -04:00
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 4bb4bbcf59 Tests: Actually test CPS generation with no config
Commit 58d9950842 (CPS: Fix empty configuration field on noconfig
builds, 2025-06-30) fixed an issue with CPS generation that would
incorrectly use the empty string to identify the configuration in some
instances. (The expected CMake behavior is that an empty configuration
is always equivalent to 'noconfig'.) However, that commit did not add
any tests for the fix.

Add those tests now. Also, tweak the tests that were added, that test
for expected non-empty configuration-specific content, to hard-code what
configuration or configurations are produced. Lastly, remove the
explicit test for existence of the CPS file in said tests; `file(READ)`
will complain if the file does not exist, so the separate test is
superfluous.
2025-07-03 13:58:31 -04:00
Vito Gamberini 7db44fbfb8 CPS: Support FILE_SET HEADERS
Fixes: #26806
2025-07-02 10:34:10 -04:00
Brad King b938922909 Merge topic 'cps-noconfig-fix'
58d9950842 CPS: Fix empty configuration field on noconfig builds

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !10922
2025-07-02 08:00:39 -04:00
Vito Gamberini 58d9950842 CPS: Fix empty configuration field on noconfig builds
Fixes: #27044
2025-07-01 17:01:13 -04:00
Matthew Woehlke 755a24ccae CPS: Add export support for [default_]license
Add `LICENSE` and `DEFAULT_LICENSE` arguments to the `PACKAGE_INFO`
modes of the `install` and `export` commands. If not otherwise
specified, the `LICENSE` will be taken from the project's
`SPDX_LICENSE`, if available.
2025-06-20 14:01:25 -04:00
Matthew Woehlke bb1e00b92c cmPackageInfoArguments: Validate new arguments
Add validation of recently added `DESCRIPTION` and `HOMEPAGE_URL`
arguments to `export`/`install` commands.
2025-06-13 14:30:46 -04:00
Matthew Woehlke da97747dac CPS: Support additional metadata
Add support for specifying CPS's supplemental `description` and
`website` attributes. Add ability to inherit these from the `project()`,
similar to how version information can be inherited.
2025-06-03 16:50:46 -04:00
Matthew Woehlke ecf81c1bc1 CPS: Get metadata from project
Modify {export,install}(PACKAGE_INFO) commands to inherit version
information from the current project in situations where it seems
reasonable to do so. Add an option to explicitly request inheritance
from a specific project.

This leverages the recently added project(COMPAT_VERSION).
2025-06-02 10:31:36 -04:00
Matthew Woehlke 9adf93d112 Tests/InstallPackageInfo: Consolidate bad arguments tests
Consolidate InstallPackageInfo's bad arguments tests into only two test
cases that each test multiple invocations, rather than having a single
test per invocation. This makes them match the similar ExportPackageInfo
tests which were necessarily consolidated due to those testing many more
variants (due to differences in the respective interfaces). This will
simplify adding additional tests in the future.
2025-06-02 10:31:36 -04:00
Daniel Tierney df3e246bc1 export: Import/export target property for license
Add import/export support and documentation for the SPDX_LICENSE
target property. A target's license can be specified by setting
this property to an SPDX license expression. CMake and CPS-format
export files generated with `export()` or `install()` will
retain the license information. CMake also imports the license
property for imported targets.

Closes: #26706
2025-05-13 17:01:20 -04:00
Taylor Sasser 555ecfa046 Add tests for install(PACKAGE_INFO) destination 2025-04-28 11:05:31 -04:00
Brad King 953e5ec831 Merge branch 'backport-export-multiple-set-not-installed' 2025-03-17 18:04:53 -04:00
Matthew Woehlke c8ccd5a9e3 export: Add build-tree CPS support
Add Common Package Specification support to export(EXPORT).
2025-02-25 15:42:23 -05:00
Matthew Woehlke 9d83a1ed1f Tests: Rename certain CPS tests
Rename the RunCMake/PackageInfo and RunCMake/CpsExportImport tests to
indicate that they cover CPS generated by the install command. This
opens space for similar tests that will cover CPS generation via the
export command.
2025-02-25 12:18:13 -05:00