1# http://www.w3.org/TR/xml/#syntax 2defineReplace(xml_escape) { 3 1 ~= s,&,&, 4 1 ~= s,\',', 5 1 ~= s,\",", 6 1 ~= s,<,<, 7 1 ~= s,>,>, 8 return($$1) 9} 10 11defineTest(qtFlattenResources) { 12 isEmpty(RCC_DIR):RCC_DIR = . 13 immediate = qmake_immediate$$QMAKE_RESOURCES_IMMEDIATE_NR 14 defined(QMAKE_RESOURCES_IMMEDIATE_NR, var): \ 15 QMAKE_RESOURCES_IMMEDIATE_NR = $$num_add($$QMAKE_RESOURCES_IMMEDIATE_NR, 1) 16 else: \ 17 QMAKE_RESOURCES_IMMEDIATE_NR = 1 18 19 RESOURCES += $$immediate 20 for(resource, RESOURCES) { 21 # Regular case of user qrc file 22 contains(resource, ".*\\.qrc$"): \ 23 next() 24 25 # Fallback for stand-alone files/directories 26 !defined($${resource}.files, var) { 27 !equals(resource, $$immediate) { 28 !exists($$absolute_path($$resource, $$_PRO_FILE_PWD_)): \ 29 warning("Failure to find: $$resource") 30 $${immediate}.files += $$resource 31 OTHER_FILES *= $$resource 32 } 33 RESOURCES -= $$resource 34 next() 35 } 36 37 RESOURCES -= $$resource 38 !android|isEmpty(BUILDS)|build_pass { 39 resource_file = $$absolute_path($$RCC_DIR/qmake_$${resource}.qrc, $$OUT_PWD) 40 RESOURCES += $$resource_file 41 } else { 42 # Android will need a resource file for each architecture make sure it is placed 43 # correctly for other functions that need the right paths for these files 44 for (arch, ANDROID_ABIS) { 45 resource_file = $$absolute_path($$RCC_DIR/$$arch/qmake_$${resource}.qrc, $$OUT_PWD) 46 RESOURCES += $$resource_file 47 } 48 } 49 50 isEmpty(BUILDS)|build_pass { 51 # Collection of files, generate qrc file 52 prefix = $$eval($${resource}.prefix) 53 isEmpty(prefix): \ 54 prefix = "/" 55 56 resource_file_content = \ 57 "<!DOCTYPE RCC><RCC version=\"1.0\">" \ 58 "<qresource prefix=\"$$xml_escape($$prefix)\">" 59 60 abs_base = $$absolute_path($$eval($${resource}.base), $$_PRO_FILE_PWD_) 61 62 for(file, $${resource}.files) { 63 abs_path = $$absolute_path($$file, $$_PRO_FILE_PWD_) 64 files = $$files($$abs_path/*, true) 65 isEmpty(files): \ 66 files = $$abs_path 67 for (file, files) { 68 exists($$file/*): next() # exclude directories 69 alias = $$relative_path($$file, $$abs_base) 70 resource_file_content += \ 71 "<file alias=\"$$xml_escape($$alias)\">$$xml_escape($$file)</file>" 72 OTHER_FILES *= $$file 73 } 74 } 75 76 resource_file_content += \ 77 "</qresource>" \ 78 "</RCC>" 79 80 !write_file($$resource_file, resource_file_content): \ 81 error() 82 } 83 } 84 export(RCC_DIR) 85 export(QMAKE_RESOURCES_IMMEDIATE_NR) 86 export(RESOURCES) 87 export(OTHER_FILES) 88 export($${immediate}.files) 89 return(true) 90} 91 92defineTest(qtEnsurePluginResourcesCpp) { 93 contains(DEFINES, QT_PLUGIN_RESOURCE_INIT_FUNCTION=.*): \ 94 return(true) 95 96 !isEmpty(RESOURCES):contains(TEMPLATE, .*lib):plugin:static { 97 pluginBaseName = $$basename(TARGET) 98 pluginName = $$lower($$replace(pluginBaseName, [-], _)) 99 resource_init_function = $${pluginName}_plugin_resource_init 100 DEFINES += "QT_PLUGIN_RESOURCE_INIT_FUNCTION=$$resource_init_function" 101 RESOURCE_INIT_CPP = $$OUT_PWD/$${pluginName}_plugin_resources.cpp 102 103 GENERATED_SOURCES += $$RESOURCE_INIT_CPP 104 QMAKE_DISTCLEAN += $$RESOURCE_INIT_CPP 105 106 isEmpty(BUILDS)|build_pass { 107 RESOURCE_INIT_CONT = \ 108 "// This file is autogenerated by qmake. It contains a function that" \ 109 "// references all resources the plugin includes and the function is" \ 110 "// referenced by Qt_(MOC_)EXPORT_PLUGIN to ensure the inclusion in" \ 111 "// the statically linked plugin." \ 112 "$${LITERAL_HASH}include <QtCore/qglobal.h>" \ 113 "void $${resource_init_function}() " \ 114 "{" \ 115 116 for (resource, RESOURCES) { 117 resource_name = $$replace($$list($$basename(resource)),\.qrc$, ) 118 resource_name = $$replace(resource_name, [^a-zA-Z0-9_], _) 119 RESOURCE_INIT_CONT += " Q_INIT_RESOURCE($$resource_name);" 120 } 121 122 RESOURCE_INIT_CONT += \ 123 "}" 124 125 write_file($$RESOURCE_INIT_CPP, RESOURCE_INIT_CONT)|error() 126 } 127 128 export(DEFINES) 129 export(GENERATED_SOURCES) 130 export(QMAKE_DISTCLEAN) 131 } 132 return(true) 133} 134