Classes and methods shared by tools providing support for C-like language such as C/C++/D/Assembly/Go (this support module is almost never used alone).


Mapping for features to waflib.ConfigSet.ConfigSet variables. See waflib.Tools.ccroot.propagate_uselib_vars().

waflib.Tools.ccroot.create_compiled_task(self, name, node)[source]

Task generator method

Create the compilation task: c, cxx, asm, etc. The output node is created automatically (object file with a typical .o extension). The task is appended to the list compiled_tasks which is then used by waflib.Tools.ccroot.apply_link()

  • name (string) – name of the task class
  • node (waflib.Node.Node) – the file to compile

The task created

Return type:


waflib.Tools.ccroot.to_incnodes(self, inlst)[source]

Task generator method

Task generator method provided to convert a list of string/nodes into a list of includes folders.

The paths are assumed to be relative to the task generator path, except if they begin by # in which case they are searched from the top-level directory (bld.srcnode). The folders are simply assumed to be existing.

The node objects in the list are returned in the output list. The strings are converted into node objects if possible. The node is searched from the source directory, and if a match is found, the equivalent build directory is created and added to the returned list too. When a folder cannot be found, it is ignored.

Parameters:inlst (space-delimited string or a list of string/nodes) – list of folders
Return type:list of waflib.Node.Node
Returns:list of include folders as nodes

Task generator method

Task generator method that processes the attribute includes:

tg = bld(features='includes', includes='.')

The folders only need to be relative to the current directory, the equivalent build directory is added automatically (for headers created in the build directory). This enables using a build directory or not (top == out).

This method will add a list of nodes read by waflib.Tools.ccroot.to_incnodes() in tg.env.INCPATHS, and the list of include paths in tg.env.INCLUDES.

Feature:c, cxx, d, asm, fc, includes

Bases: waflib.Task.Task

Base class for all link tasks. A task generator is supposed to have at most one link task bound in the attribute link_task. See waflib.Tools.ccroot.apply_link().

Inheritance diagram of waflib.Tools.ccroot.stlink_task, waflib.Tools.c.cprogram, waflib.Tools.c.cshlib, waflib.Tools.cxx.cxxstlib, waflib.Tools.cxx.cxxprogram, waflib.Tools.cxx.cxxshlib, waflib.Tools.d.dprogram, waflib.Tools.d.dshlib, waflib.Tools.d.dstlib, waflib.Tools.ccroot.fake_shlib, waflib.Tools.ccroot.fake_stlib, waflib.Tools.asm.asmprogram, waflib.Tools.asm.asmshlib, waflib.Tools.asm.asmstlib

Try to process link tasks as early as possible

Default installation path for the link task outputs, or None to disable

Default installation mode for the link task outputs

Process the target attribute to add the platform-specific prefix/suffix such as .so or .exe. The settings are retrieved from env.clsname_PATTERN

Create manifest files for VS-like compilers (msvc, ifort, …)

Bases: waflib.Tools.ccroot.link_task

Base for static link tasks, which use ar most of the time. The target is always removed before being written.

Default installation mode for the static libraries

Task generator method

This enables an optimization in the :py:func:wafilb.Tools.ccroot.processes_use: method that skips dependency and link flag optimizations for targets that generate static libraries (via the :py:class:Tools.ccroot.stlink_task task). The actual behavior is implemented in :py:func:wafilb.Tools.ccroot.processes_use: method so this feature only tells waf to enable the new behavior.


Task generator method

Collect the tasks stored in compiled_tasks (created by waflib.Tools.ccroot.create_compiled_task()), and use the outputs for a new instance of waflib.Tools.ccroot.link_task. The class to use is the first link task matching a name from the attribute features, for example:

def build(bld):
        tg = bld(features='cxx cxxprogram cprogram', source='main.c', target='app')

will create the task tg.link_task as a new instance of waflib.Tools.cxx.cxxprogram

Feature:c, cxx, d, fc, asm
waflib.Tools.ccroot.use_rec(self, name, **kw)[source]

Task generator method

Processes the use keyword recursively. This method is kind of private and only meant to be used from process_use


Task generator method

Process the use attribute which contains a list of task generator names:

def build(bld):
        bld.shlib(source='a.c', target='lib1')
        bld.program(source='main.c', target='app', use='lib1')

See waflib.Tools.ccroot.use_rec().

Feature:c, cxx, d, use, fc

Task generator method


waflib.Tools.ccroot.add_objects_from_tgen(self, tg)[source]

Task generator method

Add the objects from the depending compiled tasks as link task inputs.

Some objects are filtered: for instance, .pdb files are added to the compiled tasks but not to the link tasks (to avoid errors) PRIVATE INTERNAL USE ONLY


Task generator method

Returns:the uselib variables associated to the features attribute (see waflib.Tools.ccroot.USELIB_VARS)
Return type:list of string

Task generator method

Process uselib variables for adding flags. For example, the following target:

def build(bld):
        bld.env.AFLAGS_aaa = ['bar']
        from waflib.Tools.ccroot import USELIB_VARS
        USELIB_VARS['aaa'] = ['AFLAGS']

        tg = bld(features='aaa', aflags='test')

The aflags attribute will be processed and this method will set:

tg.env.AFLAGS = ['bar', 'test']
Feature:c, cxx, d, fc, javac, cs, uselib, asm

Task generator method

Handle dlls and their import libs on Windows-like systems.

A .dll.a file called import library is generated. It must be installed as it is required for linking the library.

Feature:cshlib, cxxshlib, fcshlib

Task generator method

Enforce version numbering on shared libraries. The valid version numbers must have either zero or two dots:

def build(bld):
        bld.shlib(source='a.c', target='foo', vnum='14.15.16')

In this example on Linux platform, is installed as, and the following symbolic links are created:


By default, the library will be assigned SONAME, effectively declaring ABI compatibility between all minor and patch releases for the major version of the library. When necessary, the compatibility can be explicitly defined using cnum parameter:

def build(bld):
bld.shlib(source=’a.c’, target=’foo’, vnum=‘14.15.16’, cnum=‘14.15’)

In this case, the assigned SONAME will be with ABI compatibility only between path releases for a specific major and minor version of the library.

On OS X platform, install-name parameter will follow the above logic for SONAME with exception that it also specifies an absolute path (based on install_path) of the library.

Feature:cshlib, cxxshlib, dshlib, fcshlib, vnum
class waflib.Tools.ccroot.vnum(*k, **kw)[source]

Bases: waflib.Task.Task

Create the symbolic links for a versioned shared library. Instances are created by waflib.Tools.ccroot.apply_vnum()

color = 'CYAN'
ext_in = ['.bin']
hcode = '\tdef run(self):\n\t\tfor x in self.outputs:\n\t\t\tpath = x.abspath()\n\t\t\ttry:\n\t\t\t\tos.remove(path)\n\t\t\texcept OSError:\n\t\t\t\tpass\n\n\t\t\ttry:\n\t\t\t\tos.symlink(self.inputs[0].name, path)\n\t\t\texcept OSError:\n\t\t\t\treturn 1\n'
class waflib.Tools.ccroot.fake_shlib(*k, **kw)[source]

Bases: waflib.Tools.ccroot.link_task

Task used for reading a system library and adding the dependency on it

class waflib.Tools.ccroot.fake_stlib(*k, **kw)[source]

Bases: waflib.Tools.ccroot.stlink_task

Task used for reading a system library and adding the dependency on it

hcode = '\tdef wrap(self):\n\t\ttry:\n\t\t\tos.remove(self.outputs[0].abspath())\n\t\texcept OSError:\n\t\t\tpass\n\t\treturn old(self)\n'
waflib.Tools.ccroot.read_shlib(self, name, paths=[], export_includes=[], export_defines=[])[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

Read a system shared library, enabling its use as a local library. Will trigger a rebuild if the file changes:

def build(bld):
        bld.program(source='main.c', use='m')
waflib.Tools.ccroot.read_stlib(self, name, paths=[], export_includes=[], export_defines=[])[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

Read a system static library, enabling a use as a local library. Will trigger a rebuild if the file changes.


Task generator method

Find the location of a foreign library. Used by waflib.Tools.ccroot.read_shlib and waflib.Tools.ccroot.read_stlib.


Decorator: attach new configuration functions to waflib.Build.BuildContext and waflib.Configure.ConfigurationContext. The methods bound will accept a parameter named ‘mandatory’ to disable the configuration errors:

def configure(conf):
        conf.find_program('abc', mandatory=False)
Parameters:f (function) – method to bind

Decorator that registers method as a task generator method. The function must accept a task generator as first parameter:

from waflib.TaskGen import taskgen_method
def mymethod(self):
Parameters:func (function) – task generator method to add
Return type:function

Decorator that registers a task generator method that will be executed when the object attribute feature contains the corresponding key(s):

from waflib.Task import feature
def myfunction(self):
        print('that is my feature!')
def build(bld):
Parameters:k (list of string) – feature names

Decorator that registera task generator method which will be executed before the functions of given name(s):

from waflib.TaskGen import feature, before
def fun1(self):
        print('feature 1!')
def fun2(self):
        print('feature 2!')
def build(bld):
Parameters:k (list of string) – method names

Decorator that registers a task generator method which will be executed after the functions of given name(s):

from waflib.TaskGen import feature, after
def fun1(self):
        print('feature 1!')
def fun2(self):
        print('feature 2!')
def build(bld):
Parameters:k (list of string) – method names

Decorator that registers a task generator method which will be invoked during the processing of source files for the extension given:

from waflib import Task
class mytask(Task):
        run_str = 'cp ${SRC} ${TGT}'
def create_maa_file(self, node):
        self.create_task('mytask', node, node.change_ext('.maa'))
def build(bld):

Task generator method

Puts object files in the task generator outputs

waflib.Tools.ccroot.read_object(self, obj)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

Read an object file, enabling injection in libs/programs. Will trigger a rebuild if the file changes.

Parameters:obj – object file path, as string or Node

Task generator method

On hp-ux, extend the libpaths and static library paths to absolute paths

Feature:cxxprogram, cprogram

Features defined in this module: