SET(PLUGIN_FILES "")
IF(LMMS_BUILD_WIN32)
	INSTALL(FILES $<TARGET_FILE:Qt5::QWindowsIntegrationPlugin> DESTINATION platforms)
ENDIF()

IF(LMMS_BUILD_WIN32 OR LMMS_INSTALL_DEPENDENCIES)
	include(InstallTargetDependencies)

	# Collect directories to search for DLLs
	GET_FILENAME_COMPONENT(QTBIN_DIR "${QT_QMAKE_EXECUTABLE}" PATH)
	set(LIB_DIRS "${QTBIN_DIR}")

	GET_PROPERTY(PLUGINS_BUILT GLOBAL PROPERTY PLUGINS_BUILT)

	IF(LMMS_BUILD_WIN32)
		SET(LMMS_DEP_DESTINATION ${BIN_DIR})
		SET(PLUGIN_DEP_DESTINATION ${BIN_DIR})
	ELSE()
		SET(LMMS_DEP_DESTINATION ${LIB_DIR})
		SET(PLUGIN_DEP_DESTINATION ${LIB_DIR})
	ENDIF()

	INSTALL_TARGET_DEPENDENCIES(
			NAME "main_binary"
			TARGETS lmms
			DESTINATION "${LMMS_DEP_DESTINATION}"
			LIB_DIRS  ${LIB_DIRS}
	)

	INSTALL_TARGET_DEPENDENCIES(
			NAME "plugins"
			TARGETS ${PLUGINS_BUILT}
			DESTINATION ${PLUGIN_DEP_DESTINATION}
			LIB_DIRS ${LIB_DIRS} "${PLUGIN_DIR}"
	)
ENDIF()

IF(LMMS_BUILD_APPLE)
	INSTALL(CODE "EXECUTE_PROCESS(COMMAND chmod u+x ${CMAKE_BINARY_DIR}/install_apple.sh)")
	INSTALL(CODE "EXECUTE_PROCESS(COMMAND ${CMAKE_BINARY_DIR}/install_apple.sh)")
ENDIF()
