53019cd2e6 install(TARGETS): Add option to install runtime deps built as other targets
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12483
Follow up commit 21cc5937c1 (install(TARGETS): Factor out reusable
helpers with config-specific support, 2026-09-10) to avoid copying the
categorized argument groups unnecessarily.
Adjust documentation of `install(CODE|SCRIPT)` to more understandably
reflect how the subcommand actually operates. Adjust argument parsing of
the same to "accept" the `COMPONENT` argument being given more than
once, consistent with how single-valued arguments are usually parsed.
21cc5937c1 install(TARGETS): Factor out reusable helpers with config-specific support
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12496
In debug builds, we assert and abort to give more useful crashes for
development (i.e., instead of triggering UB). Otherwise, we get the
optimization benefits of `unreachable()` (or the older
platform-specific fallbacks per `cm/utility`).
Installing a module target without a LIBRARY DESTINATION no longer
raises an error. On DLL platforms, the default destination is the
RUNTIME default. Otherwise, the LIBRARY default is used.
Closes: #27759
The install({TARGETS, EXPORT}) versions of the command now accept ALIAS
targets. The behavior is identical to what would happen if the name of
the target that the ALIAS references were put instead. The
export(TARGETS) command also has the same support and behavior for ALIAS
targets now.
Closes: #20979
Move some target related enumeration types from `cmStateTypes.h` to a
new header, as these really aren't "state" types. Also, make
`TargetType` a strongly-typed enumeration.
The original addition of CMD_INSTALL_ABSOLUTE_DIR by commit
39a56136a3 (Diagnostic: Add warn or error on absolute install paths,
2026-03-25) didn't cover all install signatures. Add checks to cover
those install types that weren't covered by the original commit.
Add and use a couple helper functions for issuing policy warnings. This
improves consistency and allows some simplification of many call sites.
(One or two instances in particular are greatly simplified.)
- Change default CPS install path on Windows from `cps` to `cps/<name>`,
per community recommendation that only paths containing the package name
should be considered as "officially" supported search locations (see
https://github.com/cps-org/cps/issues/79#issuecomment-2831102822).
- Change `export` to write to a subdirectory that allows the build
tree to be used as a search root.
- Change SBOM destinations to be consistent with the preceding.
Issue: #27785
Add new diagnostic categories CMD_POLICY and CMD_EXPERIMENTAL, both as
children of CMD_AUTHOR. Use the former when issuing policy warnings. Use
the latter when issuing experimental feature warnings.
Modify `cmInstallGenerator` to have a `cmDiagnosticContext` instead of
just a `cmListFileBacktrace`. Create helpers to obtain a state capture
that includes `CMD_INSTALL_ABSOLUTE_DESTINATION`. Modify most subclasses
(namely, ones that have a `DESTINATION`) to use this new state capture.
This fixes a limitation identified when 39a56136a3 (Diagnostic: Add warn
or error on absolute install paths, 2026-03-25) added the aforementioned
diagnostic, that the install generator(s) no longer have access to the
diagnostic state as of the `install` invocation which ultimately caused
the diagnostic if that scope is not the top-most scope of the current
subdirectory.
Note that some of the generators which capture context have not actually
implemented the diagnostic yet.
Fix most snake_case identifiers in cmInstall* to use camelCase instead.
Also, update clang-tidy configuration to help with applying these
changes, though the relevant check remains off by default.
Add `-Winstall-absolute-destination` diagnostic to warn or
error when an install command has an absolute destination.
This allow projects to enforce the best practice of not allowing
absolute install DESTINATIONS.
Find places that are currently relying on diagnostic-specific message
types to issue diagnostics and replace these with calls to the new
diagnostic methods.
Remove basic CPS import and export from 'experimental' status. Update
documentation and tests accordingly.
Note that mapped exports (CMAKE_EXPERIMENTAL_MAPPED_PACKAGE_INFO) are
still experimental.
The conversion between internal list representations led to empty
directories being left behind when processing generator expressions in
the destination. This ensures the intended behavior of creating a
destination directory but installing nothing into it when no <dirs> are
specified, regardless of the presence or absence of genex.
Further, an explicit empty string <dir> (via `""`, or an undefined
variable) led to the current source directory being expanded as a file
to install, leading to the generation of an infinitely recursive
install command. Disallow this behavior, forcing projects to explicitly
specify the current source directory if that is their intention.
Fixes: #27568
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.
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.
Add the ability to generate CPS package information when install(EXPORT)
is used. This relies on additional information to be passed to CMake,
and is intended as a way of getting CPS out of existing projects without
needing to make changes to the projects' CMakeLists.txt. (Particularly,
this feature is intended for package distributors, not project authors.)
Add an explicit check in `install(EXPORT)` that the export name is
non-empty. Since an empty-named export set will never exist, this is
always an error. Previously, however, the error would not be caught
until generate time. Now an error will be produced immediately.
Revert commit b70ef48b27 (install(DIRECTORY): Add
EXCLUDE_EMPTY_DIRECTORIES option, 2025-04-20, v4.1.0-rc1~212^2).
The implementation had at least two problems:
* It did not exclude the top-level directory if empty.
* It did not exclude non-empty directories whose contents are
all filtered out.
Revert the feature pending a revised implementation.
Issue: #19189Closes: #27092