Commit Graph

898 Commits

Author SHA1 Message Date
Brad King
135e6feba9 Merge topic 'find-cps'
d00201afd6 Tests: Add tests for CPS find_package
65429611b9 find_package: Fix handling of relative paths in CPS
5236984a08 Help: Describe CPS support in find_package
34828650d6 find_package: Add experimental gate for CPS support
25cc83428e find_package: Actually import .cps files
91c31ada23 find_package: Actually find .cps files
b89e43b2bc find_package: Start implementing CPS search
3e9f96079d Add additional string case functions

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !10018
2024-12-17 10:12:24 -05:00
Matthew Woehlke
3e9f96079d Add additional string case functions
Add function to perform case-insensitive comparison of two string-view
instancess. Add functions to perform case conversion on string_view.
2024-12-13 08:58:23 -05:00
Russell Greene
01d2a64980 cmSystemTools: Add GetDirCase helper function
On Linux, one can set case insensitivity on a per-directory level.
2024-12-11 16:26:01 -07:00
YunQiang Su
08040ced86 cmake: Look up on-disk case of input paths on macOS
Follow up commit 1a6015e5fc (PathResolver: Add helper to compute
normalized paths, 2024-10-30) to cover on-disk case lookup on macOS.

Fixes: #26333
2024-12-01 07:12:51 -05:00
Brad King
0994bc7929 cmake: Preserve symlinks in references to itself when possible
CMake's tools search relative to their own locations to find their
resources.  Previously they always started at their own `realpath()`.
The intention was to support invocation through symbolic links to the
binaries where the resources can only be found under the real prefix:

    /logical/prefix/bin/cmake   -> /real/prefix/bin/cmake
                                   /real/prefix/share/cmake

The generated build system refers to CMake's own tools and resources
through the `/real/prefix`.  This is not desirable in the case that the
`/logical/prefix` is meant as the canonical location and uses symbolic
links for both tools and resources as an implementation detail:

    /logical/prefix/bin/cmake   -> /real/prefix/bin/cmake
    /logical/prefix/share/cmake -> /real/prefix/share/cmake

In this case, the generated build system should refer to CMake's own
tools and resources through the `/logical/prefix`.  This way the
`/real/prefix` can be changed, and the symbolic links updated,
without breaking already-generated build systems.

Fixes: #19849
Fixes: #21059
Inspired-by: Carlo Cabrera <github@carlo.cab>
Inspired-by: Rodger Combs <rodger.combs@gmail.com>
2024-11-11 11:53:59 -05:00
Brad King
0925abb09b cmSystemTools: Invert condition to make non-bootstrap logic easier to follow 2024-11-11 11:53:00 -05:00
Brad King
46ac308249 cmSystemTools: Factor out helpers from FindCMakeResources
Factor out helpers to:

- Find our own executable
- Find resources in the install tree or the build tree
2024-11-11 11:49:43 -05:00
Brad King
b91ec8c48f cmSystemTools: Clarify decision to look for resources from the build tree 2024-11-11 11:49:43 -05:00
Brad King
cbee4eed0f cmSystemTools: Re-order resource and tool finding logic
Consolidate `CMAKE_BOOTSTRAP` conditions.
2024-11-11 11:49:05 -05:00
Brad King
f6acf1f7b7 cmSystemTools: Reduce rightward drift in success path on UNIX 2024-11-11 10:27:34 -05:00
Brad King
962e4479d4 cmSystemTools: Clarify app bundle layout on macOS 2024-11-11 10:27:34 -05:00
Brad King
56632ddaa3 cmSystemTools: Remove redundant filesystem access on Windows
Since commit 823e1df54c (cmSystemTools: Implement GetRealPath on
Windows, 2024-11-04), GetRealPath now returns the actual case
on disk.  It also returns the original path on failure.
2024-11-11 10:27:34 -05:00
Brad King
f2b3907cd0 cmSystemTools: Move static data to anonymous namespace 2024-11-11 10:27:33 -05:00
Brad King
16af27fd42 cmSystemTools: Drop GetRealPathResolvingWindowsSubst
It was created by commit 83630d4918 (cmSystemTools: Revert GetRealPath
implementation on Windows, 2018-05-29, v3.11.3~3^2) to preserve support
on Windows for one call site.  Now that `GetRealPath` works again on
Windows, we can use that instead.

Issue: #18033
2024-11-04 12:03:56 -05:00
Brad King
823e1df54c cmSystemTools: Implement GetRealPath on Windows
Use `cm::PathResolver`'s `RealPath` variant to normalize paths,
look up their on-disk case, and resolve symlinks, but without
resolving `subst` drives on Windows.

Fixes: #17206
2024-11-04 11:56:14 -05:00
Brad King
b378781c5d cmSystemTools: Cache ToNormalizedPathOnDisk actual-case lookups
Prior to re-implementing `ToNormalizedPathOnDisk`, its use of KWSys's
`GetActualCaseForPathCached` cached file actual-case lookups to avoid
redundant filesystem access.  Add caching to the actual-case lookups we
do for `cm::PathResolver`.
2024-11-03 08:30:30 -05:00
Brad King
622596c6b2 cmSystemTools: Re-implement ToNormalizedPathOnDisk without translation map
Use `cm::PathResolver`'s `LogicalPath` variant to normalize paths while
preserving symlinks not followed by `..` components.  This avoids
needing the KWSys path translation map to preserve symlinks through
`realpath` operations.  It also works with symlinks on Windows.

Fixes: #16228
2024-11-03 08:26:43 -05:00
Brad King
5aed3ee49d cmSystemTools: Add GetLogicalWorkingDirectory
Track the current working directory with symbolic links preserved.
2024-11-03 08:26:36 -05:00
Brad King
773b75e4ed cmake: Explicitly look up on-disk case of input paths on Windows
KWSys's `CollapseFullPath` no longer looks up the actual case on disk.
Add the lookup explicitly where we need it:

* `ToNormalizedPathOnDisk`
* `file(REAL_PATH)`
* `get_filename_component(... ABSOLUTE)`

Fixes: #20214
2024-10-24 16:09:38 -04:00
Brad King
ee83165923 cmake: Explicitly normalize input paths as they exist on disk
`CollapseFullPath` has two use cases:

1.  Normalize input paths from command-line arguments and environment
    variables.  On Windows, load their on-disk capitalization.

2.  Simplify paths constructed internally.  These should already have
    the correct capitalization.

Audit all `CollapseFullPath` call sites and code paths leading to them.
Replace those calls that normalize input paths with calls to
`ToNormalizedPathOnDisk` to express that they need the on-disk case.

By making this distinction we will later be able to remove the on-disk
capitalization lookup `CollapseFullPath`, thus eliminating disk accesses
from internal path processing.

Issue: #20214
2024-10-22 13:26:19 -04:00
Brad King
9fe09ebc53 cmSystemTools: Add GetEnvPathNormalized to get paths from environment 2024-10-22 13:24:40 -04:00
Brad King
2108f3507f cmSystemTools: Add SplitEnvPathNormalized to split paths from environment 2024-10-22 13:23:27 -04:00
Brad King
6d57403e14 cmSystemTools: Fix SplitEnvPath to avoid empty paths 2024-10-22 13:23:27 -04:00
Brad King
2503b43b6c cmSystemTools: Add ToNormalizedPathOnDisk helper
`CollapseFullPath` currently accesses the filesystem on Windows to
convert the path to the (upper/lower) case it has on disk.  Not all call
sites need this, so we'd eventually like to remove the behavior.  Add a
wrapper for call sites to express that they need to match the case of
on-disk paths.

Issue: #20214
2024-10-22 13:23:26 -04:00
Daniel Pfeifer
58c5f77837 clang-tidy: fix readability-redundant-* warnings 2024-10-11 15:37:21 +02:00
Yuri Witte
d8a9aabd24 file(ARCHIVE_CREATE): add WORKING_DIRECTORY option
Fixes: #25260
Issue: #21653
2024-09-11 09:52:32 -04:00
Vitaly Stakhovsky
58da4aa47d Source: Avoid comparing pointers to nullptr 2024-08-27 10:56:38 -04:00
Brad King
3d61720112 Merge topic 'autogen-predefs-emscripten'
8d1803d463 AutoGen: Run batch scripts using cmd.exe on windows platforms explicitly
9ab270f47d cmSystemTools: Add GetComspec method to get cmd on Windows

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !9733
2024-08-22 09:03:05 -04:00
Alexey Edelev
9ab270f47d cmSystemTools: Add GetComspec method to get cmd on Windows
The function attempts to read the path to cmd executable from the
COMSPEC environment variable. Falls back to cmd.exe if the respective
environment variable is not set or path doesn't exist.
2024-08-21 11:05:16 +02:00
Alex Turbov
fc36ac6b22 Refactor: Eliminate redundant operator<< calls 2024-08-14 19:56:54 +04:00
Alex Turbov
3855131c53 Refactor: Eliminate sequential calls to cmSystemTools::Stdout 2024-08-13 22:14:05 +04:00
Alex Turbov
dc38f81237 cmSystemTools: Revise MoveFileIfDifferent to return cmsys::Status
Help callers recover errors without relying on global state.
2024-07-18 10:29:47 -04:00
Martin Duffy
5b3fbd5f64 cmSystemTools: Add CMake config directory 2024-07-03 09:34:41 -04:00
Harmen Stoppels
02f3e5be6a file(RPATH_CHANGE ...): no-op for static binary
Setting `CMAKE_INSTALL_RPATH` on a project that contains statically
linked executables breaks the install step, since rpaths cannot be
changed.

This commit makes rpath adjustments not an error on static libraries.

Fixes #26078
2024-06-24 11:32:30 -04:00
Brad King
a66dfe22d7 Merge topic 'ctest-windows-std-handles'
e4d0169107 ctest: Fix spurious build failures with CTEST_USE_LAUNCHERS on Windows

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !9598
2024-06-14 09:27:06 -04:00
Brad King
e4d0169107 ctest: Fix spurious build failures with CTEST_USE_LAUNCHERS on Windows
Remove the stdio handle inheritance suppression originally added by
commit f262298bb0 (... do not inherit pipes in child procs for ctest so
it can kill them, 2007-09-11, v2.6.0~1136).  It's not clear what problem
it was trying to solve, was only done in `ctest` and not `cmake`, and
since commit 9c3ffe2474 (BUG: fix problem with stdout and stderr not
showing up in ms dos shells, 2007-09-25, v2.6.0~1066) has not been done
in `ctest` launched under interactive consoles.

Furthermore, the code has been spuriously breaking stdio when `ctest` is
started with both stdout and stderr connected to the same pipe, such as
when `ctest --launch` is used under `ninja`.  This is because it used
`DuplicateHandle` with `DUPLICATE_CLOSE_SOURCE` on the stdout handle and
then the stderr handle.  If the handles are the same, then the stderr
handle becomes invalid in between these operations, leading to
likely-undefined behavior.  Since commit 96b3dd329e
(cmCTestLaunchReporter: Replace cmsysProcess with cmUVProcessChain,
2023-07-26, v3.28.0-rc1~138^2~2) this became more noticeable because
`uv_spawn` performs additional verification on stdio handles.

This could be fixed by instead suppressing inheritance via

    SetHandleInformation(h, HANDLE_FLAG_INHERIT, 0);

However, the functionality no longer seems necessary, so remove it.
2024-06-14 07:32:29 -04:00
Charlotte Koch
4c70e72cae cmSystemTools: Fix compilation on DragonFly BSD
Define `_XOPEN_SOURCE >= 700` to make `gettimeofday()` et al. available.
2024-04-02 17:33:02 -04:00
Brad King
607051f266 MSYS,CYGWIN: Hard-code host system names when built for these runtimes
When CMake is built against the MSYS runtime library, `uname()` returns
a name that depends on the `MSYSTEM` environment variable.  Previously
we truncated `MSYS_...` to just `MSYS`, but outside `MSYSTEM=MSYS`
environments, names like `MINGW64_NT-10.0-22000` were reported.

The latter causes CMake to report an unsupported-platform error, which
users report as an issue when the real problem is that they should be
using a `MSYSTEM=MSYS` environment or a CMake that is not built against
the MSYS runtime.

For our purposes, if CMake is built against the MSYS runtime, the host
platform is always `MSYS`.  Similarly for `CYGWIN`.
2024-02-01 11:48:32 -05:00
Brad King
96010cc968 Ensure stdin, stdout, stderr FILE streams are open on Windows
Extend commit c85524a94a (Ensure stdin, stdout, and stderr pipes are always
open, 2019-05-02, v3.15.0-rc1~171^2) to cover the `stdin`, `stdout`, and
`stderr` FILE streams from `<stdio.h>`.

Issue: #25625
2024-01-25 12:42:12 -05:00
Brad King
b11c8c45f9 Merge topic 'cmuvprocesschain'
adb3e13d32 cmUVProcessChain: Tolerate fileno() of invalid FILE stream
b6e4e4babc cmUVProcessChain: Simplify SetExternalStream usage
116bb2b70f cmUVProcessChain: Simplify builder initialization
d32c30906a Tests: Add missing include in testUVProcessChainHelper on Windows

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !9181
2024-01-25 10:40:02 -05:00
Brad King
bcbb212df7 Revert use of libuv for process execution for 3.28
Wide use of CMake 3.28.{1,0[-rcN]} has uncovered some hangs and crashes
in libuv SIGCHLD handling on some platforms, particularly in virtualization
environments on macOS hosts.  Although the bug does not seem to be in CMake,
we can restore stability in the CMake 3.28 release series for users of such
platforms by reverting our new uses of libuv for process execution.

Revert implementation changes merged by commit 4771544386 (Merge topic
'replace-cmsysprocess-with-cmuvprocesschain', 2023-09-06, v3.28.0-rc1~138),
but keep test suite updates.

Issue: #25414, #25500, #25562, #25589
2024-01-24 17:10:00 -05:00
Brad King
b6e4e4babc cmUVProcessChain: Simplify SetExternalStream usage
It is commonly called with the `fileno()` of a `FILE*` stream,
so accept the latter directly.
2024-01-24 16:59:49 -05:00
Brad King
d9d9326e14 Source: Avoid out-of-range inputs to std::isspace()
`isspace` takes `int` but documents that the value must be representable
by `unsigned char`, or be EOF.  Use a wrapper to cast to `unsigned char`
to avoid sign extension while converting to `int`.  This generalizes the
fix from commit 5e8c176e2a (cmExecuteProcessCommand: Cast c to unsigned
char before cast to int, 2024-01-05) to other `isspace` call sites.

This was detected by assertions in the MSVC standard library while
processing UTF-8 text.

Issue: #25561
2024-01-17 10:17:06 -05:00
makise-homura
9bc2aba3b4 LCC: get rid of ambiguous assignments of {} for LCC
LCC 1.21 can't determine the exact type of right side
of assignment and so produces an error. Here it is resolved
by an intermediate variable.
2024-01-16 22:11:02 +03:00
Kyle Edwards
c4be9c914b cmSystemTools::RunSingleCommand(): Pass stdin to child process
Fixes: #25383
2023-11-02 10:04:00 -04:00
Kyle Edwards
50a6e78a82 cmSystemTools::RunSingleCommand(): Replace cmsysProcess with cmUVProcessChain
And pass OUTPUT_PASSTHROUGH in one call where it was missing.
2023-08-29 10:51:30 -04:00
Kyle Edwards
49a37d5a97 cmCTestScriptHandler: Replace cmsysProcess with cmUVProcessChain
And update cmSystemTools::WaitForLine() to use cmUVProcessChain.
2023-08-29 10:51:30 -04:00
Ben Boeckel
36bd3d82f8 cmSystemTools: move ComputeCertificateThumbprint to the only consumer
There's no need to have this API on `cmSystemTools` with only a single
consumer.
2023-08-08 14:25:01 -04:00
Ben Boeckel
a4e4daceaf cmSystemTools: remove ComputeFileHash method
No longer used.
2023-08-08 13:24:00 -04:00
Ben Boeckel
4d5198a986 cmSystemTools: remove ComputeStringMD5 method
No longer used.
2023-08-08 13:22:16 -04:00