Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do an out of source build with scons?

I have been using cmake to build my projects out of source, which is really convenient as you avoid polluting your source directory with unnecessary files.

Assuming the CMakeLists.txt is in the current directory, this could be done as follows:

mkdir build
cd build
cmake ..
make

How can I do the same in scons?

like image 280
D R Avatar asked Nov 19 '09 09:11

D R


People also ask

What is SCons build?

SCons is a computer software build tool that automatically analyzes source code file dependencies and operating system adaptation requirements from a software project description and generates final binary executables for installation on the target operating system platform.

What is a build directory?

The build directory is where Qt will build your project. The working / current directory is the directory the application is currently working in.

What is SCons Linux?

SCons is an Open Source software construction tool. Think of SCons as an improved, cross-platform substitute for the classic Make utility with integrated functionality similar to autoconf/automake and compiler caches such as ccache. In short, SCons is an easier, more reliable and faster way to build software.


1 Answers

In your SConstruct file, you use a variant dir:

SConscript("main.scons", variant_dir="build", duplicate=0)

Then in main.scons you set up everything as usual:

env = Environment()
env.Program(target='foo', source=Split('foo.c bar.c'))

It's possible to do this without hardcoding the variant dir into the SConstruct by (ab)using repositories, but that approach has its bugs. For the record, you would run the above as follows to build in another directory:

mkdir mybuild
cd mybuild
scons -Y .. -f ../main.scons

The easiest and most workable is to just use variant_dir. You then run this as usual from the top level source directory. All the build artefacts get produced in the build sub directory.

In response to JesperE's comment, here is how you could write the top level SConstruct to add an optionally named build directory:

AddOption('--build', default='build')
SConscript("main.scons", variant_dir=GetOption('build'), duplicate=0)

Then you would call this from the command line as follows, to create a build directory called "baz":

$ scons --build=baz
like image 136
richq Avatar answered Oct 08 '22 17:10

richq