summaryrefslogtreecommitdiffstats
path: root/mkspecs/features/resources_functions.prf
diff options
context:
space:
mode:
Diffstat (limited to 'mkspecs/features/resources_functions.prf')
-rw-r--r--mkspecs/features/resources_functions.prf80
1 files changed, 80 insertions, 0 deletions
diff --git a/mkspecs/features/resources_functions.prf b/mkspecs/features/resources_functions.prf
new file mode 100644
index 0000000000..b7a15fd1d9
--- /dev/null
+++ b/mkspecs/features/resources_functions.prf
@@ -0,0 +1,80 @@
+# http://www.w3.org/TR/xml/#syntax
+defineReplace(xml_escape) {
+ 1 ~= s,&,&,
+ 1 ~= s,\',',
+ 1 ~= s,\",",
+ 1 ~= s,<,&lt;,
+ 1 ~= s,>,&gt;,
+ return($$1)
+}
+
+defineTest(qtFlattenResources) {
+ immediate = qmake_immediate$$QMAKE_RESOURCES_IMMEDIATE_NR
+ defined(QMAKE_RESOURCES_IMMEDIATE_NR, var): \
+ QMAKE_RESOURCES_IMMEDIATE_NR = $$num_add($$QMAKE_RESOURCES_IMMEDIATE_NR, 1)
+ else: \
+ QMAKE_RESOURCES_IMMEDIATE_NR = 1
+
+ RESOURCES += $$immediate
+ for(resource, RESOURCES) {
+ # Regular case of user qrc file
+ contains(resource, ".*\\.qrc$"): \
+ next()
+
+ # Fallback for stand-alone files/directories
+ !defined($${resource}.files, var) {
+ !equals(resource, $$immediate) {
+ !exists($$absolute_path($$resource, $$_PRO_FILE_PWD_)): \
+ warning("Failure to find: $$resource")
+ $${immediate}.files += $$resource
+ OTHER_FILES *= $$resource
+ }
+ RESOURCES -= $$resource
+ next()
+ }
+
+ resource_file = $$absolute_path($$RCC_DIR/qmake_$${resource}.qrc, $$OUT_PWD)
+
+ isEmpty(BUILDS)|build_pass {
+ # Collection of files, generate qrc file
+ prefix = $$eval($${resource}.prefix)
+ isEmpty(prefix): \
+ prefix = "/"
+
+ resource_file_content = \
+ "<!DOCTYPE RCC><RCC version=\"1.0\">" \
+ "<qresource prefix=\"$$xml_escape($$prefix)\">"
+
+ abs_base = $$absolute_path($$eval($${resource}.base), $$_PRO_FILE_PWD_)
+
+ for(file, $${resource}.files) {
+ abs_path = $$absolute_path($$file, $$_PRO_FILE_PWD_)
+ files = $$files($$abs_path/*, true)
+ isEmpty(files): \
+ files = $$abs_path
+ for (file, files) {
+ exists($$file/*): next() # exclude directories
+ alias = $$relative_path($$file, $$abs_base)
+ resource_file_content += \
+ "<file alias=\"$$xml_escape($$alias)\">$$xml_escape($$file)</file>"
+ OTHER_FILES *= $$file
+ }
+ }
+
+ resource_file_content += \
+ "</qresource>" \
+ "</RCC>"
+
+ !write_file($$resource_file, resource_file_content): \
+ error()
+ }
+
+ RESOURCES -= $$resource
+ RESOURCES += $$resource_file
+ }
+ export(QMAKE_RESOURCES_IMMEDIATE_NR)
+ export(RESOURCES)
+ export(OTHER_FILES)
+ export($${immediate}.files)
+ return(true)
+}