Adding custom command-line options

The function set_options is used for three main purposes:

Adding options directly

Waf uses the optparse module from Python for adding command-line options, for example:

def set_options(opt):
	opt.add_option('--exe', action='store_true', default=False,
		help='Execute the program after it is compiled')
def shutdown():
	import Options
	print(Options.options.exe)
			

The command-line options can be displayed afterwards:

$ waf --help
Usage: waf [options] [commands ...]

* Main commands: configure build install clean dist distclean uninstall distcheck
* Example: ./waf build -j4

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -j JOBS, --jobs=JOBS  amount of parallel jobs [Default: 1]
  -f, --force           force file installation
  -k, --keep            keep running happily on independent task groups
  -p, --progress        -p: progress bar; -pp: ide output
  -v, --verbose         verbosity level -v -vv or -vvv [Default: 0]
  --destdir=DESTDIR     installation root [Default: '']
  --nocache             compile everything, even if WAFCACHE is set
  --zones=ZONES         debugging zones (task_gen, deps, tasks, etc)
  --targets=COMPILE_TARGETS
                        compile the targets given only [targets in CSV format, e.g. "target1,target2"]
  --exe                 Execute the program after it is compiled
			

and used like this:

$ waf --exe
True
$ waf
False
			

Adding options from wscript files located in sub folders

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

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

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

def set_options(opt):
	opt.sub_options('src')
			

Adding options from Waf tools

Waf tool options are not added by default because the excess of command-line options is annoying. Here is an example for adding the command-line options defined from a Waf tools named compiler_cxx

def set_options(opt):
	opt.tool_options('compiler_cxx')