Răsfoiți Sursa

Help: Document TARGET_PROPERTY genex behavior on unset property

Also add an explicit test for the case.

Fixes: #25968
Brad King 1 an în urmă
părinte
comite
d6bda72981

+ 6 - 4
Help/manual/cmake-generator-expressions.7.rst

@@ -1751,7 +1751,8 @@ These expressions look up the values of
 
 .. genex:: $<TARGET_PROPERTY:tgt,prop>
 
-  Value of the property ``prop`` on the target ``tgt``.
+  Value of the property ``prop`` on the target ``tgt``, or empty if
+  the property is not set.
 
   Note that ``tgt`` is not added as a dependency of the target this
   expression is evaluated on.
@@ -1767,9 +1768,10 @@ These expressions look up the values of
   :target: TARGET_PROPERTY:prop
 
   Value of the property ``prop`` on the target for which the expression
-  is being evaluated.  Note that for generator expressions in
-  :ref:`Target Usage Requirements` this is the consuming target rather
-  than the target specifying the requirement.
+  is being evaluated, or empty if the property is not set.
+  Note that for generator expressions in :ref:`Target Usage Requirements`
+  this is the consuming target rather than the target specifying the
+  requirement.
 
 The expressions have special evaluation rules for some properties:
 

+ 1 - 0
Tests/RunCMake/GenEx-TARGET_PROPERTY/RunCMakeTest.cmake

@@ -16,6 +16,7 @@ run_cmake(SOURCES)
 run_cmake(TransitiveBuild)
 run_cmake(TransitiveLink-CMP0166-OLD)
 run_cmake(TransitiveLink-CMP0166-NEW)
+run_cmake(Unset)
 
 block()
   run_cmake(Scope)

+ 4 - 0
Tests/RunCMake/GenEx-TARGET_PROPERTY/Unset-check.cmake

@@ -0,0 +1,4 @@
+file(READ ${RunCMake_TEST_BINARY_DIR}/out.txt out)
+if(NOT out STREQUAL "'' ''")
+  set(RunCMake_TEST_FAILED "PROPERTY_THAT_IS_NOT_SET did not evaluate as empty:\n ${out}")
+endif()

+ 3 - 0
Tests/RunCMake/GenEx-TARGET_PROPERTY/Unset.cmake

@@ -0,0 +1,3 @@
+add_library(iface INTERFACE)
+file(GENERATE OUTPUT out.txt CONTENT
+  "'$<TARGET_PROPERTY:iface,PROPERTY_THAT_IS_NOT_SET>' '$<TARGET_PROPERTY:PROPERTY_THAT_IS_NOT_SET>'" TARGET iface)