Commit Graph

930 Commits

Author SHA1 Message Date
Brad King
cef4676d3a StdIo: Factor out helper to initialize stdin, stdout, and stderr
Move logic from commit c85524a94a (Ensure stdin, stdout, and stderr pipes
are always open, 2019-05-02, v3.15.0-rc1~171^2) and commit 96010cc968
(Ensure stdin, stdout, stderr FILE streams are open on Windows, 2024-01-24,
v3.29.0-rc1~65^2) to a dedicated source.  Expose it through an `Init` class
constructor to make it optionally available during static initialization.

Issue: #26924
2025-05-08 13:39:48 -04:00
Brad King
b1c22bdc38 Source: Fix -Wformat warnings 2025-04-24 07:56:39 -04:00
Brad King
9d1a0fa256 Merge topic 'normalize-input-paths'
cd4e72ca08 Normalize PWD environment variable before using it

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !10659
2025-04-16 09:37:09 -04:00
Brad King
cd4e72ca08 Normalize PWD environment variable before using it
In commit 5aed3ee49d (cmSystemTools: Add GetLogicalWorkingDirectory,
2024-10-28, v4.0.0-rc1~528^2~6) we incorrectly trusted `PWD` to be a
normalized path so long as its realpath matches the current working
directory.

Fixes: #26870
2025-04-15 09:37:08 -04:00
Brad King
8a3860379d Merge topic 'normalize-input-paths'
5805461074 cmSystemTools: Simplify call to FindProgram for our own executable
db0e2574cb cmSystemTools: Restore FindProgram look-up of on-disk case on Windows
5d700abda4 Source: Simplify FindProgram calls

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !10620
2025-04-08 10:45:46 -04:00
Brad King
5805461074 cmSystemTools: Simplify call to FindProgram for our own executable
Remove the unnecessary `FindProgramPath` wrapper.  Call the KWSys
`FindProgram` directly, without our CMake-specific wrapper, since
we follow-up with a `ToNormalizedPathOnDisk` anyway.
2025-04-07 19:57:07 -04:00
Brad King
db0e2574cb cmSystemTools: Restore FindProgram look-up of on-disk case on Windows
KWSys's `FindProgram` no longer looks up the actual case on disk.  This
behavior change was inherited from the change to `CollapseFullPath`.
Extend commit 773b75e4ed (cmake: Explicitly look up on-disk case of
input paths on Windows, 2024-10-23, v4.0.0-rc1~589^2) to cover this by
wrapping `FindProgram` in a CMake-specific layer.

Issue: #20214
2025-04-07 19:57:07 -04:00
Brad King
07970d3c64 Merge topic 'restore-home-tidle'
01f92efeb0 Restore expansion of leading '~' as home directory in input paths

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !10580
2025-04-03 14:04:57 -04:00
Brad King
01f92efeb0 Restore expansion of leading '~' as home directory in input paths
This was accidentally dropped by commit 622596c6b2 (cmSystemTools:
Re-implement ToNormalizedPathOnDisk without translation map, 2024-10-30,
v4.0.0-rc1~528^2~5).  Previously it was done by `CollapseFullPath`.
`cm::PathResolver` intentionally does not expand `~` because it makes
sense only for transforming input paths.  Teach `ToNormalizedPathOnDisk`
to handle it directly.

Fixes: #26827
2025-04-02 14:41:48 -04:00
Brad King
27ee7ed289 Merge topic 'realpath-windows'
0a5efe8489 cmSystemTools: Fix GetRealPath implementation on Windows
5910bf0b40 cmSystemTools: Restore GetRealPathResolvingWindowsSubst

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !10452
2025-03-11 09:42:32 -04:00
Brad King
0a5efe8489 cmSystemTools: Fix GetRealPath implementation on Windows
In commit 823e1df54c (cmSystemTools: Implement GetRealPath on Windows,
2024-11-04, v4.0.0-rc1~521^2~1) we implemented the POSIX behavior that
resolves symlinks followed by '..' components.  However, Windows just
removes them lexically.  Also, we were not handling all junction types.

Instead, use `GetFinalPathNameByHandleW` via `uv_fs_realpath`.

Note that we previously attempted this in commit 640709e7db
(cmSystemTools: Implement GetRealPath on Windows, 2017-10-02,
v3.11.0-rc1~445^2~1) but reverted it in commit 83630d4918
(cmSystemTools: Revert GetRealPath implementation on Windows,
2018-05-29, v3.11.3~3^2) due to resolving `subst` drives.  This time,
add code to re-`subst`itute the drive in the resolved path.

Fixes: #26750
Issue: #17206
2025-03-10 14:50:09 -04:00
Brad King
5910bf0b40 cmSystemTools: Restore GetRealPathResolvingWindowsSubst
We need it to restore behavior on Windows.  Revert commit 16af27fd42
(cmSystemTools: Drop GetRealPathResolvingWindowsSubst, 2024-11-04,
v4.0.0-rc1~521^2), but with a cleaned up implementation.

Issue: #26750
Issue: #18033
2025-03-10 11:25:23 -04:00
Brad King
c4f8b13845 Merge topic 'normalize-input-paths'
fc5584f9bb cmSystemTools: Fix regression in input path normalization on Windows

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !10440
2025-03-10 10:21:06 -04:00
Brad King
fc5584f9bb cmSystemTools: Fix regression in input path normalization on Windows
Since commit 622596c6b2 (cmSystemTools: Re-implement
ToNormalizedPathOnDisk without translation map, 2024-10-30,
v4.0.0-rc1~528^2~5) we normalize input paths, while resolving symlinks
only if followed by `..` components, by using `cm::PathResolver`'s
`LogicalPath` mode.  However, that approach assumes POSIX semantics for
resolving paths with symlinks and is incorrect on Windows.

On Windows, file system operations naively remove any component
preceding `..` regardless of whether it is a symlink.  Prior to the
above commit, `ToNormalizedPathOnDisk` matched that behavior using
`CollapseFullPath` followed by `GetActualCaseForPath`.  Restore it using
`cm::PathResolver`'s `CasePath` mode.

Issue: #26750
2025-03-07 18:26:14 -05:00
Roger Leigh
99c8abed55 kFreeBSD: Remove support for obsolete platform
kFreeBSD is no longer maintained or supported and was never an
officially-supported release architecture for Debian.

Closes: #26742
2025-03-05 11:57:49 -05:00
Kitware Robot
1772622772 LICENSE: Replace references to Copyright.txt with LICENSE.rst
```
git grep -lz 'Copyright.txt or https://cmake.org/licensing ' |
  while IFS= read -r -d $'\0' f ; do
    sed -i '/Copyright.txt or https:\/\/cmake.org\/licensing / {
              s/Copyright.txt/LICENSE.rst/
            }' "$f" ; done
```
2025-03-03 10:43:35 -05:00
Kitware Robot
de273b2e11 LICENSE: Replace references to Copyright.txt with LICENSE.rst
```
git grep -lz 'Copyright.txt or https://cmake.org/licensing ' |
  while IFS= read -r -d $'\0' f ; do
    sed -i '/Copyright.txt or https:\/\/cmake.org\/licensing / {
              s/Copyright.txt/LICENSE.rst/
            }' "$f" ; done
```
2025-03-03 09:56:07 -05:00
Brad King
e388ed687a execute_process: Improve invocation of .cmd/.bat with spaces
Extend the fix from commit 74c9d40876 (execute_process: Fix invocation
of .cmd/.bat with spaces, 2025-01-31) to work without relying on
conversion to a "short path", which may not exist.  Instead, extending
the `cmd /c` wrapper to `cmd /c call` seems to support spaces directly.

Suggested-by: Alexandru Croitor <alexandru.croitor@qt.io>
Fixes: #26655
2025-02-10 19:44:19 -05:00
Brad King
4db9e1009d Solaris: Backport our mkdtemp code paths to SunOS 5.10 i386
`mkdtemp` is not available on this architecture until SunOS 5.11.
Look up the symbol at runtime, and if missing, fall back to an
approximate implementation.
2025-02-09 13:29:39 -05:00
Brad King
c1f6b04176 cmSystemTools: Teach MaybePrependCmdExe to always use backslashes 2025-02-03 09:13:18 -05:00
Brad King
817b3967f8 cmSystemTools: Teach MaybePrependCmdExe to return GetShortPathNameW failure 2025-02-03 09:09:29 -05:00
Brad King
611a3000f7 cmSystemTools: Make MaybePrependCmdExe case-insensitive 2025-02-03 09:05:47 -05:00
Brad King
98fed0f116 cmSystemTools: Adopt MaybePrependCmdExe 2025-01-31 11:52:09 -05:00
Kitware Robot
0b96ae1f6a Revise C++ coding style using clang-format with "east const"
Run the `clang-format.bash` script to update all our C and C++ code to a
new style defined by `.clang-format`, now with "east const" enforcement.
Use `clang-format` version 18.

* If you reached this commit for a line in `git blame`, re-run the blame
  operation starting at the parent of this commit to see older history
  for the content.

* See the parent commit for instructions to rebase a change across this
  style transition commit.

Issue: #26123
2025-01-23 13:09:50 -05:00
Kitware Robot
b2ba64add9 Revise C++ coding style using clang-format-18
Run the `clang-format.bash` script to update all our C and C++ code to a
new style defined by `.clang-format`.  Use `clang-format` version 18.

* If you reached this commit for a line in `git blame`, re-run the blame
  operation starting at the parent of this commit to see older history
  for the content.

* See the parent commit for instructions to rebase a change across this
  style transition commit.

Fixes: #26123
2025-01-23 11:43:06 -05:00
Brad King
72e27a4856 Merge topic 'fix-typos-found-by-pre-commit-hooks'
d620d77d26 FindDoxygen: Rename `_Doxygen_dne_header` -> `_Doxygen_do_not_edit_header`
e7ff3cccea PushToAndroidDevice.cmake: Rename `cmake_parse_arguments` prefix
bc8621d999 Fix: A lot of typos in code found by `typos`
b33beb7af5 Help: Fix some typos found by `sphinx-lint`
78e45c2db6 Style: Replace TABs with spaces for indentation in some files
74e0173f66 Tests(NuGet): Fix the test to ignore empty and space-only lines

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !10151
2025-01-14 09:44:34 -05:00
Brad King
80bac4de30 Merge topic 'cmake-self-symlinks'
6d9ab7964d cmake: Restore finding installed resources in their real path

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !10160
2025-01-13 11:19:56 -05:00
Alex Turbov
bc8621d999 Fix: A lot of typos in code found by typos
Yet another great code spellchecker: https://github.com/crate-ci/typos/

(Will be added later as a `pre-commit` hook)
2025-01-12 18:49:34 +04:00
Brad King
6d9ab7964d cmake: Restore finding installed resources in their real path
In commit 0994bc7929 (cmake: Preserve symlinks in references to itself
when possible, 2024-11-11) we stopped looking for resources using the
real path of the directory containing `cmake`.  Restore it as a fallback
to support layouts like `/{bin -> usr/bin}/cmake`.

Fixes: #26570
2025-01-09 16:23:54 -05:00
Tim Blechmann
339c2b886a cmSystemTools: Add RandomNumber method that avoid re-seeding from OS
When profiling Qt builds on macos, about 2.2% of a `cmake` invocation
was spent reading from `/dev/urandom`.  Use a (thread)local rng to
mitigate this cost, particularly in `cmGeneratedFileStreamBase::Open`.
2025-01-09 11:17:20 -05:00
Brad King
79e41d3cc6 Merge topic 'rpath-preserve-setuid-setgid'
0907a322f3 install: Restore SETUID/SETGID after RPATH change

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !10053
2024-12-20 09:18:24 -05:00
Volodymyr Zolotopupov
0907a322f3 install: Restore SETUID/SETGID after RPATH change
Most Unix-like systems drops the SETUID/SETGID bits when a file changes,
so after changing the RPATH, it is necessary to restore
the original file mode.
2024-12-19 08:29:44 -05:00
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