Please note:The SCons wiki is now restored from the attack in March 2013. All old passwords have been invalidated. Please reset your password if you have an account. If you note missing pages, please report them to webmaster@scons.org. Also, new account creation is currently disabled due to an ongoing spam flood (2013/08/27).

SCons, from QMake's Point of View

Tips for New SCons Users

Note there's not much point adding your QT includes in there, as you will probably want to make-clean and recompile the whole project anyway. Use this technique for that little binary-search library that you occasionally fix bugs for, or update via CVS. Similarly, libraries are found using the same algorithm as the linker uses, using LIBPATH and LIBS. So make sure your libs are findable that way and scons will pick up the dependencies automatically.

Making your .uic files depend on your custom plugin

Please note that this should be in a different page but I had problems editing the new page after linking to it.

(NOTE: This inforomation only applies for qt3. Qt4 .ui files do not need to load the plugin to generate the correct .h file.)

If you are using a custom plugin while building your projects and you use the plugin when generating the form code with uic, you need to explicitly configure the dependiences so the plugin is built before the uics are processed. Since the plugin is implicitly used by uic (uic loads the plugin as a shared library), scons cannot know that the rest of the project depends on the plugin being up to date. (The plugin should always be depended on so you can make sure the autogenerated ui code is correct and will compile.)

Say your current GUIProject SConscript looks like this:

   1 TARGET = 'GUIProject'
   2 SOURCES = ['GUI.cpp']
   3 UICS = ['GUIUI.ui']
   4  
   5 # Build the library
   6 ret = env.Program(target = TARGET, source = SOURCES+UICS)
   7 # Return the result of the compilation so another SConscript can use it. Useful when building a library
   8 Return('ret')

and you want to make an explicit dependency of the GUIProject on plugin, so you'll need to tell scons about the dependency:

   1 TARGET = 'GUIProject'
   2 SOURCES = ['GUI.cpp']
   3 UICS = ['GUIUI.ui']
   4  
   5 # Build the plugin
   6 plugin = env.SConscript('../plugin/SConscript', exports = 'env')
   7 
   8 # Generate code and header files from ui files
   9 # and make the uic_XX.cpp files depend on the plugin
  10 uic_sources = []
  11 for ui in UICS:
  12         (header, uicCode, mocCode) = env.Uic(ui)
  13         # NOTE: inorder to be safe, all of the generated files depend on the plugin for the plugin to be generated before uic generation occurs. Maybe only the header needs to depend on the plugin... Anyone??
  14         env.Depends(header, plugin)
  15         env.Depends(uicCode, plugin)            
  16         env.Depends(mocCode, plugin)
  17         uic_sources.append(mocCode)
  18         uic_sources.append(uicCode)
  19 
  20 # Build the library
  21 ret = env.Program(target = TARGET, source = SOURCES+uic_sources)
  22 # Return the result of the compilation so another SConscript can use it. Useful when building a library
  23 Return('ret')

Now the only problem is that uic needs to know the plugin's path so it can load it. This is solved by using an undocumented commandline option in uic '-L'. So the final SConscript looks like:

   1 TARGET = 'GUIProject'
   2 SOURCES = ['GUI.cpp']
   3 UICS = ['GUIUI.ui']
   4  
   5 # Build the plugin
   6 plugin = env.SConscript('../plugin/SConscript', exports = 'env')
   7 path = str(plugin[0])
   8 # Get the path to the plugin
   9 path = path.split('/')
  10 path = "/".join(path[0:-1])
  11 # print "path = " + path
  12 # Extend the uic command so it uses the directory of the plugin as a search path
  13 libEnv.Append(QT_UIC = " -L " + path)
  14 
  15 # Generate code and header files from ui files
  16 # and make the uic_XX.cpp files depend on the plugin
  17 uic_sources = []
  18 for ui in UICS:
  19         (header, uicCode, mocCode) = env.Uic(ui)
  20         # NOTE: inorder to be safe, all of the generated files depend on the plugin for the plugin to be generated before uic generation occurs. Maybe only the header needs to depend on the plugin... Anyone??
  21         env.Depends(header, plugin)
  22         env.Depends(uicCode, plugin)            
  23         env.Depends(mocCode, plugin)
  24         uic_sources.append(mocCode)
  25         uic_sources.append(uicCode)
  26 
  27 # Build the library
  28 ret = env.Program(target = TARGET, source = SOURCES+uic_sources)
  29 # Return the result of the compilation so another SConscript can use it. Useful when building a library
  30 Return('ret')

Hopefully, someone can wrap this up into a builder eventually because it's pretty straight forward code.

FromQmakeToScons (last edited 2008-03-12 02:47:01 by localhost)