cmake_print_properties: Deprecate in favor of cmake_language(PRINT_PROPERTIES)

Re-implement it in terms of the replacement command.

Issue: #27513
This commit is contained in:
Tom Osika
2026-08-10 17:45:47 -04:00
parent 2a2012e913
commit 048ee670f2
26 changed files with 102 additions and 215 deletions
@@ -4,3 +4,7 @@ print_all_properties
* The :command:`cmake_language(PRINT_PROPERTIES)` command was added
to print CMake entities' properties in human-readable form for
debugging.
* The :module:`CMakePrintHelpers` module's :command:`cmake_print_properties`
command is now deprecated in favor of
:command:`cmake_language(PRINT_PROPERTIES)`.
+23 -38
View File
@@ -21,6 +21,10 @@ This module provides the following commands:
.. command:: cmake_print_properties
.. deprecated:: 4.5
Use :command:`cmake_language(PRINT_PROPERTIES)` instead.
Prints the values of properties for the specified targets, source files,
directories, tests, or cache entries:
@@ -111,6 +115,23 @@ endfunction()
function(cmake_print_properties)
message(DEPRECATION
"cmake_print_properties() is deprecated. Use cmake_language(PRINT_PROPERTIES) instead.")
set(_cppmode_reserved_keywords
ALL NAMED PROPERTY_NAME_REGEX PROPERTY_VALUE_REGEX
DEFERRED FOLLOW_DEPENDENCIES __CMAKE_PRINT_PROPERTIES)
foreach(_arg IN LISTS ARGV)
if(_arg IN_LIST _cppmode_reserved_keywords)
message(FATAL_ERROR
"cmake_print_properties() got \"${_arg}\", which is a reserved "
"keyword in cmake_language(PRINT_PROPERTIES). If you wish to use "
"it as a keyword to the command, use cmake_language(PRINT_PROPERTIES) "
"directly.")
return()
endif()
endforeach()
set(options )
set(oneValueArgs )
set(cpp_multiValueArgs PROPERTIES )
@@ -146,39 +167,30 @@ function(cmake_print_properties)
set(mode)
set(items)
set(keyword)
if(CPPMODE_TARGETS)
set(items ${CPPMODE_TARGETS})
set(mode ${mode} TARGETS)
set(keyword TARGET)
endif()
if(CPPMODE_SOURCES)
set(items ${CPPMODE_SOURCES})
set(mode ${mode} SOURCES)
set(keyword SOURCE)
endif()
if(CPPMODE_TESTS)
set(items ${CPPMODE_TESTS})
set(mode ${mode} TESTS)
set(keyword TEST)
endif()
if(CPPMODE_DIRECTORIES)
set(items ${CPPMODE_DIRECTORIES})
set(mode ${mode} DIRECTORIES)
set(keyword DIRECTORY)
endif()
if(CPPMODE_CACHE_ENTRIES)
set(items ${CPPMODE_CACHE_ENTRIES})
set(mode ${mode} CACHE_ENTRIES)
# This is a workaround for the fact that passing `CACHE` as an argument to
# set() causes a cache variable to be set.
set(keyword "")
string(APPEND keyword CACHE)
endif()
if(NOT mode)
@@ -193,33 +205,6 @@ function(cmake_print_properties)
return()
endif()
set(msg "\n")
foreach(item ${items})
set(itemExists TRUE)
if(keyword STREQUAL "TARGET")
if(NOT TARGET ${item})
set(itemExists FALSE)
string(APPEND msg "\n No such TARGET \"${item}\" !\n\n")
endif()
endif()
if (itemExists)
string(APPEND msg " Properties for ${keyword} ${item}:\n")
foreach(prop ${CPP_PROPERTIES})
get_property(propertySet ${keyword} ${item} PROPERTY "${prop}" SET)
if(propertySet)
get_property(property ${keyword} ${item} PROPERTY "${prop}")
string(APPEND msg " ${item}.${prop} = \"${property}\"\n")
else()
string(APPEND msg " ${item}.${prop} = <NOTFOUND>\n")
endif()
endforeach()
endif()
endforeach()
message(STATUS "${msg}")
cmake_language(PRINT_PROPERTIES ${mode} ${items} NAMED ${CPP_PROPERTIES}
__CMAKE_PRINT_PROPERTIES)
endfunction()
@@ -4,17 +4,5 @@
+mylib\.NAME = "mylib"
--.*
+Printing all properties for TARGET mylib matching name '\^MY_PROP_' and value '\^alpha\$':
+mylib\.MY_PROP_X = "alpha"
-- Configuring done .*
--.*
+Printing all properties for TARGET mylib \(and all reachable\) matching name '\^MY_PROP_' and value '\^alpha\$':
+mylib\.MY_PROP_X = "alpha"
+mydep\.MY_PROP_X = "alpha"
--.*
+Properties for TARGET mylib:
+mylib\.TYPE = "STATIC_LIBRARY"
-- Generating done .*
+Properties for SOURCE [^"]+/stub\.c:
+[^"]+/stub\.c\.LANGUAGE = "C"
@@ -1,49 +1,13 @@
include(CMakePrintHelpers)
enable_language(C)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/stub.c" "void stub(void) {}\n")
add_library(mydep STATIC "${CMAKE_CURRENT_BINARY_DIR}/stub.c")
set_target_properties(mydep PROPERTIES
MY_PROP_X "alpha"
MY_PROP_Y "beta"
OTHER_PROP "alpha"
)
add_library(mylib STATIC "${CMAKE_CURRENT_BINARY_DIR}/stub.c")
target_link_libraries(mylib PRIVATE mydep)
set_target_properties(mylib PROPERTIES
MY_PROP_X "alpha"
MY_PROP_Y "beta"
OTHER_PROP "alpha"
)
# (1) configure-time, specific properties — exercises forwarding of TARGETS
# + PROPERTIES <names>.
# TARGETS scope: forwards as TARGETS mylib NAMED TYPE NAME.
cmake_print_properties(TARGETS mylib PROPERTIES TYPE NAME)
# (2) configure-time, ALL + both regex keywords — exercises forwarding of
# PROPERTY_NAME_REGEX and PROPERTY_VALUE_REGEX together.
# SOURCES scope: forwards as SOURCES stub.c NAMED LANGUAGE. Confirms
# scope-keyword translation covers more than just TARGETS.
cmake_print_properties(
TARGETS mylib
PROPERTIES ALL
PROPERTY_NAME_REGEX "^MY_PROP_"
PROPERTY_VALUE_REGEX "^alpha$"
)
# (3) DEFERRED + FOLLOW_DEPENDENCIES + ALL + both regexes — exercises
# forwarding of every new keyword at once, and verifies the walker
# actually reaches the PRIVATE dep at generate time (mydep must appear
# in the output, not just mylib).
cmake_print_properties(
TARGETS mylib
DEFERRED
FOLLOW_DEPENDENCIES
PROPERTIES ALL
PROPERTY_NAME_REGEX "^MY_PROP_"
PROPERTY_VALUE_REGEX "^alpha$"
)
# (4) DEFERRED alone + specific name — exercises DEFERRED forwarding by
# itself (no dependency walk; mydep must NOT appear).
cmake_print_properties(TARGETS mylib DEFERRED PROPERTIES TYPE)
SOURCES "${CMAKE_CURRENT_BINARY_DIR}/stub.c"
PROPERTIES LANGUAGE)
@@ -0,0 +1,13 @@
# cmake_print_properties() must reproduce its historical output byte-for-byte.
set(expected "-- \n Properties for TARGET foo:")
string(APPEND expected "\n foo.MY_PROP = \"val\"")
string(APPEND expected "\n foo.NOT_SET = <NOTFOUND>")
string(FIND "${actual_stdout}" "${expected}" idx)
if(idx EQUAL -1)
set(RunCMake_TEST_FAILED
"cmake_print_properties() output is not byte-for-byte backward compatible.\n"
"Expected to find:\n[${expected}]\n"
"in actual stdout:\n[${actual_stdout}]")
endif()
@@ -0,0 +1,6 @@
include(CMakePrintHelpers)
add_library(foo INTERFACE)
set_property(TARGET foo PROPERTY MY_PROP "val")
cmake_print_properties(TARGETS foo PROPERTIES MY_PROP NOT_SET)
@@ -0,0 +1,5 @@
CMake Warning \(deprecated\) at .*CMakePrintHelpers\.cmake:[0-9]+ \(message\):
cmake_print_properties\(\) is deprecated\. Use
cmake_language\(PRINT_PROPERTIES\) instead\.
Call Stack \(most recent call first\):
PrintPropertiesDeprecation\.cmake:[0-9]+ \(cmake_print_properties\)
@@ -0,0 +1,2 @@
.*Properties for TARGET mylib:.*
.*mylib\.TYPE = "STATIC_LIBRARY".*
@@ -0,0 +1,6 @@
include(CMakePrintHelpers)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/stub.c" "void stub(void) {}\n")
add_library(mylib STATIC "${CMAKE_CURRENT_BINARY_DIR}/stub.c")
cmake_print_properties(TARGETS mylib PROPERTIES TYPE)
@@ -0,0 +1,4 @@
CMake Error at .*CMakePrintHelpers\.cmake:[0-9]+ \(message\):
cmake_print_properties\(\) got "DEFERRED", which is a reserved keyword in
cmake_language\(PRINT_PROPERTIES\)\. If you wish to use it as a keyword to
the command, use cmake_language\(PRINT_PROPERTIES\) directly\.
@@ -0,0 +1,11 @@
include(CMakePrintHelpers)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/stub.c" "void stub(void) {}\n")
add_library(mylib STATIC "${CMAKE_CURRENT_BINARY_DIR}/stub.c")
# Reserved keyword as positional argument
cmake_print_properties(
DEFERRED
TARGETS mylib
PROPERTIES MY_PROP
)
@@ -0,0 +1,4 @@
CMake Error at .*CMakePrintHelpers\.cmake:[0-9]+ \(message\):
cmake_print_properties\(\) got "ALL", which is a reserved keyword in
cmake_language\(PRINT_PROPERTIES\)\. If you wish to use it as a keyword to
the command, use cmake_language\(PRINT_PROPERTIES\) directly\.
@@ -0,0 +1,10 @@
include(CMakePrintHelpers)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/stub.c" "void stub(void) {}\n")
add_library(mylib STATIC "${CMAKE_CURRENT_BINARY_DIR}/stub.c")
# Reserved keyword as a property name.
cmake_print_properties(
TARGETS mylib
PROPERTIES ALL
)
@@ -1,14 +0,0 @@
.*Properties for TARGET nothing:.*
.*nothing\.LINKER_LANGUAGE = <NOTFOUND>.*
.*nothing\.TYPE = \"STATIC_LIBRARY\".*
.*Properties for TARGET something:.*
.*something\.LINKER_LANGUAGE = <NOTFOUND>.*
.*something\.TYPE = \"EXECUTABLE\".*
+
.*
.*Properties for SOURCE nothing\.c:.*
.*nothing\.c\.COMPILE_DEFINITIONS = <NOTFOUND>.*
.*nothing\.c\.LANGUAGE = \"C\".*
.*Properties for SOURCE something\.c:.*
.*something\.c\.COMPILE_DEFINITIONS = \"SOMETHING=1\".*
.*something\.c\.LANGUAGE = \"C\".*
@@ -1,26 +0,0 @@
enable_language(C)
set_property(SOURCE nothing.c PROPERTY LANGUAGE C)
set_property(SOURCE something.c PROPERTY
COMPILE_DEFINITIONS SOMETHING=1)
add_library(nothing STATIC nothing.c nothing.h)
add_executable(something something.c something.h)
target_link_libraries(something PUBLIC nothing)
include(CMakePrintHelpers)
cmake_print_properties(
TARGETS nothing something
PROPERTIES
LINKER_LANGUAGE
TYPE
)
cmake_print_properties(
SOURCES nothing.c something.c
PROPERTIES
COMPILE_DEFINITIONS
LANGUAGE
)
@@ -1,8 +0,0 @@
.*Properties for TARGET rot13:.*
.*rot13.SOURCES = \"rot13.c;rot13.h\".*
.*rot13.POSITION_INDEPENDENT_CODE = \"True\".*
+
.*--.*
.*Properties for SOURCE rot13.c:.*
.*rot13.c.LOCATION = \"[^\"]*/PrintHelpers/rot13.c\".*
.*rot13.c.LANGUAGE = \"C\".*
@@ -1,19 +0,0 @@
set_property(SOURCE rot13.c PROPERTY LANGUAGE C)
add_library(rot13 SHARED rot13.c rot13.h)
include(CMakePrintHelpers)
cmake_print_properties(
TARGETS rot13
PROPERTIES
SOURCES
POSITION_INDEPENDENT_CODE
)
cmake_print_properties(
SOURCES rot13.c
PROPERTIES
LOCATION
LANGUAGE
)
@@ -2,9 +2,12 @@ include(RunCMake)
block()
set(RunCMake_TEST_OPTIONS -Wno-deprecated)
run_cmake(PrintPropertiesArgForwarding)
run_cmake(PrintPropertiesBackwardCompat)
run_cmake(PrintPropertiesReservedKeywordPositionalArg)
run_cmake(PrintPropertiesReservedKeywordPropertyName)
run_cmake(VariablesArgForwarding)
run_cmake(VariablesReservedKeyword)
endblock()
run_cmake(PrintPropertiesDeprecation)
run_cmake(VariablesDeprecation)
run_cmake(Properties)
run_cmake(PropertiesSources)
-6
View File
@@ -1,6 +0,0 @@
#include "nothing.h"
void nothing(void)
{
(void*)0;
}
-8
View File
@@ -1,8 +0,0 @@
#ifndef NOTHING_H
#define NOTHING_H
#include <stdlib.h>
void nothing();
#endif
-15
View File
@@ -1,15 +0,0 @@
#include "rot13.h"
void rot13(char* in)
{
char* end = in + strlen(in);
for (char* c = in; c < end; c++) {
if (*c >= 'a' && *c <= 'z') {
*c += (*c < 'n') ? 13 : -13;
continue;
}
if (*c >= 'A' && *c <= 'Z') {
*c += (*c < 'N') ? 13 : -13;
}
}
}
-9
View File
@@ -1,9 +0,0 @@
#ifndef ROT13_H
#define ROT13_H
#include <stdlib.h>
#include <string.h>
void rot13(char* in);
#endif
-7
View File
@@ -1,7 +0,0 @@
#include "something.h"
int main(void)
{
nothing();
return 0;
}
-8
View File
@@ -1,8 +0,0 @@
#ifndef SOMETHING_H
#define SOMETHING_H
#include <stdlib.h>
#include "nothing.h"
#endif