Writing KDE and Qt applications easily with scons
This article describes how to use scons for quick creation of KDE-based applications
Why do I use scons? Eh... New KDE uses it too
check bksys and you'll see the power of scons.
Before I start, few wards about scons as a build system. scons is a replacement for aucoconf/automake/qmake/make. It is based on Python but do don't really need to know Python. At least while you're using my scripts 
The SConstruct file is something like Makefile. It starts from this lines:
kdelib = ['kdeui', 'kdecore']
import os
import sys
If your application uses some other libs besides kdeui and kdecore you have to declare them at the first line. Next two lines import some Python functions that we will use later.
To get information about KDE paths (KDE include and lib directories) we use kde-config application (from kdelibs):
# Checking for kde-config
whichkdeconf = os.system('which kde-config &> /dev/null')
if whichkdeconf != 0:
print 'kde-config NOT found. Possibly KDE bin directory is not in $PATH'
print 'Please update your $PATH and run scons again'
sys.exit(1)
If kde-config was found we get --prefix and --libsuffix options:
# Get KDE base dir (we assume, kde-config is installed and is somewhere in the $PATH)
kdebase = os.popen('kde-config --prefix').read().strip()
kdelibsuffix = os.popen('kde-config --libsuffix').read().strip()
We have two configuration flags: RELEASE and DEBUG. RELEASE appends -O2 to CFLAGS, DEBUG appends -g and removes -O2 if set by RELEASE:
# Parse options
opts = Options("options.py", ARGUMENTS)
opts.AddOptions(
BoolOption("DEBUG", "Set to build for debug", 0),
BoolOption("RELEASE", "Set to build for release, default. Ignored if DEBUG is set", 1),
)
Both flags accept 1 or 0 values.
Here's the rest of the file:
# Init environment
BuildDir('build', 'src', duplicate=0)
env = Environment(tools=['default','qt'])
Help(opts.GenerateHelpText(env))
# Set environment flags
debug = ARGUMENTS.get('DEBUG', 0)
release = ARGUMENTS.get('RELEASE', 1)
if int(debug) == 1:
env.Append(CCFLAGS = '-g')
if int(debug) == 0 and int(release) == 1:
env.Append(CCFLAGS = '-O2')
env.Append(CPPPATH=[kdebase + '/include', '.'])
env.Append(LIBS=kdelib)
env.Append(LIBPATH= kdebase + '/lib' + kdelibsuffix + '/')
# Build all in src
SConscript('build/SConscript', exports='env')
This is scons stuff that sets output directory to build, sets required flags in CCFLAGS, adds KDE-related stuff and build all source files according to the build rules from src/SConscript. This file is rather small and it looks like this one:
Import('*')
sources = Split("""
DialogConfigBase.ui
HistoryBrowserBase.ui
trayicon.cpp
dialogconfig.cpp
kdelognotifier.cpp
historybrowser.cpp
notificationpopup.cpp
filesource.cpp
""")
env.Program('../bin/kdelognotifier', sources)
You have to define all *.ui and *.cpp files in sources and set output binary name in the last line (in this example resulting binary is located in bin/kdelognotifier).
You can check downloads section for kdelognotifier source code that is based on this scons configuration files.







