Commits

dirkbaechle committed c76fa7c

- Based on an idea and patch by Kyle Strand, the simple automoc strategy now also supports CXX files that directly include
the moc'ed header output (#include "moc_foo.cc"). The created .cc file doesn't get compiled, but is simply set as additional
dependency for the CXX file.
- Adapted tests to the latest revision of the SCons test framework.

  • Participants
  • Parent commits 8bd1edd

Comments (0)

Files changed (9)

         if h and self.qo_search.search(h_contents):
             # h file with the Q_OBJECT macro found -> add moc_cpp
             moc_cpp = env.Moc4(h)
-            moc_o = self.objBuilder(moc_cpp)
-            out_sources.extend(moc_o)
             if moc_options['debug']:
                 print "scons: qt4: found Q_OBJECT macro in '%s', moc'ing to '%s'" % (str(h), str(moc_cpp))
+            
+            # Now, check whether the corresponding CPP file
+            # includes the moc'ed output directly...
+            inc_moc_cpp = r'^\s*#\s*include\s+"%s"' % str(moc_cpp[0])
+            if cpp and re.search(inc_moc_cpp, cpp_contents, re.M):
+                if moc_options['debug']:
+                    print "scons: qt4: CXX file '%s' directly includes the moc'ed output '%s', no compiling required" % (str(cpp), str(moc_cpp))
+                env.Depends(cpp, moc_cpp)
+            else:
+                moc_o = self.objBuilder(moc_cpp)
+                if moc_options['debug']:
+                    print "scons: qt4: compiling '%s' to '%s'" % (str(cpp), str(moc_o))
+                out_sources.extend(moc_o)
         if cpp and self.qo_search.search(cpp_contents):
             # cpp file with Q_OBJECT macro found -> add moc
             # (to be included in cpp)

test/basic/moc-from-header-nocompile/image/SConscript

+Import("qtEnv dup")
+
+qtEnv.EnableQt4Modules(['QtCore','QtGui'])
+
+if dup == 0: qtEnv.Append(CPPPATH=['.', '#build_dup0'])
+qtEnv.Program('aaa', 'aaa.cpp', 
+              QT4_MOCHPREFIX = 'moc_',
+              QT4_MOCHSUFFIX = '.cc')

test/basic/moc-from-header-nocompile/image/SConstruct

+import qtenv
+
+qtEnv = qtenv.createQtEnvironment()
+
+dup = 1
+if ARGUMENTS.get('variant_dir', 0):
+    if ARGUMENTS.get('chdir', 0):
+        SConscriptChdir(1)
+    else:
+        SConscriptChdir(0)
+    dup=int(ARGUMENTS.get('dup', 1))
+    if dup == 0:
+        builddir = 'build_dup0'
+        qtEnv['QT4_DEBUG'] = 1
+    else:
+        builddir = 'build'
+    VariantDir(builddir, '.', duplicate=dup)
+    print builddir, dup
+    sconscript = Dir(builddir).File('SConscript')
+else:
+    sconscript = File('SConscript')
+
+Export("qtEnv dup")
+SConscript( sconscript )

test/basic/moc-from-header-nocompile/image/aaa.cpp

+#include "moc_aaa.cc"
+
+int main() 
+{ 
+  aaa a; 
+  return 0; 
+}

test/basic/moc-from-header-nocompile/image/aaa.h

+#include <QObject>
+
+class aaa : public QObject
+{
+  Q_OBJECT
+
+public:
+  aaa() {};
+};

test/basic/moc-from-header-nocompile/sconstest-moc-from-header-nocompile.py

+#!/usr/bin/env python
+#
+# Copyright (c) 2001-2010 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+"""
+Create a moc file from a header file, but don't
+compile it to an Object because the moc'ed output gets directly
+included to the CXX file.
+"""
+
+import TestSCons
+
+test = TestSCons.TestSCons()
+test.dir_fixture('image')
+test.file_fixture('../../qtenv.py')
+test.file_fixture('../../../__init__.py','site_scons/site_tools/qt4/__init__.py')
+
+aaa_exe = 'aaa' + TestSCons._exe
+build_aaa_exe = test.workpath('build', aaa_exe)
+moc = 'moc_aaa.cc'
+moc_obj = 'moc_aaa' + TestSCons._obj
+
+test.run()
+
+# Ensure that the object file for the MOC output wasn't generated
+test.must_not_exist(moc_obj)
+
+test.up_to_date(options = '-n', arguments=aaa_exe)
+test.up_to_date(options = '-n', arguments=aaa_exe)
+
+test.write('aaa.h', r"""
+#include <QObject>
+
+// Introducing a change...
+class aaa : public QObject
+{
+  Q_OBJECT
+
+public:
+  aaa() {};
+};
+""")
+
+test.not_up_to_date(options='-n', arguments = moc)
+
+test.run(arguments = "variant_dir=1 " + build_aaa_exe)
+
+test.run(arguments = "variant_dir=1 chdir=1 " + build_aaa_exe)
+
+test.must_exist(test.workpath('build', moc))
+test.must_not_exist(test.workpath('build', moc_obj))
+
+test.run(options='-c')
+
+test.run(arguments = "variant_dir=1 chdir=1 dup=0 " +
+                     test.workpath('build_dup0', aaa_exe) )
+
+test.must_exist(test.workpath('build_dup0', moc))
+test.must_not_exist(moc_obj)
+test.must_not_exist(test.workpath('build_dup0', moc_obj))
+
+test.pass_test()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:

test/basic/variantdir/image/SConstruct

 
 qtEnv = qtenv.createQtEnvironment()
 qtEnv.EnableQt4Modules(['QtCore','QtGui'])
+qtEnv.Append(CPPPATH=['bld'])
 
-qtEnv.VariantDir('bld', '.')
+qtEnv.VariantDir('bld', '.', duplicate=0)
 qtEnv.Uic4('bld/anUiFile.ui')
 qtEnv.Program('bld/test_realqt', ['bld/mocFromCpp.cpp',
                                   'bld/mocFromH.cpp',

test/qt_examples/sconstest.skip

Empty file added.

test/sconstest.skip

Empty file added.