From: stevenknight Date: Sat, 3 Apr 2004 06:53:14 +0000 (+0000) Subject: Add a variable to control whether to compile moc-generated files. (Chad Austin) X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=54afccaee5c42dd5b4d7cd3c97b3ea82303d5ab4;p=scons.git Add a variable to control whether to compile moc-generated files. (Chad Austin) git-svn-id: http://scons.tigris.org/svn/scons/trunk@943 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/doc/man/scons.1 b/doc/man/scons.1 index 82878cb2..dfeb3df1 100644 --- a/doc/man/scons.1 +++ b/doc/man/scons.1 @@ -4997,6 +4997,10 @@ The implementation files generated from .ui files are handled much the same as yacc or lex files. Because there are also generated headers, you may need to specify duplicate=1 in calls to BuildDir. +.IP QT_AUTOBUILD_MOC_SOURCES +If true, moc-generated sources are automatically compiled into the +program or library that uses them. Defaults to 1. + .IP QT_LIB Default value is 'qt'. You may want to set this to 'qt-mt' diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 24761404..0501093a 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -16,6 +16,9 @@ RELEASE 0.96 - XXX - Allow construction variable substitutions in $LIBS specifications. + - Add a $QT_AUTOBUILD_MOC_SOURCES construction variable that controls + whether moc-generated .cpp files get compiled. + From Charles Crain: - Restore the ability to do construction variable substitutions in all diff --git a/src/engine/SCons/Tool/qt.py b/src/engine/SCons/Tool/qt.py index 693f77ec..a5a53b76 100644 --- a/src/engine/SCons/Tool/qt.py +++ b/src/engine/SCons/Tool/qt.py @@ -64,12 +64,14 @@ class _Automoc: Smart autoscan function. Gets the list of objects for the Program or Lib. Adds objects and builders for the special qt files. """ + FS = SCons.Node.FS.default_fs + splitext = SCons.Util.splitext + # To make the following work, we assume that we stay in the # root directory old_os_cwd = os.getcwd() - old_fs_cwd = SCons.Node.FS.default_fs.getcwd() - SCons.Node.FS.default_fs.chdir(SCons.Node.FS.default_fs.Dir('#'), - change_os_dir=1) + old_fs_cwd = FS.getcwd() + FS.chdir(FS.Dir('#'), change_os_dir=1) # a regular expression for the Q_OBJECT macro # currently fails, when Q_OBJECT is in comment (e.g. /* Q_OBJECT */) @@ -77,21 +79,21 @@ class _Automoc: # out_sources contains at least all sources for the Library or Prog out_sources = source[:] for s in source: - prefix, suffix = SCons.Util.splitext(str(s)) + prefix, suffix = splitext(str(s)) # Nodes for header (h) / moc file (moc_cpp) / cpp file (cpp) # and ui.h file (ui_h) cpp = s.sources[0] ui = None if cpp.sources != None and len(cpp.sources) > 0: - src_src_suffix = SCons.Util.splitext(str(cpp.sources[0]))[1] + src_src_suffix = splitext(str(cpp.sources[0]))[1] if src_src_suffix == env.subst('$QT_UISUFFIX'): ui = cpp.sources[0] - src_prefix, src_suffix = SCons.Util.splitext(str(cpp.srcnode())) + src_prefix, src_suffix = splitext(str(cpp.srcnode())) h=None for h_ext in header_extensions: if os.path.exists(src_prefix + h_ext): - h = SCons.Node.FS.default_fs.File(prefix + h_ext) + h = FS.File(prefix + h_ext) if ui: # file built from .ui file -> build also header from .ui @@ -100,34 +102,38 @@ class _Automoc: ui_h_suff = env.subst('$QT_UIHSUFFIX') if os.path.exists(src_prefix + ui_h_suff): # if a .ui.h file exists, we need to specify the dependecy ... - ui_h = SCons.Node.FS.default_fs.File(prefix + ui_h_suff) + ui_h = FS.File(prefix + ui_h_suff) env.Depends(cpp, ui_h) if (h and q_object_search.search(h.get_contents())) or ui: # h file with the Q_OBJECT macro found -> add moc_cpp dir,base = os.path.split(prefix) - src_ext = SCons.Util.splitext(str(h))[1] - moc_cpp = SCons.Node.FS.default_fs.File(os.path.join(dir, + src_ext = splitext(str(h))[1] + moc_cpp = FS.File(os.path.join(dir, env['QT_MOCNAMEGENERATOR'](base, src_ext, env))) objBuilder = getattr(env, self.objBuilderName) - moc_o = objBuilder(source=moc_cpp) - out_sources.append(moc_o) - objBuilder(moc_o, moc_cpp) + if env.get('QT_AUTOBUILD_MOC_SOURCES'): + moc_o = objBuilder(source=moc_cpp) + out_sources.append(moc_o) + 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()): # cpp file with Q_OBJECT macro found -> add moc # (to be included in cpp) dir,base = os.path.split(prefix) - src_ext = SCons.Util.splitext(str(cpp))[1] - moc = SCons.Node.FS.default_fs.File(os.path.join(dir, + src_ext = splitext(str(cpp))[1] + moc = FS.File(os.path.join(dir, env['QT_MOCNAMEGENERATOR'](base, src_ext, env))) self.mocFromCppBld(env, moc, cpp) env.Ignore(moc, moc) moc.source_scanner = SCons.Defaults.CScan os.chdir(old_os_cwd) - SCons.Node.FS.default_fs.chdir(old_fs_cwd) - return (target, out_sources) + FS.chdir(old_fs_cwd) + if env.get('QT_AUTOBUILD_MOC_SOURCES'): + return (target, out_sources) + else: + return (target, source) def _detect(env): """Not really safe, but fast method to detect the QT library""" @@ -142,15 +148,18 @@ def _detect(env): QTDIR = os.path.dirname(os.path.dirname(moc)) else: QTDIR = None - env['QTDIR'] = QTDIR return QTDIR def generate(env): """Add Builders and construction variables for qt to an Environment.""" - _detect(env) - env['QT_MOC'] = os.path.join('$QTDIR','bin','moc') - env['QT_UIC'] = os.path.join('$QTDIR','bin','uic') - env['QT_LIB'] = 'qt' + + env['QTDIR'] = _detect(env) + env['QT_MOC'] = os.path.join('$QTDIR','bin','moc') + env['QT_UIC'] = os.path.join('$QTDIR','bin','uic') + env['QT_LIB'] = 'qt' + + # Should moc-generated sources be automatically compiled? + env['QT_AUTOBUILD_MOC_SOURCES'] = 1 # Some QT specific flags. I don't expect someone wants to # manipulate those ... @@ -164,7 +173,7 @@ def generate(env): env['QT_UISUFFIX'] = '.ui' env['QT_UIHSUFFIX'] = '.ui.h' env['QT_MOCNAMEGENERATOR'] = \ - lambda x, src_suffix, env: 'moc_' + x + env.get('CXXFILESUFFIX','.cc') + lambda x, src_suffix, env: 'moc_' + x + env.get('CXXFILESUFFIX','.cc') # Commands for the qt support ... # command to generate implementation (cpp) file from a .ui file diff --git a/test/QT.py b/test/QT.py index 8fe6e2a5..af4c4af8 100644 --- a/test/QT.py +++ b/test/QT.py @@ -148,7 +148,8 @@ Export("env") SConscript( sconscript ) """ % (QT, QT_LIB, QT_MOC, QT_UIC)) -test.subdir( 'work1', 'work2', 'work3', 'work4', 'work5', 'work6', 'work7' ) +test.subdir( 'work1', 'work2', 'work3', 'work4', + 'work5', 'work6', 'work7', 'work8' ) ############################################################################## # 1. create a moc file from a header file. @@ -527,5 +528,44 @@ int main() { else: print "Could not find QT, skipping test(s)." +############################################################################## +# 8. test the $QT_AUTOBUUILD_MOC_SOURCES variable + +aaa_dll = dll_ + 'aaa' + _dll +moc = 'moc_aaa.cc' + +createSConstruct(test, ['work8', 'SConstruct']) + +test.write(['work8', 'SConscript'], """ +Import("env") +env = env.Copy(QT_AUTOBUILD_MOC_SOURCES = 0) +env.SharedLibrary(target = 'aaa', source = ['aaa.ui', 'useit.cpp']) +""") + +test.write(['work8', 'aaa.ui'], r""" +void aaa(void) +""") + +test.write(['work8', 'useit.cpp'], r""" +#include "aaa.h" +void useit() { + aaa(); +} +""") + +test.run(chdir='work8', arguments = aaa_dll) + +test.must_not_exist(test.workpath('work8', moc)) + +test.write(['work8', 'SConscript'], """ +Import("env") +env = env.Copy(QT_AUTOBUILD_MOC_SOURCES = 1) +env.SharedLibrary(target = 'aaa', source = ['aaa.ui', 'useit.cpp']) +""") + +test.run(chdir='work8', arguments = aaa_dll) + +test.must_exist(test.workpath('work8', moc)) + test.pass_test()