Configuring a project

The function configure is used for four main purposes:

Indicating configuration sub folders

The function configure may reference configure functions in wscript present in sub folders, for example:

.
`-- wscript
|-- src
|   `-- wscript
			

The top-level wscript may indicate there is a configure function to execute in src/wscript using:

def configure(conf):
	conf.sub_config('src')
			

As a matter of fact, any wscript file may indicate a sub-configuration function to execute.

Storing and loading configuration parameters

srcdir = '.'
blddir = 'build'

def set_options(opt):
    pass
def configure(conf):
    conf.env['test'] = 'hello'
def build(bld):
    print(bld.env['test'])
				

The execution will result in:

$ waf configure
Configuration finished successfully (00:00:00); project is now ready to build.
$ waf
hello
				

This configuration modifications (on conf.env) are persistent, they are reused during the build (using bld.env). Let us look at the files produced:

.
|-- build
|   |-- c4che
|   |   |-- build.config.py
|   |   `-- default.cache.py
|   |-- config.log
|   `-- default
`-- wscript
				

The contents of the file default.cache.py is reproduced here:

$ cat build/c4che/default.cache.py
PREFIX = '/usr/local'
test = 'hello'
				

Using configuration helpers

Setting up many parameters manually is a tedious process, and Waf provide configuration helpers to automate the process of finding the settings. For example:

srcdir = '.'
blddir = 'build'

def set_options(opt):
    pass
def configure(conf):
    conf.find_program('tar', var='TAR')
def build(bld):
    print(bld.env['TAR'])
				

Will produce the following results:

$ waf configure
Checking for program tar                 : ok /bin/tar
Configuration finished successfully (00:00:00); project is now ready to build.
$ waf
/bin/tar
Compilation finished successfully (00:00:00)
				

Loading Waf tools

The Waf tools are extensions that provide task types (for languages such as c, java, ...), more configuration tests, and command-line options. To make certain that the Waf tools used during the configuration are also available during the build, they are stored during the configuration and loaded automatically afterwards. Here is an example:

def configure(conf):
	conf.check_tool('gcc')
				

By default, tools are loaded from the Waf library, but it is possible to load tools from the source directory using the following:

def configure(conf):
	conf.check_tool('my_tool', tooldir='.')