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?
In your
SConstruct
file, you use a variant dir:Then in
main.scons
you set up everything as usual: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:
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 thebuild
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:
Then you would call this from the command line as follows, to create a build directory called "baz":