Last active
November 13, 2022 11:40
-
-
Save sighingnow/da3d70bb631c115b21581126cd33c7f6 to your computer and use it in GitHub Desktop.
Print properties of a target in CMake
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get all propreties that cmake supports | |
if(NOT CMAKE_PROPERTY_LIST) | |
execute_process(COMMAND cmake --help-property-list OUTPUT_VARIABLE CMAKE_PROPERTY_LIST) | |
# Convert command output into a CMake list | |
string(REGEX REPLACE ";" "\\\\;" CMAKE_PROPERTY_LIST "${CMAKE_PROPERTY_LIST}") | |
string(REGEX REPLACE "\n" ";" CMAKE_PROPERTY_LIST "${CMAKE_PROPERTY_LIST}") | |
endif() | |
list(APPEND CMAKE_PROPERTY_LIST "IMPORTED_LOCATION") | |
list(APPEND CMAKE_PROPERTY_LIST "IMPORTED_LOCATION_DEBUG") | |
list(APPEND CMAKE_PROPERTY_LIST "IMPORTED_LOCATION_RELEASE") | |
list(APPEND CMAKE_PROPERTY_LIST "IMPORTED_LOCATION_NOCONFIG") | |
list(REMOVE_DUPLICATES CMAKE_PROPERTY_LIST) | |
function(print_properties) | |
message("CMAKE_PROPERTY_LIST = ${CMAKE_PROPERTY_LIST}") | |
endfunction() | |
function(print_target_properties target) | |
if(NOT TARGET ${target}) | |
message(STATUS "There is no target named '${target}'") | |
return() | |
endif() | |
foreach(property ${CMAKE_PROPERTY_LIST}) | |
string(REPLACE "<CONFIG>" "${CMAKE_BUILD_TYPE}" property ${property}) | |
# Fix https://stackoverflow.com/questions/32197663/how-can-i-remove-the-the-location-property-may-not-be-read-from-target-error-i | |
if(property STREQUAL "LOCATION" OR property MATCHES "^LOCATION_" OR property MATCHES "_LOCATION$") | |
continue() | |
endif() | |
get_property(was_set TARGET ${target} PROPERTY ${property} SET) | |
if(was_set) | |
get_target_property(value ${target} ${property}) | |
message("${target} ${property} = ${value}") | |
endif() | |
endforeach() | |
endfunction() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment