Please note:The SCons wiki is now restored from the attack in March 2013. All old passwords have been invalidated. Please reset your password if you have an account. If you note missing pages, please report them to webmaster@scons.org. Also, new account creation is currently disabled due to an ongoing spam flood (2013/08/27).

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])

CheckBoostVersion (last edited 2008-04-30 09:34:58 by RenaudDetry)