Пример #1
0
def generate(env):
    """Add a Builder factory function and construction variables for
    kicad gerber builder to an Environment."""
    if not env.has_key('KICAD_PYTHONCOM'):
        pcbnew_com = find(env, 'pcbnew')
        if pcbnew_com:
            pcbnew_com_dir = os.path.dirname(pcbnew_com)
        else:
            print(
                "Error: While loading Kicad Gerber scons tool, cannot find pcbnew executable."
            )
            print("Please add executable path on the path variable.")
            env.Exit(1)
        env['KICAD_PYTHONCOM'] = os.path.join(pcbnew_com_dir, "python.exe")

    Builder = SCons.Builder.Builder

    def builder_print_action():
        # Suppress action command line printing... each action has its own
        # pretty message.
        pass

    env['__kicad_gen_gerbers_py'] = os.path.join(
        env.Dir('#site_scons/site_tools').abspath, "gen_gerbers.py")
    first_action = SCons.Action.Action(
        '$KICAD_PYTHONCOM "$__kicad_gen_gerbers_py" -i ${SOURCE.srcdir.abspath}/${SOURCE.name}  -o ${TARGET.srcdir.abspath}',
        'Generating:  Gerber files for "$SOURCE.name"',
        show=builder_print_action)

    kicad_gerber_builder_action = [first_action]
    kicad_gerber_builder = Builder(action=kicad_gerber_builder_action,
                                   emitter=kicadgerber_Emitter)

    env.Append(BUILDERS={'KiCadGerber': kicad_gerber_builder})
Пример #2
0
def TOOL_WRITE_VAL(env):
    env.Append(TOOLS = 'WRITE_VAL')
    def write_val(target, source, env):
        """Write the contents of the first source into the target.
        source is usually a Value() node, but could be a file."""
        f = open(str(target[0]), 'wb')
        f.write(source[0].get_contents())
        f.close()
    env['BUILDERS']['WriteVal'] = Builder(action=write_val)
Пример #3
0
def generate(env, **kw):
    Builder = SCons.Builder.Builder

    env['MSGFMT'] = env.Detect('msgfmt') or 'msgfmt'

    GettextMOBuilder = Builder(action=env['MSGFMT'] + ' -o $TARGET $SOURCE',
                               suffix='.mo',
                               src_suffix='.po')
    env['BUILDERS']['MO'] = GettextMOBuilder
Пример #4
0
def init(env):
    SConsEnvironment.HookedAlias = env.Alias
    SConsEnvironment.AliasHelpData = AliasHelpData()
    SConsEnvironment.Alias = AliasHelp
    SConsEnvironment.AddAliasDescription = AddAliasDescription
    bld = Builder(action=SCons.Action.Action(PrintTargets, PrintTargetsDummy))
    env.Append(BUILDERS={'PrintTargets': bld})
    action = env.PrintTargets('dummy', 'SConstruct')
    env.AlwaysBuild(env.HookedAlias('targets', action))
Пример #5
0
def registerBuilders(env):
    bldModule = Builder.Builder(action=buildModule,
                                suffix='.fs',
                                src_suffix='')
    bldBom = Builder.Builder(action=buildBom, suffix='.bom', src_suffix='')
    bldTaggedProg = Builder.Builder(action=buildTaggedProg,
                                    suffix="",
                                    src_suffix='.unt')
    bldTarBall = Builder.Builder(action=buildTarBall,
                                 suffix=".tgz",
                                 src_suffix='')
    bldSignedUpg = Builder.Builder(action=buildSignedUpg,
                                   suffix=".upg",
                                   src_suffix='')
    env['BUILDERS']['TaggedProg'] = bldTaggedProg
    env['BUILDERS']['Module'] = bldModule
    env['BUILDERS']['Bom'] = bldBom
    env['BUILDERS']['TarBall'] = bldTarBall
    env['BUILDERS']['SignedUpg'] = bldSignedUpg
Пример #6
0
def generate(env):
    """
        Add builders and construction variables for the DistTar builder.
        """

    disttar_action = SCons.Action.Action(disttar, disttar_string)
    env['BUILDERS']['DistTar'] = Builder(action=disttar_action,
                                         emitter=disttar_emitter,
                                         suffix=disttar_suffix,
                                         target_factory=env.fs.Entry)

    env.AppendUnique(DISTTAR_FORMAT='gz')
Пример #7
0
def generate(env):
	"""Add Builders and construction variables for qt to an Environment."""

	def locateQt4Command(env, command, qtdir) :
		if len(qtdir) == 0 :
			qtdir = "/usr"
		suffixes = [
			'-qt4',
			'-qt4.exe',
			'4',
			'4.exe',
			'',
			'.exe',
		]
		triedPaths = []
		for suffix in suffixes :
			fullpath = os.path.join(qtdir,'bin',command + suffix)
			if os.access(fullpath, os.X_OK) :
				return fullpath
			triedPaths.append(fullpath)

		fullpath = env.Detect([command+'-qt4', command+'4', command])
		if not (fullpath is None) : return fullpath

		raise Exception("Qt4 command '" + command + "' not found. Tried: " + ', '.join(triedPaths))
		

	CLVar = SCons.Util.CLVar
	Action = SCons.Action.Action
	Builder = SCons.Builder.Builder
	splitext = SCons.Util.splitext

	env['QTDIR']	= _detect(env)
	# TODO: 'Replace' should be 'SetDefault'
#	env.SetDefault(
	env.Replace(
		QTDIR  = _detect(env),
		# TODO: This is not reliable to QTDIR value changes but needed in order to support '-qt4' variants
		QT4_MOC = locateQt4Command(env,'moc', env['QTDIR']),
		QT4_UIC = locateQt4Command(env,'uic', env['QTDIR']),
		QT4_RCC = locateQt4Command(env,'rcc', env['QTDIR']),
		QT4_LUPDATE = locateQt4Command(env,'lupdate', env['QTDIR']),
		QT4_LRELEASE = locateQt4Command(env,'lrelease', env['QTDIR']),
		QT4_LIB = '', # KLUDGE to avoid linking qt3 library

		QT4_AUTOSCAN = 1, # Should the qt tool try to figure out, which sources are to be moc'ed?

		# Some QT specific flags. I don't expect someone wants to
		# manipulate those ...
		QT4_UICFLAGS = CLVar(''),
		QT4_MOCFROMHFLAGS = CLVar(''),
		QT4_MOCFROMCXXFLAGS = CLVar('-i'),
		QT4_QRCFLAGS = '',

		# suffixes/prefixes for the headers / sources to generate
		QT4_UISUFFIX = '.ui',
		QT4_UICDECLPREFIX = 'ui_',
		QT4_UICDECLSUFFIX = '.h',
		QT4_MOCHPREFIX = 'moc_',
		QT4_MOCHSUFFIX = '$CXXFILESUFFIX',
		QT4_MOCCXXPREFIX = '',
		QT4_MOCCXXSUFFIX = '.moc',
		QT4_QRCSUFFIX = '.qrc',
		QT4_QRCCXXSUFFIX = '$CXXFILESUFFIX',
		QT4_QRCCXXPREFIX = 'qrc_',
		QT4_MOCCPPPATH = [],
		QT4_MOCINCFLAGS = '$( ${_concat("-I", QT4_MOCCPPPATH, INCSUFFIX, __env__, RDirs)} $)',

		# Commands for the qt support ...
		QT4_UICCOM = '$QT4_UIC $QT4_UICFLAGS -o $TARGET $SOURCE',
		QT4_MOCFROMHCOM = '$QT4_MOC $QT4_MOCFROMHFLAGS $QT4_MOCINCFLAGS -o $TARGET $SOURCE',
		QT4_MOCFROMCXXCOM = [
			'$QT4_MOC $QT4_MOCFROMCXXFLAGS $QT4_MOCINCFLAGS -o $TARGET $SOURCE',
			Action(checkMocIncluded,None)],
		QT4_LUPDATECOM = '$QT4_LUPDATE $SOURCE -ts $TARGET',
		QT4_LRELEASECOM = '$QT4_LRELEASE -silent $SOURCE -qm $TARGET',
		QT4_RCCCOM = '$QT4_RCC $QT4_QRCFLAGS -name $SOURCE $SOURCE -o $TARGET',
		)
	if len(env["QTDIR"]) > 0 :
		env.Replace(QT4_LIBPATH = os.path.join('$QTDIR', 'lib'))

	# Translation builder
	tsbuilder = Builder(
		action = SCons.Action.Action('$QT4_LUPDATECOM'), #,'$QT4_LUPDATECOMSTR'),
		multi=1
		)
	env.Append( BUILDERS = { 'Ts': tsbuilder } )
	qmbuilder = Builder(
		action = SCons.Action.Action('$QT4_LRELEASECOM', cmdstr = '$QT4_LRELEASECOMSTR'),
		src_suffix = '.ts',
		suffix = '.qm',
		single_source = True
		)
	env.Append( BUILDERS = { 'Qm': qmbuilder } )

	# Resource builder
	def scanResources(node, env, path, arg):
		# I've being careful on providing names relative to the qrc file
		# If that was not needed that code could be simplified a lot
		def recursiveFiles(basepath, path) :
			result = []
			for item in os.listdir(os.path.join(basepath, path)) :
				itemPath = os.path.join(path, item)
				if os.path.isdir(os.path.join(basepath, itemPath)) :
					result += recursiveFiles(basepath, itemPath)
				else:
					result.append(itemPath)
			return result
		contents = node.get_contents()
		includes = qrcinclude_re.findall(contents)
		qrcpath = os.path.dirname(node.path)
		dirs = [included for included in includes if os.path.isdir(os.path.join(qrcpath,included))]
		# dirs need to include files recursively
		for dir in dirs :
			includes.remove(dir)
			includes+=recursiveFiles(qrcpath,dir)
		return includes
	qrcscanner = SCons.Scanner.Scanner(name = 'qrcfile',
		function = scanResources,
		argument = None,
		skeys = ['.qrc'])
	qrcbuilder = Builder(
		action = SCons.Action.Action('$QT4_RCCCOM', cmdstr = '$QT4_RCCCOMSTR'), 
		source_scanner = qrcscanner,
		src_suffix = '$QT4_QRCSUFFIX',
		suffix = '$QT4_QRCCXXSUFFIX',
		prefix = '$QT4_QRCCXXPREFIX',
		single_source = True
		)
	env.Append( BUILDERS = { 'Qrc': qrcbuilder } )

	# Interface builder
	uic4builder = Builder(
		action = SCons.Action.Action('$QT4_UICCOM', cmdstr = '$QT4_UICCOMSTR'), 
		src_suffix='$QT4_UISUFFIX',
		suffix='$QT4_UICDECLSUFFIX',
		prefix='$QT4_UICDECLPREFIX',
		single_source = True
		#TODO: Consider the uiscanner on new scons version
		)
	env['BUILDERS']['Uic4'] = uic4builder

	# Metaobject builder
	mocBld = Builder(action={}, prefix={}, suffix={})
	for h in header_extensions:
		act = SCons.Action.Action('$QT4_MOCFROMHCOM', cmdstr = '$QT4_MOCFROMHCOMSTR')
		mocBld.add_action(h, act)
		mocBld.prefix[h] = '$QT4_MOCHPREFIX'
		mocBld.suffix[h] = '$QT4_MOCHSUFFIX'
	for cxx in cxx_suffixes:
		act = SCons.Action.Action('$QT4_MOCFROMCXXCOM', cmdstr = '$QT4_MOCFROMCXXCOMSTR')
		mocBld.add_action(cxx, act)
		mocBld.prefix[cxx] = '$QT4_MOCCXXPREFIX'
		mocBld.suffix[cxx] = '$QT4_MOCCXXSUFFIX'
	env['BUILDERS']['Moc4'] = mocBld

	# er... no idea what that was for
	static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
	static_obj.src_builder.append('Uic4')
	shared_obj.src_builder.append('Uic4')

	# We use the emitters of Program / StaticLibrary / SharedLibrary
	# to scan for moc'able files
	# We can't refer to the builders directly, we have to fetch them
	# as Environment attributes because that sets them up to be called
	# correctly later by our emitter.
	env.AppendUnique(PROGEMITTER =[AutomocStatic],
					 SHLIBEMITTER=[AutomocShared],
					 LIBEMITTER  =[AutomocStatic],
					 # Of course, we need to link against the qt libraries
					 LIBPATH=["$QT4_LIBPATH"],
					 LIBS=['$QT4_LIB'])

	# TODO: Does dbusxml2cpp need an adapter
	env.AddMethod(enable_modules, "EnableQt4Modules")
Пример #8
0
def generate(env):
    """Add Builders and construction variables for qt to an Environment."""
    CLVar = SCons.Util.CLVar
    Action = SCons.Action.Action
    Builder = SCons.Builder.Builder

    env.SetDefault(QTDIR  = _detect(env),
                   QT_BINPATH = os.path.join('$QTDIR', 'bin'),
                   QT_CPPPATH = os.path.join('$QTDIR', 'include'),
                   QT_LIBPATH = os.path.join('$QTDIR', 'lib'),
                   QT_MOC = os.path.join('$QT_BINPATH','moc'),
                   QT_UIC = os.path.join('$QT_BINPATH','uic'),
                   QT_LIB = 'qt', # may be set to qt-mt

                   QT_AUTOSCAN = 1, # scan for moc'able sources

                   # Some QT specific flags. I don't expect someone wants to
                   # manipulate those ...
                   QT_UICIMPLFLAGS = CLVar(''),
                   QT_UICDECLFLAGS = CLVar(''),
                   QT_MOCFROMHFLAGS = CLVar(''),
                   QT_MOCFROMCXXFLAGS = CLVar('-i'),

                   # suffixes/prefixes for the headers / sources to generate
                   QT_UICDECLPREFIX = '',
                   QT_UICDECLSUFFIX = '.h',
                   QT_UICIMPLPREFIX = 'uic_',
                   QT_UICIMPLSUFFIX = '$CXXFILESUFFIX',
                   QT_MOCHPREFIX = 'moc_',
                   QT_MOCHSUFFIX = '$CXXFILESUFFIX',
                   QT_MOCCXXPREFIX = '',
                   QT_MOCCXXSUFFIX = '.moc',
                   QT_UISUFFIX = '.ui',

                   # Commands for the qt support ...
                   # command to generate header, implementation and moc-file
                   # from a .ui file
                   QT_UICCOM = [
                    CLVar('$QT_UIC $QT_UICDECLFLAGS -o ${TARGETS[0]} $SOURCE'),
                    CLVar('$QT_UIC $QT_UICIMPLFLAGS -impl ${TARGETS[0].file} '
                          '-o ${TARGETS[1]} $SOURCE'),
                    CLVar('$QT_MOC $QT_MOCFROMHFLAGS -o ${TARGETS[2]} ${TARGETS[0]}')],
                   # command to generate meta object information for a class
                   # declarated in a header
                   QT_MOCFROMHCOM = (
                          '$QT_MOC $QT_MOCFROMHFLAGS -o ${TARGETS[0]} $SOURCE'),
                   # command to generate meta object information for a class
                   # declarated in a cpp file
                   QT_MOCFROMCXXCOM = [
                    CLVar('$QT_MOC $QT_MOCFROMCXXFLAGS -o ${TARGETS[0]} $SOURCE'),
                    Action(checkMocIncluded,None)])

    # ... and the corresponding builders
    uicBld = Builder(action=SCons.Action.Action('$QT_UICCOM', '$QT_UICCOMSTR'),
                     emitter=uicEmitter,
                     src_suffix='$QT_UISUFFIX',
                     suffix='$QT_UICDECLSUFFIX',
                     prefix='$QT_UICDECLPREFIX',
                     source_scanner=uicScanner)
    mocBld = Builder(action={}, prefix={}, suffix={})
    for h in header_extensions:
        act = SCons.Action.Action('$QT_MOCFROMHCOM', '$QT_MOCFROMHCOMSTR')
        mocBld.add_action(h, act)
        mocBld.prefix[h] = '$QT_MOCHPREFIX'
        mocBld.suffix[h] = '$QT_MOCHSUFFIX'
    for cxx in cxx_suffixes:
        act = SCons.Action.Action('$QT_MOCFROMCXXCOM', '$QT_MOCFROMCXXCOMSTR')
        mocBld.add_action(cxx, act)
        mocBld.prefix[cxx] = '$QT_MOCCXXPREFIX'
        mocBld.suffix[cxx] = '$QT_MOCCXXSUFFIX'

    # register the builders 
    env['BUILDERS']['Uic'] = uicBld
    env['BUILDERS']['Moc'] = mocBld
    static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
    static_obj.add_src_builder('Uic')
    shared_obj.add_src_builder('Uic')

    # We use the emitters of Program / StaticLibrary / SharedLibrary
    # to scan for moc'able files
    # We can't refer to the builders directly, we have to fetch them
    # as Environment attributes because that sets them up to be called
    # correctly later by our emitter.
    env.AppendUnique(PROGEMITTER =[AutomocStatic],
                     SHLIBEMITTER=[AutomocShared],
                     LIBEMITTER  =[AutomocStatic],
                     # Of course, we need to link against the qt libraries
                     CPPPATH=["$QT_CPPPATH"],
                     LIBPATH=["$QT_LIBPATH"],
                     LIBS=['$QT_LIB'])
Пример #9
0
def generate(env):
    """Add Builders and construction variables for qt to an Environment."""

    print("Loading qt5 tool...")

    def locateQt5Command(env, command, qtdir):
        fullpath1 = os.path.join(qtdir, 'bin', command + '-qt5')
        if (os.access(fullpath1, os.X_OK)
                or os.access(fullpath1 + ".exe", os.X_OK)):
            return fullpath1
        fullpath3 = os.path.join(qtdir, 'bin', command + '5')
        if (os.access(fullpath3, os.X_OK)
                or os.access(fullpath3 + ".exe", os.X_OK)):
            return fullpath3
        fullpath2 = os.path.join(qtdir, 'bin', command)
        if (os.access(fullpath2, os.X_OK)
                or os.access(fullpath2 + ".exe", os.X_OK)):
            return fullpath2
        fullpath = env.Detect([command + '-qt5', command + '5', command])
        if not (fullpath is None):
            return fullpath
        raise Exception("Qt4 command '" + command + "' not found. Tried: " +
                        fullpath1 + " and " + fullpath2)

    CLVar = SCons.Util.CLVar
    Action = SCons.Action.Action
    Builder = SCons.Builder.Builder
    splitext = SCons.Util.splitext

    env['QTDIR'] = _detect(env)
    # TODO: 'Replace' should be 'SetDefault'
    #    env.SetDefault(
    env.Replace(
        QTDIR=_detect(env),
        QT5_BINPATH=os.path.join('$QTDIR', 'bin'),
        QT5_CPPPATH=os.path.join('$QTDIR', 'include'),
        QT5_LIBPATH=os.path.join('$QTDIR', 'lib'),
        # TODO: This is not reliable to QTDIR value changes but needed in order to support '-qt4' variants
        QT5_MOC=locateQt5Command(env, 'moc', env['QTDIR']),
        QT5_UIC=locateQt5Command(env, 'uic', env['QTDIR']),
        QT5_RCC=locateQt5Command(env, 'rcc', env['QTDIR']),
        QT5_LUPDATE=locateQt5Command(env, 'lupdate', env['QTDIR']),
        QT5_LRELEASE=locateQt5Command(env, 'lrelease', env['QTDIR']),
        QT5_LIB='',  # KLUDGE to avoid linking qt3 library
        QT5_AUTOSCAN=
        1,  # Should the qt tool try to figure out, which sources are to be moc'ed?

        # Some QT specific flags. I don't expect someone wants to
        # manipulate those ...
        QT5_UICFLAGS=CLVar(''),
        QT5_MOCFROMHFLAGS=CLVar(''),
        QT5_MOCFROMCXXFLAGS=CLVar('-i'),
        QT5_QRCFLAGS='',

        # suffixes/prefixes for the headers / sources to generate
        QT5_UISUFFIX='.ui',
        QT5_UICDECLPREFIX='ui_',
        QT5_UICDECLSUFFIX='.h',
        QT5_MOCHPREFIX='moc_',
        QT5_MOCHSUFFIX='$CXXFILESUFFIX',
        QT5_MOCCXXPREFIX='moc_',
        QT5_MOCCXXSUFFIX='.moc',
        QT5_QRCSUFFIX='.qrc',
        QT5_QRCCXXSUFFIX='$CXXFILESUFFIX',
        QT5_QRCCXXPREFIX='qrc_',

        # Commands for the qt support ...
        QT5_UICCOM='$QT5_UIC $QT5_UICFLAGS -o $TARGET $SOURCE',
        QT5_MOCFROMHCOM='$QT5_MOC $QT5_MOCFROMHFLAGS -o $TARGET $SOURCE',
        QT5_MOCFROMCXXCOM=[
            '$QT5_MOC $QT5_MOCFROMCXXFLAGS -o $TARGET $SOURCE',
            Action(checkMocIncluded, None)
        ],
        QT5_LUPDATECOM='$QT5_LUPDATE $SOURCE -ts $TARGET',
        QT5_LRELEASECOM='$QT5_LRELEASE $SOURCE',
        QT5_RCCCOM='$QT5_RCC $QT5_QRCFLAGS $SOURCE -o $TARGET',
    )

    # Translation builder
    tsbuilder = Builder(
        action=SCons.Action.Action(
            '$QT5_LUPDATECOM'),  #,'$QT5_LUPDATECOMSTR'),
        multi=1)
    env.Append(BUILDERS={'Ts': tsbuilder})
    qmbuilder = Builder(
        action=SCons.Action.Action(
            '$QT5_LRELEASECOM'),  # , '$QT5_LRELEASECOMSTR'),
        src_suffix='.ts',
        suffix='.qm',
        single_source=True)
    env.Append(BUILDERS={'Qm': qmbuilder})

    # Resource builder
    def scanResources(node, env, path, arg):
        contents = node.get_contents()
        includes = qrcinclude_re.findall(contents)
        return includes

    qrcscanner = SCons.Scanner.Scanner(name='qrcfile',
                                       function=scanResources,
                                       argument=None,
                                       skeys=['.qrc'])
    qrcbuilder = Builder(
        action=SCons.Action.Action('$QT5_RCCCOM'),  #, '$QT5_RCCCOMSTR'),
        source_scanner=qrcscanner,
        src_suffix='$QT5_QRCSUFFIX',
        suffix='$QT5_QRCCXXSUFFIX',
        prefix='$QT5_QRCCXXPREFIX',
        single_source=True)
    env.Append(BUILDERS={'Qrc': qrcbuilder})

    # Interface builder
    uic5builder = Builder(
        action=SCons.Action.Action('$QT5_UICCOM'),  #, '$QT5_UICCOMSTR'),
        src_suffix='$QT5_UISUFFIX',
        suffix='$QT5_UICDECLSUFFIX',
        prefix='$QT5_UICDECLPREFIX',
        single_source=True
        #TODO: Consider the uiscanner on new scons version
    )
    env.Append(BUILDERS={'Uic5': uic5builder})

    # Metaobject builder
    mocBld = Builder(action={}, prefix={}, suffix={})
    for h in header_extensions:
        act = SCons.Action.Action(
            '$QT5_MOCFROMHCOM')  #, '$QT5_MOCFROMHCOMSTR')
        mocBld.add_action(h, act)
        mocBld.prefix[h] = '$QT5_MOCHPREFIX'
        mocBld.suffix[h] = '$QT5_MOCHSUFFIX'
    for cxx in cxx_suffixes:
        act = SCons.Action.Action(
            '$QT5_MOCFROMCXXCOM')  #, '$QT5_MOCFROMCXXCOMSTR')
        mocBld.add_action(cxx, act)
        mocBld.prefix[cxx] = '$QT5_MOCCXXPREFIX'
        mocBld.suffix[cxx] = '$QT5_MOCCXXSUFFIX'
    env.Append(BUILDERS={'Moc5': mocBld})

    # er... no idea what that was for
    static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
    static_obj.src_builder.append('Uic5')
    shared_obj.src_builder.append('Uic5')

    # We use the emitters of Program / StaticLibrary / SharedLibrary
    # to scan for moc'able files
    # We can't refer to the builders directly, we have to fetch them
    # as Environment attributes because that sets them up to be called
    # correctly later by our emitter.
    env.AppendUnique(
        PROGEMITTER=[AutomocStatic],
        SHLIBEMITTER=[AutomocShared],
        LIBEMITTER=[AutomocStatic],
        # Of course, we need to link against the qt libraries
        CPPPATH=["$QT5_CPPPATH"],
        LIBPATH=["$QT5_LIBPATH"],
        LIBS=['$QT5_LIB'])

    #import new
    #method = new.instancemethod(enable_modules, env, SCons.Environment)
    #env.EnableQt4Modules=method
    SConsEnvironment.EnableQt5Modules = enable_modules
    SConsEnvironment.EnableQtModules = enable_modules
Пример #10
0
def generate(env):
    """Add Builders and construction variables for qt to an Environment."""
    CLVar = SCons.Util.CLVar
    Action = SCons.Action.Action
    Builder = SCons.Builder.Builder

    env.SetDefault(
        QTDIR=_detect(env),
        QT_BINPATH=os.path.join('$QTDIR', 'bin'),
        QT_CPPPATH=os.path.join('$QTDIR', 'include'),
        QT_LIBPATH=os.path.join('$QTDIR', 'lib'),
        QT_MOC=os.path.join('$QT_BINPATH', 'moc'),
        QT_UIC=os.path.join('$QT_BINPATH', 'uic'),
        QT_LIB='qt',  # may be set to qt-mt
        QT_AUTOSCAN=1,  # scan for moc'able sources

        # Some QT specific flags. I don't expect someone wants to
        # manipulate those ...
        QT_UICIMPLFLAGS=CLVar(''),
        QT_UICDECLFLAGS=CLVar(''),
        QT_MOCFROMHFLAGS=CLVar(''),
        QT_MOCFROMCXXFLAGS=CLVar('-i'),

        # suffixes/prefixes for the headers / sources to generate
        QT_UICDECLPREFIX='',
        QT_UICDECLSUFFIX='.h',
        QT_UICIMPLPREFIX='uic_',
        QT_UICIMPLSUFFIX='$CXXFILESUFFIX',
        QT_MOCHPREFIX='moc_',
        QT_MOCHSUFFIX='$CXXFILESUFFIX',
        QT_MOCCXXPREFIX='',
        QT_MOCCXXSUFFIX='.moc',
        QT_UISUFFIX='.ui',

        # Commands for the qt support ...
        # command to generate header, implementation and moc-file
        # from a .ui file
        QT_UICCOM=[
            CLVar('$QT_UIC $QT_UICDECLFLAGS -o ${TARGETS[0]} $SOURCE'),
            CLVar('$QT_UIC $QT_UICIMPLFLAGS -impl ${TARGETS[0].file} '
                  '-o ${TARGETS[1]} $SOURCE'),
            CLVar('$QT_MOC $QT_MOCFROMHFLAGS -o ${TARGETS[2]} ${TARGETS[0]}')
        ],
        # command to generate meta object information for a class
        # declarated in a header
        QT_MOCFROMHCOM=('$QT_MOC $QT_MOCFROMHFLAGS -o ${TARGETS[0]} $SOURCE'),
        # command to generate meta object information for a class
        # declarated in a cpp file
        QT_MOCFROMCXXCOM=[
            CLVar('$QT_MOC $QT_MOCFROMCXXFLAGS -o ${TARGETS[0]} $SOURCE'),
            Action(checkMocIncluded, None)
        ])

    # ... and the corresponding builders
    uicBld = Builder(action=SCons.Action.Action('$QT_UICCOM', '$QT_UICCOMSTR'),
                     emitter=uicEmitter,
                     src_suffix='$QT_UISUFFIX',
                     suffix='$QT_UICDECLSUFFIX',
                     prefix='$QT_UICDECLPREFIX',
                     source_scanner=uicScanner)
    mocBld = Builder(action={}, prefix={}, suffix={})
    for h in header_extensions:
        act = SCons.Action.Action('$QT_MOCFROMHCOM', '$QT_MOCFROMHCOMSTR')
        mocBld.add_action(h, act)
        mocBld.prefix[h] = '$QT_MOCHPREFIX'
        mocBld.suffix[h] = '$QT_MOCHSUFFIX'
    for cxx in cxx_suffixes:
        act = SCons.Action.Action('$QT_MOCFROMCXXCOM', '$QT_MOCFROMCXXCOMSTR')
        mocBld.add_action(cxx, act)
        mocBld.prefix[cxx] = '$QT_MOCCXXPREFIX'
        mocBld.suffix[cxx] = '$QT_MOCCXXSUFFIX'

    # register the builders
    env['BUILDERS']['Uic'] = uicBld
    env['BUILDERS']['Moc'] = mocBld
    static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
    static_obj.add_src_builder('Uic')
    shared_obj.add_src_builder('Uic')

    # We use the emitters of Program / StaticLibrary / SharedLibrary
    # to scan for moc'able files
    # We can't refer to the builders directly, we have to fetch them
    # as Environment attributes because that sets them up to be called
    # correctly later by our emitter.
    env.AppendUnique(
        PROGEMITTER=[AutomocStatic],
        SHLIBEMITTER=[AutomocShared],
        LIBEMITTER=[AutomocStatic],
        # Of course, we need to link against the qt libraries
        CPPPATH=["$QT_CPPPATH"],
        LIBPATH=["$QT_LIBPATH"],
        LIBS=['$QT_LIB'])
Пример #11
0
def generate(env):
    """Add Builders and construction variables for qt5 to an Environment."""

    suffixes = [
        '-qt5',
        '-qt5.exe',
        '5',
        '5.exe',
        '',
        '.exe',
    ]
    command_suffixes = ['-qt5', '5', '']

    def locateQt5Command(env, command, qtdir) :
        triedPaths = []
        for suffix in suffixes :
            fullpath = os.path.join(qtdir,'bin',command + suffix)
            if os.access(fullpath, os.X_OK) :
                return fullpath
            triedPaths.append(fullpath)

        fullpath = env.Detect([command+s for s in command_suffixes])
        if not (fullpath is None) : return fullpath

        raise Exception("Qt5 command '" + command + "' not found. Tried: " + ', '.join(triedPaths))

    CLVar = SCons.Util.CLVar
    Action = SCons.Action.Action
    Builder = SCons.Builder.Builder

    env['QT5DIR']  = _detect(env)
    # TODO: 'Replace' should be 'SetDefault'
    env.SetDefault(
#S    env.Replace(
        QT5DIR  = _detect(env),
        QT5_BINPATH = os.path.join('$QT5DIR', 'bin'),
        # TODO: This is not reliable to QT5DIR value changes but needed in order to support '-qt5' variants
        QT5_MOC = locateQt5Command(env,'moc', env['QT5DIR']),
        QT5_UIC = locateQt5Command(env,'uic', env['QT5DIR']),
        QT5_RCC = locateQt5Command(env,'rcc', env['QT5DIR']),
        QT5_LUPDATE = locateQt5Command(env,'lupdate', env['QT5DIR']),
        QT5_LRELEASE = locateQt5Command(env,'lrelease', env['QT5DIR']),

        QT5_AUTOSCAN = 1, # Should the qt5 tool try to figure out, which sources are to be moc'ed?
        QT5_AUTOSCAN_STRATEGY = 0, # While scanning for files to moc, should we search for includes in qtsolutions style?
        QT5_GOBBLECOMMENTS = 0, # If set to 1, comments are removed before scanning cxx/h files.
        QT5_CPPDEFINES_PASSTOMOC = 1, # If set to 1, all CPPDEFINES get passed to the moc executable.
        QT5_CLEAN_TS = 0, # If set to 1, translation files (.ts) get cleaned on 'scons -c'
        QT5_AUTOMOC_SCANCPPPATH = 1, # If set to 1, the CPPPATHs (or QT5_AUTOMOC_CPPPATH) get scanned for moc'able files
        QT5_AUTOMOC_CPPPATH = [], # Alternative paths that get scanned for moc files

        # Some Qt5 specific flags. I don't expect someone wants to
        # manipulate those ...
        QT5_UICFLAGS = CLVar(''),
        QT5_MOCFROMHFLAGS = CLVar(''),
        QT5_MOCFROMCXXFLAGS = CLVar('-i'),
        QT5_QRCFLAGS = '',
        QT5_LUPDATEFLAGS = '',
        QT5_LRELEASEFLAGS = '',

        # suffixes/prefixes for the headers / sources to generate
        QT5_UISUFFIX = '.ui',
        QT5_UICDECLPREFIX = 'ui_',
        QT5_UICDECLSUFFIX = '.h',
        QT5_MOCINCPREFIX = '-I',
        QT5_MOCHPREFIX = 'moc_',
        QT5_MOCHSUFFIX = '$CXXFILESUFFIX',
        QT5_MOCCXXPREFIX = '',
        QT5_MOCCXXSUFFIX = '.moc',
        QT5_QRCSUFFIX = '.qrc',
        QT5_QRCCXXSUFFIX = '$CXXFILESUFFIX',
        QT5_QRCCXXPREFIX = 'qrc_',
        QT5_MOCDEFPREFIX = '-D',
        QT5_MOCDEFSUFFIX = '',
        QT5_MOCDEFINES = '${_defines(QT5_MOCDEFPREFIX, CPPDEFINES, QT5_MOCDEFSUFFIX, __env__)}',
        QT5_MOCCPPPATH = [],
        QT5_MOCINCFLAGS = '$( ${_concat(QT5_MOCINCPREFIX, QT5_MOCCPPPATH, INCSUFFIX, __env__, RDirs)} $)',

        # Commands for the qt5 support ...
        QT5_UICCOM = '$QT5_UIC $QT5_UICFLAGS -o $TARGET $SOURCE',
        QT5_LUPDATECOM = '$QT5_LUPDATE $QT5_LUPDATEFLAGS $SOURCES -ts $TARGET',
        QT5_LRELEASECOM = '$QT5_LRELEASE $QT5_LRELEASEFLAGS -qm $TARGET $SOURCES',

        # Specialized variables for the Extended Automoc support
        # (Strategy #1 for qtsolutions)
        QT5_XMOCHPREFIX = 'moc_',
        QT5_XMOCHSUFFIX = '.cpp',
        QT5_XMOCCXXPREFIX = '',
        QT5_XMOCCXXSUFFIX = '.moc',

        )

    try:
        env.AddMethod(Ts5, "Ts5")
        env.AddMethod(Qm5, "Qm5")
        env.AddMethod(Qrc5, "Qrc5")
        env.AddMethod(ExplicitMoc5, "ExplicitMoc5")
        env.AddMethod(ExplicitUic5, "ExplicitUic5")
    except AttributeError:
        # Looks like we use a pre-0.98 version of SCons...
        from SCons.Script.SConscript import SConsEnvironment
        SConsEnvironment.Ts5 = Ts5
        SConsEnvironment.Qm5 = Qm5
        SConsEnvironment.Qrc5 = Qrc5
        SConsEnvironment.ExplicitMoc5 = ExplicitMoc5
        SConsEnvironment.ExplicitUic5 = ExplicitUic5

    # Interface builder
    uic5builder = Builder(
        action = SCons.Action.Action('$QT5_UICCOM', '$QT5_UICCOMSTR'),
        src_suffix='$QT5_UISUFFIX',
        suffix='$QT5_UICDECLSUFFIX',
        prefix='$QT5_UICDECLPREFIX',
        single_source = True
        #TODO: Consider the uiscanner on new scons version
        )
    env['BUILDERS']['Uic5'] = uic5builder

    # Metaobject builder
    mocBld = Builder(action={}, prefix={}, suffix={})
    for h in header_extensions:
        act = SCons.Action.CommandGeneratorAction(__moc_generator_from_h, {})
        mocBld.add_action(h, act)
        mocBld.prefix[h] = '$QT5_MOCHPREFIX'
        mocBld.suffix[h] = '$QT5_MOCHSUFFIX'
    for cxx in cxx_suffixes:
        act = SCons.Action.CommandGeneratorAction(__moc_generator_from_cxx, {})
        mocBld.add_action(cxx, act)
        mocBld.prefix[cxx] = '$QT5_MOCCXXPREFIX'
        mocBld.suffix[cxx] = '$QT5_MOCCXXSUFFIX'
    env['BUILDERS']['Moc5'] = mocBld

    # Metaobject builder for the extended auto scan feature
    # (Strategy #1 for qtsolutions)
    xMocBld = Builder(action={}, prefix={}, suffix={})
    for h in header_extensions:
        act = SCons.Action.CommandGeneratorAction(__mocx_generator_from_h, {})
        xMocBld.add_action(h, act)
        xMocBld.prefix[h] = '$QT5_XMOCHPREFIX'
        xMocBld.suffix[h] = '$QT5_XMOCHSUFFIX'
    for cxx in cxx_suffixes:
        act = SCons.Action.CommandGeneratorAction(__mocx_generator_from_cxx, {})
        xMocBld.add_action(cxx, act)
        xMocBld.prefix[cxx] = '$QT5_XMOCCXXPREFIX'
        xMocBld.suffix[cxx] = '$QT5_XMOCCXXSUFFIX'
    env['BUILDERS']['XMoc5'] = xMocBld

    # Add the Qrc5 action to the CXX file builder (registers the
    # *.qrc extension with the Environment)
    cfile_builder, cxxfile_builder = SCons.Tool.createCFileBuilders(env)
    qrc_act = SCons.Action.CommandGeneratorAction(__qrc_generator, {})
    cxxfile_builder.add_action('$QT5_QRCSUFFIX', qrc_act)
    cxxfile_builder.add_emitter('$QT5_QRCSUFFIX', __qrc_emitter)

    # We use the emitters of Program / StaticLibrary / SharedLibrary
    # to scan for moc'able files
    # We can't refer to the builders directly, we have to fetch them
    # as Environment attributes because that sets them up to be called
    # correctly later by our emitter.
    env.AppendUnique(PROGEMITTER =[AutomocStatic],
                     SHLIBEMITTER=[AutomocShared],
                     LIBEMITTER  =[AutomocStatic],
                    )

    # TODO: Does dbusxml2cpp need an adapter
    try:
        env.AddMethod(enable_modules, "EnableQt5Modules")
    except AttributeError:
        # Looks like we use a pre-0.98 version of SCons...
        from SCons.Script.SConscript import SConsEnvironment
        SConsEnvironment.EnableQt5Modules = enable_modules
Пример #12
0
def appendbuilders(env):
    subbuilder = Builder(action=substitute, single_source=True)
    env.Append(BUILDERS={'Substitute': subbuilder})
Пример #13
0
def generate(env):
    """Add Builders and construction variables for qt to an Environment."""
    CLVar = SCons.Util.CLVar
    Action = SCons.Action.Action
    Builder = SCons.Builder.Builder
    splitext = SCons.Util.splitext

    dep_include = env["OPTICKSDEPENDENCIESINCLUDE"]
    dep_bin = env["OPTICKSDEPENDENCIESBIN"]
    env.AppendUnique(QT_BINPATH = dep_bin,
                     QT_CPPPATH = os.path.join(dep_include, 'qt4'),
                     QT_MOC = os.path.join('$QT_BINPATH','moc'),
                     QT_UIC = os.path.join('$QT_BINPATH','uic'),
                     QT_QRC = os.path.join('$QT_BINPATH','rcc'),
                     QT_LIB = None,     # filled in by AddModules
                     QT_MODULES = [], # filled in by AddModules
                     QT_AUTOSCAN = 1, # scan for moc'able sources

                     # Some QT specific flags. I don't expect someone wants to
                     # manipulate those ...
                     QT_UICIMPLFLAGS = CLVar(''),
                     QT_UICDECLFLAGS = CLVar(''),
                     QT_MOCFROMHFLAGS = CLVar(''),
                     QT_MOCFROMCXXFLAGS = CLVar('-i'),

                     # suffixes/prefixes for the headers / sources to generate
                     QT_UICDECLPREFIX = 'ui_',
                     QT_UICDECLSUFFIX = '.h',
                     QT_QRCIMPLSUFFIX = '_qrc.cpp', 
                     QT_MOCHPREFIX = 'moc_',
                     QT_MOCHSUFFIX = '$CXXFILESUFFIX',
                     QT_MOCCXXPREFIX = '',
                     QT_MOCCXXSUFFIX = '.moc',
                     QT_UISUFFIX = '.ui',
                     QT_QRCSUFFIX = '.qrc',
                     # Commands for the qt support ...
                     # command to generate header, implementation and moc-file
                     # from a .qrc file
                     QT_QRCCOM = [
                      CLVar('$QT_QRC $QT_QRCDECLFLAGS $SOURCE -name ${SOURCE.filebase} -o ${TARGETS[0]}')],
                     # from a .ui file
                     QT_UICCOM = [
                      CLVar('$QT_UIC $QT_UICDECLFLAGS -o ${TARGETS[0]} $SOURCE')],
                     # command to generate meta object information for a class
                     # declarated in a header
                     QT_MOCFROMHCOM = (
                            '$QT_MOC $QT_MOCFROMHFLAGS -o ${TARGETS[0]} $SOURCE'),
                     # command to generate meta object information for a class
                     # declarated in a cpp file
                     QT_MOCFROMCXXCOM = [
                      CLVar('$QT_MOC $QT_MOCFROMCXXFLAGS -o ${TARGETS[0]} $SOURCE'),
                      Action(checkMocIncluded,None)])

    # ... and the corresponding builders
    qrcBld = Builder(action={'$QT_QRCSUFFIX':'$QT_QRCCOM'},
                     suffix='$QT_QRCIMPLSUFFIX',
                     src_suffix='$QT_QRCSUFFIX')
    uicBld = Builder(action={'$QT_UISUFFIX':'$QT_UICCOM'},
                     src_suffix='$QT_UISUFFIX',
                     suffix='$QT_UICDECLSUFFIX',
                     prefix='$QT_UICDECLPREFIX',
                     source_scanner=uicScanner)
    mocBld = Builder(action={}, prefix={}, suffix={})
    for h in header_extensions:
        mocBld.add_action(h, '$QT_MOCFROMHCOM')
        mocBld.prefix[h] = '$QT_MOCHPREFIX'
        mocBld.suffix[h] = '$QT_MOCHSUFFIX'
    for cxx in cxx_suffixes:
        mocBld.add_action(cxx, '$QT_MOVFROMCXXCOM')
        mocBld.prefix[cxx] = '$QT_MOCCXXPREFIX'
        mocBld.suffix[cxx] = '$QT_MOCCXXSUFFIX'

    # register the builders 

    env['BUILDERS']['Uic'] = uicBld
    env['BUILDERS']['Moc'] = mocBld
    env['BUILDERS']['Qrc'] = qrcBld

    static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
    static_obj.src_builder.append('Qrc')
    shared_obj.src_builder.append('Qrc')

    # We use the emitters of Program / StaticLibrary / SharedLibrary
    # to scan for moc'able files
    # We can't refer to the builders directly, we have to fetch them
    # as Environment attributes because that sets them up to be called
    # correctly later by our emitter.
    env.AppendUnique(PROGEMITTER =[AutomocStatic],
                     SHLIBEMITTER=[AutomocShared],
                     LIBEMITTER  =[AutomocStatic])
Пример #14
0
def generate(env):
    """Add Builders and construction variables for qt to an Environment."""

    print "Loading qt4 tool..."

    def locateQt4Command(env, command, qtdir) :
        fullpath1 = os.path.join(qtdir, 'bin', command +'-qt4')
        if os.access(fullpath1, os.X_OK) or \
            os.access(fullpath1+".exe", os.X_OK):
            return fullpath1
        fullpath3 = os.path.join(qtdir, 'bin', command +'4')
        if os.access(fullpath3, os.X_OK) or \
            os.access(fullpath3+".exe", os.X_OK):
            return fullpath3
        fullpath2 = os.path.join(qtdir, 'bin', command)
        if os.access(fullpath2, os.X_OK) or \
            os.access(fullpath2+".exe", os.X_OK):
            return fullpath2
        fullpath = env.Detect([command+'-qt4', command+'4', command])
        if not (fullpath is None):
            return fullpath
        raise Exception("Qt4 command '" + command + "' not found. Tried: " + fullpath1 + " and "+ fullpath2)
        

    CLVar = SCons.Util.CLVar
    Action = SCons.Action.Action
    Builder = SCons.Builder.Builder
    splitext = SCons.Util.splitext

    env['QTDIR']  = _detect(env)
    # TODO: 'Replace' should be 'SetDefault'
#    env.SetDefault(
    env.Replace(
        QTDIR  = _detect(env),
        QT4_BINPATH = os.path.join('$QTDIR', 'bin'),
        QT4_CPPPATH = os.path.join('$QTDIR', 'include'),
        QT4_LIBPATH = os.path.join('$QTDIR', 'lib'),
        # TODO: This is not reliable to QTDIR value changes but needed in order to support '-qt4' variants
        QT4_MOC = locateQt4Command(env,'moc', env['QTDIR']),
        QT4_UIC = locateQt4Command(env,'uic', env['QTDIR']),
        QT4_RCC = locateQt4Command(env,'rcc', env['QTDIR']),
        QT4_LUPDATE = locateQt4Command(env,'lupdate', env['QTDIR']),
        QT4_LRELEASE = locateQt4Command(env,'lrelease', env['QTDIR']),
        QT4_LIB = '', # KLUDGE to avoid linking qt3 library

        QT4_AUTOSCAN = 1, # Should the qt tool try to figure out, which sources are to be moc'ed?

        # Some QT specific flags. I don't expect someone wants to
        # manipulate those ...
        QT4_UICFLAGS = CLVar(''),
        QT4_MOCFROMHFLAGS = CLVar(''),
        QT4_MOCFROMCXXFLAGS = CLVar('-i'),
        QT4_QRCFLAGS = '',

        # suffixes/prefixes for the headers / sources to generate
        QT4_UISUFFIX = '.ui',
        QT4_UICDECLPREFIX = 'ui_',
        QT4_UICDECLSUFFIX = '.h',
        QT4_MOCHPREFIX = 'moc_',
        QT4_MOCHSUFFIX = '$CXXFILESUFFIX',
        QT4_MOCCXXPREFIX = 'moc_',
        QT4_MOCCXXSUFFIX = '.moc',
        QT4_QRCSUFFIX = '.qrc',
        QT4_QRCCXXSUFFIX = '$CXXFILESUFFIX',
        QT4_QRCCXXPREFIX = 'qrc_',

        # Commands for the qt support ...
        QT4_UICCOM = '$QT4_UIC $QT4_UICFLAGS -o $TARGET $SOURCE',
        QT4_MOCFROMHCOM = '$QT4_MOC $QT4_MOCFROMHFLAGS -o $TARGET $SOURCE',
        QT4_MOCFROMCXXCOM = [
            '$QT4_MOC $QT4_MOCFROMCXXFLAGS -o $TARGET $SOURCE',
            Action(checkMocIncluded,None)],
        QT4_LUPDATECOM = '$QT4_LUPDATE $SOURCE -ts $TARGET',
        QT4_LRELEASECOM = '$QT4_LRELEASE $SOURCE',
        QT4_RCCCOM = '$QT4_RCC $QT4_QRCFLAGS $SOURCE -o $TARGET',
        )

    # Translation builder
    tsbuilder = Builder(
        action = SCons.Action.Action('$QT4_LUPDATECOM'), #,'$QT4_LUPDATECOMSTR'),
        multi=1
        )
    env.Append( BUILDERS = { 'Ts': tsbuilder } )
    qmbuilder = Builder(
        action = SCons.Action.Action('$QT4_LRELEASECOM'),# , '$QT4_LRELEASECOMSTR'),
        src_suffix = '.ts',
        suffix = '.qm',
        single_source = True
        )
    env.Append( BUILDERS = { 'Qm': qmbuilder } )

    # Resource builder
    def scanResources(node, env, path, arg):
        contents = node.get_contents()
        includes = qrcinclude_re.findall(contents)
        return includes
    qrcscanner = SCons.Scanner.Scanner(name = 'qrcfile',
        function = scanResources,
        argument = None,
        skeys = ['.qrc'])
    qrcbuilder = Builder(
        action = SCons.Action.Action('$QT4_RCCCOM'), #, '$QT4_RCCCOMSTR'),
        source_scanner = qrcscanner,
        src_suffix = '$QT4_QRCSUFFIX',
        suffix = '$QT4_QRCCXXSUFFIX',
        prefix = '$QT4_QRCCXXPREFIX',
        single_source = True
        )
    env.Append( BUILDERS = { 'Qrc': qrcbuilder } )

    # Interface builder
    uic4builder = Builder(
        action = SCons.Action.Action('$QT4_UICCOM'), #, '$QT4_UICCOMSTR'),
        src_suffix='$QT4_UISUFFIX',
        suffix='$QT4_UICDECLSUFFIX',
        prefix='$QT4_UICDECLPREFIX',
        single_source = True
        #TODO: Consider the uiscanner on new scons version
        )
    env.Append( BUILDERS = { 'Uic4': uic4builder } )

    # Metaobject builder
    mocBld = Builder(action={}, prefix={}, suffix={})
    for h in header_extensions:
        act = SCons.Action.Action('$QT4_MOCFROMHCOM') #, '$QT4_MOCFROMHCOMSTR')
        mocBld.add_action(h, act)
        mocBld.prefix[h] = '$QT4_MOCHPREFIX'
        mocBld.suffix[h] = '$QT4_MOCHSUFFIX'
    for cxx in cxx_suffixes:
        act = SCons.Action.Action('$QT4_MOCFROMCXXCOM') #, '$QT4_MOCFROMCXXCOMSTR')
        mocBld.add_action(cxx, act)
        mocBld.prefix[cxx] = '$QT4_MOCCXXPREFIX'
        mocBld.suffix[cxx] = '$QT4_MOCCXXSUFFIX'
    env.Append( BUILDERS = { 'Moc4': mocBld } )

    # er... no idea what that was for
    static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
    static_obj.src_builder.append('Uic4')
    shared_obj.src_builder.append('Uic4')

    # We use the emitters of Program / StaticLibrary / SharedLibrary
    # to scan for moc'able files
    # We can't refer to the builders directly, we have to fetch them
    # as Environment attributes because that sets them up to be called
    # correctly later by our emitter.
    env.AppendUnique(PROGEMITTER =[AutomocStatic],
                     SHLIBEMITTER=[AutomocShared],
                     LIBEMITTER  =[AutomocStatic],
                     # Of course, we need to link against the qt libraries
                     CPPPATH=["$QT4_CPPPATH"],
                     LIBPATH=["$QT4_LIBPATH"],
                     LIBS=['$QT4_LIB'])
    
    #import new
    #method = new.instancemethod(enable_modules, env, SCons.Environment)
    #env.EnableQt4Modules=method
    SConsEnvironment.EnableQt4Modules = enable_modules
Пример #15
0
def TOOL_SUBST(env):
    """Adds SubstInFile builder, which substitutes the keys->values of SUBST_DICT
    from the source to the target.
    The values of SUBST_DICT first have any construction variables expanded
    (its keys are not expanded).
    If a value of SUBST_DICT is a python callable function, it is called and
    the result is expanded as the value.
    If there's more than one source and more than one target, each target gets
    substituted from the corresponding source.
    """
    env.Append(TOOLS='SUBST')

    def do_subst_in_file(targetfile, sourcefile, dict):
        """Replace all instances of the keys of dict with their values.
        For example, if dict is {'%VERSION%': '1.2345', '%BASE%': 'MyProg'},
        then all instances of %VERSION% in the file will be replaced with 1.2345 etc.
        """
        try:
            f = open(sourcefile, 'rb')
            contents = f.read()
            f.close()
        except:
            raise SCons.Errors.UserError, "Can't read source file %s" % sourcefile
        for (k, v) in dict.items():
            contents = re.sub(k, v, contents)
        try:
            f = open(targetfile, 'wb')
            f.write(contents)
            f.close()
        except:
            raise SCons.Errors.UserError, "Can't write target file %s" % targetfile
        return 0  # success

    def subst_in_file(target, source, env):
        print source, 'is now thought in folder', os.getcwd()
        if not env.has_key('SUBST_DICT'):
            raise SCons.Errors.UserError, "SubstInFile requires SUBST_DICT to be set."
        d = dict(env['SUBST_DICT'])  # copy it
        for (k, v) in d.items():
            if callable(v):
                d[k] = env.subst(v())
            elif SCons.Util.is_String(v):
                d[k] = env.subst(v)
            else:
                raise SCons.Errors.UserError, "SubstInFile: key %s: %s must be a string or callable" % (
                    k, repr(v))
        for (t, s) in zip(target, source):
            return do_subst_in_file(str(t), str(s), d)

    def subst_in_file_string(target, source, env):
        """This is what gets printed on the console."""
        return '\n'.join([
            'Substituting vars from %s into %s' % (str(s), str(t))
            for (t, s) in zip(target, source)
        ])

    def subst_emitter(target, source, env):
        """Add dependency from substituted SUBST_DICT to target.
        Returns original target, source tuple unchanged.
        """
        d = env['SUBST_DICT'].copy()  # copy it
        for (k, v) in d.items():
            if callable(v):
                d[k] = env.subst(v())
            elif SCons.Util.is_String(v):
                d[k] = env.subst(v)
        env.Depends(target, SCons.Node.Python.Value(d))
        # Depends(target, source) # this doesn't help the install-sapphire-linux.sh problem
        return target, source

    subst_action = SCons.Action.Action(subst_in_file, subst_in_file_string)
    env['BUILDERS']['SubstInFile'] = Builder(action=subst_action,
                                             emitter=subst_emitter)
Пример #16
0
def generate(env):
    """Add Builders and construction variables for qt5 to an Environment."""

    suffixes = [
        '-qt5',
        '-qt5.exe',
        '5',
        '5.exe',
        '',
        '.exe',
    ]
    command_suffixes = ['-qt5', '5', '']

    def locateQt5Command(env, command, qtdir):
        triedPaths = []
        for suffix in suffixes:
            fullpath = os.path.join(qtdir, 'bin', command + suffix)
            if os.access(fullpath, os.X_OK):
                return fullpath
            triedPaths.append(fullpath)

        fullpath = env.Detect([command + s for s in command_suffixes])
        if not (fullpath is None): return fullpath

        raise Exception("Qt5 command '" + command + "' not found. Tried: " +
                        ', '.join(triedPaths))

    CLVar = SCons.Util.CLVar
    Action = SCons.Action.Action
    Builder = SCons.Builder.Builder

    env['QT5DIR'] = _detect(env)
    # TODO: 'Replace' should be 'SetDefault'
    #    env.SetDefault(
    env.Replace(
        QT5DIR=_detect(env),
        QT5_BINPATH=os.path.join('$QT5DIR', 'bin'),
        # TODO: This is not reliable to QT5DIR value changes but needed in order to support '-qt5' variants
        QT5_MOC=locateQt5Command(env, 'moc', env['QT5DIR']),
        QT5_UIC=locateQt5Command(env, 'uic', env['QT5DIR']),
        QT5_RCC=locateQt5Command(env, 'rcc', env['QT5DIR']),
        QT5_LUPDATE=locateQt5Command(env, 'lupdate', env['QT5DIR']),
        QT5_LRELEASE=locateQt5Command(env, 'lrelease', env['QT5DIR']),
        QT5_AUTOSCAN=
        1,  # Should the qt5 tool try to figure out, which sources are to be moc'ed?
        QT5_AUTOSCAN_STRATEGY=
        0,  # While scanning for files to moc, should we search for includes in qtsolutions style?
        QT5_GOBBLECOMMENTS=
        0,  # If set to 1, comments are removed before scanning cxx/h files.
        QT5_CPPDEFINES_PASSTOMOC=
        1,  # If set to 1, all CPPDEFINES get passed to the moc executable.
        QT5_CLEAN_TS=
        0,  # If set to 1, translation files (.ts) get cleaned on 'scons -c'
        QT5_AUTOMOC_SCANCPPPATH=
        1,  # If set to 1, the CPPPATHs (or QT5_AUTOMOC_CPPPATH) get scanned for moc'able files
        QT5_AUTOMOC_CPPPATH=
        [],  # Alternative paths that get scanned for moc files

        # Some Qt5 specific flags. I don't expect someone wants to
        # manipulate those ...
        QT5_UICFLAGS=CLVar(''),
        QT5_MOCFROMHFLAGS=CLVar(''),
        QT5_MOCFROMCXXFLAGS=CLVar('-i'),
        QT5_QRCFLAGS='',
        QT5_LUPDATEFLAGS='',
        QT5_LRELEASEFLAGS='',

        # suffixes/prefixes for the headers / sources to generate
        QT5_UISUFFIX='.ui',
        QT5_UICDECLPREFIX='ui_',
        QT5_UICDECLSUFFIX='.h',
        QT5_MOCINCPREFIX='-I',
        QT5_MOCHPREFIX='moc_',
        QT5_MOCHSUFFIX='$CXXFILESUFFIX',
        QT5_MOCCXXPREFIX='',
        QT5_MOCCXXSUFFIX='.moc',
        QT5_QRCSUFFIX='.qrc',
        QT5_QRCCXXSUFFIX='$CXXFILESUFFIX',
        QT5_QRCCXXPREFIX='qrc_',
        QT5_MOCDEFPREFIX='-D',
        QT5_MOCDEFSUFFIX='',
        QT5_MOCDEFINES=
        '${_defines(QT5_MOCDEFPREFIX, CPPDEFINES, QT5_MOCDEFSUFFIX, __env__)}',
        QT5_MOCCPPPATH=[],
        QT5_MOCINCFLAGS=
        '$( ${_concat(QT5_MOCINCPREFIX, QT5_MOCCPPPATH, INCSUFFIX, __env__, RDirs)} $)',

        # Commands for the qt5 support ...
        QT5_UICCOM='$QT5_UIC $QT5_UICFLAGS -o $TARGET $SOURCE',
        QT5_LUPDATECOM='$QT5_LUPDATE $QT5_LUPDATEFLAGS $SOURCES -ts $TARGET',
        QT5_LRELEASECOM='$QT5_LRELEASE $QT5_LRELEASEFLAGS -qm $TARGET $SOURCES',

        # Specialized variables for the Extended Automoc support
        # (Strategy #1 for qtsolutions)
        QT5_XMOCHPREFIX='moc_',
        QT5_XMOCHSUFFIX='.cpp',
        QT5_XMOCCXXPREFIX='',
        QT5_XMOCCXXSUFFIX='.moc',
    )

    try:
        env.AddMethod(Ts5, "Ts5")
        env.AddMethod(Qm5, "Qm5")
        env.AddMethod(Qrc5, "Qrc5")
        env.AddMethod(ExplicitMoc5, "ExplicitMoc5")
        env.AddMethod(ExplicitUic5, "ExplicitUic5")
    except AttributeError:
        # Looks like we use a pre-0.98 version of SCons...
        from SCons.Script.SConscript import SConsEnvironment
        SConsEnvironment.Ts5 = Ts5
        SConsEnvironment.Qm5 = Qm5
        SConsEnvironment.Qrc5 = Qrc5
        SConsEnvironment.ExplicitMoc5 = ExplicitMoc5
        SConsEnvironment.ExplicitUic5 = ExplicitUic5

    # Interface builder
    uic5builder = Builder(action=SCons.Action.Action('$QT5_UICCOM',
                                                     '$QT5_UICCOMSTR'),
                          src_suffix='$QT5_UISUFFIX',
                          suffix='$QT5_UICDECLSUFFIX',
                          prefix='$QT5_UICDECLPREFIX',
                          single_source=True
                          #TODO: Consider the uiscanner on new scons version
                          )
    env['BUILDERS']['Uic5'] = uic5builder

    # Metaobject builder
    mocBld = Builder(action={}, prefix={}, suffix={})
    for h in header_extensions:
        act = SCons.Action.CommandGeneratorAction(__moc_generator_from_h,
                                                  {'cmdstr': '$QT5_MOCCOMSTR'})
        mocBld.add_action(h, act)
        mocBld.prefix[h] = '$QT5_MOCHPREFIX'
        mocBld.suffix[h] = '$QT5_MOCHSUFFIX'
    for cxx in cxx_suffixes:
        act = SCons.Action.CommandGeneratorAction(__moc_generator_from_cxx,
                                                  {'cmdstr': '$QT5_MOCCOMSTR'})
        mocBld.add_action(cxx, act)
        mocBld.prefix[cxx] = '$QT5_MOCCXXPREFIX'
        mocBld.suffix[cxx] = '$QT5_MOCCXXSUFFIX'
    env['BUILDERS']['Moc5'] = mocBld

    # Metaobject builder for the extended auto scan feature
    # (Strategy #1 for qtsolutions)
    xMocBld = Builder(action={}, prefix={}, suffix={})
    for h in header_extensions:
        act = SCons.Action.CommandGeneratorAction(__mocx_generator_from_h,
                                                  {'cmdstr': '$QT5_MOCCOMSTR'})
        xMocBld.add_action(h, act)
        xMocBld.prefix[h] = '$QT5_XMOCHPREFIX'
        xMocBld.suffix[h] = '$QT5_XMOCHSUFFIX'
    for cxx in cxx_suffixes:
        act = SCons.Action.CommandGeneratorAction(__mocx_generator_from_cxx,
                                                  {'cmdstr': '$QT5_MOCCOMSTR'})
        xMocBld.add_action(cxx, act)
        xMocBld.prefix[cxx] = '$QT5_XMOCCXXPREFIX'
        xMocBld.suffix[cxx] = '$QT5_XMOCCXXSUFFIX'
    env['BUILDERS']['XMoc5'] = xMocBld

    # Add the Qrc5 action to the CXX file builder (registers the
    # *.qrc extension with the Environment)
    cfile_builder, cxxfile_builder = SCons.Tool.createCFileBuilders(env)
    qrc_act = SCons.Action.CommandGeneratorAction(__qrc_generator,
                                                  {'cmdstr': '$QT5_QRCCOMSTR'})
    cxxfile_builder.add_action('$QT5_QRCSUFFIX', qrc_act)
    cxxfile_builder.add_emitter('$QT5_QRCSUFFIX', __qrc_emitter)

    # We use the emitters of Program / StaticLibrary / SharedLibrary
    # to scan for moc'able files
    # We can't refer to the builders directly, we have to fetch them
    # as Environment attributes because that sets them up to be called
    # correctly later by our emitter.
    env.AppendUnique(
        PROGEMITTER=[AutomocStatic],
        SHLIBEMITTER=[AutomocShared],
        LIBEMITTER=[AutomocStatic],
    )

    # TODO: Does dbusxml2cpp need an adapter
    try:
        env.AddMethod(enable_modules, "EnableQt5Modules")
    except AttributeError:
        # Looks like we use a pre-0.98 version of SCons...
        from SCons.Script.SConscript import SConsEnvironment
        SConsEnvironment.EnableQt5Modules = enable_modules
Пример #17
0
def generate(env):
    """Add Builders and construction variables for qt to an Environment."""

    def locateQt4Command(env, command, qtdir):
        if len(qtdir) == 0:
            qtdir = "/usr"
        if env["qt5"]:
            suffixes = ["-qt5", "-qt5.exe", "5", "5.exe", "", ".exe"]
        else:
            suffixes = ["-qt4", "-qt4.exe", "4", "4.exe", "", ".exe"]
        triedPaths = []
        for suffix in suffixes:
            fullpath = os.path.join(qtdir, "bin", command + suffix)
            if os.access(fullpath, os.X_OK):
                return fullpath
            triedPaths.append(fullpath)

        fullpath = env.Detect([command + "-qt4", command + "4", command])
        if not (fullpath is None):
            return fullpath

        raise Exception("Qt4 command '" + command + "' not found. Tried: " + ", ".join(triedPaths))

    CLVar = SCons.Util.CLVar
    Action = SCons.Action.Action
    Builder = SCons.Builder.Builder
    splitext = SCons.Util.splitext

    env["QTDIR"] = _detect(env)
    # TODO: 'Replace' should be 'SetDefault'
    # 	env.SetDefault(
    env.Replace(
        QTDIR=_detect(env),
        # TODO: This is not reliable to QTDIR value changes but needed in order to support '-qt4' variants
        QT4_MOC=locateQt4Command(env, "moc", env["QTDIR"]),
        QT4_UIC=locateQt4Command(env, "uic", env["QTDIR"]),
        QT4_RCC=locateQt4Command(env, "rcc", env["QTDIR"]),
        QT4_LUPDATE=locateQt4Command(env, "lupdate", env["QTDIR"]),
        QT4_LRELEASE=locateQt4Command(env, "lrelease", env["QTDIR"]),
        QT4_LIB="",  # KLUDGE to avoid linking qt3 library
        QT4_AUTOSCAN=1,  # Should the qt tool try to figure out, which sources are to be moc'ed?
        # Some QT specific flags. I don't expect someone wants to
        # manipulate those ...
        QT4_UICFLAGS=CLVar(""),
        QT4_MOCFROMHFLAGS=CLVar(""),
        QT4_MOCFROMCXXFLAGS=CLVar("-i"),
        QT4_QRCFLAGS="",
        # suffixes/prefixes for the headers / sources to generate
        QT4_UISUFFIX=".ui",
        QT4_UICDECLPREFIX="ui_",
        QT4_UICDECLSUFFIX=".h",
        QT4_MOCHPREFIX="moc_",
        QT4_MOCHSUFFIX="$CXXFILESUFFIX",
        QT4_MOCCXXPREFIX="",
        QT4_MOCCXXSUFFIX=".moc",
        QT4_QRCSUFFIX=".qrc",
        QT4_QRCCXXSUFFIX="$CXXFILESUFFIX",
        QT4_QRCCXXPREFIX="qrc_",
        QT4_MOCCPPPATH=[],
        QT4_MOCINCFLAGS='$( ${_concat("-I", QT4_MOCCPPPATH, INCSUFFIX, __env__, RDirs)} $)',
        # Commands for the qt support ...
        QT4_UICCOM="$QT4_UIC $QT4_UICFLAGS -o $TARGET $SOURCE",
        # FIXME: The -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED flag is a hack to work
        # around an issue in Qt
        # See https://bugreports.qt-project.org/browse/QTBUG-22829
        QT4_MOCFROMHCOM="$QT4_MOC -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED $QT4_MOCFROMHFLAGS $QT4_MOCINCFLAGS -o $TARGET $SOURCE",
        QT4_MOCFROMCXXCOM=[
            "$QT4_MOC -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED $QT4_MOCFROMCXXFLAGS $QT4_MOCINCFLAGS -o $TARGET $SOURCE",
            Action(checkMocIncluded, None),
        ],
        QT4_LUPDATECOM="$QT4_LUPDATE $SOURCE -ts $TARGET",
        QT4_LRELEASECOM="$QT4_LRELEASE -silent $SOURCE -qm $TARGET",
        QT4_RCCCOM="$QT4_RCC $QT4_QRCFLAGS -name $SOURCE $SOURCE -o $TARGET",
    )
    if len(env["QTDIR"]) > 0:
        env.Replace(QT4_LIBPATH=os.path.join("$QTDIR", "lib"))

        # Translation builder
    tsbuilder = Builder(action=SCons.Action.Action("$QT4_LUPDATECOM"), multi=1)  # ,'$QT4_LUPDATECOMSTR'),
    env.Append(BUILDERS={"Ts": tsbuilder})
    qmbuilder = Builder(
        action=SCons.Action.Action("$QT4_LRELEASECOM", cmdstr="$QT4_LRELEASECOMSTR"),
        src_suffix=".ts",
        suffix=".qm",
        single_source=True,
    )
    env.Append(BUILDERS={"Qm": qmbuilder})

    # Resource builder
    def scanResources(node, env, path, arg):
        # I've being careful on providing names relative to the qrc file
        # If that was not needed that code could be simplified a lot
        def recursiveFiles(basepath, path):
            result = []
            for item in os.listdir(os.path.join(basepath, path)):
                itemPath = os.path.join(path, item)
                if os.path.isdir(os.path.join(basepath, itemPath)):
                    result += recursiveFiles(basepath, itemPath)
                else:
                    result.append(itemPath)
            return result

        contents = node.get_contents()
        includes = [included[1] for included in qrcinclude_re.findall(contents)]
        qrcpath = os.path.dirname(node.path)
        dirs = [included for included in includes if os.path.isdir(os.path.join(qrcpath, included))]
        # dirs need to include files recursively
        for dir in dirs:
            includes.remove(dir)
            includes += recursiveFiles(qrcpath, dir)
        return includes

    qrcscanner = SCons.Scanner.Scanner(name="qrcfile", function=scanResources, argument=None, skeys=[".qrc"])
    qrcbuilder = Builder(
        action=SCons.Action.Action("$QT4_RCCCOM", cmdstr="$QT4_RCCCOMSTR"),
        source_scanner=qrcscanner,
        src_suffix="$QT4_QRCSUFFIX",
        suffix="$QT4_QRCCXXSUFFIX",
        prefix="$QT4_QRCCXXPREFIX",
        single_source=True,
    )
    env.Append(BUILDERS={"Qrc": qrcbuilder})

    # Interface builder
    uic4builder = Builder(
        action=SCons.Action.Action("$QT4_UICCOM", cmdstr="$QT4_UICCOMSTR"),
        src_suffix="$QT4_UISUFFIX",
        suffix="$QT4_UICDECLSUFFIX",
        prefix="$QT4_UICDECLPREFIX",
        single_source=True
        # TODO: Consider the uiscanner on new scons version
    )
    env["BUILDERS"]["Uic4"] = uic4builder

    # Metaobject builder
    mocBld = Builder(action={}, prefix={}, suffix={})
    for h in header_extensions:
        act = SCons.Action.Action("$QT4_MOCFROMHCOM", cmdstr="$QT4_MOCFROMHCOMSTR")
        mocBld.add_action(h, act)
        mocBld.prefix[h] = "$QT4_MOCHPREFIX"
        mocBld.suffix[h] = "$QT4_MOCHSUFFIX"
    for cxx in cxx_suffixes:
        act = SCons.Action.Action("$QT4_MOCFROMCXXCOM", cmdstr="$QT4_MOCFROMCXXCOMSTR")
        mocBld.add_action(cxx, act)
        mocBld.prefix[cxx] = "$QT4_MOCCXXPREFIX"
        mocBld.suffix[cxx] = "$QT4_MOCCXXSUFFIX"
    env["BUILDERS"]["Moc4"] = mocBld

    # er... no idea what that was for
    static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
    static_obj.src_builder.append("Uic4")
    shared_obj.src_builder.append("Uic4")

    # We use the emitters of Program / StaticLibrary / SharedLibrary
    # to scan for moc'able files
    # We can't refer to the builders directly, we have to fetch them
    # as Environment attributes because that sets them up to be called
    # correctly later by our emitter.
    env.AppendUnique(
        PROGEMITTER=[AutomocStatic],
        SHLIBEMITTER=[AutomocShared],
        LIBEMITTER=[AutomocStatic],
        # Of course, we need to link against the qt libraries
        LIBPATH=["$QT4_LIBPATH"],
        LIBS=["$QT4_LIB"],
    )

    # TODO: Does dbusxml2cpp need an adapter
    env.AddMethod(enable_modules, "EnableQt4Modules")
Пример #18
0
def generate(env):
    """Add Builders and construction variables for qt to an Environment."""
    def locateQt4Command(env, command, qtdir):
        if len(qtdir) == 0:
            qtdir = "/usr"
        if env["qt5"]:
            suffixes = [
                '-qt5',
                '-qt5.exe',
                '5',
                '5.exe',
                '',
                '.exe',
            ]
        else:
            suffixes = [
                '-qt4',
                '-qt4.exe',
                '4',
                '4.exe',
                '',
                '.exe',
            ]
        triedPaths = []
        for suffix in suffixes:
            fullpath = os.path.join(qtdir, 'bin', command + suffix)
            if os.access(fullpath, os.X_OK):
                return fullpath
            triedPaths.append(fullpath)

        fullpath = env.Detect([command + '-qt4', command + '4', command])
        if not (fullpath is None): return fullpath

        raise Exception("Qt4 command '" + command + "' not found. Tried: " +
                        ', '.join(triedPaths))

    CLVar = SCons.Util.CLVar
    Action = SCons.Action.Action
    Builder = SCons.Builder.Builder
    splitext = SCons.Util.splitext

    env['QTDIR'] = _detect(env)
    # TODO: 'Replace' should be 'SetDefault'
    #   env.SetDefault(
    env.Replace(
        QTDIR=_detect(env),
        # TODO: This is not reliable to QTDIR value changes but needed in order to support '-qt4' variants
        QT4_MOC=locateQt4Command(env, 'moc', env['QTDIR']),
        QT4_UIC=locateQt4Command(env, 'uic', env['QTDIR']),
        QT4_RCC=locateQt4Command(env, 'rcc', env['QTDIR']),
        QT4_LUPDATE=locateQt4Command(env, 'lupdate', env['QTDIR']),
        QT4_LRELEASE=locateQt4Command(env, 'lrelease', env['QTDIR']),
        QT4_LIB='',  # KLUDGE to avoid linking qt3 library
        QT4_AUTOSCAN=
        1,  # Should the qt tool try to figure out, which sources are to be moc'ed?

        # Some QT specific flags. I don't expect someone wants to
        # manipulate those ...
        QT4_UICFLAGS=CLVar(''),
        QT4_MOCFROMHFLAGS=CLVar(''),
        QT4_MOCFROMCXXFLAGS=CLVar('-i'),
        QT4_QRCFLAGS='--compress 9 --threshold 5',

        # suffixes/prefixes for the headers / sources to generate
        QT4_UISUFFIX='.ui',
        QT4_UICDECLPREFIX='ui_',
        QT4_UICDECLSUFFIX='.h',
        QT4_MOCHPREFIX='moc_',
        QT4_MOCHSUFFIX='$CXXFILESUFFIX',
        QT4_MOCCXXPREFIX='',
        QT4_MOCCXXSUFFIX='.moc',
        QT4_QRCSUFFIX='.qrc',
        QT4_QRCCXXSUFFIX='$CXXFILESUFFIX',
        QT4_QRCCXXPREFIX='qrc_',
        QT4_MOCCPPPATH=[],
        QT4_MOCINCFLAGS=
        '$( ${_concat("-I", QT4_MOCCPPPATH, INCSUFFIX, __env__, RDirs)} $)',

        # Commands for the qt support ...
        QT4_UICCOM='$QT4_UIC $QT4_UICFLAGS -o $TARGET $SOURCE',
        # FIXME: The -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED flag is a hack to work
        # around an issue in Qt
        # See https://bugreports.qt-project.org/browse/QTBUG-22829
        QT4_MOCFROMHCOM=
        '$QT4_MOC -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED $QT4_MOCFROMHFLAGS $QT4_MOCINCFLAGS -o $TARGET $SOURCE',
        QT4_MOCFROMCXXCOM=[
            '$QT4_MOC -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED $QT4_MOCFROMCXXFLAGS $QT4_MOCINCFLAGS -o $TARGET $SOURCE',
            Action(checkMocIncluded, None)
        ],
        QT4_LUPDATECOM='$QT4_LUPDATE $SOURCE -ts $TARGET',
        QT4_LRELEASECOM='$QT4_LRELEASE -silent $SOURCE -qm $TARGET',
        QT4_RCCCOM='$QT4_RCC $QT4_QRCFLAGS -name $SOURCE $SOURCE -o $TARGET',
    )
    if len(env["QTDIR"]) > 0:
        env.Replace(QT4_LIBPATH=os.path.join('$QTDIR', 'lib'))

    # Translation builder
    tsbuilder = Builder(
        action=SCons.Action.Action(
            '$QT4_LUPDATECOM'),  #,'$QT4_LUPDATECOMSTR'),
        multi=1)
    env.Append(BUILDERS={'Ts': tsbuilder})
    qmbuilder = Builder(action=SCons.Action.Action(
        '$QT4_LRELEASECOM', cmdstr='$QT4_LRELEASECOMSTR'),
                        src_suffix='.ts',
                        suffix='.qm',
                        single_source=True)
    env.Append(BUILDERS={'Qm': qmbuilder})

    # Resource builder
    def scanResources(node, env, path, arg):
        # I've being careful on providing names relative to the qrc file
        # If that was not needed that code could be simplified a lot
        def recursiveFiles(basepath, path):
            result = []
            for item in os.listdir(os.path.join(basepath, path)):
                itemPath = os.path.join(path, item)
                if os.path.isdir(os.path.join(basepath, itemPath)):
                    result += recursiveFiles(basepath, itemPath)
                else:
                    result.append(itemPath)
            return result

        contents = node.get_contents()
        includes = [
            included[1] for included in qrcinclude_re.findall(contents)
        ]
        qrcpath = os.path.dirname(node.path)
        dirs = [
            included for included in includes
            if os.path.isdir(os.path.join(qrcpath, included))
        ]
        # dirs need to include files recursively
        for dir in dirs:
            includes.remove(dir)
            includes += recursiveFiles(qrcpath, dir)
        return includes

    qrcscanner = SCons.Scanner.Scanner(name='qrcfile',
                                       function=scanResources,
                                       argument=None,
                                       skeys=['.qrc'])
    qrcbuilder = Builder(action=SCons.Action.Action('$QT4_RCCCOM',
                                                    cmdstr='$QT4_RCCCOMSTR'),
                         source_scanner=qrcscanner,
                         src_suffix='$QT4_QRCSUFFIX',
                         suffix='$QT4_QRCCXXSUFFIX',
                         prefix='$QT4_QRCCXXPREFIX',
                         single_source=True)
    env.Append(BUILDERS={'Qrc': qrcbuilder})

    # Interface builder
    def addDisableWarningsPragmaToFile(target, source, env):
        assert (len(target) == 1)
        assert (len(source) == 1)
        srcf = str(source[0])
        dstf = str(target[0])
        with open(dstf, 'r+') as uiHeader:
            data = uiHeader.read()

            template = Template("""#pragma once
#pragma warning(push, 0)
#pragma GCC system_header
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wall"
$uiheadertext
#pragma clang diagnostic pop
#pragma warning(pop)
""")
            uiHeader.seek(0)
            uiHeader.write(template.substitute(uiheadertext=data))
            uiHeader.truncate()

    uic4builder = Builder(action=[
        SCons.Action.Action('$QT4_UICCOM', cmdstr='$QT4_UICCOMSTR'),
        SCons.Action.Action(addDisableWarningsPragmaToFile, None)
    ],
                          src_suffix='$QT4_UISUFFIX',
                          suffix='$QT4_UICDECLSUFFIX',
                          prefix='$QT4_UICDECLPREFIX',
                          single_source=True
                          #TODO: Consider the uiscanner on new scons version
                          )
    env['BUILDERS']['Uic4'] = uic4builder

    # Metaobject builder
    mocBld = Builder(action={}, prefix={}, suffix={})
    for h in header_extensions:
        act = SCons.Action.Action('$QT4_MOCFROMHCOM',
                                  cmdstr='$QT4_MOCFROMHCOMSTR')
        mocBld.add_action(h, act)
        mocBld.prefix[h] = '$QT4_MOCHPREFIX'
        mocBld.suffix[h] = '$QT4_MOCHSUFFIX'
    for cxx in cxx_suffixes:
        act = SCons.Action.Action('$QT4_MOCFROMCXXCOM',
                                  cmdstr='$QT4_MOCFROMCXXCOMSTR')
        mocBld.add_action(cxx, act)
        mocBld.prefix[cxx] = '$QT4_MOCCXXPREFIX'
        mocBld.suffix[cxx] = '$QT4_MOCCXXSUFFIX'
    env['BUILDERS']['Moc4'] = mocBld

    # er... no idea what that was for
    static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
    static_obj.src_builder.append('Uic4')
    shared_obj.src_builder.append('Uic4')

    # We use the emitters of Program / StaticLibrary / SharedLibrary
    # to scan for moc'able files
    # We can't refer to the builders directly, we have to fetch them
    # as Environment attributes because that sets them up to be called
    # correctly later by our emitter.
    env.AppendUnique(
        PROGEMITTER=[AutomocStatic],
        SHLIBEMITTER=[AutomocShared],
        LIBEMITTER=[AutomocStatic],
        # Of course, we need to link against the qt libraries
        LIBPATH=["$QT4_LIBPATH"],
        LIBS=['$QT4_LIB'])

    # TODO: Does dbusxml2cpp need an adapter
    env.AddMethod(enable_modules, "EnableQt4Modules")
Пример #19
0
def generate(env):
	"""Add Builders and construction variables for qt to an Environment."""
	CLVar = SCons.Util.CLVar
	Action = SCons.Action.Action
	Builder = SCons.Builder.Builder

	env.SetDefault(
		QT_AUTOSCAN = 1, # scan for moc'able sources

		# Some QT specific flags. I don't expect someone wants to
		# manipulate those ...
		QT_UICIMPLFLAGS = CLVar(''),
		QT_UICDECLFLAGS = CLVar(''),
		QT_MOCFROMHFLAGS = CLVar(''),
		QT_MOCFROMCXXFLAGS = CLVar('-i'),

		# suffixes/prefixes for the headers / sources to generate
		QT_UICDECLPREFIX = '', #'ui_',
		QT_UICDECLSUFFIX = '.h',
		QT_UICIMPLPREFIX = '', #'ui_',
		QT_UICIMPLSUFFIX = '$CXXFILESUFFIX',
		QT_MOCHPREFIX = 'moc_',
		QT_MOCHSUFFIX = '$CXXFILESUFFIX',
		QT_MOCCXXPREFIX = '',
		QT_MOCCXXSUFFIX = '.moc',
		QT_UISUFFIX = '.ui',

		# Commands for the qt support ...
		# command to generate header, implementation and moc-file
		# from a .ui file
		QT_UICCOM = [
			CLVar('$QT_UIC $QT_UICDECLFLAGS -o ${TARGETS[0]} $SOURCE'),
			CLVar('$QT_UIC $QT_UICIMPLFLAGS -impl ${TARGETS[0].file} '
				  '-o ${TARGETS[1]} $SOURCE'),
			#CLVar('$QT_MOC $QT_MOCFROMHFLAGS -o ${TARGETS[2]} ${TARGETS[0]}'),
		],
		# command to generate meta object information for a class
		# declarated in a header
		QT_MOCFROMHCOM = (
			  '$QT_MOC $QT_MOCFROMHFLAGS -o ${TARGETS[0]} $SOURCE'
		),
		# command to generate meta object information for a class
		# declarated in a cpp file
		QT_MOCFROMCXXCOM = [
			CLVar('$QT_MOC $QT_MOCFROMCXXFLAGS -o ${TARGETS[0]} $SOURCE'),
			Action(checkMocIncluded,None),
		]
	)

	# ... and the corresponding builders
	uicBld = Builder(
			action = SCons.Action.Action('$QT_UICCOM', '$QT_UICCOMSTR'),
			emitter = uicEmitter,
			src_suffix = '$QT_UISUFFIX',
			suffix = '$QT_UICDECLSUFFIX',
			prefix = '$QT_UICDECLPREFIX',
			source_scanner = uicScanner,
		)

	mocBld = Builder(action={}, prefix={}, suffix={})
	for h in header_extensions:
		act = SCons.Action.Action('$QT_MOCFROMHCOM', '$QT_MOCFROMHCOMSTR')
		mocBld.add_action(h, act)
		mocBld.prefix[h] = '$QT_MOCHPREFIX'
		mocBld.suffix[h] = '$QT_MOCHSUFFIX'
	for cxx in cxx_suffixes:
		act = SCons.Action.Action('$QT_MOCFROMCXXCOM', '$QT_MOCFROMCXXCOMSTR')
		mocBld.add_action(cxx, act)
		mocBld.prefix[cxx] = '$QT_MOCCXXPREFIX'
		mocBld.suffix[cxx] = '$QT_MOCCXXSUFFIX'

	# register the builders 
	env['BUILDERS']['Uic'] = uicBld
	env['BUILDERS']['Moc'] = mocBld
	static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
	static_obj.add_src_builder('Uic')
	shared_obj.add_src_builder('Uic')

	env.AddMethod( enableQtEmmitters, "EnableQtEmmitters")
Пример #20
0
def generate(env):
    """Add Builders and construction variables for qt to an Environment."""
    CLVar = SCons.Util.CLVar
    Action = SCons.Action.Action
    Builder = SCons.Builder.Builder

    env.SetDefault(
        QT_AUTOSCAN=1,  # scan for moc'able sources

        # Some QT specific flags. I don't expect someone wants to
        # manipulate those ...
        QT_UICIMPLFLAGS=CLVar(''),
        QT_UICDECLFLAGS=CLVar(''),
        QT_MOCFROMHFLAGS=CLVar(''),
        QT_MOCFROMCXXFLAGS=CLVar('-i'),

        # suffixes/prefixes for the headers / sources to generate
        QT_UICDECLPREFIX='',  #'ui_',
        QT_UICDECLSUFFIX='.h',
        QT_UICIMPLPREFIX='',  #'ui_',
        QT_UICIMPLSUFFIX='$CXXFILESUFFIX',
        QT_MOCHPREFIX='moc_',
        QT_MOCHSUFFIX='$CXXFILESUFFIX',
        QT_MOCCXXPREFIX='',
        QT_MOCCXXSUFFIX='.moc',
        QT_UISUFFIX='.ui',
        QT4_LUPDATE=os.path.join('$QT_BINPATH', 'lupdate'),
        QT4_LRELEASE=os.path.join('$QT_BINPATH', 'lrelease'),
        QT4_LUPDATECOM='$QT4_LUPDATE $SOURCE -ts $TARGET',
        QT4_LRELEASECOM='$QT4_LRELEASE $SOURCE',

        # Commands for the qt support ...
        # command to generate header, implementation and moc-file
        # from a .ui file
        QT_UICCOM=[
            CLVar('$QT_UIC $QT_UICDECLFLAGS -o ${TARGETS[0]} $SOURCE'),
            CLVar('$QT_UIC $QT_UICIMPLFLAGS -impl ${TARGETS[0].file} '
                  '-o ${TARGETS[1]} $SOURCE'),
            #CLVar('$QT_MOC $QT_MOCFROMHFLAGS -o ${TARGETS[2]} ${TARGETS[0]}'),
        ],
        # command to generate meta object information for a class
        # declarated in a header
        QT_MOCFROMHCOM=('$QT_MOC $QT_MOCFROMHFLAGS -o ${TARGETS[0]} $SOURCE'),
        # command to generate meta object information for a class
        # declarated in a cpp file
        QT_MOCFROMCXXCOM=[
            CLVar('$QT_MOC $QT_MOCFROMCXXFLAGS -o ${TARGETS[0]} $SOURCE'),
            Action(checkMocIncluded, None),
            Action(simplifyInclude)
        ])

    # ... and the corresponding builders
    uicBld = Builder(
        action=SCons.Action.Action('$QT_UICCOM', '$QT_UICCOMSTR'),
        emitter=uicEmitter,
        src_suffix='$QT_UISUFFIX',
        suffix='$QT_UICDECLSUFFIX',
        prefix='$QT_UICDECLPREFIX',
        source_scanner=uicScanner,
    )

    mocBld = Builder(action={}, prefix={}, suffix={})
    for h in header_extensions:
        act = SCons.Action.Action('$QT_MOCFROMHCOM', '$QT_MOCFROMHCOMSTR')
        mocBld.add_action(h, act)
        mocBld.prefix[h] = '$QT_MOCHPREFIX'
        mocBld.suffix[h] = '$QT_MOCHSUFFIX'
    for cxx in cxx_suffixes:
        act = SCons.Action.Action('$QT_MOCFROMCXXCOM', '$QT_MOCFROMCXXCOMSTR')
        mocBld.add_action(cxx, act)
        mocBld.prefix[cxx] = '$QT_MOCCXXPREFIX'
        mocBld.suffix[cxx] = '$QT_MOCCXXSUFFIX'

    # register the builders
    # Translation builder
    tsbuilder = Builder(
        action=SCons.Action.Action(
            '$QT4_LUPDATECOM'),  #,'$QT4_LUPDATECOMSTR'),
        multi=1)
    qmbuilder = Builder(
        action=SCons.Action.Action(
            '$QT4_LRELEASECOM'),  # , '$QT4_LRELEASECOMSTR'),
        src_suffix='.ts',
        suffix='.qm',
        single_source=True)

    env['BUILDERS']['Ts'] = tsbuilder
    env['BUILDERS']['Qm'] = qmbuilder
    env['BUILDERS']['Uic'] = uicBld
    env['BUILDERS']['Moc'] = mocBld
    static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
    static_obj.add_src_builder('Uic')
    shared_obj.add_src_builder('Uic')

    env.AddMethod(enableQtEmmitters, "EnableQtEmmitters")
Пример #21
0
def generate(env):
    """Add Builders and construction variables for qt4 to an Environment."""

    def locateQt4Command(env, command, qtdir):
        suffixes = ["-qt4", "-qt4.exe", "4", "4.exe", "", ".exe"]
        triedPaths = []
        for suffix in suffixes:
            fullpath = os.path.join(qtdir, "bin", command + suffix)
            if os.access(fullpath, os.X_OK):
                return fullpath
            triedPaths.append(fullpath)

        fullpath = env.Detect([command + "-qt4", command + "4", command])
        if not (fullpath is None):
            return fullpath

        raise Exception("Qt4 command '" + command + "' not found. Tried: " + ", ".join(triedPaths))

    CLVar = SCons.Util.CLVar
    Action = SCons.Action.Action
    Builder = SCons.Builder.Builder

    env["QT4DIR"] = _detect(env)
    # TODO: 'Replace' should be 'SetDefault'
    #    env.SetDefault(
    env.Replace(
        QT4DIR=_detect(env),
        QT4_BINPATH=os.path.join("$QT4DIR", "bin"),
        # TODO: This is not reliable to QT4DIR value changes but needed in order to support '-qt4' variants
        QT4_MOC=locateQt4Command(env, "moc", env["QT4DIR"]),
        QT4_UIC=locateQt4Command(env, "uic", env["QT4DIR"]),
        QT4_RCC=locateQt4Command(env, "rcc", env["QT4DIR"]),
        QT4_LUPDATE=locateQt4Command(env, "lupdate", env["QT4DIR"]),
        QT4_LRELEASE=locateQt4Command(env, "lrelease", env["QT4DIR"]),
        QT4_AUTOSCAN=1,  # Should the qt4 tool try to figure out, which sources are to be moc'ed?
        QT4_AUTOSCAN_STRATEGY=0,  # While scanning for files to moc, should we search for includes in qtsolutions style?
        QT4_GOBBLECOMMENTS=0,  # If set to 1, comments are removed before scanning cxx/h files.
        QT4_CPPDEFINES_PASSTOMOC=1,  # If set to 1, all CPPDEFINES get passed to the moc executable.
        QT4_CLEAN_TS=0,  # If set to 1, translation files (.ts) get cleaned on 'scons -c'
        QT4_AUTOMOC_SCANCPPPATH=1,  # If set to 1, the CPPPATHs (or QT4_AUTOMOC_CPPPATH) get scanned for moc'able files
        QT4_AUTOMOC_CPPPATH=[],  # Alternative paths that get scanned for moc files
        # Some Qt4 specific flags. I don't expect someone wants to
        # manipulate those ...
        QT4_UICFLAGS=CLVar(""),
        QT4_MOCFROMHFLAGS=CLVar(""),
        QT4_MOCFROMCXXFLAGS=CLVar("-i"),
        QT4_QRCFLAGS="",
        QT4_LUPDATEFLAGS="",
        QT4_LRELEASEFLAGS="",
        # suffixes/prefixes for the headers / sources to generate
        QT4_UISUFFIX=".ui",
        QT4_UICDECLPREFIX="ui_",
        QT4_UICDECLSUFFIX=".h",
        QT4_MOCINCPREFIX="-I",
        QT4_MOCHPREFIX="moc_",
        QT4_MOCHSUFFIX="$CXXFILESUFFIX",
        QT4_MOCCXXPREFIX="",
        QT4_MOCCXXSUFFIX=".moc",
        QT4_QRCSUFFIX=".qrc",
        QT4_QRCCXXSUFFIX="$CXXFILESUFFIX",
        QT4_QRCCXXPREFIX="qrc_",
        QT4_MOCDEFPREFIX="-D",
        QT4_MOCDEFSUFFIX="",
        QT4_MOCDEFINES="${_defines(QT4_MOCDEFPREFIX, CPPDEFINES, QT4_MOCDEFSUFFIX, __env__)}",
        QT4_MOCCPPPATH=[],
        QT4_MOCINCFLAGS="$( ${_concat(QT4_MOCINCPREFIX, QT4_MOCCPPPATH, INCSUFFIX, __env__, RDirs)} $)",
        # Commands for the qt4 support ...
        QT4_UICCOM="$QT4_UIC $QT4_UICFLAGS -o $TARGET $SOURCE",
        QT4_LUPDATECOM="$QT4_LUPDATE $QT4_LUPDATEFLAGS $SOURCES -ts $TARGET",
        QT4_LRELEASECOM="$QT4_LRELEASE $QT4_LRELEASEFLAGS -qm $TARGET $SOURCES",
        # Specialized variables for the Extended Automoc support
        # (Strategy #1 for qtsolutions)
        QT4_XMOCHPREFIX="moc_",
        QT4_XMOCHSUFFIX=".cpp",
        QT4_XMOCCXXPREFIX="",
        QT4_XMOCCXXSUFFIX=".moc",
    )

    try:
        env.AddMethod(Ts4, "Ts4")
        env.AddMethod(Qm4, "Qm4")
        env.AddMethod(Qrc4, "Qrc4")
        env.AddMethod(ExplicitMoc4, "ExplicitMoc4")
        env.AddMethod(ExplicitUic4, "ExplicitUic4")
    except AttributeError:
        # Looks like we use a pre-0.98 version of SCons...
        from SCons.Script.SConscript import SConsEnvironment

        SConsEnvironment.Ts4 = Ts4
        SConsEnvironment.Qm4 = Qm4
        SConsEnvironment.Qrc4 = Qrc4
        SConsEnvironment.ExplicitMoc4 = ExplicitMoc4
        SConsEnvironment.ExplicitUic4 = ExplicitUic4

    # Interface builder
    uic4builder = Builder(
        action=SCons.Action.Action("$QT4_UICCOM", "$QT4_UICCOMSTR"),
        src_suffix="$QT4_UISUFFIX",
        suffix="$QT4_UICDECLSUFFIX",
        prefix="$QT4_UICDECLPREFIX",
        single_source=True
        # TODO: Consider the uiscanner on new scons version
    )
    env["BUILDERS"]["Uic4"] = uic4builder

    # Metaobject builder
    mocBld = Builder(action={}, prefix={}, suffix={})
    for h in header_extensions:
        act = SCons.Action.CommandGeneratorAction(__moc_generator_from_h, {})
        mocBld.add_action(h, act)
        mocBld.prefix[h] = "$QT4_MOCHPREFIX"
        mocBld.suffix[h] = "$QT4_MOCHSUFFIX"
    for cxx in cxx_suffixes:
        act = SCons.Action.CommandGeneratorAction(__moc_generator_from_cxx, {})
        mocBld.add_action(cxx, act)
        mocBld.prefix[cxx] = "$QT4_MOCCXXPREFIX"
        mocBld.suffix[cxx] = "$QT4_MOCCXXSUFFIX"
    env["BUILDERS"]["Moc4"] = mocBld

    # Metaobject builder for the extended auto scan feature
    # (Strategy #1 for qtsolutions)
    xMocBld = Builder(action={}, prefix={}, suffix={})
    for h in header_extensions:
        act = SCons.Action.CommandGeneratorAction(__mocx_generator_from_h, {})
        xMocBld.add_action(h, act)
        xMocBld.prefix[h] = "$QT4_XMOCHPREFIX"
        xMocBld.suffix[h] = "$QT4_XMOCHSUFFIX"
    for cxx in cxx_suffixes:
        act = SCons.Action.CommandGeneratorAction(__mocx_generator_from_cxx, {})
        xMocBld.add_action(cxx, act)
        xMocBld.prefix[cxx] = "$QT4_XMOCCXXPREFIX"
        xMocBld.suffix[cxx] = "$QT4_XMOCCXXSUFFIX"
    env["BUILDERS"]["XMoc4"] = xMocBld

    # Add the Qrc4 action to the CXX file builder (registers the
    # *.qrc extension with the Environment)
    cfile_builder, cxxfile_builder = SCons.Tool.createCFileBuilders(env)
    qrc_act = SCons.Action.CommandGeneratorAction(__qrc_generator, {})
    cxxfile_builder.add_action("$QT4_QRCSUFFIX", qrc_act)
    cxxfile_builder.add_emitter("$QT4_QRCSUFFIX", __qrc_emitter)

    # We use the emitters of Program / StaticLibrary / SharedLibrary
    # to scan for moc'able files
    # We can't refer to the builders directly, we have to fetch them
    # as Environment attributes because that sets them up to be called
    # correctly later by our emitter.
    env.AppendUnique(PROGEMITTER=[AutomocStatic], SHLIBEMITTER=[AutomocShared], LIBEMITTER=[AutomocStatic])

    # TODO: Does dbusxml2cpp need an adapter
    try:
        env.AddMethod(enable_modules, "EnableQt4Modules")
    except AttributeError:
        # Looks like we use a pre-0.98 version of SCons...
        from SCons.Script.SConscript import SConsEnvironment

        SConsEnvironment.EnableQt4Modules = enable_modules
Пример #22
0
def generate(env):
    """Add Builders and construction variables for qt to an Environment."""
    CLVar = SCons.Util.CLVar
    Action = SCons.Action.Action
    Builder = SCons.Builder.Builder
    splitext = SCons.Util.splitext

    dep_include = env["OPTICKSDEPENDENCIESINCLUDE"]
    dep_bin = env["OPTICKSDEPENDENCIESBIN"]
    env.AppendUnique(
        QT_BINPATH=dep_bin,
        QT_CPPPATH=os.path.join(dep_include, 'qt4'),
        QT_MOC=os.path.join('$QT_BINPATH', 'moc'),
        QT_UIC=os.path.join('$QT_BINPATH', 'uic'),
        QT_QRC=os.path.join('$QT_BINPATH', 'rcc'),
        QT_LIB=None,  # filled in by AddModules
        QT_MODULES=[],  # filled in by AddModules
        QT_AUTOSCAN=1,  # scan for moc'able sources

        # Some QT specific flags. I don't expect someone wants to
        # manipulate those ...
        QT_UICIMPLFLAGS=CLVar(''),
        QT_UICDECLFLAGS=CLVar(''),
        QT_MOCFROMHFLAGS=CLVar(''),
        QT_MOCFROMCXXFLAGS=CLVar('-i'),

        # suffixes/prefixes for the headers / sources to generate
        QT_UICDECLPREFIX='ui_',
        QT_UICDECLSUFFIX='.h',
        QT_QRCIMPLSUFFIX='_qrc.cpp',
        QT_MOCHPREFIX='moc_',
        QT_MOCHSUFFIX='$CXXFILESUFFIX',
        QT_MOCCXXPREFIX='',
        QT_MOCCXXSUFFIX='.moc',
        QT_UISUFFIX='.ui',
        QT_QRCSUFFIX='.qrc',
        # Commands for the qt support ...
        # command to generate header, implementation and moc-file
        # from a .qrc file
        QT_QRCCOM=[
            CLVar(
                '$QT_QRC $QT_QRCDECLFLAGS $SOURCE -name ${SOURCE.filebase} -o ${TARGETS[0]}'
            )
        ],
        # from a .ui file
        QT_UICCOM=[CLVar('$QT_UIC $QT_UICDECLFLAGS -o ${TARGETS[0]} $SOURCE')],
        # command to generate meta object information for a class
        # declarated in a header
        QT_MOCFROMHCOM=('$QT_MOC $QT_MOCFROMHFLAGS -o ${TARGETS[0]} $SOURCE'),
        # command to generate meta object information for a class
        # declarated in a cpp file
        QT_MOCFROMCXXCOM=[
            CLVar('$QT_MOC $QT_MOCFROMCXXFLAGS -o ${TARGETS[0]} $SOURCE'),
            Action(checkMocIncluded, None)
        ])

    # ... and the corresponding builders
    qrcBld = Builder(action={'$QT_QRCSUFFIX': '$QT_QRCCOM'},
                     suffix='$QT_QRCIMPLSUFFIX',
                     src_suffix='$QT_QRCSUFFIX')
    uicBld = Builder(action={'$QT_UISUFFIX': '$QT_UICCOM'},
                     src_suffix='$QT_UISUFFIX',
                     suffix='$QT_UICDECLSUFFIX',
                     prefix='$QT_UICDECLPREFIX',
                     source_scanner=uicScanner)
    mocBld = Builder(action={}, prefix={}, suffix={})
    for h in header_extensions:
        mocBld.add_action(h, '$QT_MOCFROMHCOM')
        mocBld.prefix[h] = '$QT_MOCHPREFIX'
        mocBld.suffix[h] = '$QT_MOCHSUFFIX'
    for cxx in cxx_suffixes:
        mocBld.add_action(cxx, '$QT_MOVFROMCXXCOM')
        mocBld.prefix[cxx] = '$QT_MOCCXXPREFIX'
        mocBld.suffix[cxx] = '$QT_MOCCXXSUFFIX'

    # register the builders

    env['BUILDERS']['Uic'] = uicBld
    env['BUILDERS']['Moc'] = mocBld
    env['BUILDERS']['Qrc'] = qrcBld

    static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
    static_obj.src_builder.append('Qrc')
    shared_obj.src_builder.append('Qrc')

    # We use the emitters of Program / StaticLibrary / SharedLibrary
    # to scan for moc'able files
    # We can't refer to the builders directly, we have to fetch them
    # as Environment attributes because that sets them up to be called
    # correctly later by our emitter.
    env.AppendUnique(PROGEMITTER=[AutomocStatic],
                     SHLIBEMITTER=[AutomocShared],
                     LIBEMITTER=[AutomocStatic])
Пример #23
0
def generate(env):
    """Add Builders and construction variables for qt to an Environment."""
    def locateQt5Command(env, command, qtdir):
        suffixes = [
            '-qt5',
            '-qt5.exe',
            '5',
            '5.exe',
            '',
            '.exe',
        ]
        triedPaths = []
        for suffix in suffixes:
            fullpath = os.path.join(qtdir, 'bin', command + suffix)
            if os.access(fullpath, os.X_OK):
                return fullpath
            triedPaths.append(fullpath)

        fullpath = env.Detect([command + '-qt5', command + '5', command])
        if not (fullpath is None): return fullpath

        raise Exception("Qt5 command '" + command + "' not found. Tried: " +
                        ', '.join(triedPaths))

    CLVar = SCons.Util.CLVar
    Action = SCons.Action.Action
    Builder = SCons.Builder.Builder
    splitext = SCons.Util.splitext

    env['QTDIR'] = env.GetBuildPath(_detect(env))

    # TODO: 'Replace' should be 'SetDefault'
    #       env.SetDefault(
    env.Replace(
        QTDIR=_detect(env),
        QT5_BINPATH=os.path.join('$QTDIR', 'bin'),
        QT5_LIBPATH=os.path.join('$QTDIR', 'lib'),
        # TODO: This is not reliable to QTDIR value changes but needed in order to support '-qt5' variants
        QT5_MOC=locateQt5Command(env, 'moc', env['QTDIR']),
        QT5_UIC=locateQt5Command(env, 'uic', env['QTDIR']),
        QT5_RCC=locateQt5Command(env, 'rcc', env['QTDIR']),
        QT5_LUPDATE=locateQt5Command(env, 'lupdate', env['QTDIR']),
        QT5_LRELEASE=locateQt5Command(env, 'lrelease', env['QTDIR']),
        QT5_AUTOSCAN=
        1,  # Should the qt tool try to figure out, which sources are to be moc'ed?

        # Some QT specific flags. I don't expect someone wants to
        # manipulate those ...
        QT5_UICFLAGS=CLVar(''),
        QT5_MOCFROMHFLAGS=CLVar(''),
        QT5_MOCFROMCXXFLAGS=CLVar('-i'),
        QT5_QRCFLAGS='',

        # suffixes/prefixes for the headers / sources to generate
        QT5_UISUFFIX='.ui',
        QT5_UICDECLPREFIX='ui_',
        QT5_UICDECLSUFFIX='.h',
        QT5_MOCINCPREFIX='-I',
        QT5_MOCHPREFIX='moc_',
        QT5_MOCHSUFFIX='$CXXFILESUFFIX',
        QT5_MOCCXXPREFIX='',
        QT5_MOCCXXSUFFIX='.moc',
        QT5_QRCSUFFIX='.qrc',
        QT5_QRCCXXSUFFIX='$CXXFILESUFFIX',
        QT5_QRCCXXPREFIX='qrc_',
        QT5_MOCCPPPATH=[],
        QT5_MOCINCFLAGS=
        '$( ${_concat(QT5_MOCINCPREFIX, QT5_MOCCPPPATH, INCSUFFIX, __env__, RDirs)} $)',

        # Commands for the qt support ...
        QT5_UICCOM='"$QT5_UIC" $QT5_UICFLAGS -o $TARGET $SOURCE',
        QT5_MOCFROMHCOM=
        '"$QT5_MOC" $QT5_MOCFROMHFLAGS $QT5_MOCINCFLAGS -o $TARGET $SOURCE',
        QT5_MOCFROMCXXCOM=[
            '$QT5_MOC $QT5_MOCFROMCXXFLAGS $QT5_MOCINCFLAGS -o $TARGET $SOURCE',
            Action(checkMocIncluded, None)
        ],
        QT5_LUPDATECOM='"$QT5_LUPDATE" $SOURCE -ts $TARGET',
        QT5_LRELEASECOM='"$QT5_LRELEASE" $SOURCE',
        QT5_RCCCOM='"$QT5_RCC" $QT5_QRCFLAGS $SOURCE -o $TARGET',
    )

    print "%s" % (env['QTDIR'])

    # Translation builder
    tsbuilder = Builder(
        action=SCons.Action.Action(
            '$QT5_LUPDATECOM'),  #,'$QT5_LUPDATECOMSTR'),
        multi=1)
    env.Append(BUILDERS={'Ts': tsbuilder})
    qmbuilder = Builder(
        action=SCons.Action.Action(
            '$QT5_LRELEASECOM'),  # , '$QT5_LRELEASECOMSTR'),
        src_suffix='.ts',
        suffix='.qm',
        single_source=True)
    env.Append(BUILDERS={'Qm': qmbuilder})

    # Resource builder
    def scanResources(node, env, path, arg):
        # I've being careful on providing names relative to the qrc file
        # If that was not needed that code could be simplified a lot
        def recursiveFiles(basepath, path):
            result = []
            for item in os.listdir(os.path.join(basepath, path)):
                itemPath = os.path.join(path, item)
                if os.path.isdir(os.path.join(basepath, itemPath)):
                    result += recursiveFiles(basepath, itemPath)
                else:
                    result.append(itemPath)
            return result

        contents = node.get_contents()
        includes = qrcinclude_re.findall(contents)
        qrcpath = os.path.dirname(node.path)
        dirs = [
            included for included in includes
            if os.path.isdir(os.path.join(qrcpath, included))
        ]
        # dirs need to include files recursively
        for dir in dirs:
            includes.remove(dir)
            includes += recursiveFiles(qrcpath, dir)
        return includes

    qrcscanner = SCons.Scanner.Scanner(name='qrcfile',
                                       function=scanResources,
                                       argument=None,
                                       skeys=['.qrc'])
    qrcbuilder = Builder(action=SCons.Action.Action('$QT5_RCCCOM',
                                                    '$QT5_RCCCOMSTR'),
                         source_scanner=qrcscanner,
                         src_suffix='$QT5_QRCSUFFIX',
                         suffix='$QT5_QRCCXXSUFFIX',
                         prefix='$QT5_QRCCXXPREFIX',
                         single_source=True)
    env.Append(BUILDERS={'Qrc': qrcbuilder})

    # Interface builder
    uic5builder = Builder(action=SCons.Action.Action('$QT5_UICCOM',
                                                     '$QT5_UICCOMSTR'),
                          src_suffix='$QT5_UISUFFIX',
                          suffix='$QT5_UICDECLSUFFIX',
                          prefix='$QT5_UICDECLPREFIX',
                          single_source=True
                          #TODO: Consider the uiscanner on new scons version
                          )
    env['BUILDERS']['Uic5'] = uic5builder

    # Metaobject builder
    mocBld = Builder(action={}, prefix={}, suffix={})
    for h in header_extensions:
        act = SCons.Action.Action('$QT5_MOCFROMHCOM', '$QT5_MOCFROMHCOMSTR')
        mocBld.add_action(h, act)
        mocBld.prefix[h] = '$QT5_MOCHPREFIX'
        mocBld.suffix[h] = '$QT5_MOCHSUFFIX'
    for cxx in cxx_suffixes:
        act = SCons.Action.Action('$QT5_MOCFROMCXXCOM',
                                  '$QT5_MOCFROMCXXCOMSTR')
        mocBld.add_action(cxx, act)
        mocBld.prefix[cxx] = '$QT5_MOCCXXPREFIX'
        mocBld.suffix[cxx] = '$QT5_MOCCXXSUFFIX'
    env['BUILDERS']['Moc5'] = mocBld

    # er... no idea what that was for
    static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
    static_obj.src_builder.append('Uic5')
    shared_obj.src_builder.append('Uic5')

    # We use the emitters of Program / StaticLibrary / SharedLibrary
    # to scan for moc'able files
    # We can't refer to the builders directly, we have to fetch them
    # as Environment attributes because that sets them up to be called
    # correctly later by our emitter.
    env.AppendUnique(
        PROGEMITTER=[AutomocStatic],
        SHLIBEMITTER=[AutomocShared],
        LIBEMITTER=[AutomocStatic],
    )

    # TODO: Does dbusxml2cpp need an adapter
    env.AddMethod(enable_modules, "EnableQt5Modules")
Пример #24
0
Файл: qt.py Проект: berkus/okl4
def generate(env):
    """Add Builders and construction variables for qt to an Environment."""
    CLVar = SCons.Util.CLVar
    Action = SCons.Action.Action
    Builder = SCons.Builder.Builder
    splitext = SCons.Util.splitext

    env.SetDefault(
        QTDIR=_detect(env),
        QT_BINPATH=os.path.join("$QTDIR", "bin"),
        QT_CPPPATH=os.path.join("$QTDIR", "include"),
        QT_LIBPATH=os.path.join("$QTDIR", "lib"),
        QT_MOC=os.path.join("$QT_BINPATH", "moc"),
        QT_UIC=os.path.join("$QT_BINPATH", "uic"),
        QT_LIB="qt",  # may be set to qt-mt
        QT_AUTOSCAN=1,  # scan for moc'able sources
        # Some QT specific flags. I don't expect someone wants to
        # manipulate those ...
        QT_UICIMPLFLAGS=CLVar(""),
        QT_UICDECLFLAGS=CLVar(""),
        QT_MOCFROMHFLAGS=CLVar(""),
        QT_MOCFROMCXXFLAGS=CLVar("-i"),
        # suffixes/prefixes for the headers / sources to generate
        QT_UICDECLPREFIX="",
        QT_UICDECLSUFFIX=".h",
        QT_UICIMPLPREFIX="uic_",
        QT_UICIMPLSUFFIX="$CXXFILESUFFIX",
        QT_MOCHPREFIX="moc_",
        QT_MOCHSUFFIX="$CXXFILESUFFIX",
        QT_MOCCXXPREFIX="",
        QT_MOCCXXSUFFIX=".moc",
        QT_UISUFFIX=".ui",
        # Commands for the qt support ...
        # command to generate header, implementation and moc-file
        # from a .ui file
        QT_UICCOM=[
            CLVar("$QT_UIC $QT_UICDECLFLAGS -o ${TARGETS[0]} $SOURCE"),
            CLVar("$QT_UIC $QT_UICIMPLFLAGS -impl ${TARGETS[0].file} " "-o ${TARGETS[1]} $SOURCE"),
            CLVar("$QT_MOC $QT_MOCFROMHFLAGS -o ${TARGETS[2]} ${TARGETS[0]}"),
        ],
        # command to generate meta object information for a class
        # declarated in a header
        QT_MOCFROMHCOM=("$QT_MOC $QT_MOCFROMHFLAGS -o ${TARGETS[0]} $SOURCE"),
        # command to generate meta object information for a class
        # declarated in a cpp file
        QT_MOCFROMCXXCOM=[
            CLVar("$QT_MOC $QT_MOCFROMCXXFLAGS -o ${TARGETS[0]} $SOURCE"),
            Action(checkMocIncluded, None),
        ],
    )

    # ... and the corresponding builders
    uicBld = Builder(
        action=SCons.Action.Action("$QT_UICCOM", "$QT_UICCOMSTR"),
        emitter=uicEmitter,
        src_suffix="$QT_UISUFFIX",
        suffix="$QT_UICDECLSUFFIX",
        prefix="$QT_UICDECLPREFIX",
        source_scanner=uicScanner,
    )
    mocBld = Builder(action={}, prefix={}, suffix={})
    for h in header_extensions:
        act = SCons.Action.Action("$QT_MOCFROMHCOM", "$QT_MOCFROMHCOMSTR")
        mocBld.add_action(h, act)
        mocBld.prefix[h] = "$QT_MOCHPREFIX"
        mocBld.suffix[h] = "$QT_MOCHSUFFIX"
    for cxx in cxx_suffixes:
        act = SCons.Action.Action("$QT_MOCFROMCXXCOM", "$QT_MOCFROMCXXCOMSTR")
        mocBld.add_action(cxx, act)
        mocBld.prefix[cxx] = "$QT_MOCCXXPREFIX"
        mocBld.suffix[cxx] = "$QT_MOCCXXSUFFIX"

    # register the builders
    env["BUILDERS"]["Uic"] = uicBld
    env["BUILDERS"]["Moc"] = mocBld
    static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
    static_obj.src_builder.append("Uic")
    shared_obj.src_builder.append("Uic")

    # We use the emitters of Program / StaticLibrary / SharedLibrary
    # to scan for moc'able files
    # We can't refer to the builders directly, we have to fetch them
    # as Environment attributes because that sets them up to be called
    # correctly later by our emitter.
    env.AppendUnique(
        PROGEMITTER=[AutomocStatic],
        SHLIBEMITTER=[AutomocShared],
        LIBEMITTER=[AutomocStatic],
        # Of course, we need to link against the qt libraries
        CPPPATH=["$QT_CPPPATH"],
        LIBPATH=["$QT_LIBPATH"],
        LIBS=["$QT_LIB"],
    )