StaticLibraries.
"""
- def __init__(self, objBuilder,uicDeclBuild,mocFromHBld,mocFromCppBld):
- self.objBuilder = objBuilder
+ def __init__(self, objBuilderName,uicDeclBuild,mocFromHBld,mocFromCppBld):
+ self.objBuilderName = objBuilderName
self.uicDeclBld = uicDeclBuild
self.mocFromHBld = mocFromHBld
self.mocFromCppBld = mocFromCppBld
src_ext = SCons.Util.splitext(str(h))[1]
moc_cpp = SCons.Node.FS.default_fs.File(os.path.join(dir,
env['QT_MOCNAMEGENERATOR'](base, src_ext, env)))
- moc_o = self.objBuilder(source=moc_cpp)
+ objBuilder = getattr(env, self.objBuilderName)
+ moc_o = objBuilder(source=moc_cpp)
out_sources.append(moc_o)
- self.objBuilder(moc_o, moc_cpp)
+ objBuilder(moc_o, moc_cpp)
self.mocFromHBld(env, moc_cpp, h)
moc_cpp.target_scanner = SCons.Defaults.CScan
if cpp and q_object_search.search(cpp.get_contents()):
# 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['PROGEMITTER'] = _Automoc(env.StaticObject,
+ env['PROGEMITTER'] = _Automoc('StaticObject',
uicDeclBld,mocFromHBld,mocFromCppBld)
- env['SHLIBEMITTER'] = _Automoc(env.SharedObject,
+ env['SHLIBEMITTER'] = _Automoc('SharedObject',
uicDeclBld,mocFromHBld,mocFromCppBld)
- env['LIBEMITTER'] = _Automoc(env.StaticObject,
+ env['LIBEMITTER'] = _Automoc('StaticObject',
uicDeclBld,mocFromHBld,mocFromCppBld)
# Of course, we need to link against the qt libraries
env.Append(CPPPATH=os.path.join('$QTDIR', 'include'))
generation of qt's moc files.
"""
-import TestSCons
import os.path
+import string
+
+import TestSCons
python = TestSCons.python
_exe = TestSCons._exe
QT_MOC = '%s %s' % (python, test.workpath('qt','bin','mymoc.py'))
QT_UIC = '%s %s' % (python, test.workpath('qt','bin','myuic.py'))
-# 3 test cases with 3 different operation modes
+##############################################################################
+# 4 test cases with 4 different operation modes
def createSConstruct(test,place):
test.write(place, """
SConscript( sconscript )
""" % (QT, QT_LIB, QT_MOC, QT_UIC))
-test.subdir( 'work1', 'work2', 'work3', 'work4' )
+test.subdir( 'work1', 'work2', 'work3', 'work4', 'work5' )
+##############################################################################
# 1. create a moc file from a header file.
aaa_exe = 'aaa' + _exe
test.fail_test( not os.path.exists(test.workpath('work1', 'build', moc)) )
+##############################################################################
# 2. create .cpp, .h, moc_....cpp from .ui file
aaa_dll = dll_ + 'aaa' + _dll
not os.path.exists(test.workpath('work2','build',cpp)) or
not os.path.exists(test.workpath('work2','build',h)))
+##############################################################################
# 3. create a moc file from a cpp file
lib_aaa = lib_ + 'aaa' + _lib
test.fail_test(not os.path.exists(test.workpath('work3', 'build', moc)))
+##############################################################################
+# 4. Test with a copied environment.
+
+createSConstruct(test, ['work4', 'SConstruct'])
+test.write(['work4', 'SConscript'], """\
+Import("env")
+env.Append(CPPDEFINES = ['FOOBAZ'])
+
+copy = env.Copy()
+copy.Append(CPPDEFINES = ['MYLIB_IMPL'])
+
+copy.SharedLibrary(
+ target = 'MyLib',
+ source = ['MyFile.cpp','MyForm.ui']
+)
+""")
+
+test.write(['work4', 'MyFile.h'], r"""
+void aaa(void);
+""")
+
+test.write(['work4', 'MyFile.cpp'], r"""
+#include "MyFile.h"
+void useit() {
+ aaa();
+}
+""")
+
+test.write(['work4', 'MyForm.ui'], r"""
+void aaa(void)
+""")
+
+test.run(chdir='work4')
+moc_MyForm = filter(lambda x: string.find(x, 'moc_MyForm') != -1,
+ string.split(test.stdout(), '\n'))
+MYLIB_IMPL = filter(lambda x: string.find(x, 'MYLIB_IMPL') != -1, moc_MyForm)
+if not MYLIB_IMPL:
+ print "Did not find MYLIB_IMPL on moc_MyForm compilation line:"
+ print test.stdout()
+ test.fail_test()
+
# look if qt is installed, and try out all builders
QTDIR=os.environ['QTDIR']
- test.write( ['work4', 'SConstruct'],"""
+ test.write( ['work5', 'SConstruct'],"""
import os
dummy_env = Environment()
ENV = dummy_env['ENV']
'main.cpp'])
""")
- test.write( ['work4', 'mocFromCpp.h'],"""
+ test.write( ['work5', 'mocFromCpp.h'],"""
void mocFromCpp();
""")
- test.write( ['work4', 'mocFromCpp.cpp'],"""
+ test.write( ['work5', 'mocFromCpp.cpp'],"""
#include <qobject.h>
#include "mocFromCpp.h"
class MyClass1 : public QObject {
#include "moc_mocFromCpp.cpp"
""")
- test.write( ['work4', 'mocFromH.h'],"""
+ test.write( ['work5', 'mocFromH.h'],"""
#include <qobject.h>
class MyClass2 : public QObject {
Q_OBJECT;
void mocFromH();
""")
- test.write( ['work4', 'mocFromH.cpp'],"""
+ test.write( ['work5', 'mocFromH.cpp'],"""
#include "mocFromH.h"
MyClass2::MyClass2() : QObject() {}
}
""")
- test.write( ['work4', 'anUiFile.ui'],"""
+ test.write( ['work5', 'anUiFile.ui'],"""
<!DOCTYPE UI><UI>
<class>MyWidget</class>
<widget>
</UI>
""")
- test.write( ['work4', 'main.cpp'], """
+ test.write( ['work5', 'main.cpp'], """
#include "mocFromCpp.h"
#include "mocFromH.h"
#include "anUiFile.h"
}
""")
- test.run(chdir='work4', arguments="test_realqt" + _exe)
+ test.run(chdir='work5', arguments="test_realqt" + _exe)
QTDIR=os.environ['QTDIR']
del os.environ['QTDIR']
- test.run(chdir='work4', arguments="-c test_realqt" + _exe)
- test.run(chdir='work4', arguments="PATH=%s/bin test_realqt%s"%(QTDIR,_exe))
+ test.run(chdir='work5', arguments="-c test_realqt" + _exe)
+ test.run(chdir='work5', arguments="PATH=%s/bin test_realqt%s"%(QTDIR,_exe))
else:
print "Could not find QT, skipping test(s)."