A nice page on SCons syntax: http://www.scons.org/wiki/SConsCrashCourse
To build a C++ program with my favorite libraries, put this in a file,
SConstruct
:
import os
env = Environment(ENV = {'PATH':os.environ['PATH']} )
env.ParseConfig('root-config --cflags')
env.ParseConfig('root-config --libs')
env.MergeFlags('-fPIC -O2')
#Checking for things to exist (~autoConf)
if not env.GetOption("clean"):
conf = Configure(env)
if not conf.CheckCXX():
print("Error: C++ Compiler Broken")
Exit(1)
if not conf.CheckSHCXX():
print("Error: C++ Compiler Broken")
Exit(1)
if not conf.CheckLibWithHeader("Hist","TH1F.h","c++","TH1F h;"):
print("Error: ROOT libs must be installed!")
Exit(1)
if not conf.CheckLibWithHeader("EG","TGenerator.h","c++","TGenerator g;"):
print("Error: ROOT lib libEG.a must be installed!")
Exit(1)
if not conf.CheckLibWithHeader("boost_regex",["boost/regex.h","boost/regex.hpp"],"c++",'boost::regex e("abcd");',True):
print("Error: boost regex must be installed!")
Exit(1)
conf.CheckLibWithHeader("armadillo","armadillo","c++",'arma::mat A;',True)
env = conf.Finish()
includes = []
libpath = []
libs = []
# For RooFit and RooStats
#env.MergeFlags('-lMinuit -lRooFit -lRooFitCore -lFoam -lMathMore')
#env.MergeFlags('-lRooStats')
env.Append(CPPPATH=includes)
env.Append(LIBPATH=libpath)
env.Append(LIBS=libs)
runSources=["hello.cc"]
env.Program(target="run", source=runSources)
Make sure that the autoconf-like stuff comes before the declaration of any build targets (or inclusion of Sconscripts with build targets), or else the script will try to build them all before doing your test.