+###################################################################################################
+# Provides a library that contains data files as a Qt resource (.qrc).
+#
+# quassel_add_resource(QrcName
+# [BASEDIR basedir]
+# [PREFIX prefix]
+# PATTERNS pattern1 pattern2...
+# [DEPENDS dep1 dep2...]
+# )
+#
+# The first parameter is the CamelCased name of the resource; the library target will be called
+# "Quassel::Resource::QrcName". The library provides a Qt resource named "qrcname" (lowercased QrcName)
+# containing the files matching PATTERNS relative to BASEDIR (by default, the current source dir).
+# The resource prefix can be set by giving the PREFIX argument.
+# Additional target dependencies can be specified with DEPENDS.
+#
+function(quassel_add_resource _name)
+ set(options )
+ set(oneValueArgs BASEDIR PREFIX)
+ set(multiValueArgs DEPENDS PATTERNS)
+ cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+
+ if (NOT ARG_BASEDIR)
+ set(ARG_BASEDIR ${CMAKE_CURRENT_SOURCE_DIR})
+ endif()
+ get_filename_component(basedir ${ARG_BASEDIR} REALPATH)
+
+ string(TOLOWER ${_name} lower_name)
+
+ set(qrc_target quassel-qrc-${lower_name})
+ set(qrc_file ${lower_name}.qrc)
+ set(qrc_src qrc_${lower_name}.cpp)
+ set(qrc_filepath ${CMAKE_CURRENT_BINARY_DIR}/${qrc_file})
+ set(qrc_srcpath ${CMAKE_CURRENT_BINARY_DIR}/${qrc_src})
+
+ # This target will always be built, so the qrc file will always be freshly generated.
+ # That way, changes to the glob result are always taken into account.
+ add_custom_target(${qrc_target} VERBATIM
+ COMMENT "Generating ${qrc_file}"
+ COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/cmake/GenerateQrc.cmake "${qrc_filepath}" "${ARG_PREFIX}" "${ARG_PATTERNS}"
+ DEPENDS ${ARG_DEPENDS}
+ BYPRODUCTS ${qrc_filepath}
+ WORKING_DIRECTORY ${basedir}
+ )
+ set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${qrc_filepath})
+
+ # RCC sucks and expects the data files relative to the qrc file, with no way to configure it differently.
+ # Only when reading from stdin ("-") it takes the working directory as a base, so we have to use this if
+ # we want to use generated qrc files (which obviously cannot be placed in the source directory).
+ # Since neither autorcc nor qt5_add_resources() support this, we have to invoke rcc manually :(
+ #
+ # On Windows, input redirection apparently doesn't work, however piping does. Use this for all platforms for
+ # consistency, accommodating for the fact that the 'cat' equivalent on Windows is 'type'.
+ if (WIN32)
+ set(cat_cmd type)