FeatureSummary: Introduce policy CMP0183 for full Condition Syntax

Closes: #26468
This commit is contained in:
Peter Kokot
2024-11-26 02:16:43 +01:00
committed by Brad King
parent 467d6f00cc
commit 6a7d5e414d
15 changed files with 142 additions and 9 deletions

View File

@@ -57,6 +57,7 @@ Policies Introduced by CMake 3.32
.. toctree::
:maxdepth: 1
CMP0183: add_feature_info() supports full Condition Syntax. </policy/CMP0183>
CMP0182: Create shared library archives by default on AIX. </policy/CMP0182>
CMP0181: Link command-line fragment variables are parsed and re-quoted. </policy/CMP0181>

33
Help/policy/CMP0183.rst Normal file
View File

@@ -0,0 +1,33 @@
CMP0183
-------
.. versionadded:: 3.32
:command:`add_feature_info` supports full :ref:`Condition Syntax`.
The ``<enabled>`` parameter accepts a :ref:`semicolon-separated list <CMake
Language Lists>` of conditions. CMake 3.31 and lower evaluate each
``condition`` as ``if(${condition})``, which does not properly handle
conditions with nested paren groups. CMake 3.32 and above instead prefer
to evaluate each ``condition`` as ``if(<condition>)``, where ``<condition>``
is re-parsed as if literally written in a call to :command:`if`. This
allows expressions like::
"A AND (B OR C)"
but requires expressions like::
"FOO MATCHES (UPPER|lower)"
to be re-written as::
"FOO MATCHES \"(UPPER|lower)\""
Policy ``CMP0183`` provides compatibility for projects that have not
been updated to expect the new behavior.
.. |INTRODUCED_IN_CMAKE_VERSION| replace:: 3.32
.. |WARNS_OR_DOES_NOT_WARN| replace:: warns
.. include:: STANDARD_ADVICE.txt
.. include:: DEPRECATED.txt

View File

@@ -0,0 +1,6 @@
add_feature_info
----------------
* The :module:`FeatureSummary` module :command:`add_feature_info`
command now supports full :ref:`Condition Syntax`.
See policy :policy:`CMP0183`.

View File

@@ -627,6 +627,10 @@ endfunction()
.. versionchanged:: 3.8
``<enabled>`` can be a list of conditions.
.. versionchanged:: 3.32
Full :ref:`Condition Syntax` is now supported for ``<enabled>``.
See policy :policy:`CMP0183`.
Example for setting the info for a feature:
.. code-block:: cmake
@@ -635,15 +639,29 @@ endfunction()
add_feature_info(Foo WITH_FOO "The Foo feature provides very cool stuff.")
#]=======================================================================]
function(ADD_FEATURE_INFO _name _depends _desc)
cmake_policy(GET CMP0183 _CDO_CMP0183
PARENT_SCOPE # undocumented, do not use outside of CMake
)
set(_enabled 1)
foreach(_d ${_depends})
string(REGEX REPLACE " +" ";" _d "${_d}")
if(${_d})
else()
set(_enabled 0)
break()
endif()
endforeach()
if("x${_CDO_CMP0183}x" STREQUAL "xNEWx")
foreach(_d ${_depends})
cmake_language(EVAL CODE "
if(${_d})
else()
set(_enabled 0)
endif()"
)
endforeach()
else()
foreach(_d ${_depends})
string(REGEX REPLACE " +" ";" _d "${_d}")
if(${_d})
else()
set(_enabled 0)
break()
endif()
endforeach()
endif()
if (${_enabled})
set_property(GLOBAL APPEND PROPERTY ENABLED_FEATURES "${_name}")
else ()
@@ -651,6 +669,12 @@ function(ADD_FEATURE_INFO _name _depends _desc)
endif ()
set_property(GLOBAL PROPERTY _CMAKE_${_name}_DESCRIPTION "${_desc}" )
if("x${_CDO_CMP0183}x" STREQUAL "xx" AND "x${_depends}x" MATCHES "[^A-Za-z0-9_.; ]")
cmake_policy(GET_WARNING CMP0183 _CDO_CMP0183_WARNING)
message(AUTHOR_WARNING "${_CDO_CMP0183_WARNING}")
endif()
unset(_CDO_CMP0183)
endfunction()

View File

@@ -550,7 +550,10 @@ class cmMakefile;
"Link command-line fragment variables are parsed and re-quoted.", 3, \
32, 0, WARN) \
SELECT(POLICY, CMP0182, \
"Create shared library archives by default on AIX.", 3, 32, 0, WARN)
"Create shared library archives by default on AIX.", 3, 32, 0, WARN) \
SELECT(POLICY, CMP0183, \
"add_feature_info() supports full Condition Syntax.", 3, 32, 0, \
WARN)
#define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
#define CM_FOR_EACH_POLICY_ID(POLICY) \

View File

@@ -0,0 +1,3 @@
-- The following features have been enabled:
\* Foo, Foo\.

View File

@@ -0,0 +1,11 @@
include(FeatureSummary)
cmake_policy(SET CMP0183 NEW)
set(WITH_FOO 1)
set(WITH_BAR 1)
set(WITH_BAZ 0)
add_feature_info(Foo "WITH_FOO AND (WITH_BAR OR WITH_BAZ)" "Foo.")
feature_summary(WHAT ALL)

View File

@@ -0,0 +1,9 @@
^CMake Warning \(dev\) at [^
]*/Modules/FeatureSummary\.cmake:[0-9]+ \(message\):
Policy CMP0183 is not set: add_feature_info\(\) supports full Condition
Syntax\. Run "cmake --help-policy CMP0183" for policy details. Use the
cmake_policy command to set the policy and suppress this warning\.
Call Stack \(most recent call first\):
FeatureSummaryParentheses-CMP0183-WARN\.cmake:[0-9]+ \(add_feature_info\)
CMakeLists\.txt:[0-9]+ \(include\)
This warning is for project developers. Use -Wno-dev to suppress it.$

View File

@@ -0,0 +1,7 @@
-- The following features have been enabled:
\* Bar, Bar\.
-- The following features have been disabled:
\* Foo, Foo\.

View File

@@ -0,0 +1,10 @@
include(FeatureSummary)
set(WITH_FOO 1)
set(WITH_BAR 1)
set(WITH_BAZ 0)
add_feature_info(Foo "WITH_FOO AND (WITH_BAR OR WITH_BAZ)" "Foo.")
add_feature_info(Bar "WITH_FOO;WITH_BAR" "Bar.")
feature_summary(WHAT ALL)

View File

@@ -0,0 +1,3 @@
-- The following features have been enabled:
\* Foo, Foo\.

View File

@@ -0,0 +1,8 @@
include(FeatureSummary)
cmake_policy(SET CMP0183 NEW)
set(FOO "lower")
add_feature_info(Foo "FOO MATCHES \"(UPPER|lower)\"" "Foo.")
feature_summary(WHAT ALL)

View File

@@ -0,0 +1,3 @@
-- The following features have been enabled:
\* Foo, Foo\.

View File

@@ -0,0 +1,8 @@
include(FeatureSummary)
cmake_policy(SET CMP0183 OLD)
set(FOO "lower")
add_feature_info(Foo "FOO MATCHES (UPPER|lower)" "Foo.")
feature_summary(WHAT ALL)

View File

@@ -21,3 +21,7 @@ run_cmake(FeatureSummaryCustomRequired)
run_cmake(FeatureSummaryCustomRequiredListA)
run_cmake(FeatureSummaryCustomRequiredListB)
run_cmake(FeatureSummaryCustomDescription)
run_cmake(FeatureSummaryParentheses-CMP0183-NEW)
run_cmake(FeatureSummaryParentheses-CMP0183-WARN)
run_cmake(FeatureSummaryRegex-CMP0183-NEW)
run_cmake(FeatureSummaryRegex-CMP0183-OLD)