foreach(TARGET ${INSTALL_DEPENDENCIES})

    if(MSVC AND NOT CMAKE_GENERATOR STREQUAL "Ninja" )
        if(USE_CONAN)
            set(TARGET_EXE ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_BUILD_TYPE}/${TARGET}${CMAKE_EXECUTABLE_SUFFIX})
        else()
            set(TARGET_EXE ${EXECUTABLE_OUTPUT_PATH}/Release/${TARGET}${CMAKE_EXECUTABLE_SUFFIX})
        endif()
    else()
        set(TARGET_EXE ${EXECUTABLE_OUTPUT_PATH}/${TARGET}${CMAKE_EXECUTABLE_SUFFIX})
    endif()

    if(EXISTS ${TARGET_EXE})
        include(GetPrerequisites)
        # arg3: exclude system, arg4: recursive
        if (VTK_BUILD_SHARED_LIBS)
            list(APPEND dirs ${vtkIOXML_RUNTIME_LIBRARY_DIRS})
        endif()
        list(APPEND dirs "/usr/local/lib")
        get_prerequisites(${TARGET_EXE} TARGET_DEPENDENCIES 1 1 "" ${dirs})
        if(PRE_INSTALL_RUN)
            message("-- Dependencies of target ${TARGET}:")
        endif()
        foreach(DEPENDENCY ${TARGET_DEPENDENCIES})
            if(NOT ${DEPENDENCY} MATCHES "@loader_path")
                gp_resolve_item("${TARGET_EXE}" "${DEPENDENCY}" "" "" DEPENDENCY_PATH)
                get_filename_component(RESOLVED_DEPENDENCY_PATH "${DEPENDENCY_PATH}" REALPATH)
                string(TOLOWER ${DEPENDENCY} DEPENDENCY_LOWER)
                set(DEPENDENCY_PATHS ${DEPENDENCY_PATHS} ${RESOLVED_DEPENDENCY_PATH})
                if(PRE_INSTALL_RUN)
                    message("     ${RESOLVED_DEPENDENCY_PATH}")
                endif()
            endif()
        endforeach()
        if(PRE_INSTALL_RUN)
            message("")
        endif()
        install(FILES ${DEPENDENCY_PATHS} DESTINATION bin)
    endif()

endforeach()

unset(PRE_INSTALL_RUN CACHE)
