cmake_path(IS_PREFIX) and $<PATH:IS_PREFIX> treated an empty path as a
prefix of every path, including another empty path, following
std::filesystem::path. A prefix that is empty because a variable was
set to an empty value, or because a generator expression argument
expanded to nothing, therefore satisfied a check meant to reject it.
Return false for an empty prefix, in cmCMakePath::IsPrefix so that every
caller shares one implementation and both the plain and NORMALIZE forms
are covered. Normalizing an empty path leaves it empty, so no separate
handling of NORMALIZE is needed. Unlike the component comparison, which
follows std::filesystem::path deliberately, IsPrefix has no counterpart
in the standard: it borrows path iteration but the predicate itself is
defined by CMake, so an empty prefix is a gap to fill rather than a
standard answer to override.
Add policy CMP0223 and restore the old result behind it at the two
released surfaces. The other callers of IsPrefix, source_group() and
the Makefile generator's source classification, take the new behavior
ungated: source_group() rejects an empty TREE argument before reaching
it, and the generator passes the source and binary directories.
The if(PATH_IS_PREFIX) operator, new in this same release, follows the
policy too rather than simply taking the new behavior, so that it agrees
with cmake_path(IS_PREFIX) in every policy state and the parity
assertions in its test hold unconditionally.
Fixes: #28077
The IS_PREFIX test asserted four cases: duplicate separators collapsing,
a non-normalized '..' in the prefix, and two NORMALIZE cases. None of
the rules a caller is most likely to get wrong were covered.
Add assertions for the non-strict self-prefix, trailing separators on
either operand, '.' components, the sibling-prefix trap, the absence of
relative-to-absolute reconciliation including the root directory, and
the empty path. Add a host-path-model block covering backslashes, case
sensitivity of both ordinary components and the root-name, drive-
relative paths, and UNC root-names.
`cmake_path(GET "foo/.." STEM out)` is supposed to set `out` to `".."`,
the entire `cmake_path(GET "foo/.." FILENAME)` result.
However, the `GetNarrowStem()` logic in `cmCMakePath` was lacking
the `.` and `..` special-casing logic present in other methods.
As a result, it would erroneously trim the second `.` off of a stem
of `..` and return only `.`.
This caused the result of `cmake_path(GET "foo/.." STEM)` to be `"."`.
Making the standard empty-or-.-or-.. checks and bailing out early
fixes the result of `cmCMakePaths{".."}.GetNarrowStem()`.
Fixes: #26235
For policy-specific tests, use the version before the policy was
introduced. Otherwise, use 3.5 where possible.
Also, remove `cmake_minimum_required()` and `project()` calls from
individual cases where they are handled by `CMakeLists.txt`.