Skip to content

Instantly share code, notes, and snippets.

@scivision
Last active December 20, 2023 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scivision/027b6099665d3ed7acee0f2e373451dd to your computer and use it in GitHub Desktop.
Save scivision/027b6099665d3ed7acee0f2e373451dd to your computer and use it in GitHub Desktop.
CMake print all target properties
cmake_minimum_required(VERSION 3.5)
project(demoTgtProps LANGUAGES C)
find_package(ZLIB REQUIRED)
include(print_target_props.cmake)
print_target_props(ZLIB::ZLIB)
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