option (BUILD_PLUGINS "Switch to OFF if you do not want to build plugins" ON)

if (BUILD_PLUGINS)
	foreach (plugin ${COMPILE_PLUGINS})
		file (STRINGS "${plugin}/${plugin}.desc" plugin_dependencies REGEX "^Dependencies")
		string (REPLACE "Dependencies=" "" plugin_dependencies "${plugin_dependencies}")
		string (REPLACE " " ";" plugin_dependencies "${plugin_dependencies}")
		foreach (dependency ${plugin_dependencies})
			list (FIND COMPILE_PLUGINS "${dependency}" index)
			if (index EQUAL -1)
				message (FATAL_ERROR "`${plugin}' plugin requires `${dependency}' plugin. Please enable `${dependency}' plugin.")
			endif ()
		endforeach ()

		message (STATUS "Plugin: " ${plugin})
		add_subdirectory (${plugin})
	endforeach ()
endif ()

if (KADU_INSTALL_SDK)
	if (WIN32)
		install (FILES pluginbase.rc.in DESTINATION "${KADU_INSTALL_SDK_DIR}/plugins")
	endif ()

	install (FILES PluginConfig.cmake.in DESTINATION "${KADU_INSTALL_SDK_DIR}/plugins")
endif ()
