import os.path
import re
+import fnmatch
import SCons.Action
import SCons.Builder
# TODO: Does dbusxml2cpp need an adapter
env.AddMethod(enable_modules, "EnableQt4Modules")
+ resourceDirectoryBuilder = Builder(
+ action = Action(resourceDirectory),
+ source_factory = env.Dir)
+ env.Append( BUILDERS = { 'Qt4ResourceFromDirectory' : resourceDirectoryBuilder } )
+
# Utilities
env.AddMethod(qt4glob, "Qt4Glob")
def qt4glob(env):
resources = env.Glob("*.qrc")
sources = [ f for f in env.Glob("*.cc")
- if not f.name.startswith("qrc_") ]
+ if not f.name.startswith("qrc_") and not f.name.startswith("moc_") ]
return sources + resources
+def scanResourceDirectory(directory, prefix="", exclude=[]):
+ rv = [
+ '<!DOCTYPE RCC>',
+ # '<?xml version="1.0" encoding="utf-8"?>',
+ '<RCC version="1.0">' ]
+ for base, subdirs, files in os.walk(str(directory)):
+ rv.append('<qresource prefix="%s">' % os.path.join(prefix, base[len(str(directory)):]))
+ for f in files:
+ if not [True for pattern in exclude if fnmatch.fnmatch(f,pattern)]:
+ rv.append('<file alias="%s">%s</file>' % (f, os.path.join(base, f)))
+ rv.append("'</qresource>'")
+ rv.append('</RCC>\n')
+ return '\n'.join(rv)
+
+def resourceDirectory(env, target, source):
+ file(str(target[0]), 'w').write(scanResourceDirectory(
+ source[0], prefix=env.get('RESOURCE_PREFIX', ''), exclude=env.get('EXCLUDE', [])))
+
def exists(env):
return _detect(env)