# usage: from your CMakeLists.txt:
#
# include(echo_target_properties.make)
#
# echo_target_properties(my_target)
#
# example:
# find_package(ZLIB)
# echo_target_properties(ZLIB::ZLIB)
#
# reference: https://blog.kitware.com/cmake-target-properties/

function(echo_target_property tgt prop)
  # v for value, d for defined, s for set
  get_property(v TARGET ${tgt} PROPERTY ${prop})
  get_property(d TARGET ${tgt} PROPERTY ${prop} DEFINED)
  get_property(s TARGET ${tgt} PROPERTY ${prop} SET)

  # only produce output for values that are set
  if(s)
    message(STATUS "${tgt}   property: ${prop}   defined: ${d}   set: ${s}
      value: ${v}")
  endif()
endfunction()


function(echo_target tgt)
  if(NOT TARGET ${tgt})
    message(STATUS "There is no target ${tgt}")
    return()
  endif()

# https://cmake.org/cmake/help/latest/manual/cmake-properties.7.html#target-properties

  set(props

ADDITIONAL_CLEAN_FILES
AIX_EXPORT_ALL_SYMBOLS
ALIAS_GLOBAL
ALIASED_TARGET
ANDROID_ANT_ADDITIONAL_OPTIONS
ANDROID_API
ANDROID_API_MIN
ANDROID_ARCH
ANDROID_ASSETS_DIRECTORIES
ANDROID_GUI
ANDROID_JAR_DEPENDENCIES
ANDROID_JAR_DIRECTORIES
ANDROID_JAVA_SOURCE_DIR
ANDROID_NATIVE_LIB_DEPENDENCIES
ANDROID_NATIVE_LIB_DIRECTORIES
ANDROID_PROCESS_MAX
ANDROID_PROGUARD
ANDROID_PROGUARD_CONFIG_PATH
ANDROID_SECURE_PROPS_PATH
ANDROID_SKIP_ANT_STEP
ANDROID_STL_TYPE
ARCHIVE_OUTPUT_DIRECTORY
ARCHIVE_OUTPUT_DIRECTORY_RELEASE
ARCHIVE_OUTPUT_NAME
ARCHIVE_OUTPUT_NAME_RELEASE
AUTOGEN_BUILD_DIR
AUTOGEN_ORIGIN_DEPENDS
AUTOGEN_PARALLEL
AUTOGEN_TARGET_DEPENDS
AUTOMOC
AUTOMOC_COMPILER_PREDEFINES
AUTOMOC_DEPEND_FILTERS
AUTOMOC_EXECUTABLE
AUTOMOC_MACRO_NAMES
AUTOMOC_MOC_OPTIONS
AUTOMOC_PATH_PREFIX
AUTORCC
AUTORCC_EXECUTABLE
AUTORCC_OPTIONS
AUTOUIC
AUTOUIC_EXECUTABLE
AUTOUIC_OPTIONS
AUTOUIC_SEARCH_PATHS
BINARY_DIR
BUILD_RPATH
BUILD_RPATH_USE_ORIGIN
BUILD_WITH_INSTALL_NAME_DIR
BUILD_WITH_INSTALL_RPATH
BUNDLE
BUNDLE_EXTENSION
C_EXTENSIONS
C_STANDARD
C_STANDARD_REQUIRED
COMMON_LANGUAGE_RUNTIME
COMPATIBLE_INTERFACE_BOOL
COMPATIBLE_INTERFACE_NUMBER_MAX
COMPATIBLE_INTERFACE_NUMBER_MIN
COMPATIBLE_INTERFACE_STRING
COMPILE_DEFINITIONS
COMPILE_FEATURES
COMPILE_FLAGS
COMPILE_OPTIONS
COMPILE_PDB_NAME
COMPILE_PDB_NAME_RELEASE
COMPILE_PDB_OUTPUT_DIRECTORY
COMPILE_PDB_OUTPUT_DIRECTORY_RELEASE
RELEASE_OUTPUT_NAME
RELEASE_POSTFIX
CROSSCOMPILING_EMULATOR
CUDA_ARCHITECTURES
CUDA_EXTENSIONS
CUDA_PTX_COMPILATION
CUDA_RESOLVE_DEVICE_SYMBOLS
CUDA_RUNTIME_LIBRARY
CUDA_SEPARABLE_COMPILATION
CUDA_STANDARD
CUDA_STANDARD_REQUIRED
CXX_EXTENSIONS
CXX_STANDARD
CXX_STANDARD_REQUIRED
DEBUG_POSTFIX
DEFINE_SYMBOL
DEPLOYMENT_ADDITIONAL_FILES
DEPLOYMENT_REMOTE_DIRECTORY
DEPRECATION
DISABLE_PRECOMPILE_HEADERS
DOTNET_TARGET_FRAMEWORK
DOTNET_TARGET_FRAMEWORK_VERSION
EchoString
ENABLE_EXPORTS
EXCLUDE_FROM_ALL
EXCLUDE_FROM_DEFAULT_BUILD
EXCLUDE_FROM_DEFAULT_BUILD_RELEASE
EXPORT_NAME
EXPORT_PROPERTIES
FOLDER
Fortran_FORMAT
Fortran_MODULE_DIRECTORY
Fortran_PREPROCESS
FRAMEWORK
FRAMEWORK_MULTI_CONFIG_POSTFIX_RELEASE
FRAMEWORK_VERSION
GENERATOR_FILE_NAME
GHS_INTEGRITY_APP
GHS_NO_SOURCE_GROUP_FILE
GNUtoMS
HAS_CXX
IMPLICIT_DEPENDS_INCLUDE_TRANSFORM
IMPORTED
IMPORTED_COMMON_LANGUAGE_RUNTIME
IMPORTED_CONFIGURATIONS
IMPORTED_GLOBAL
IMPORTED_IMPLIB
IMPORTED_IMPLIB_RELEASE
IMPORTED_LIBNAME
IMPORTED_LIBNAME_RELEASE
IMPORTED_LINK_DEPENDENT_LIBRARIES
IMPORTED_LINK_DEPENDENT_LIBRARIES_RELEASE
IMPORTED_LINK_INTERFACE_LANGUAGES
IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE
IMPORTED_LINK_INTERFACE_LIBRARIES
IMPORTED_LINK_INTERFACE_LIBRARIES_RELEASE
IMPORTED_LINK_INTERFACE_MULTIPLICITY
IMPORTED_LINK_INTERFACE_MULTIPLICITY_RELEASE
IMPORTED_LOCATION
IMPORTED_LOCATION_RELEASE
IMPORTED_NO_SONAME
IMPORTED_NO_SONAME_RELEASE
IMPORTED_OBJECTS
IMPORTED_OBJECTS_RELEASE
IMPORTED_SONAME
IMPORTED_SONAME_RELEASE
IMPORT_PREFIX
IMPORT_SUFFIX
INCLUDE_DIRECTORIES
INSTALL_NAME_DIR
INSTALL_REMOVE_ENVIRONMENT_RPATH
INSTALL_RPATH
INSTALL_RPATH_USE_LINK_PATH
INTERFACE_AUTOUIC_OPTIONS
INTERFACE_COMPILE_DEFINITIONS
INTERFACE_COMPILE_FEATURES
INTERFACE_COMPILE_OPTIONS
INTERFACE_INCLUDE_DIRECTORIES
INTERFACE_LINK_DEPENDS
INTERFACE_LINK_DIRECTORIES
INTERFACE_LINK_LIBRARIES
INTERFACE_LINK_OPTIONS
INTERFACE_POSITION_INDEPENDENT_CODE
INTERFACE_PRECOMPILE_HEADERS
INTERFACE_SOURCES
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES
INTERPROCEDURAL_OPTIMIZATION
INTERPROCEDURAL_OPTIMIZATION_RELEASE
IOS_INSTALL_COMBINED
ISPC_HEADER_DIRECTORY
ISPC_HEADER_SUFFIX
ISPC_INSTRUCTION_SETS
JOB_POOL_COMPILE
JOB_POOL_LINK
JOB_POOL_PRECOMPILE_HEADER
LABELS
C_CLANG_TIDY
C_COMPILER_LAUNCHER
C_CPPCHECK
C_CPPLINT
C_INCLUDE_WHAT_YOU_USE
C_VISIBILITY_PRESET
CXX_CLANG_TIDY
CXX_COMPILER_LAUNCHER
CXX_CPPCHECK
CXX_CPPLINT
CXX_INCLUDE_WHAT_YOU_USE
CXX_VISIBILITY_PRESET
LIBRARY_OUTPUT_DIRECTORY
LIBRARY_OUTPUT_DIRECTORY_RELEASE
LIBRARY_OUTPUT_NAME
LIBRARY_OUTPUT_NAME_RELEASE
LINK_DEPENDS
LINK_DEPENDS_NO_SHARED
LINK_DIRECTORIES
LINK_FLAGS
LINK_FLAGS_RELEASE
LINK_INTERFACE_LIBRARIES
LINK_INTERFACE_LIBRARIES_RELEASE
LINK_INTERFACE_MULTIPLICITY
LINK_INTERFACE_MULTIPLICITY_RELEASE
LINK_LIBRARIES
LINK_OPTIONS
LINK_SEARCH_END_STATIC
LINK_SEARCH_START_STATIC
LINK_WHAT_YOU_USE
LINKER_LANGUAGE
LOCATION
LOCATION_RELEASE
MACHO_COMPATIBILITY_VERSION
MACHO_CURRENT_VERSION
MACOSX_BUNDLE
MACOSX_BUNDLE_INFO_PLIST
MACOSX_FRAMEWORK_INFO_PLIST
MACOSX_RPATH
MANUALLY_ADDED_DEPENDENCIES
MAP_IMPORTED_CONFIG_RELEASE
MSVC_RUNTIME_LIBRARY
NAME
NO_SONAME
NO_SYSTEM_FROM_IMPORTED
OBJC_EXTENSIONS
OBJC_STANDARD
OBJC_STANDARD_REQUIRED
OBJCXX_EXTENSIONS
OBJCXX_STANDARD
OBJCXX_STANDARD_REQUIRED
OPTIMIZE_DEPENDENCIES
OSX_ARCHITECTURES
OSX_ARCHITECTURES_RELEASE
OUTPUT_NAME
OUTPUT_NAME_RELEASE
PCH_WARN_INVALID
PCH_INSTANTIATE_TEMPLATES
PDB_NAME
PDB_NAME_RELEASE
PDB_OUTPUT_DIRECTORY
PDB_OUTPUT_DIRECTORY_RELEASE
POSITION_INDEPENDENT_CODE
PRECOMPILE_HEADERS
PRECOMPILE_HEADERS_REUSE_FROM
PREFIX
PRIVATE_HEADER
PROJECT_LABEL
PUBLIC_HEADER
RESOURCE
RULE_LAUNCH_COMPILE
RULE_LAUNCH_CUSTOM
RULE_LAUNCH_LINK
RUNTIME_OUTPUT_DIRECTORY
RUNTIME_OUTPUT_DIRECTORY_RELEASE
RUNTIME_OUTPUT_NAME
RUNTIME_OUTPUT_NAME_RELEASE
SKIP_BUILD_RPATH
SOURCE_DIR
SOURCES
SOVERSION
STATIC_LIBRARY_FLAGS
STATIC_LIBRARY_FLAGS_RELEASE
STATIC_LIBRARY_OPTIONS
SUFFIX
Swift_DEPENDENCIES_FILE
Swift_LANGUAGE_VERSION
Swift_MODULE_DIRECTORY
Swift_MODULE_NAME
TYPE
UNITY_BUILD
UNITY_BUILD_BATCH_SIZE
UNITY_BUILD_CODE_AFTER_INCLUDE
UNITY_BUILD_CODE_BEFORE_INCLUDE
UNITY_BUILD_MODE
VERSION
VISIBILITY_INLINES_HIDDEN
VS_CONFIGURATION_TYPE
VS_DEBUGGER_COMMAND
VS_DEBUGGER_COMMAND_ARGUMENTS
VS_DEBUGGER_ENVIRONMENT
VS_DEBUGGER_WORKING_DIRECTORY
VS_DESKTOP_EXTENSIONS_VERSION
VS_DOTNET_DOCUMENTATION_FILE
VS_DOTNET_REFERENCE_<refname>
VS_DOTNET_REFERENCEPROP_<refname>_TAG_<tagname>
VS_DOTNET_REFERENCES
VS_DOTNET_REFERENCES_COPY_LOCAL
VS_DOTNET_TARGET_FRAMEWORK_VERSION
VS_DPI_AWARE
VS_GLOBAL_KEYWORD
VS_GLOBAL_PROJECT_TYPES
VS_GLOBAL_ROOTNAMESPACE
VS_GLOBAL_<variable>
VS_IOT_EXTENSIONS_VERSION
VS_IOT_STARTUP_TASK
VS_JUST_MY_CODE_DEBUGGING
VS_KEYWORD
VS_MOBILE_EXTENSIONS_VERSION
VS_NO_SOLUTION_DEPLOY
VS_PACKAGE_REFERENCES
VS_PLATFORM_TOOLSET
VS_PROJECT_IMPORT
VS_SCC_AUXPATH
VS_SCC_LOCALPATH
VS_SCC_PROJECTNAME
VS_SCC_PROVIDER
VS_SDK_REFERENCES
VS_SOLUTION_DEPLOY
VS_SOURCE_SETTINGS_<tool>
VS_USER_PROPS
VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION
VS_WINRT_COMPONENT
VS_WINRT_EXTENSIONS
VS_WINRT_REFERENCES
WIN32_EXECUTABLE
WINDOWS_EXPORT_ALL_SYMBOLS
XCODE_ATTRIBUTE_<an-attribute>
XCODE_EXPLICIT_FILE_TYPE
XCODE_GENERATE_SCHEME
XCODE_LINK_BUILD_PHASE_MODE
XCODE_PRODUCT_TYPE
XCODE_SCHEME_ADDRESS_SANITIZER
XCODE_SCHEME_ADDRESS_SANITIZER_USE_AFTER_RETURN
XCODE_SCHEME_ARGUMENTS
XCODE_SCHEME_DEBUG_AS_ROOT
XCODE_SCHEME_DEBUG_DOCUMENT_VERSIONING
XCODE_SCHEME_DISABLE_MAIN_THREAD_CHECKER
XCODE_SCHEME_DYNAMIC_LIBRARY_LOADS
XCODE_SCHEME_DYNAMIC_LINKER_API_USAGE
XCODE_SCHEME_ENVIRONMENT
XCODE_SCHEME_EXECUTABLE
XCODE_SCHEME_GUARD_MALLOC
XCODE_SCHEME_MAIN_THREAD_CHECKER_STOP
XCODE_SCHEME_MALLOC_GUARD_EDGES
XCODE_SCHEME_MALLOC_SCRIBBLE
XCODE_SCHEME_MALLOC_STACK
XCODE_SCHEME_THREAD_SANITIZER
XCODE_SCHEME_THREAD_SANITIZER_STOP
XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER
XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER_STOP
XCODE_SCHEME_WORKING_DIRECTORY
XCODE_SCHEME_ZOMBIE_OBJECTS
XCTEST
)

  message("======================== ${tgt} ========================")
  foreach(p ${props})
    echo_target_property("${t}" "${p}")
  endforeach()

  message("")
endfunction()


function(echo_target_properties)
  set(tgts ${ARGV})
  foreach(t ${tgts})
    echo_target("${t}")
  endforeach()
endfunction()
