
function(buildsys_print_target_property target property)
    get_property(propval TARGET ${target} PROPERTY ${property} SET)
    if(propval)
        get_target_property(propval ${target} ${property})
        message(STATUS "${property} = ${propval}")
    endif()
endfunction()

function(buildsys_print_target_properties target)
    message(STATUS "----------------------------------------------------------------")
    message(STATUS "print target (${target}) properties begin")
    message(STATUS "----------------------------------------------------------------")

    execute_process(COMMAND cmake --help-property-list OUTPUT_VARIABLE properties)
    string(REGEX REPLACE ";" "\\\\;" properties "${properties}")
    string(REGEX REPLACE "\n" ";" properties "${properties}")
    list(FILTER properties EXCLUDE REGEX "^LOCATION$|^LOCATION_|_LOCATION$")
    list(REMOVE_DUPLICATES properties)

    get_target_property(targettype ${target} TYPE)
    if(targettype STREQUAL "INTERFACE_LIBRARY")
        # interface library has a limited set of properties
        unset(whitelisted)
        foreach(prop ${properties})
            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)$")
                list(APPEND whitelisted ${prop})
            endif()
        endforeach(prop)
        set(properties ${whitelisted})
    endif()

    set(configs "${CMAKE_CONFIGURATION_TYPES};${CMAKE_BUILD_TYPE}")
    list(REMOVE_DUPLICATES configs)
    string(TOUPPER "${configs}" configs)

    foreach(prop ${properties})
        string(FIND ${prop} "<CONFIG>" hasconfig)
        if(hasconfig EQUAL -1)
            buildsys_print_target_property(${target} ${prop})
        else()
            foreach(conf ${configs})
                string(REPLACE "<CONFIG>" ${conf} propc ${prop})
                buildsys_print_target_property(${target} ${propc})
            endforeach()
        endif()
    endforeach(prop)

    message(STATUS "----------------------------------------------------------------")
    message(STATUS "print target (${target}) properties end")
    message(STATUS "----------------------------------------------------------------")
endfunction()
