INCLUDE(GetPrerequisites)

SET(SKIP_FILES
	"^/usr/X11.*$"
	)

FOREACH(LOCATION @PONYPROG_BINARY_LOCATIONS@)
	MESSAGE(STATUS "Installing: ${LOCATION} dependencies")

	# Excludes system dependencies, but finds recursive dependencies  
	GET_PREREQUISITES(${LOCATION} DEPENDENCIES 1 0 "" "")

	FOREACH(DEPENDENCY ${DEPENDENCIES})
		GET_FILENAME_COMPONENT(DEPENDENCY_NAME "${DEPENDENCY}" NAME)
		GET_FILENAME_COMPONENT(DEPENDENCY_ACTUAL "${DEPENDENCY}" REALPATH)

		SET(INSTALL_FILE 1)
		FOREACH(SKIP_FILE ${SKIP_FILES})
			IF(DEPENDENCY_ACTUAL MATCHES "${SKIP_FILE}")
				SET(INSTALL_FILE 0)
				BREAK()
			ENDIF()
		ENDFOREACH()

		IF(INSTALL_FILE)
			MESSAGE(STATUS "Copying ${DEPENDENCY_ACTUAL} to ${CMAKE_INSTALL_PREFIX}/lib/${DEPENDENCY_NAME}")

			EXECUTE_PROCESS(
				COMMAND ${CMAKE_COMMAND} -E copy_if_different "${DEPENDENCY_ACTUAL}" "${CMAKE_INSTALL_PREFIX}/lib/${DEPENDENCY_NAME}"
				)
		ENDIF()
	ENDFOREACH()
ENDFOREACH()

