Do not define CMAKE_PARENT_LIST_FILE in CMakeLists.txt

Add policy `CMP0198` for compatibility.

Issue: #25026
This commit is contained in:
Benjamin Buch
2025-07-05 00:04:17 -04:00
committed by Brad King
parent 79b5b4ae26
commit 41aea12941
20 changed files with 175 additions and 4 deletions
+8
View File
@@ -92,6 +92,14 @@ Supported Policies
The following policies are supported.
Policies Introduced by CMake 4.2
--------------------------------
.. toctree::
:maxdepth: 1
CMP0198: CMAKE_PARENT_LIST_FILE is not defined in CMakeLists.txt. </policy/CMP0198>
Policies Introduced by CMake 4.1
--------------------------------
+23
View File
@@ -0,0 +1,23 @@
CMP0198
-------
.. versionadded:: 4.2
:variable:`CMAKE_PARENT_LIST_FILE` is not defined in ``CMakeLists.txt``.
CMake 4.1 and below defined ``CMAKE_PARENT_LIST_FILE`` when processing
a ``CMakeLists.txt`` even though there is no parent file. CMake 4.2
and above prefer to not define ``CMAKE_PARENT_LIST_FILE``. This policy
provides compatibility for projects that accidentally relied on the
old behavior.
The ``OLD`` behavior for this policy is to set
:variable:`CMAKE_PARENT_LIST_FILE` to :variable:`CMAKE_CURRENT_LIST_FILE`
when processing a ``CMakeLists.txt``. The ``NEW`` behavior for this policy
is to not set :variable:`CMAKE_PARENT_LIST_FILE`.
.. |INTRODUCED_IN_CMAKE_VERSION| replace:: 4.2
.. |WARNS_OR_DOES_NOT_WARN| replace:: does *not* warn
.. include:: include/STANDARD_ADVICE.rst
.. include:: include/DEPRECATED.rst
+5
View File
@@ -0,0 +1,5 @@
cmake-parent-fix
----------------
* :variable:`CMAKE_PARENT_LIST_FILE` is no longer defined when processing
a ``CMakeLists.txt`` file. See policy :policy:`CMP0198`.
+2 -1
View File
@@ -8,7 +8,8 @@ While processing a CMake file loaded by :command:`include` or
including it.
While processing a ``CMakeLists.txt`` file, even in subdirectories,
this variable has the same value as :variable:`CMAKE_CURRENT_LIST_FILE`.
this variable is not defined. See policy :policy:`CMP0198`.
While processing a :option:`cmake -P` script, this variable is not defined
in the outermost script.