Integrating scons into IDEs

IDEs can often parse the output of build tools like scons which output the warnings and errors from the compiler etc as if the IDE had called the compiler itself. By using scons with your favourite IDE the best of both worlds can be obtained.

Below are instructions to get started using scons with some particular IDEs.

Visual Studio .NET 2003 / Visual Studio 2005 (Windows)

  1. Launch Visual Studio with the /useenv command line switch otherwise it won't be able to find scons.
  2. File->New Project General->Make File Project

  3. Save the project into the same directory as your SConstruct file.
  4. In the project settings, just add "scons" as the build command , and "scons -c" as the clean command and configuration is done.
  5. You should now be able to build using scons by using the build menu from visual studio.

Note: VS2005 seems to need absolute paths to filenames for the click-on-errors integration to work. --björnen

Xcode (Mac OS X)

  1. File->New Project, choose "External Build System"

  2. Save the project into the same directory as your SConstruct file.
  3. In Groups and Files -> Targets, double click the target that was automatically created.

  4. In the Build Tool field, put the full path to scons - like "/System/Library/Frameworks/Python.framework/Versions/2.3/bin/scons"
  5. You should now be able to build using the Build command from Xcode
  6. Right click "Executables" and choose "Add new custom executable" and point it to the executable you are building and then you can debug using Xcode.
  7. Use Debug -> Breakpoints menu to add a symbolic breakpoint at main() - just type main where it says 'Double click for Symbol' - if you don't add this break point none of the breakpoints set in the editors will work, because gdb doesn't have the symbol information until you start debugging (Jim Ingham suggests turning off "Lazy Symbol Loading" in Debug Preferences.)

Eclipse

There is an Eclipse plugin available for SCons, though its documentation is scarce to nonexistent.

Pros: It offers integrated support for building doxygen documentation and cppunit tests.

Cons: It imposes a build tree hierarchy which may work for smaller projects, but would be cumbersome for larger projects.

KDevelop

See SCons Setup and Custom Project at the KDevelop FAQ. Here's a quick copy of these two topics.

How can I set up a project with SCons?

SCons is a software construction tool. KDevelop (as of version 3.2.2) does not support SCons projects directly. However, it is possible to set up a project very simply using SCons by writing a "stub" Makefile and using the "Custom Makefiles" project type. An example of a simple stub Makefile is the following (note that lines after target names should be indented with tabs, not spaces):

This will enable the Build Project and Clean Project actions to work.

How to create a simple project with just a Makefile (also known as Custom Project) ?

Create a Custom Project. There is no direct way to create a custom project (i.e. a project which does use its own makefiles). Use Project->Import Existing Project instead. Remember to set the appropriate Project Type, labeled by an additional (Custom Makefiles) in the dialog. Use Project Options Early. Whenever you start a new project do not forget to set the Project->Project Options... to your needs.

Working within Emacs and XEmacs

First of all, you are going to want PythonMode if you don't have it already. If you are running on a system with a package manager, you might wish to look there first. On my Fedora system, the base XEmacs install was missing many useful accessories. I achieved a more complete installation with the command:

For Emacs, it is suggested to add the following to your .emacs files, to enable Python mode for SConstruct and SConscript files.

 (setq auto-mode-alist
      (cons '("SConstruct" . python-mode) auto-mode-alist))
 (setq auto-mode-alist
      (cons '("SConscript" . python-mode) auto-mode-alist))

For XEmacs, a different reference suggests an alternate syntax added to your ~/.xemacs/init.el:

 (add-to-list 'auto-mode-alist '("SConstruct" . python-mode))
 (add-to-list 'auto-mode-alist '("SConscript" . python-mode))

If you wish to invoke a compilation via SCons from within Emacs/XEmacs, there are two ways to go about it. You can add a simple Makefile stub to your project directory with a rule to immediately delegate to SCons instead. The simplest example is just:

Make certain the second line begins with a tab character. make and gmake have a hangup about that. This is also helpful for others to invoke your project build who aren't used to invoking SCons directly. Emacs/Xemacs will normally invoke make or gmake as the default compile command, and this simple Makefile will then transfer the build to SCons.

You can also change your Emacs/XEmacs default compile command by adding the following to your init file:

This setting might affect other projects you compile normally with make or gmake, but if you compile everything via SCons, it eliminates the clutter and indirection of the Makefile stubs. If you use Makefile stubs, you might discover you need a separate Makefile stub in each project subdirectory where you compile code.

Compilation mode and error navigation

Compilation mode and its usage is documented as part of the GNU Emacs Manual.

If you employ a custom or unusual build tool as part of your build process, you might find your Emacs/XEmacs is unable to navigate the error text in the *compilation* buffer. To fix this, you can provide a custom regular expression for the variable compilation-error-regexp-alist.

This is a fairly advanced undertaking. The page (efaq)Compiler error messages can get you started. It suggests cribbing something similar to what you require from the Emacs source for compile.el, which contains many elaborations. On my Fedora system, this file is located at /usr/share/xemacs/xemacs-packages/lisp/xemacs-base/compile.el, but only after I manually installed the package sources (.el files) as described above. If you only find compile.elc, you have the package installed, but not the package sources.

Hi MaxEnt -- here's what I use, it's much simpler. You'll need a recent emacs (more recent than 21.1). It just processes the filenames to remove the build dirs.

;;; SCons builds into a 'build' subdir, but we want to find the errors
;;; in the regular source dir.  So we remove build/XXX/YYY/{dbg,final}/ from the
;;; filenames.
(defun process-error-filename (filename)
  (let ((case-fold-search t))
    (setq f (replace-regexp-in-string
             "[Ss]?[Bb]uild[\\/].*\\(final\\|dbg\\)[^\\/]*[\\/]" "" filename))
    (cond ((file-exists-p f)
           f)
          (t filename))))

(setq compilation-parse-errors-filename-function 'process-error-filename)

-- GaryOberbrunner

IDEIntegration (last edited 2008-03-12 02:46:58 by localhost)