Skip to content
garyo edited this page Dec 13, 2014 · 1 revision

Check the version of Boost libraries

Boost does not provide any pkg-config files so to check the version of the Boost libraries, we need to use the means that the library itself provides.

def CheckBoost(context, version):
    # Boost versions are in format major.minor.subminor
    v_arr = version.split(".")
    version_n = 0
    if len(v_arr) > 0:
        version_n += int(v_arr[0])*100000
    if len(v_arr) > 1:
        version_n += int(v_arr[1])*100
    if len(v_arr) > 2:
        version_n += int(v_arr[2])
        
    context.Message('Checking for Boost version >= %s... ' % (version))
    ret = context.TryRun("""
    #include <boost/version.hpp>

    int main() 
    {
        return BOOST_VERSION >= %d ? 0 : 1;
    }
    """ % version_n, '.cpp')[0]
    context.Result(ret)
    return ret

conf = Configure(env, custom_tests = { 'CheckBoost' : CheckBoost })

if not (conf.CheckBoost('1.33')):
    print 'Boost version >= 1.33 needed'

Note by Jan Hudec

TryRun is not good for cross-compiling. Fortunately the BOOST_VERSION is a preprocessor define, so it should be enough to TryCompile. Replace the call to TryRun above with:

    ret = context.TryCompile("""
#include <boost/version.hpp>

#if BOOST_VERSION < %d
#error Installed boost is too old!
#endif
    int main() 
    {
        return 0;
    }
    """ % version_n, '.cpp')

(I didn't test it, so there might be typo in this code. Please fix this page if you actually try it. Fixed. TryCompile returns an int. Removed tuple subscript [0])

Clone this wiki locally