mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-09-25 04:09:36 +03:00
Testing whether one path is a prefix of another is possible today with
cmake_path(IS_PREFIX), but the idiom needs a separate statement plus a
scratch variable and takes the prefix as a variable name, so projects
reach for if(path MATCHES "^${prefix}") instead. That is wrong whenever
the prefix contains a regex metacharacter, and it accepts siblings,
because '^/a/b' matches '/a/bc'.
Add a binary operator where the left operand is the candidate prefix and
the right is the path, matching the operand order of cmake_path(IS_PREFIX)
and $<PATH:IS_PREFIX> so that the same operation reads the same way on all
three surfaces. Neither operand is normalized, matching the default of
cmake_path(IS_PREFIX) and the existing PATH_EQUAL operator, so '.' and
'..' are compared as ordinary components. The test is non-strict, purely
lexical, and applies no relative-to-absolute reconciliation.
Add policy CMP0222 for compatibility, modeled on CMP0139. The keyword
is consumed as an operator only when it appears in the second argument
slot, so a variable named PATH_IS_PREFIX keeps working in unary and
left-operand position. What the policy covers is such a variable
appearing after another token, as in if(NOT PATH_IS_PREFIX AND other),
which becomes a configure error under NEW.
Since the operator is an if() spelling of cmake_path(IS_PREFIX) and shares
its implementation, test it by asserting the two agree over a corpus of
inputs rather than by restating expected values. Those are pinned by the
cmake_path(IS_PREFIX) test, so the operator's tests stay limited to what
has no command equivalent, and no platform branching is needed because
parity holds whatever the host path model answers.
Fixes: #28040
13 lines
628 B
Plaintext
13 lines
628 B
Plaintext
CMake Warning \(policy\) at CMP0222-WARN-churn\.cmake:[0-9]+ \(if\):
|
|
Policy CMP0222 is not set: The if\(\) command supports path prefix tests
|
|
using PATH_IS_PREFIX operator\. Run "cmake --help-policy CMP0222" for
|
|
policy details\. Use the cmake_policy command to set the policy and
|
|
suppress this warning\.
|
|
|
|
PATH_IS_PREFIX will be interpreted as an operator when the policy is set to
|
|
NEW\. Since the policy is not set the OLD behavior will be used\.
|
|
Call Stack \(most recent call first\):
|
|
CMakeLists\.txt:[0-9]+ \(include\)
|
|
This warning is for project developers\. Use -Wno-author or -Wno-policy to
|
|
suppress it\.
|