The methods check_cc and check_cxx are used to detect parameters using a small build project. The main parameters are the following
Here is a concrete example:
def configure(conf): conf.check_cc(header_name='time.h')conf.check_cc(function_name='printf', header_name="stdio.h", mandatory=1)
conf.check_cc(fragment='int main() {2+2==4;}\n', define_name="boobah")
conf.check_cc(lib='m', ccflags='-Wall', defines=['var=foo', 'x=y'], uselib_store='M')
conf.check_cc(lib='linux', uselib='M')
conf.check_cc(fragment=''' #include <stdio.h> int main() { printf("4"); return 0; } ''', define_name="booeah", execute="1", define_ret="1", msg="Checking for something")
conf.write_config_header('config.h')
![]()
Try to compile a program using the configuration header time.h, if present on the system, if the test is successful, the define HAVE_TIME_H will be added | |
Try to compile a program with the function printf, adding the header stdio.h (the header_name may be a list of additional headers). The parameter mandatory will make the test raise an exception if it fails. | |
Try to compile a piece of code, and if the test is successful, define the name boobah | |
Modifications made to the task generator environment are not stored. When the test is successful and when the attribute uselib_store is provided, the names lib, cflags and defines will be converted into uselib variables LIB_M, CCFLAGS_M and DEFINE_M and the flag values are added to the configuration environment. | |
Try to compile a simple c program against a library called 'linux', and reuse the previous parameters for libm (uselib) | |
Execute a simple program, collect the output, and put it in a define when successful | |
After all the tests are executed, write a configuration header in the build directory (optional). The configuration header is used to limit the size of the command-line. |
Here is an example of a config.h produced with the previous test code:
/* Configuration header created by Waf - do not edit */ #ifndef _CONFIG_H_WAF #define _CONFIG_H_WAF #define HAVE_PRINTF 1 #define HAVE_TIME_H 1 #define boobah 1 #define booeah "4" #endif /* _CONFIG_H_WAF */
The file default.cache.py
will contain the following variables:
CCDEFINES_M = ['var=foo', 'x=y'] CXXDEFINES_M = ['var=foo', 'x=y'] CXXFLAGS_M = ['-Wall'] CCFLAGS_M = ['-Wall'] LIB_M = ['m'] boobah = 1 booeah = '4' defines = {'booeah': '"4"', 'boobah': 1, 'HAVE_TIME_H': 1, 'HAVE_PRINTF': 1} dep_files = ['config.h'] waf_config_files = ['/compilation/waf/demos/adv/build/default/config.h']