C/C++/D configuration helpers
default name for the config.h file
Code template for checking for functions
Code template for checking for types
Configuration Method bound to waflib.Configure.ConfigurationContext
Parses flags from the input lines, and adds them to the relevant use variables:
def configure(conf):
conf.parse_flags('-O3', 'FOO')
# conf.env.CXXFLAGS_FOO = ['-O3']
# conf.env.CFLAGS_FOO = ['-O3']
Parameters: |
|
---|
Configuration Method bound to waflib.Configure.ConfigurationContext
Searches for the program pkg-config if missing, and validates the parameters to pass to waflib.Tools.c_config.exec_cfg().
Parameters: |
|
---|
Configuration Method bound to waflib.Configure.ConfigurationContext
Executes pkg-config or other -config applications to colect configuration flags:
Parameters: |
|
---|
Configuration Method bound to waflib.Configure.ConfigurationContext
Checks for configuration flags using a -config-like program (pkg-config, sdl-config, etc). This wraps internal 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)
# variables
conf.check_cfg(package='gtk+-2.0', variables=['includedir', 'prefix'], uselib_store='FOO')
print(conf.env.FOO_includedir)
Build function that is used for running configuration tests with conf.check()
Configuration Method bound to waflib.Configure.ConfigurationContext
Pre-checks the parameters that will be given to waflib.Configure.run_build()
Parameters: |
|
---|
Configuration Method bound to waflib.Configure.ConfigurationContext
Sets the variables after a test executed in waflib.Tools.c_config.check() was run successfully
Configuration Method bound to waflib.Configure.ConfigurationContext
Performs a configuration test by calling waflib.Configure.run_build(). For the complete list of parameters, see waflib.Tools.c_config.validate_c(). To force a specific compiler, pass compiler='c' or compiler='cxx' to the list of arguments
Besides build targets, complete builds can be given though a build function. All files will be written to a temporary directory:
def build(bld):
lib_node = bld.srcnode.make_node('libdir/liblc1.c')
lib_node.parent.mkdir()
lib_node.write('#include <stdio.h>\nint lib_func(void) { FILE *f = fopen("foo", "r");}\n', 'w')
bld(features='c cshlib', source=[lib_node], linkflags=conf.env.EXTRA_LDFLAGS, target='liblc')
conf.check(build_fun=build, msg=msg)
Bases: waflib.Task.Task
A task that runs programs after they are built. See waflib.Tools.c_config.test_exec_fun().
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 |
---|
Configuration Method bound to waflib.Configure.ConfigurationContext
Runs a test with a task generator of the form:
conf.check(features='cxx cxxprogram', ...)
Configuration Method bound to waflib.Configure.ConfigurationContext
Runs a test with a task generator of the form:
conf.check(features='c cprogram', ...)
Configuration Method bound to waflib.Configure.ConfigurationContext
Sets a comment that will appear in the configuration header
Configuration Method bound to waflib.Configure.ConfigurationContext
Returns the comment associated to a define
Configuration Method bound to waflib.Configure.ConfigurationContext
Stores a single define and its state into conf.env.DEFINES. The value is cast to an integer (0/1).
Parameters: |
|
---|
Configuration Method bound to waflib.Configure.ConfigurationContext
Removes a global define from conf.env.DEFINES
Parameters: | key (string) – define name |
---|
Configuration Method bound to waflib.Configure.ConfigurationContext
Conditionally defines a name:
def configure(conf):
conf.define_cond('A', True)
# equivalent to:
# if val: conf.define('A', 1)
# else: conf.undefine('A')
Parameters: |
|
---|
Configuration Method bound to waflib.Configure.ConfigurationContext
Indicates whether a particular define is globally set in conf.env.DEFINES.
Parameters: | key (string) – define name |
---|---|
Returns: | True if the define is set |
Return type: | bool |
Configuration Method bound to waflib.Configure.ConfigurationContext
Returns the value of an existing define, or None if not found
Parameters: | key (string) – define name |
---|---|
Return type: | string |
Configuration Method bound to waflib.Configure.ConfigurationContext
Returns a variable suitable for command-line or header use by removing invalid characters and prefixing it with HAVE_
Parameters: | key (string) – define name |
---|---|
Returns: | the input key prefixed by HAVE_ and substitute any invalid characters. |
Return type: | string |
Configuration Method bound to waflib.Configure.ConfigurationContext
Writes a configuration header containing defines and includes:
def configure(cnf):
cnf.define('A', 1)
cnf.write_config_header('config.h')
This function only adds include guards (if necessary), consult waflib.Tools.c_config.get_config_header() for details on the body.
Parameters: |
|
---|
Configuration Method bound to waflib.Configure.ConfigurationContext
Creates 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.
A prelude will be added from the variable env.WAF_CONFIG_H_PRELUDE if provided. This can be used to insert complex macros or include guards:
def configure(conf):
conf.env.WAF_CONFIG_H_PRELUDE = '#include <unistd.h>\n'
conf.write_config_header('config.h')
Parameters: |
|
---|---|
Returns: | the contents of a config.h file |
Return type: | string |
Configuration Method bound to waflib.Configure.ConfigurationContext
Adds CFLAGS / CPPFLAGS from os.environ to conf.env
Configuration Method bound to waflib.Configure.ConfigurationContext
Adds CXXFLAGS / CPPFLAGS from os.environ to conf.env
Configuration Method bound to waflib.Configure.ConfigurationContext
Adds LINKFLAGS / LDFLAGS from os.environ to conf.env
Configuration Method bound to waflib.Configure.ConfigurationContext
Loads the Waf c extensions
Configuration Method bound to waflib.Configure.ConfigurationContext
Loads the Waf c++ extensions
Configuration Method bound to waflib.Configure.ConfigurationContext
Runs the preprocessor to determine the gcc/icc/clang version
The variables CC_VERSION, DEST_OS, DEST_BINFMT and DEST_CPU will be set in conf.env
Raise: | waflib.Errors.ConfigurationError |
---|
Configuration Method bound to waflib.Configure.ConfigurationContext
Returns the Aix compiler version
Raise: | waflib.Errors.ConfigurationError |
---|
Configuration Method bound to waflib.Configure.ConfigurationContext
Returns the Sun compiler version
Raise: | waflib.Errors.ConfigurationError |
---|
Configuration Method bound to waflib.Configure.ConfigurationContext
Adds --as-needed to the LINKFLAGS On some platforms, it is a default flag. In some cases (e.g., in NS-3) it is necessary to explicitly disable this feature with -Wl,–no-as-needed flag.
Bases: waflib.Task.TaskBase
A task that executes build configuration tests (calls conf.check)
Make sure to use locks if concurrent access to the same conf.env data is necessary.
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 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 |
---|
Decorator that registers 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 |
---|
Configuration Method bound to waflib.Configure.ConfigurationContext
Runs configuration tests in parallel; results are printed sequentially at the end of the build but each test must provide its own msg value to display a line:
def test_build(ctx):
ctx.in_msg = True # suppress console outputs
ctx.check_large_file(mandatory=False)
conf.multicheck(
{'header_name':'stdio.h', 'msg':'... stdio', 'uselib_store':'STDIO', 'global_define':False},
{'header_name':'xyztabcd.h', 'msg':'... optional xyztabcd.h', 'mandatory': False},
{'header_name':'stdlib.h', 'msg':'... stdlib', 'okmsg': 'aye', 'errmsg': 'nope'},
{'func': test_build, 'msg':'... testing an arbitrary build function', 'okmsg':'ok'},
msg = 'Checking for headers in parallel',
mandatory = True, # mandatory tests raise an error at the end
run_all_tests = True, # try running all tests
)
The configuration tests may modify the values in conf.env in any order, and the define values can affect configuration tests being executed. It is hence recommended to provide uselib_store values with global_define=False to prevent such issues.
Features defined in this module: