Changeset 1200

Show
Ignore:
Timestamp:
07/01/09 19:52:51 (14 months ago)
Author:
dane
Message:

scons: provide support for auto-detection of boost libs/headers/libname in using set of prefix directories (should help auto-detection of source installs of boost in /usr/local and macports installs in /opt/local) - closes #297

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/SConstruct

    r1193 r1200  
    7575# directory SCons uses to stash build tests 
    7676SCONF_TEMP_DIR = '.sconf_temp' 
     77# auto-search directories for boost libs/headers 
     78BOOST_SEARCH_PREFIXES = ['/usr/local','/opt/local','/sw','/usr',] 
     79 
    7780 
    7881# Core plugin build configuration 
     
    122125     
    123126    # Boost variables 
    124     PathVariable('BOOST_INCLUDES', 'Search path for boost include files', '/usr/include', PathVariable.PathAccept), 
    125     PathVariable('BOOST_LIBS', 'Search path for boost library files', '/usr/' + LIBDIR_SCHEMA, PathVariable.PathAccept), 
     127    # default is '/usr/include', see FindBoost method below 
     128    ('BOOST_INCLUDES', 'Search path for boost include files', '',False), 
     129    # default is '/usr/' + LIBDIR_SCHEMA, see FindBoost method below 
     130    ('BOOST_LIBS', 'Search path for boost library files', '',False), 
    126131    ('BOOST_TOOLKIT','Specify boost toolkit, e.g., gcc41.','',False), 
    127132    ('BOOST_ABI', 'Specify boost ABI, e.g., d.','',False), 
     
    348353            env[variable] = item.default 
    349354 
     355def FindBoost(context, prefixes): 
     356    """Routine to auto-find boost header dir, lib dir, and library naming structure. 
     357     
     358    """ 
     359    context.Message( 'Searching for boost libs and headers... ' ) 
     360    env = context.env 
     361      
     362    BOOST_LIB_DIR = None 
     363    BOOST_INCLUDE_DIR = None 
     364    BOOST_APPEND = None 
     365    env['BOOST_APPEND'] = str() 
     366 
     367    for searchDir in prefixes: 
     368        libItems = glob(os.path.join(searchDir, LIBDIR_SCHEMA, 'libboost_filesystem*-*.*')) 
     369        if not libItems: 
     370            libItems = glob(os.path.join(searchDir, 'lib/libboost_filesystem*-*.*')) 
     371        incItems = glob(os.path.join(searchDir, 'include/boost*/')) 
     372        if len(libItems) >= 1 and len(incItems) >= 1: 
     373            BOOST_LIB_DIR = os.path.dirname(libItems[0]) 
     374            BOOST_INCLUDE_DIR = incItems[0].rstrip('boost/') 
     375            match = re.search(r'libboost_filesystem-(.*)\..*', libItems[0]) 
     376            if hasattr(match,'groups'): 
     377                BOOST_APPEND = match.groups()[0] 
     378            break 
     379     
     380    msg = str() 
     381     
     382    if not env['BOOST_LIBS']: 
     383        if BOOST_LIB_DIR: 
     384            msg += '\n  *libs found: %s' % BOOST_LIB_DIR 
     385            env['BOOST_LIBS'] = BOOST_LIB_DIR 
     386        else: 
     387            env['BOOST_LIBS'] = '/usr' + LIBDIR_SCHEMA 
     388    else: 
     389        msg += '\n  *using boost lib dir: %s' % env['BOOST_LIBS'] 
     390            
     391    if not env['BOOST_INCLUDES']: 
     392        if BOOST_INCLUDE_DIR: 
     393            msg += '\n  *headers found: %s' % BOOST_INCLUDE_DIR 
     394            env['BOOST_INCLUDES'] = BOOST_INCLUDE_DIR 
     395        else: 
     396            env['BOOST_INCLUDES'] = '/usr/include' 
     397    else: 
     398        msg += '\n  *using boost include dir: %s' % env['BOOST_INCLUDES']     
     399                
     400    if not env['BOOST_TOOLKIT'] and not env['BOOST_ABI'] and not env['BOOST_VERSION']: 
     401        if BOOST_APPEND: 
     402            msg += '\n  *lib naming extension found: %s' % BOOST_APPEND 
     403            env['BOOST_APPEND'] = '-' + BOOST_APPEND 
     404        else: 
     405            msg += '\n  *no lib naming extension found' 
     406    else: 
     407        # Creating BOOST_APPEND according to the Boost library naming order, 
     408        # which goes <toolset>-<threading>-<abi>-<version>. See: 
     409        #  http://www.boost.org/doc/libs/1_35_0/more/getting_started/unix-variants.html#library-naming 
     410        append_params = [''] 
     411        if env['BOOST_TOOLKIT']: append_params.append(env['BOOST_TOOLKIT']) 
     412        if thread_flag: append_params.append(thread_flag) 
     413        if env['BOOST_ABI']: append_params.append(env['BOOST_ABI']) 
     414        if env['BOOST_VERSION']: append_params.append(env['BOOST_VERSION']) 
     415 
     416        # Constructing the BOOST_APPEND setting that will be used to find the 
     417        # Boost libraries. 
     418        if len(append_params) > 1:  
     419            env['BOOST_APPEND'] = '-'.join(append_params) 
     420        msg += '\n  *using boost lib naming: %s' % env['BOOST_APPEND'] 
     421 
     422    env.AppendUnique(CPPPATH = env['BOOST_INCLUDES']) 
     423    env.AppendUnique(LIBPATH = env['BOOST_LIBS'])     
     424    if env['COLOR_PRINT']: 
     425        msg = "\033[94m%s\033[0m" % (msg) 
     426    ret = context.Result(msg) 
     427    return ret 
     428 
    350429def CheckBoost(context, version, silent=False): 
    351430    # Boost versions are in format major.minor.subminor 
     
    421500conf_tests = { 'CheckPKGConfig' : CheckPKGConfig, 
    422501               'CheckPKG' : CheckPKG, 
     502               'FindBoost' : FindBoost, 
    423503               'CheckBoost' : CheckBoost, 
    424504               'GetBoostLibVersion' : GetBoostLibVersion, 
     
    530610        if env['THREADING'] == 'multi': 
    531611            env['CXXFLAGS'] = ['-mt'] 
    532      
     612         
    533613    # Adding the required prerequisite library directories to the include path for 
    534614    # compiling and the library path for linking, respectively. 
    535     for required in ('BOOST', 'PNG', 'JPEG', 'TIFF','PROJ','ICU'): 
     615    for required in ('PNG', 'JPEG', 'TIFF','PROJ','ICU'): 
    536616        inc_path = env['%s_INCLUDES' % required] 
    537617        lib_path = env['%s_LIBS' % required] 
     
    566646    ] 
    567647     
     648     
     649    for libinfo in LIBSHEADERS: 
     650        if not conf.CheckLibWithHeader(libinfo[0], libinfo[1], libinfo[3]): 
     651            if libinfo[2]: 
     652                color_print (1,'Could not find required header or shared library for %s' % libinfo[0]) 
     653                env['MISSING_DEPS'].append(libinfo[0]) 
     654            else: 
     655                color_print(4,'Could not find optional header or shared library for %s' % libinfo[0]) 
     656                env['SKIPPED_DEPS'].append(libinfo[0])             
     657 
     658    if env['THREADING'] == 'multi': 
     659        thread_flag = thread_suffix 
     660    else: 
     661        thread_flag = '' 
     662         
     663    conf.FindBoost(BOOST_SEARCH_PREFIXES) 
     664     
    568665    # get boost version from boost headers rather than previous approach 
    569666    # of fetching from the user provided INCLUDE path 
     
    590687    if env['THREADING'] == 'multi': 
    591688        BOOST_LIBSHEADERS.append(['thread', 'boost/thread/mutex.hpp', True]) 
    592         thread_flag = thread_suffix 
    593     else: 
    594         thread_flag = '' 
    595      
    596     for libinfo in LIBSHEADERS: 
    597         if not conf.CheckLibWithHeader(libinfo[0], libinfo[1], libinfo[3]): 
    598             if libinfo[2]: 
    599                 color_print (1,'Could not find required header or shared library for %s' % libinfo[0]) 
    600                 env['MISSING_DEPS'].append(libinfo[0]) 
    601             else: 
    602                 color_print(4,'Could not find optional header or shared library for %s' % libinfo[0]) 
    603                 env['SKIPPED_DEPS'].append(libinfo[0])             
    604      
    605     # Creating BOOST_APPEND according to the Boost library naming order, 
    606     # which goes <toolset>-<threading>-<abi>-<version>. See: 
    607     #  http://www.boost.org/doc/libs/1_35_0/more/getting_started/unix-variants.html#library-naming 
    608     append_params = [''] 
    609     if env['BOOST_TOOLKIT']: append_params.append(env['BOOST_TOOLKIT']) 
    610     if thread_flag: append_params.append(thread_flag) 
    611     if env['BOOST_ABI']: append_params.append(env['BOOST_ABI']) 
    612     if env['BOOST_VERSION']: append_params.append(env['BOOST_VERSION']) 
    613      
     689                 
    614690    # if the user is not setting custom boost configuration 
    615691    # enforce boost version greater than or equal to 1.34 
     
    620696    else: 
    621697        color_print (4,'Found boost lib version... %s' % boost_lib_version_from_header ) 
    622      
    623     # Constructing the BOOST_APPEND setting that will be used to find the 
    624     # Boost libraries. 
    625     if len(append_params) > 1:  
    626         env['BOOST_APPEND'] = '-'.join(append_params) 
    627     else:  
    628         env['BOOST_APPEND'] = '' 
    629698     
    630699    for count, libinfo in enumerate(BOOST_LIBSHEADERS): 
     
    863932    SConscript('agg/SConscript') 
    864933 
    865  
    866  
    867934# Build the core library 
    868935SConscript('src/SConscript')