Last active
December 20, 2023 14:10
-
-
Save scivision/027b6099665d3ed7acee0f2e373451dd to your computer and use it in GitHub Desktop.
CMake print all target properties
This file contains 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
cmake_minimum_required(VERSION 3.5) | |
project(demoTgtProps LANGUAGES C) | |
find_package(ZLIB REQUIRED) | |
include(print_target_props.cmake) | |
print_target_props(ZLIB::ZLIB) |
This file contains 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
execute_process(COMMAND ${CMAKE_COMMAND} --help-property-list | |
OUTPUT_VARIABLE _props OUTPUT_STRIP_TRAILING_WHITESPACE | |
) | |
STRING(REGEX REPLACE "\n" ";" _props "${_props}") | |
list(REMOVE_DUPLICATES _props) | |
function(print_target_props tgt) | |
if(NOT TARGET ${tgt}) | |
message(WARNING "Target ${tgt} not found") | |
return() | |
endif() | |
message(STATUS "Target: ${tgt} properties") | |
foreach(p IN LISTS _props) | |
if(p MATCHES "<CONFIG>" AND NOT CMAKE_BUILD_TYPE) | |
continue() | |
endif() | |
string(REPLACE "<CONFIG>" "${CMAKE_BUILD_TYPE}" p "${p}") | |
get_property(v TARGET ${tgt} PROPERTY "${p}") | |
if(v) | |
message(STATUS "${tgt} ${p} = ${v}") | |
endif() | |
endforeach() | |
endfunction() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment