c_config

C/C++/D configuration helpers

waflib.Tools.c_config.WAF_CONFIG_H

default name for the config.h file

waflib.Tools.c_config.SNIP_FUNCTION

Code template for checking for functions

waflib.Tools.c_config.SNIP_TYPE

Code template for checking for types

waflib.Tools.c_config.parse_flags(self, line, uselib, env=None, force_static=False)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

Parse the flags from the input lines, and add them to the relevant use variables:

def configure(conf):
        conf.parse_flags('-O3', uselib_store='FOO')
        # conf.env.CXXFLAGS_FOO = ['-O3']
        # conf.env.CFLAGS_FOO = ['-O3']
Parameters:
  • line (string) – flags
  • uselib (string) – where to add the flags
  • env (waflib.ConfigSet.ConfigSet) – config set or conf.env by default
waflib.Tools.c_config.ret_msg(self, f, kw)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

waflib.Tools.c_config.validate_cfg(self, kw)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

Search for the program pkg-config if missing, and validate the parameters to pass to waflib.Tools.c_config.exec_cfg().

Parameters:
  • path (list of string) – the -config program to use (default is pkg-config)
  • msg (string) – message to display to describe the test executed
  • okmsg (string) – message to display when the test is successful
  • errmsg (string) – message to display in case of error
waflib.Tools.c_config.exec_cfg(self, kw)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

Execute the program pkg-config:

  • if atleast_pkgconfig_version is given, check that pkg-config has the version n and return
  • if modversion is given, then return the module version
  • else, execute the -config program with the args and variables given, and set the flags on the conf.env.FLAGS_name variable
Parameters:
  • atleast_pkgconfig_version (string) – minimum pkg-config version to use (disable other tests)
  • package (string) – package name, for example gtk+-2.0
  • uselib_store (string) – if the test is successful, define HAVE_*name*. It is also used to define conf.env.FLAGS_name variables.
  • modversion (string) – if provided, return the version of the given module and define name_VERSION
  • args (list of string) – arguments to give to package when retrieving flags
  • variables (list of string) – return the values of particular variables
  • define_variable (dict(string: string)) – additional variables to define (also in conf.env.PKG_CONFIG_DEFINES)
waflib.Tools.c_config.check_cfg(self, *k, **kw)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

Check for configuration flags using a -config-like program (pkg-config, sdl-config, etc). Encapsulate the calls to waflib.Tools.c_config.validate_cfg() and waflib.Tools.c_config.exec_cfg()

A few examples:

def configure(conf):
        conf.load('compiler_c')
        conf.check_cfg(package='glib-2.0', args='--libs --cflags')
        conf.check_cfg(package='glib-2.0', uselib_store='GLIB', atleast_version='2.10.0',
                args='--cflags --libs')
        conf.check_cfg(package='pango')
        conf.check_cfg(package='pango', uselib_store='MYPANGO', args=['--cflags', '--libs'])
        conf.check_cfg(package='pango',
                args=['pango >= 0.1.0', 'pango < 9.9.9', '--cflags', '--libs'],
                msg="Checking for 'pango 0.1.0'")
        conf.check_cfg(path='sdl-config', args='--cflags --libs', package='', uselib_store='SDL')
        conf.check_cfg(path='mpicc', args='--showme:compile --showme:link',
                package='', uselib_store='OPEN_MPI', mandatory=False)
waflib.Tools.c_config.validate_c(self, kw)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

pre-check the parameters that will be given to run_c_code

Parameters:
  • env (waflib.ConfigSet.ConfigSet) – an optional environment (modified -> provide a copy)
  • compiler (string) – c or cxx (tries to guess what is best)
  • type (binary to create) – cprogram, cshlib, cstlib - not required if features are given directly
  • feature (list of string) – desired features for the task generator that will execute the test, for example cxx cxxstlib
  • fragment (string) – provide a piece of code for the test (default is to let the system create one)
  • uselib_store (string) – define variables after the test is executed (IMPORTANT!)
  • use (list of string) – parameters to use for building (just like the normal use keyword)
  • define_name (string) – define to set when the check is over
  • execute (bool) – execute the resulting binary
  • define_ret (bool) – if execute is set to True, use the execution output in both the define and the return value
  • header_name (string) – check for a particular header
  • auto_add_header_name (bool) – if header_name was set, add the headers in env.INCKEYS so the next tests will include these headers
waflib.Tools.c_config.post_check(self, *k, **kw)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext Set the variables after a test executed in waflib.Tools.c_config.check() was run successfully

waflib.Tools.c_config.check(self, *k, **kw)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

Perform a configuration test by calling waflib.Tools.c_config.run_c_code(). For the complete list of parameters, see waflib.Tools.c_config.validate_c(). To force a specific compiler, prefer the methods waflib.Tools.c_config.check_cxx() or waflib.Tools.c_config.check_cc()

class waflib.Tools.c_config.test_exec(*k, **kw)[source]

Bases: waflib.Task.Task

A task for executing a programs after they are built. See waflib.Tools.c_config.test_exec_fun().

waflib.Tools.c_config.test_exec_fun(self)[source]

Task generator method

The feature test_exec is used to create a task that will to execute the binary created (link task output) during the build. The exit status will be set on the build context, so only one program may have the feature test_exec. This is used by configuration tests:

def configure(conf):
        conf.check(execute=True)
Feature :test_exec
waflib.Tools.c_config.run_c_code(self, *k, **kw)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

Create a temporary build context to execute a build. A reference to that build context is kept on self.test_bld for debugging purposes, and you should not rely on it too much (read the note on the cache below). The parameters given in the arguments to this function are passed as arguments for a single task generator created in the build. Only three parameters are obligatory:

Parameters:
  • features (list of string) – features to pass to a task generator created in the build
  • compile_filename (string) – file to create for the compilation (default: test.c)
  • code (string) – code to write in the filename to compile

Though this function returns 0 by default, the build may set an attribute named retval on the build context object to return a particular value. See waflib.Tools.c_config.test_exec_fun() for example.

This function also provides a limited cache. To use it, provide the following option:

def options(opt):
        opt.add_option('--confcache', dest='confcache', default=0,
                action='count', help='Use a configuration cache')

And execute the configuration with the following command-line:

$ waf configure --confcache
waflib.Tools.c_config.check_cxx(self, *k, **kw)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

Same as waflib.Tools.c_config.check() but default to the c++ programming language

waflib.Tools.c_config.check_cc(self, *k, **kw)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

Same as waflib.Tools.c_config.check() but default to the c programming language

waflib.Tools.c_config.define(self, key, val, quote=True)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

Store a single define and its state into conf.env.DEFINES

Parameters:
  • key (string) – define name
  • val (int or string) – value
  • quote (bool) – enclose strings in quotes (yes by default)
waflib.Tools.c_config.undefine(self, key)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

Remove a define from conf.env.DEFINES

Parameters:key (string) – define name
waflib.Tools.c_config.define_cond(self, key, val)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

Conditionally define a name:

def configure(conf):
        conf.define_cond('A', True)
        # equivalent to:
        # if val: conf.define('A', 1)
        # else: conf.undefine('A')
Parameters:
  • key (string) – define name
  • val (int or string) – value
waflib.Tools.c_config.is_defined(self, key)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

Parameters:key (string) – define name
Returns:True if the define is set
Return type:bool
waflib.Tools.c_config.get_define(self, key)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

Parameters:key (string) – define name
Returns:the value of a previously stored define or None if it is not set
waflib.Tools.c_config.have_define(self, key)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

Parameters:key (string) – define name
Returns:the input key prefixed by HAVE_ and substitute any invalid characters.
Return type:string
waflib.Tools.c_config.write_config_header(self, configfile='', guard='', top=False, env=None, defines=True, headers=False, remove=True)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

Write a configuration header containing defines and includes:

def configure(cnf):
        cnf.define('A', 1)
        cnf.write_config_header('config.h')
Parameters:
  • configfile (string) – relative path to the file to create
  • env (waflib.ConfigSet.ConfigSet) – config set to read the definitions from (default is conf.env)
  • top (bool) – write the configuration header from the build directory (default is from the current path)
  • defines (bool) – add the defines (yes by default)
  • headers (bool) – add #include in the file
  • remove (bool) – remove the defines after they are added (yes by default)
waflib.Tools.c_config.get_config_header(self, defines=True, headers=False)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

Create the contents of a config.h file from the defines and includes set in conf.env.define_key / conf.env.include_key. No include guards are added.

Parameters:
  • defines (bool) – write the defines values
  • headers (bool) – write the headers
Returns:

the contents of a config.h file

Return type:

string

waflib.Tools.c_config.cc_add_flags(conf)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

Read the CFLAGS/CPPFLAGS from os.environ and add to conf.env.CFLAGS

waflib.Tools.c_config.cxx_add_flags(conf)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

Read the CXXFLAGS/CPPFLAGS and add to conf.env.CXXFLAGS

Configuration Method bound to waflib.Configure.ConfigurationContext

Read the LINKFLAGS/LDFLAGS and add to conf.env.LDFLAGS

waflib.Tools.c_config.cc_load_tools(conf)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

Load the c tool

waflib.Tools.c_config.cxx_load_tools(conf)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

Load the cxx tool

waflib.Tools.c_config.get_cc_version(conf, cc, gcc=False, icc=False)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

Run the preprocessor to determine the compiler version

The variables CC_VERSION, DEST_OS, DEST_BINFMT and DEST_CPU will be set in conf.env

waflib.Tools.c_config.get_xlc_version(conf, cc)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext Get the compiler version

waflib.Tools.c_config.add_as_needed(self)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

Add --as-needed to the LINKFLAGS

class waflib.Tools.c_config.cfgtask(*k, **kw)[source]

Bases: waflib.Task.TaskBase

A task that executes configuration tests make sure that the checks write to conf.env in a thread-safe manner

for the moment it only executes conf.check

waflib.Tools.c_config.conf(f)

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
waflib.Tools.c_config.feature(*k)

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

from waflib.Task import feature
@feature('myfeature')
def myfunction(self):
        print('that is my feature!')
def build(bld):
        bld(features='myfeature')
Parameters:k (list of string) – feature names
waflib.Tools.c_config.before_method(*k)

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

from waflib.TaskGen import feature, before
@feature('myfeature')
@before_method('fun2')
def fun1(self):
        print('feature 1!')
@feature('myfeature')
def fun2(self):
        print('feature 2!')
def build(bld):
        bld(features='myfeature')
Parameters:k (list of string) – method names
waflib.Tools.c_config.after_method(*k)

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

from waflib.TaskGen import feature, after
@feature('myfeature')
@after_method('fun2')
def fun1(self):
        print('feature 1!')
@feature('myfeature')
def fun2(self):
        print('feature 2!')
def build(bld):
        bld(features='myfeature')
Parameters:k (list of string) – method names
waflib.Tools.c_config.multicheck(self, *k, **kw)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

Use tuples to perform parallel configuration tests

Features defined in this module:

Previous topic

cxx

Next topic

c_osx

This Page