• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1
2# This example shows performing configure checks in B2,
3# e.g. to check for some system function or compiler quirk.
4
5# First, declare a metatarget that we'll try to build.
6obj foo : foo.cpp ;
7# Make it explicit so that it's only built if used by a configure check
8explicit foo ;
9
10# Declare a target that depends on configure check result.
11exe main
12    : main.cpp
13    # The check-target-builds invocation in requirements section will
14    # - build the specified metatarget
15    # - if it builds OK, add the properties in the second parameter
16    # - otherwise, add the properties in the third parameter
17    : [ check-target-builds foo : <define>FOO=1 : <define>FOO=0 ]
18    ;
19
20# To test this:
21#
22# 1. Build with "b2". You should see a "foo builds: yes" message, and running
23#    the produced executable will show that FOO is set to 1.
24# 2. Modify foo.cpp to contain a compile error, rebuild with
25#    "b2 -a --reconfigure". You should see a "foo builds: no" message, and running
26#    the produced executable should show that FOO is now set to 0.
27#
28# The output from the check is not shown on the console, instead it is
29# redirected to the bin/config.log file
30