FUNCTION(PRINT_PROPERTY TARGET PROPERTY_NAME)
    get_target_property(PROPERTY_NAME ${TARGET} ${PROPERTY_NAME})
	MESSAGE("PROPERTY_NAME=${PROPERTY_NAME}")
ENDFUNCTION()


FUNCTION(REMOVEPATH var)
    set(listVar "")
    foreach(f ${ARGN})
        set(temp "")
        get_filename_component(temp ${f} NAME)
        list(APPEND listVar "${temp}")
    endforeach()
    set(${var} "${listVar}" PARENT_SCOPE)
ENDFUNCTION(REMOVEPATH)

FUNCTION(PREPEND var prefix)
    set(listVar "")
        foreach(f ${ARGN})
    list(APPEND listVar "${prefix}${f}")
    endforeach()
    SET(${var} "${listVar}" PARENT_SCOPE)
ENDFUNCTION(PREPEND)



function(copy_target_properites_to SOURCE_TARGET METHOD DEST_TARGET)
    get_target_inherited_property(INCLUDE_DIRECTORIES ${SOURCE_TARGET} INCLUDE_DIRECTORIES)
    get_target_inherited_property(COMPILE_OPTIONS ${SOURCE_TARGET} COMPILE_OPTIONS)
    get_target_inherited_property(COMPILE_FLAGS ${SOURCE_TARGET} COMPILE_FLAGS)
    get_target_inherited_property(LINK_OPTIONS ${SOURCE_TARGET} LINK_OPTIONS)
    get_target_inherited_property(LINK_FLAGS ${SOURCE_TARGET} LINK_FLAGS)
    get_target_inherited_property(COMPILE_DEFINITIONS ${SOURCE_TARGET} COMPILE_DEFINITIONS)

    target_include_directories(${DEST_TARGET}   ${METHOD} ${INCLUDE_DIRECTORIES})
    target_compile_options (${DEST_TARGET}      ${METHOD} ${COMPILE_OPTIONS})
    target_compile_options(${DEST_TARGET}       ${METHOD} ${COMPILE_FLAGS})
    target_link_options(${DEST_TARGET}          ${METHOD} ${LINK_OPTIONS})
    target_link_options(${DEST_TARGET}          ${METHOD} ${LINK_FLAGS})
    target_compile_definitions(${DEST_TARGET}   ${METHOD} ${COMPILE_DEFINITIONS})
endfunction()

function(print_target_info TARGET METHOD)
list(APPEND CMAKE_MESSAGE_CONTEXT "info")
get_target_property(TARGET_NAME ${TARGET} OUTPUT_NAME)
get_target_inherited_property(INCLUDE_DIRECTORIES ${TARGET_NAME} INCLUDE_DIRECTORIES)
get_target_inherited_property(COMPILE_OPTIONS ${TARGET_NAME} COMPILE_OPTIONS)
get_target_inherited_property(COMPILE_FLAGS ${TARGET_NAME} COMPILE_FLAGS)
get_target_inherited_property(LINK_OPTIONS ${TARGET_NAME} LINK_OPTIONS)
get_target_inherited_property(LINK_FLAGS ${TARGET_NAME} LINK_FLAGS)
get_target_inherited_property(COMPILE_DEFINITIONS ${TARGET_NAME} COMPILE_DEFINITIONS)
    MESSAGE(${METHOD} "Target INCLUDE_DIRECTORIES=${INCLUDE_DIRECTORIES}")
    MESSAGE(${METHOD} "Target COMPILE_OPTIONS=${COMPILE_OPTIONS}")
    MESSAGE(${METHOD} "Target COMPILE_FLAGS=${COMPILE_FLAGS}")
    MESSAGE(${METHOD} "Target LINK_OPTIONS=${LINK_OPTIONS}")
    MESSAGE(${METHOD} "Target LINK_FLAGS=${LINK_FLAGS}")
    MESSAGE(${METHOD} "Target COMPILE_DEFINITIONS=${COMPILE_DEFINITIONS}")
list(POP_BACK CMAKE_MESSAGE_CONTEXT)
endfunction()

macro (get_target_inherited_property OUT TARGET PROPERTY)
    SET(${OUT} "")
    list(APPEND CMAKE_MESSAGE_CONTEXT "utils")
    get_target_property(RESULT ${TARGET} ${PROPERTY})
    get_target_property(LINK_LIBRARIES ${TARGET} LINK_LIBRARIES)
    MESSAGE(TRACE "Extract ${PROPERTY} of target ${TARGET}: ${RESULT}")
    if (RESULT)
        LIST(APPEND ${OUT} ${RESULT})
    endif()
    if (LINK_LIBRARIES)
        foreach(library ${LINK_LIBRARIES})
            get_target_inherited_property_(${OUT} ${library} ${PROPERTY})
        endforeach()  
    endif()
    list(POP_BACK CMAKE_MESSAGE_CONTEXT)
endmacro()

macro (get_target_inherited_property_ OUT TARGET PROPERTY)
    get_target_property(RESULT ${TARGET} INTERFACE_${PROPERTY})
    get_target_property(INTERFACE_LINK_LIBRARIES ${TARGET} INTERFACE_LINK_LIBRARIES)
    MESSAGE(TRACE "Extract inherited ${PROPERTY} of target ${TARGET}: ${RESULT}")
    if (RESULT)
        LIST(APPEND ${OUT} ${RESULT})
    endif()
    if (INTERFACE_LINK_LIBRARIES)
        foreach(library ${INTERFACE_LINK_LIBRARIES})
        get_target_inherited_property_(${OUT} ${library} ${PROPERTY})
        endforeach()
    endif()
endmacro()




function (ListToString result delim)
    list(GET ARGV 2 temp)
    math(EXPR N "${ARGC}-1")
    foreach(IDX RANGE 3 ${N})
        list(GET ARGV ${IDX} STR)
        set(temp "${temp}${delim}${STR}")
    endforeach()
    set(${result} "${temp}" PARENT_SCOPE)
endfunction(ListToString)