Debian Codegraph @

cmake-proxies/cmake-modules/PrintProperties.cmake

raw
1 #
2 # From https://stackoverflow.com/a/51987470 but modified
3 #
4 function(print_properties typ tgt)
5 message("Properties for ${typ} ${tgt}:")
6
7 # Get all propreties that cmake supports
8 execute_process(COMMAND cmake --help-property-list OUTPUT_VARIABLE CMAKE_PROPERTY_LIST)
9
10 # Convert command output into a CMake list
11 STRING(REGEX REPLACE ";" "\\\\;" CMAKE_PROPERTY_LIST "${CMAKE_PROPERTY_LIST}")
12 STRING(REGEX REPLACE "\n" ";" CMAKE_PROPERTY_LIST "${CMAKE_PROPERTY_LIST}")
13
14 # Fix https://stackoverflow.com/questions/32197663/how-can-i-remove-the-the-location-property-may-not-be-read-from-target-error-i
15 list(FILTER CMAKE_PROPERTY_LIST EXCLUDE REGEX "^LOCATION$|^LOCATION_|_LOCATION$")
16
17 # For some reason, "TYPE" shows up twice - others might too?
18 list(REMOVE_DUPLICATES CMAKE_PROPERTY_LIST)
19
20 # build whitelist by filtering down from CMAKE_PROPERTY_LIST in case cmake is
21 # a different version, and one of our hardcoded whitelisted properties
22 # doesn't exist!
23 unset(CMAKE_WHITELISTED_PROPERTY_LIST)
24 foreach(prop ${CMAKE_PROPERTY_LIST})
25 if(prop MATCHES "^(INTERFACE|[_a-z]|IMPORTED_LIBNAME_|MAP_IMPORTED_CONFIG_)|^(COMPATIBLE_INTERFACE_(BOOL|NUMBER_MAX|NUMBER_MIN|STRING)|EXPORT_NAME|IMPORTED(_GLOBAL|_CONFIGURATIONS|_LIBNAME)?|NAME|TYPE|NO_SYSTEM_FROM_IMPORTED)$")
26 list(APPEND CMAKE_WHITELISTED_PROPERTY_LIST ${prop})
27 endif()
28 endforeach()
29
30 set(PROP_LIST ${CMAKE_PROPERTY_LIST})
31 if( typ MATCHES "TARGET" )
32 get_target_property(target_type ${tgt} TYPE)
33 if(target_type STREQUAL "INTERFACE_LIBRARY")
34 set(PROP_LIST ${CMAKE_WHITELISTED_PROPERTY_LIST})
35 endif()
36 endif()
37
38 foreach (prop ${PROP_LIST})
39 string(REPLACE "<CONFIG>" "${CMAKE_BUILD_TYPE}" prop ${prop})
40 get_property(propval ${typ} ${tgt} PROPERTY ${prop} SET)
41 if (propval)
42 get_property(propval ${typ} ${tgt} PROPERTY ${prop})
43 if (NOT propval STREQUAL "propval-NOTFOUND")
44 message (" ${prop} = ${propval}")
45 endif()
46 endif()
47 endforeach()
48 endfunction()
49