def try_location(self, ctx, base, **kwargs): ctx.Log('Checking for %s in %s.\n' % (self.name, base)) loc_callback = kwargs.get('loc_callback', None) libs = copy.deepcopy(conv.to_iter(self.libs)) extra_libs = copy.deepcopy(conv.to_iter(self.extra_libs)) sub_dirs = conv.to_iter(self.sub_dirs) if not sub_dirs: sub_dirs = [[]] res = (False, None) for inc_sub_dirs, lib_sub_dirs in sub_dirs: inc_sub_dirs = list(conv.to_iter(inc_sub_dirs)) lib_sub_dirs = list(conv.to_iter(lib_sub_dirs)) for i in range(len(inc_sub_dirs)): if not os.path.isabs(inc_sub_dirs[i]): inc_sub_dirs[i] = os.path.join(base, inc_sub_dirs[i]) for i in range(len(lib_sub_dirs)): if not os.path.isabs(lib_sub_dirs[i]): lib_sub_dirs[i] = os.path.join(base, lib_sub_dirs[i]) # Remove any directories that can already be found in # in their respective lists. inc_sub_dirs = [ d for d in inc_sub_dirs if d not in ctx.env.get('CPPPATH', []) ] lib_sub_dirs = [ d for d in lib_sub_dirs if d not in ctx.env.get('LIBPATH', []) ] if loc_callback: loc_callback(ctx, base, inc_sub_dirs, lib_sub_dirs, libs, extra_libs) ctx.Log('Trying include dirs: ' + str(inc_sub_dirs) + '\n') ctx.Log('Trying library dirs: ' + str(lib_sub_dirs) + '\n') # Before continuing, try and find all of the sample headers. if not self.try_headers(ctx, inc_sub_dirs, **kwargs): continue bkp = env_setup(ctx.env, CPPPATH=ctx.env.get('CPPPATH', []) + inc_sub_dirs, LIBPATH=ctx.env.get('LIBPATH', []) + lib_sub_dirs, RPATH=ctx.env.get('RPATH', []) + lib_sub_dirs) res = self.try_libs(ctx, libs, extra_libs, **kwargs) if res[0]: self.base_dir = base # set base directory break env_restore(ctx.env, bkp) return res
def try_location(self, ctx, base, **kwargs): ctx.Log('Checking for %s in %s.\n'%(self.name, base)) loc_callback = kwargs.get('loc_callback', None) libs = copy.deepcopy(conv.to_iter(self.libs)) extra_libs = copy.deepcopy(conv.to_iter(self.extra_libs)) sub_dirs = conv.to_iter(self.sub_dirs) if not sub_dirs: sub_dirs = [[]] res = (False, None) for inc_sub_dirs, lib_sub_dirs in sub_dirs: inc_sub_dirs = list(conv.to_iter(inc_sub_dirs)) lib_sub_dirs = list(conv.to_iter(lib_sub_dirs)) for i in range(len(inc_sub_dirs)): if not os.path.isabs(inc_sub_dirs[i]): inc_sub_dirs[i] = os.path.join(base, inc_sub_dirs[i]) for i in range(len(lib_sub_dirs)): if not os.path.isabs(lib_sub_dirs[i]): lib_sub_dirs[i] = os.path.join(base, lib_sub_dirs[i]) # Remove any directories that can already be found in # in their respective lists. inc_sub_dirs = [d for d in inc_sub_dirs if d not in ctx.env.get('CPPPATH', [])] lib_sub_dirs = [d for d in lib_sub_dirs if d not in ctx.env.get('LIBPATH', [])] if loc_callback: loc_callback(ctx, base, inc_sub_dirs, lib_sub_dirs, libs, extra_libs) ctx.Log('Trying include dirs: ' + str(inc_sub_dirs) + '\n') ctx.Log('Trying library dirs: ' + str(lib_sub_dirs) + '\n') # Before continuing, try and find all of the sample headers. if not self.try_headers(ctx, inc_sub_dirs, **kwargs): continue bkp = env_setup(ctx.env, CPPPATH=ctx.env.get('CPPPATH', []) + inc_sub_dirs, LIBPATH=ctx.env.get('LIBPATH', []) + lib_sub_dirs, RPATH=ctx.env.get('RPATH', []) + lib_sub_dirs) res = self.try_libs(ctx, libs, extra_libs, **kwargs) if res[0]: self.base_dir = base # set base directory break env_restore(ctx.env, bkp) return res
def try_libs(self, ctx, libs, extra_libs=[], **kwargs): if not libs: libs = [[]] if not extra_libs: extra_libs = [[]] ctx.Log("try to compile with one of the following libs: " + str(libs) + "\n") if len(extra_libs) > 0: ctx.Log( "also always try to include one of the following extra libs: " + str(extra_libs) + "\n") for l in libs: l = conv.to_iter(l) ctx.Log("try library " + str(l) + "\n") l_bkp = self.env_setup_libs(ctx, l) for e in extra_libs: e = conv.to_iter(e) # add extra lib linkflags = None if 'LINKFLAGS' in ctx.env: linkflags = ctx.env['LINKFLAGS'] e_bkp = env_setup(ctx.env, LIBS=ctx.env.get('LIBS', []) + e, LINKFLAGS=linkflags) # try to link or run program res = self.try_link(ctx, **kwargs) # if succeeded if res[0]: if not self.auto_add_libs: env_restore(ctx.env, e_bkp) env_restore(ctx.env, l_bkp) self._used_libs = l break env_restore(ctx.env, e_bkp) if res[0]: ctx.Log("this was successful (using " + str(l) + "), done with list of libraries\n") break env_restore(ctx.env, l_bkp) return res
def env_backup(env, names): names = conv.to_iter(names) bkp = {} for n in names: if n not in env: bkp[n] = None else: bkp[n] = env[n] return bkp
def env_setup_libs(self, env, libs): defaults = { 'prepend': True, 'libraries': libs, } # If we were given a dictionary update our defaults. if len(libs) and isinstance(libs[0], dict): defaults.update(libs[0]) defaults['libraries'] = conv.to_iter(defaults['libraries']) # Remove any pre-existing libraries. defaults['libraries'] = [d for d in defaults['libraries'] if d not in env.get('LIBS', [])] # Prepend or append? if defaults['prepend']: libs = defaults['libraries'] + conv.to_iter(env.get('LIBS', [])) else: libs = conv.to_iter(env.get('LIBS', [])) + defaults['libraries'] return env_setup(env, LIBS=libs)
def env_setup_libs(self, ctx, libs): defaults = { 'prepend': True, 'libraries': libs, } env = ctx.env # If we were given a dictionary update our defaults. if len(libs) and isinstance(libs[0], dict): defaults.update(libs[0]) defaults['libraries'] = conv.to_iter(defaults['libraries']) # Remove any pre-existing libraries. defaults['libraries'] = [d for d in defaults['libraries'] if d not in env.get('LIBS', [])] # Prepend or append? if defaults['prepend']: libs = defaults['libraries'] + conv.to_iter(env.get('LIBS', [])) else: libs = conv.to_iter(env.get('LIBS', [])) + defaults['libraries'] return env_setup(env, LIBS=libs)
def try_libs(self, ctx, libs, extra_libs=[], **kwargs): if not libs: libs = [[]] if not extra_libs: extra_libs = [[]] for l in libs: l = conv.to_iter(l) l_bkp = self.env_setup_libs(ctx.env, l) for e in extra_libs: e = conv.to_iter(e) e_bkp = env_setup(ctx.env, LIBS=ctx.env.get('LIBS', []) + e) res = self.try_link(ctx, **kwargs) if res[0]: if not self.auto_add_libs: env_restore(ctx.env, e_bkp) env_restore(ctx.env, l_bkp) self._used_libs = l break env_restore(ctx.env, e_bkp) if res[0]: break env_restore(ctx.env, l_bkp) return res
def try_location(self, ctx, base_dirs, **kwargs): if type(base_dirs) is not list: base_dirs = [base_dirs] for base in base_dirs: ctx.Log('Checking for %s in %s.\n' % (self.name, base)) ctx.Log('Searching for headers: ' + str(self.headers) + ", libs: " + str(self.libs) + '\n') loc_callback = kwargs.get('loc_callback', None) libs = copy.deepcopy(conv.to_iter(self.libs)) extra_libs = copy.deepcopy(conv.to_iter(self.extra_libs)) sub_dirs = conv.to_iter(self.sub_dirs) if not sub_dirs: sub_dirs = [[]] ctx.Log( "Try the following combinations of (include, lib) directories: " + str(sub_dirs) + "\n") res = (False, None) for inc_sub_dirs, lib_sub_dirs in sub_dirs: inc_sub_dirs = list(conv.to_iter(inc_sub_dirs)) lib_sub_dirs = list(conv.to_iter(lib_sub_dirs)) for i in range(len(inc_sub_dirs)): if not os.path.isabs(inc_sub_dirs[i]): inc_sub_dirs[i] = os.path.join(base, inc_sub_dirs[i]) for i in range(len(lib_sub_dirs)): if not os.path.isabs(lib_sub_dirs[i]): lib_sub_dirs[i] = os.path.join(base, lib_sub_dirs[i]) # Remove any directories that can already be found # in their respective lists. #inc_sub_dirs = [d for d in inc_sub_dirs if d not in ctx.env.get('CPPPATH', [])] #lib_sub_dirs = [d for d in lib_sub_dirs if d not in ctx.env.get('LIBPATH', [])] if loc_callback: loc_callback(ctx, base, inc_sub_dirs, lib_sub_dirs, libs, extra_libs) ctx.Log('Trying include directories: "' + str(inc_sub_dirs) + '" and library directories: "' + str(lib_sub_dirs) + '"\n') # Before continuing, try and find all of the sample headers. if not self.try_headers(ctx, inc_sub_dirs, **kwargs): continue system_inc_dirs = [] for inc_dir in inc_sub_dirs: system_inc_dirs.append( ('-isystem', inc_dir) ) # -isystem is the same is -I for gcc, except it suppresses warning (useful for dependencies) if self.set_rpath: bkp = env_setup( ctx.env, #CPPPATH=ctx.env.get('CPPPATH', []) + inc_sub_dirs, LIBPATH=ctx.env.get('LIBPATH', []) + lib_sub_dirs, RPATH=ctx.env.get('RPATH', []) + lib_sub_dirs, CCFLAGS=ctx.env.get('CCFLAGS', []) + system_inc_dirs) else: bkp = env_setup( ctx.env, #CPPPATH=ctx.env.get('CPPPATH', []) + inc_sub_dirs, LIBPATH=ctx.env.get('LIBPATH', []) + lib_sub_dirs, #RPATH=ctx.env.get('RPATH', []) + lib_sub_dirs, CCFLAGS=ctx.env.get('CCFLAGS', []) + system_inc_dirs) self.base_dir = base # set base directory (is needed by try_libs) res = self.try_libs(ctx, libs, extra_libs, **kwargs) if res[0]: self.base_dir = base # set base directory ctx.Log("Combination of (include, lib) directories " + str(inc_sub_dirs) + "," + str(lib_sub_dirs) + " was successful, done with combinations.") return res #break env_restore(ctx.env, bkp) return res