c_config¶
C/C++/D configuration helpers
-
waflib.Tools.c_config.
WAF_CONFIG_H
= 'config.h'¶ default name for the config.h file
-
waflib.Tools.c_config.
SNIP_FUNCTION
= '\nint main(int argc, char **argv) {\n\tvoid (*p)();\n\t(void)argc; (void)argv;\n\tp=(void(*)())(%s);\n\treturn !p;\n}\n'¶ Code template for checking for functions
-
waflib.Tools.c_config.
SNIP_TYPE
= '\nint main(int argc, char **argv) {\n\t(void)argc; (void)argv;\n\tif ((%(type_name)s *) 0) return 0;\n\tif (sizeof (%(type_name)s)) return 0;\n\treturn 1;\n}\n'¶ Code template for checking for types
-
waflib.Tools.c_config.
parse_flags
(self, line, uselib_store, env=None, force_static=False, posix=None)[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', 'FOO') # conf.env.CXXFLAGS_FOO = ['-O3'] # conf.env.CFLAGS_FOO = ['-O3']
Parameters: - line (string) – flags
- uselib_store (string) – where to add the flags
- env (
waflib.ConfigSet.ConfigSet
) – config set or conf.env by default
-
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()
andwaflib.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)
-
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
waflib.Configure.run_build()
Parameters: - 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 inwaflib.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.Configure.run_build()
. For the complete list of parameters, seewaflib.Tools.c_config.validate_c()
. To force a specific compiler, pass “compiler=’c’” or “compiler=’cxx’” in the argumentsBesides 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)
-
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()
.-
color
= 'PINK'¶
-
__doc__
= '\n\tA task for executing a programs after they are built. See :py:func:`waflib.Tools.c_config.test_exec_fun`.\n\t'¶
-
__module__
= 'waflib.Tools.c_config'¶
-
hcode
= "\tdef run(self):\n\t\tif getattr(self.generator, 'rpath', None):\n\t\t\tif getattr(self.generator, 'define_ret', False):\n\t\t\t\tself.generator.bld.retval = self.generator.bld.cmd_and_log([self.inputs[0].abspath()])\n\t\t\telse:\n\t\t\t\tself.generator.bld.retval = self.generator.bld.exec_command([self.inputs[0].abspath()])\n\t\telse:\n\t\t\tenv = self.env.env or {}\n\t\t\tenv.update(dict(os.environ))\n\t\t\tfor var in ('LD_LIBRARY_PATH', 'DYLD_LIBRARY_PATH', 'PATH'):\n\t\t\t\tenv[var] = self.inputs[0].parent.abspath() + os.path.pathsep + env.get(var, '')\n\t\t\tif getattr(self.generator, 'define_ret', False):\n\t\t\t\tself.generator.bld.retval = self.generator.bld.cmd_and_log([self.inputs[0].abspath()], env=env)\n\t\t\telse:\n\t\t\t\tself.generator.bld.retval = self.generator.bld.exec_command([self.inputs[0].abspath()], env=env)\n"¶
-
-
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.
check_cxx
(self, *k, **kw)[source]¶ Configuration Method bound to
waflib.Configure.ConfigurationContext
-
waflib.Tools.c_config.
check_cc
(self, *k, **kw)[source]¶ Configuration Method bound to
waflib.Configure.ConfigurationContext
-
waflib.Tools.c_config.
set_define_comment
(self, key, comment)[source]¶ Configuration Method bound to
waflib.Configure.ConfigurationContext
-
waflib.Tools.c_config.
get_define_comment
(self, key)[source]¶ Configuration Method bound to
waflib.Configure.ConfigurationContext
-
waflib.Tools.c_config.
define
(self, key, val, quote=True, comment='')[source]¶ Configuration Method bound to
waflib.Configure.ConfigurationContext
Store a single define and its state into conf.env.DEFINES. If the value is True, False or None it is cast to 1 or 0.
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, comment='')[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, comment='')[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, defines=True, headers=False, remove=True, define_prefix='')[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')
This function only adds include guards (if necessary), consult
waflib.Tools.c_config.get_config_header()
for details on the body.Parameters: - configfile (string) – path to the file to create (relative or absolute)
- guard (string) – include guard name to add, by default it is computed from the file name
- 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, works like in autoconf)
- define_prefix (string) – prefix all the defines in the file with a particular prefix
-
waflib.Tools.c_config.
get_config_header
(self, defines=True, headers=False, define_prefix='')[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.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: - defines (bool) – write the defines values
- headers (bool) – write include entries for each element in self.env.INCKEYS
- define_prefix (string) – prefix all the defines with a particular prefix
Returns: the contents of a
config.h
fileReturn type: string
-
waflib.Tools.c_config.
cc_add_flags
(conf)[source]¶ Configuration Method bound to
waflib.Configure.ConfigurationContext
Add CFLAGS / CPPFLAGS from os.environ to conf.env
-
waflib.Tools.c_config.
cxx_add_flags
(conf)[source]¶ Configuration Method bound to
waflib.Configure.ConfigurationContext
Add CXXFLAGS / CPPFLAGS from os.environ to conf.env
-
waflib.Tools.c_config.
link_add_flags
(conf)[source]¶ Configuration Method bound to
waflib.Configure.ConfigurationContext
Add LINKFLAGS / LDFLAGS from os.environ to conf.env
-
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, clang=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.
get_suncc_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 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.
-
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
-
__doc__
= '\n\tA task that executes configuration tests\n\tmake sure that the checks write to conf.env in a thread-safe manner\n\n\tfor the moment it only executes conf.check\n\t'¶
-
__module__
= 'waflib.Tools.c_config'¶
-
hcode
= '\tdef run(self):\n\t\tconf = self.conf\n\t\tbld = Build.BuildContext(top_dir=conf.srcnode.abspath(), out_dir=conf.bldnode.abspath())\n\t\tbld.env = conf.env\n\t\tbld.init_dirs()\n\t\tbld.in_msg = 1 # suppress top-level start_msg\n\t\tbld.logger = self.logger\n\t\ttry:\n\t\t\tbld.check(**self.args)\n\t\texcept Exception:\n\t\t\treturn 1\n'¶
-
-
waflib.Tools.c_config.
conf
(f)¶ Decorator: attach new configuration functions to
waflib.Build.BuildContext
andwaflib.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.
after_method
(*k)[source]¶ 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: