Commit Graph

1531 Commits

Author SHA1 Message Date
Brad King
7abd3137b7 Linking: Optionally reorder direct dependencies from LINK_LIBRARIES
Traditionally CMake generates link lines by starting with the direct
link dependencies specified by `LINK_LIBRARIES` in their original order
and then appending indirect dependencies that the direct dependencies
do not express.  This gives projects control over ordering among
independent entries, which can be important when intermixing flags
and libraries, or when multiple libraries provide the same symbol.
However, it may also result in inefficient link lines.

Add support for an alternative strategy that can reorder direct link
dependencies to produce more efficient link lines.  This is useful
for projects that cannot easily specify their targets' direct
dependencies in an order that satisfies indirect dependencies.

Add a `CMAKE_LINK_LIBRARIES_STRATEGY` variable and corresponding
`LINK_LIBRARIES_STRATEGY` target property to select a strategy.

Fixes: #26271
2024-09-25 06:48:57 -04:00
Brad King
fdceee50e6 Merge topic 'normalize-install-destination-paths'
6a1fac1450 install: Normalize DESTINATION paths
2184fcfb00 Tests: Configure RunCMake.install cases with correct build type
5a8a6dfe81 cmGeneratorExpression: Change Find() parameter type to cm::string_view
d810374b3d install(PACKAGE_INFO): Remove outdated TODO comment
d13ed01d54 Tests: Remove unused files from RunCMake.install

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !9800
2024-09-20 10:27:30 -04:00
Craig Scott
6a1fac1450 install: Normalize DESTINATION paths
The file generated by install(EXPORT) computes _IMPORT_PREFIX
in a way that assumes a normalized path. If the DESTINATION
contains any ../ components, the computed _IMPORT_PREFIX
would be wrong. Force the DESTINATION path to be normalized,
subject to the new CMP0176 policy.

Also normalize all other DESTINATION paths for consistency,
except for INCLUDES DESTINATION, which is not strictly a
destination but rather a search path to add.

Fixes: #26252
2024-09-19 20:31:47 +10:00
Chen Linxuan
39603a7e5c install: Add TYPE LIBEXEC for FILES and DIRECTORY
Signed-off-by: Chen Linxuan <me@black-desk.cn>
2024-09-18 11:05:28 -04:00
Brad King
e782811cfe execute_process: Change default ENCODING to UTF-8
Windows is heading toward making UTF-8 the preferred MBCS.  As CMake's
internal encoding, `UTF-8` is effectively equivalent to `NONE`, which
was CMake's behavior prior to 3.15's accidental change to `AUTO`.
Behavior of `ENCODING UTF-8` is independent of CMake's internal
encoding, making it in principle a better default than `NONE`.

Add policy CMP0176 for compatibility and to document the default's
history.

Fixes: #26262
2024-09-16 06:37:46 -04:00
Brad King
3898e53e82 execute_process: Document and test ENCODING default
The default was originally AUTO in commit 2ed473b3b8 (execute_process:
Add ENCODING option for Windows child process output, 2016-11-23,
v3.8.0-rc1~232^2) but was changed back to NONE by commit 07c3380a6e
(execute_process: Restore no-decoding default behavior, 2017-02-13,
v3.8.0-rc2~26^2) for CMake 3.8.  Later it was accidentally changed back
to AUTO by commit b783e62533 (cmExecuteProcessCommand: Port to
cmArgumentParser, 2019-03-25, v3.15.0-rc1~270^2) in CMake 3.15 but the
documentation was not updated.  Document the current default, AUTO, and
add a test case to verify it.

Issue: #26262
2024-09-13 08:19:57 -04:00
Brad King
d67519fce8 Help/command/execute_process: Improve formatting of ENCODING names 2024-09-13 08:19:35 -04:00
Brad King
b91ea1b368 Merge topic 'file-archive-workdir'
d8a9aabd24 file(ARCHIVE_CREATE): add WORKING_DIRECTORY option
d65b5a8e03 Help: Format file(ARCHIVE*) options as definition lists

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !9803
2024-09-12 08:10:54 -04:00
Yuri Witte
d8a9aabd24 file(ARCHIVE_CREATE): add WORKING_DIRECTORY option
Fixes: #25260
Issue: #21653
2024-09-11 09:52:32 -04:00
Brad King
d65b5a8e03 Help: Format file(ARCHIVE*) options as definition lists 2024-09-11 09:50:55 -04:00
Brad King
dd023d9707 Merge topic 'add_custom_command-arg-handling'
ec519f3e97 add_custom_command: Validate arguments more rigorously
8dc8be0884 AndroidTestUtilities: Remove DEPENDS that was being silently ignored
316840b430 Tests: Add missing POST_BUILD to custom commands
f5f80305ef ExternalProject: Ensure keywords requiring an argument have one

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !9785
2024-09-11 09:32:24 -04:00
Craig Scott
ec519f3e97 add_custom_command: Validate arguments more rigorously
Add a new CMP0175 policy to preserve backward compatibility
for projects that were using unsupported keywords or arguments.

Fixes: #26096, #21089, #18976
2024-09-10 08:19:09 +10:00
Craig Scott
012d116260 Merge topic 'cmp0168-populate-nondeclare-regression'
cbb727ca6b FetchContent: Don't update verify script timestamp if it doesn't change
795e7b44f2 Help: file(CONFIGURE) only updates output file timestamp if it changes

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !9799
2024-09-08 18:32:40 -04:00
Craig Scott
795e7b44f2 Help: file(CONFIGURE) only updates output file timestamp if it changes 2024-09-06 15:48:38 +10:00
Craig Scott
2000abe74f Help: Recommend good prefixes for cmake_parse_arguments, expand example
Fixes: #25773
2024-08-31 18:33:14 +10:00
Craig Scott
bb37d0e1a5 Help: Improve grammar and wording for cmake_parse_arguments 2024-08-31 18:10:32 +10:00
Brad King
241f923a6f Drop Visual Studio 12 2013 generator
This generator has been deprecated since CMake 3.28.  Remove it.
2024-08-28 14:13:05 -04:00
Brad King
cb2467d69a Merge topic 'if-space-dldt'
2c0d16df7b Help/command/if: fix formatting in precedence order overview

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !9777
2024-08-28 10:04:04 -04:00
Brad King
72607d3402 Merge topic 'cps-export'
b2dc1bd149 CMake: Suppress IBM XL optimization warning
1a846c8849 Tests: Add tests for install(PACKAGE_INFO)
3d52d70b84 export: Add initial CPS support

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !9693
2024-08-27 09:43:51 -04:00
Aleksei Shpakovskii
2c0d16df7b Help/command/if: fix formatting in precedence order overview
Due to extra space symbols, it was rendered as definition list inside
list item, instead of plain list item.
2024-08-27 14:07:58 +02:00
Brad King
d625e832ed Merge topic 'cmake-parse-arguments-one-arg-empty-string'
ceeea4e511 cmake_parse_arguments: Set variable if empty string given after keyword
2f5cc6afa1 cmParseArgumentsCommand: Use cmStrCat() for string concatenation

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !9748
2024-08-26 09:53:16 -04:00
Craig Scott
d48834d277 Merge topic 'doc-get_property-undefined'
a1fdcb9d47 Help: get_property() result var is unset if property is not set
edee1b18b2 Help: Minor formatting and grammar fixes for get_property()

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !9769
2024-08-23 19:16:03 -04:00
Craig Scott
a1fdcb9d47 Help: get_property() result var is unset if property is not set
Fixes: #26152
2024-08-23 09:58:46 +10:00
Craig Scott
edee1b18b2 Help: Minor formatting and grammar fixes for get_property() 2024-08-23 09:57:14 +10:00
Craig Scott
ceeea4e511 cmake_parse_arguments: Set variable if empty string given after keyword
If a single-value keyword is followed by an empty string, the
command unsets the variable for that keyword instead of setting
it to the empty string. This is inconsistent and unexpected. Add
policy CMP0174 which ensures the variable for a single-value
keyword is always set when any value is given, not just for a
non-empty value.

The new CMP0174 policy only affects the PARSE_ARGV form of
cmake_parse_arguments. The older form silently drops all empty
string arguments before processing the argument list.

Fixes: #25972
2024-08-23 09:42:13 +10:00
Aleksei Shpakovskii
2e634501fd Help/command/if: list all condition operators in precedence order overview
This section is near the top and so can serve as an exhaustive
table of contents for the things that `if()` can check.
2024-08-22 11:31:12 -04:00
Brad King
e4a359e5d4 Help/command/if: Document variable expansion by IN_LIST
Previously this behavior was only mentioned implicitly by the command
signature.  Describe it explicitly as we do for other conditions that
automatically expand variables.

Fixes: #26234
2024-08-21 09:17:21 -04:00
Brad King
89d7ed5497 Merge topic 'fix-dependencies-searching'
4d4e008e69 file(GET_RUNTIME_DEPENDENCIES): Fix resolution of repeated ELF dependencies

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !9704
2024-08-20 11:38:27 -04:00
Aliaksandr Averchanka
4d4e008e69 file(GET_RUNTIME_DEPENDENCIES): Fix resolution of repeated ELF dependencies
When a library file name is encountered multiple times, reuse the result
from the first time.  This more closely matches the behavior of the
dynamic loader on Linux.

Fixes: #24621
2024-08-19 08:57:04 +03:00
Craig Scott
13bf4dc9ef Help: State valid scopes for using proj_SOURCE_DIR and proj_BINARY_DIR
Fixes: #25714
2024-08-17 16:11:22 +10:00
Matthew Woehlke
3d52d70b84 export: Add initial CPS support
Add initial support for exporting (install only, for now) Common Package
Specification (https://cps-org.github.io/cps/) format package
descriptions. This has some limitations, such as not supporting
generator expressions (as these cannot be portably exported), and only
partially supporting transitive dependencies, but should be usable for
at least some simple cases. (Actually, $<LINK_ONLY> is theoretically
supportable, but is not yet implemented.)

This still needs tests; these will be added in the next commit. Other
potential improvements include support for language-specific compile
definitions and inferring some package properties from project
properties. Additionally, there is no module support yet; this is partly
pending on having a tool agnostic format for providing the necessary
information.
2024-08-14 15:25:27 -04:00
FeRD (Frank Dana)
38aae609df Help(install): Move RENAME docs to FILES signature
The document's intro claims that the options documented up top are
the ones common to multiple signatures, but `RENAME` is only valid
for `install(FILES ...)`. Move it to that section of the docs.
2024-08-01 12:41:43 -04:00
Vito Gamberini
8555c33d92 PkgC: Add cmake_pkg_config(EXTRACT) command
* Wraps the llpkgc parser with cmPkgConfigParser
* Adds various resolution and mangling code under cmPkgConfigResolver
* Documents new command cmake_pkg_config(EXTRACT). Documentation is written with
  the assumption additional subcommands will be added soon.
* Adds various tests for the above
2024-07-29 13:14:46 -04:00
Brad King
b0ba99f152 Merge topic 'doc-add_test-typo'
ca39258a66 Help: Fix typo in add_test documentation

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !9687
2024-07-29 10:59:00 -04:00
Brad King
ca39258a66 Help: Fix typo in add_test documentation 2024-07-26 10:37:35 -04:00
Martin Duffy
159ba027b9 Install: Add parallel installation option
Fixes: #26000
2024-07-15 11:49:29 -04:00
Juan Ramos
197cb419d1 add_custom_command: Add CODEGEN support
By specifying CODEGEN as an argument to add_custom_command the
custom command will be added to a codegen build target.

The intent is to provide a convenient way for users to get
their generated files without having to build the whole project.

This can be helpful for code analysis tools which can be useful
for IDEs and CI.
2024-07-01 12:02:49 -04:00
Asit Dhal
95323c90a1 file(MAKE_DIRECTORY): Add optional RESULT keyword to capture failure.
Fixes: #26041
2024-06-24 02:20:43 +02:00
Brad King
60da7cb84e Merge topic 'doc-add_subdirectory-EXCLUDE_FROM_ALL'
2449c04d8d Help: improve docs for the EXCLUDE_FROM_ALL directory property

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !9497
2024-06-06 08:41:59 -04:00
Brad King
97328b05c3 Merge topic 'doc-add_subdirectory-EXCLUDE_FROM_ALL' into release-3.30
2449c04d8d Help: improve docs for the EXCLUDE_FROM_ALL directory property

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !9497
2024-06-06 08:41:58 -04:00
Alex Neundorf
2449c04d8d Help: improve docs for the EXCLUDE_FROM_ALL directory property
This patch improves the wording of the documentation of the
EXCLUDE_FROM_ALL directory property, and makes the
add_subdirectory()- and fetchcontent-documentation refer to it.
2024-06-04 16:58:54 +02:00
Brad King
d1cf2a2206 Merge topic 'file-accept-empty-lists'
7c516f7e28 file(): TOUCH, TOUCH_NOCREATE and MAKE_DIRECTORY accept empty lists

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !9570
2024-06-03 09:08:52 -04:00
Craig Scott
422ab50a8e Merge topic 'doc-find_package-typical-usage'
4b55d56259 Help: Start find_package() docs with a new "Typical Usage" section

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !9567
2024-06-01 18:25:18 -04:00
Brad King
e0a11dfa24 Merge topic 'dep-provider-try_compile'
4cb5bb014d try_compile: Propagating top level includes into whole-project calls

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Robert Maynard <robertjmaynard@gmail.com>
Merge-request: !9532
2024-05-31 09:20:27 -04:00
Craig Scott
7c516f7e28 file(): TOUCH, TOUCH_NOCREATE and MAKE_DIRECTORY accept empty lists
Projects may be generating a list of files or directories to pass as arguments
to file(TOUCH), file(TOUCH_NOCREATE), or file(MAKE_DIRECTORY). Those
lists might end up being empty, so rather than requiring at least one item,
allow an empty list.

Fixes: #24897
2024-05-31 22:55:20 +10:00
Craig Scott
4b55d56259 Help: Start find_package() docs with a new "Typical Usage" section
Fixes: #22680
2024-05-31 16:05:23 +10:00
Craig Scott
4cb5bb014d try_compile: Propagating top level includes into whole-project calls
Fixes: #24151
2024-05-30 19:01:03 +10:00
Brad King
645ca62b1b Merge topic 'doc-macro'
67171a99be Help: Fix inaccurate use of "function" in macro docs

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Juan Ramos <juan.ramos@kitware.com>
Merge-request: !9534
2024-05-21 09:17:17 -04:00
Dave Abrahams
67171a99be Help: Fix inaccurate use of "function" in macro docs 2024-05-21 09:13:57 -04:00
Brad King
d37467e036 Merge topic 'custom-command-output-hash-character'
8d2a503c1e add_custom_command: Allow OUTPUT filenames containing a hash '#' character
b38000d774 cmGlobalXCodeGenerator: Re-implement legacy makefile path escaping
d929089687 cmGlobalXCodeGenerator: Do not use legacy makefile escaping in shell commands
d61fc2c52e cmGlobalXCodeGenerator: Migrate legacy makefile path escaping to local helper
6010e007c7 cmState: Add method to check for the Borland Makefiles generator

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !9514
2024-05-16 11:24:56 -04:00