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: #19849Fixes: #21059
Inspired-by: Carlo Cabrera <github@carlo.cab>
Inspired-by: Rodger Combs <rodger.combs@gmail.com>
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.
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
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
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`.
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
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
`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
`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
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
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.
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
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.
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`.
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
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
`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