34 from __future__
import print_function
42 from optparse
import OptionParser
45 if (sys.platform ==
"darwin"):
48 link_static =
'ROS_BOOST_LINK' in os.environ
and os.environ[
'ROS_BOOST_LINK'] ==
"static" 52 no_L_or_I =
'ROS_BOOST_NO_L_OR_I' in os.environ
55 if (
'ROS_BOOST_VERSION' in os.environ
and len(os.environ[
'ROS_BOOST_VERSION']) > 0):
56 ver = os.environ[
'ROS_BOOST_VERSION']
59 boost_version = [int(v)
for v
in ver]
60 if (len(boost_version) == 2):
61 boost_version.append(0)
64 print(
"Usage: rosboost-cfg --lflags [thread,regex,graph,...]")
65 print(
" rosboost-cfg --cflags")
66 print(
" rosboost-cfg --libs [thread,regex,graph,...]")
67 print(
" rosboost-cfg --include_dirs")
68 print(
" rosboost-cfg --lib_dirs")
69 print(
" rosboost-cfg --root")
76 return repr(self.
value)
79 def __init__(self, major, minor, patch, root, include_dir, lib_dir, is_default_search_location):
90 if (self.
major != other.major):
91 if self.
major < other.major:
95 if (self.
minor != other.minor):
96 if self.
minor < other.minor:
100 if (self.
patch != other.patch):
101 if self.
patch < other.patch:
112 if (
'ROS_BOOST_LIB_DIR_NAME' in os.environ):
113 possible_dirs = [os.path.join(root_dir, os.environ[
'ROS_BOOST_LIB_DIR_NAME'])]
115 possible_dirs = [os.path.join(root_dir,
"lib64"), os.path.join(root_dir,
"lib")]
117 possible_dirs = [os.path.join(root_dir,
"lib/%s" % multiarch)] + possible_dirs
119 for p
in possible_dirs:
120 glob_files = glob(
"%s*"%(os.path.join(p,
"libboost*")))
121 if (len(glob_files) > 0):
127 version_paths = [os.path.join(dir,
"version.hpp"),
128 os.path.join(dir,
"boost",
"version.hpp")]
129 glob_dirs = glob(
"%s*"%(os.path.join(dir,
"boost-")))
130 [version_paths.append(os.path.join(gdir,
"boost",
"version.hpp"))
for gdir
in glob_dirs]
134 for p
in version_paths:
136 if (os.path.isfile(p)):
138 lines = fh.readlines() 141 if line.find(
"#define BOOST_VERSION ") > -1:
142 def_string = line.split()
143 ver_string = def_string[2]
144 ver_int = int(ver_string)
145 patch = ver_int % 100
146 minor = ver_int / 100 % 1000
147 major = ver_int / 100000
148 include_dir = os.path.split(os.path.split(p)[0])[0]
149 root_dir = os.path.split(dir)[0]
151 versions.append(
Version(major, minor, patch, root_dir, include_dir, lib_dir, is_default_search_location))
158 for path, system
in search_paths:
159 path = os.path.join(path,
"include")
161 [vers.append(ver)
for ver
in pvers]
166 if (boost_version
is not None):
168 if (v.major == boost_version[0]
and v.minor == boost_version[1]
and v.patch == boost_version[2]):
171 raise BoostError(
'Could not find boost version %s required by ROS_BOOST_VERSION environment variable'%(boost_version))
181 sys.stderr.write(
"WARN, found multiple boost versions '%s', using latest"%result)
185 _search_paths = [(sysroot+
'/usr',
True),
186 (sysroot+
'/usr/local',
True),
187 (
None if 'INCLUDE_DIRS' not in os.environ
else os.environ[
'INCLUDE_DIRS'],
True),
188 (
None if 'CPATH' not in os.environ
else os.environ[
'CPATH'],
True),
189 (
None if 'C_INCLUDE_PATH' not in os.environ
else os.environ[
'C_INCLUDE_PATH'],
True),
190 (
None if 'CPLUS_INCLUDE_PATH' not in os.environ
else os.environ[
'CPLUS_INCLUDE_PATH'],
True),
191 (
None if 'ROS_BOOST_ROOT' not in os.environ
else os.environ[
'ROS_BOOST_ROOT'],
False)]
194 for (str, system)
in _search_paths:
195 if (str
is not None):
196 dirs = str.split(
':')
199 if (dir.endswith(
'/include')):
200 dir = dir[:-len(
'/include')]
201 search_paths.append((dir, system))
211 dynamic_search_paths = []
212 static_search_paths = []
214 if (ver.is_system_install):
215 dynamic_search_paths = [
"libboost_%s-mt.%s"%(name, lib_suffix),
216 "libboost_%s.%s"%(name, lib_suffix)]
217 static_search_paths = [
"libboost_%s-mt.a"%(name),
218 "libboost_%s.a"%(name)]
220 dynamic_search_paths = [
"libboost_%s*%s_%s*.%s"%(name, ver.major, ver.minor, lib_suffix),
221 "libboost_%s-mt*.%s"%(name, lib_suffix),
222 "libboost_%s*.%s"%(name, lib_suffix)]
223 static_search_paths = [
"libboost_%s*%s_%s*.a"%(name, ver.major, ver.minor),
224 "libboost_%s-mt*.a"%(name),
225 "libboost_%s*.a"%(name)]
228 if (name ==
"python"):
229 python_ver = platform.python_version().split(
'.')
230 dynamic_search_paths = [
"libboost_%s-mt-py%s%s.%s"%(name, python_ver[0], python_ver[1], lib_suffix),
231 "libboost_%s-py%s%s.%s"%(name, python_ver[0], python_ver[1], lib_suffix)] + dynamic_search_paths
232 static_search_paths = [
"libboost_%s-mt-py%s%s.a"%(name, python_ver[0], python_ver[1]),
233 "libboost_%s-py%s%s.a"%(name, python_ver[0], python_ver[1])] + static_search_paths
235 search_paths = static_search_paths
if link_static
else dynamic_search_paths
240 raise BoostError(
'Could not locate library [%s], version %s'%(name, ver))
242 for p
in search_paths:
243 globstr = os.path.join(dir, p)
249 return os.path.basename(libs[0])
251 raise BoostError(
'Could not locate library [%s], version %s in lib directory [%s]'%(name, ver, dir))
254 if ver.is_system_install
or no_L_or_I:
257 return " %s%s"%(prefix, ver.include_dir)
263 if not ver.is_default_search_location:
265 return ' -L%s -Wl,-rpath,%s'%(dir, dir)
275 return ' -l%s'%(os.path.splitext(lib)[0][len(
'lib'):])
290 if (ver.is_default_search_location
or no_L_or_I):
295 OPTIONS = [
'libs',
'include_dirs',
'lib_dirs',
'cflags',
'lflags',
'root',
'print_versions',
'version']
298 for k
in dir(options):
300 v = getattr(options, k)
302 raise BoostError(
"Only one option (excepting sysroot) is allowed at a time")
305 if (len(sys.argv) < 2):
308 parser = OptionParser()
309 parser.add_option(
"-l",
"--libs", dest=
"libs", type=
"string", help=
"")
310 parser.add_option(
"-i",
"--include_dirs", dest=
"include_dirs", action=
"store_true", default=
False, help=
"")
311 parser.add_option(
"-d",
"--lib_dirs", dest=
"lib_dirs", action=
"store_true", help=
"")
312 parser.add_option(
"-c",
"--cflags", dest=
"cflags", action=
"store_true", default=
False, help=
"")
313 parser.add_option(
"-f",
"--lflags", dest=
"lflags", type=
"string", help=
"")
314 parser.add_option(
"-r",
"--root", dest=
"root", action=
"store_true", default=
False, help=
"")
315 parser.add_option(
"-p",
"--print_versions", dest=
"print_versions", action=
"store_true", default=
False, help=
"")
316 parser.add_option(
"-v",
"--version", dest=
"version", action=
"store_true", default=
False, help=
"")
317 parser.add_option(
"-s",
"--sysroot", dest=
"sysroot", type=
"string", default=
'', help=
"Location of the system root (usually toolchain root).")
318 parser.add_option(
"-m",
"--multiarch", dest=
"multiarch", type=
"string", default=
'', help=
"Name of multiarch to search below 'lib' folder for libraries.")
320 (options, args) = parser.parse_args()
322 if (options.print_versions):
325 print(
'%s.%s.%s root=%s include_dir=%s'%(ver.major, ver.minor, ver.patch, ver.root, ver.include_dir))
336 print(
'%s.%s.%s root=%s include_dir=%s'%(ver.major, ver.minor, ver.patch, ver.root, ver.include_dir))
339 if ver.major < 1
or (ver.major == 1
and ver.minor < 37):
340 raise BoostError(
'Boost version %s.%s.%s does not meet the minimum requirements of boost 1.37.0'%(ver.major, ver.minor, ver.patch))
350 output =
libs(ver, options.libs.split(
','))
351 elif (options.include_dirs):
354 elif (options.lib_dirs):
357 elif (options.cflags):
360 elif (options.lflags):
362 output =
lflags(ver, options.lflags.split(
','))
366 print(output.strip())
368 if __name__ ==
"__main__":
def check_one_option(options, key)
def __init__(self, value)
def find_versions(search_paths, multiarch='')
def search_paths(sysroot)
def find_lib(ver, name, full_lib=link_static)
def extract_versions(dir, is_default_search_location, multiarch='')
def find_boost(search_paths, multiarch='')
def __init__(self, major, minor, patch, root, include_dir, lib_dir, is_default_search_location)
def find_lib_dir(root_dir, multiarch='')
def print_usage_and_exit()
def include_dirs(ver, prefix='')
is_default_search_location