34 from __future__
import print_function
40 from optparse
import OptionParser
43 if (sys.platform ==
'darwin'):
46 link_static =
'ROS_BOOST_LINK' in os.environ
and os.environ[
'ROS_BOOST_LINK'] ==
'static' 50 no_L_or_I =
'ROS_BOOST_NO_L_OR_I' in os.environ
53 if (
'ROS_BOOST_VERSION' in os.environ
and len(os.environ[
'ROS_BOOST_VERSION']) > 0):
54 ver = os.environ[
'ROS_BOOST_VERSION']
57 boost_version = [int(v)
for v
in ver]
58 if (len(boost_version) == 2):
59 boost_version.append(0)
63 print(
'Usage: rosboost-cfg --lflags [thread,regex,graph,...]')
64 print(
' rosboost-cfg --cflags')
65 print(
' rosboost-cfg --libs [thread,regex,graph,...]')
66 print(
' rosboost-cfg --include_dirs')
67 print(
' rosboost-cfg --lib_dirs')
68 print(
' rosboost-cfg --root')
78 return repr(self.
value)
83 def __init__(self, major, minor, patch, root, include_dir, lib_dir, is_default_search_location):
94 if (self.
major != other.major):
95 if self.
major < other.major:
99 if (self.
minor != other.minor):
100 if self.
minor < other.minor:
104 if (self.
patch != other.patch):
105 if self.
patch < other.patch:
118 if (
'ROS_BOOST_LIB_DIR_NAME' in os.environ):
119 possible_dirs = [os.path.join(root_dir, os.environ[
'ROS_BOOST_LIB_DIR_NAME'])]
121 possible_dirs = [os.path.join(root_dir,
'lib64'), os.path.join(root_dir,
'lib')]
123 possible_dirs = [os.path.join(root_dir,
'lib/%s' % multiarch)] + possible_dirs
125 for p
in possible_dirs:
126 glob_files = glob(
'%s*' % (os.path.join(p,
'libboost*')))
127 if (len(glob_files) > 0):
134 version_paths = [os.path.join(dir,
'version.hpp'),
135 os.path.join(dir,
'boost',
'version.hpp')]
136 glob_dirs = glob(
'%s*' % (os.path.join(dir,
'boost-')))
137 [version_paths.append(os.path.join(gdir,
'boost',
'version.hpp'))
for gdir
in glob_dirs]
141 for p
in version_paths:
143 if (os.path.isfile(p)):
145 lines = fh.readlines() 148 if line.find(
'#define BOOST_VERSION ') > -1:
149 def_string = line.split()
150 ver_string = def_string[2]
151 ver_int = int(ver_string)
152 patch = ver_int % 100
153 minor = ver_int / 100 % 1000
154 major = ver_int / 100000
155 include_dir = os.path.split(os.path.split(p)[0])[0]
156 root_dir = os.path.split(dir)[0]
158 versions.append(
Version(major, minor, patch, root_dir, include_dir, lib_dir, is_default_search_location))
166 for path, system
in search_paths:
167 path = os.path.join(path,
'include')
169 [vers.append(ver)
for ver
in pvers]
174 if (boost_version
is not None):
176 if (v.major == boost_version[0]
and v.minor == boost_version[1]
and v.patch == boost_version[2]):
179 raise BoostError(
'Could not find boost version %s required by ROS_BOOST_VERSION environment variable' % (boost_version))
190 sys.stderr.write(
"WARN, found multiple boost versions '%s', using latest" % result)
195 _search_paths = [(sysroot+
'/usr',
True),
196 (sysroot+
'/usr/local',
True),
197 (
None if 'INCLUDE_DIRS' not in os.environ
else os.environ[
'INCLUDE_DIRS'],
True),
198 (
None if 'CPATH' not in os.environ
else os.environ[
'CPATH'],
True),
199 (
None if 'C_INCLUDE_PATH' not in os.environ
else os.environ[
'C_INCLUDE_PATH'],
True),
200 (
None if 'CPLUS_INCLUDE_PATH' not in os.environ
else os.environ[
'CPLUS_INCLUDE_PATH'],
True),
201 (
None if 'ROS_BOOST_ROOT' not in os.environ
else os.environ[
'ROS_BOOST_ROOT'],
False)]
204 for (str, system)
in _search_paths:
205 if (str
is not None):
206 dirs = str.split(
':')
209 if (dir.endswith(
'/include')):
210 dir = dir[:-len(
'/include')]
211 search_paths.append((dir, system))
223 dynamic_search_paths = []
224 static_search_paths = []
226 if (ver.is_system_install):
227 dynamic_search_paths = [
'libboost_%s-mt.%s' % (name, lib_suffix),
228 'libboost_%s.%s' % (name, lib_suffix)]
229 static_search_paths = [
'libboost_%s-mt.a' % (name),
230 'libboost_%s.a' % (name)]
232 dynamic_search_paths = [
'libboost_%s*%s_%s*.%s' % (name, ver.major, ver.minor, lib_suffix),
233 'libboost_%s-mt*.%s' % (name, lib_suffix),
234 'libboost_%s*.%s' % (name, lib_suffix)]
235 static_search_paths = [
'libboost_%s*%s_%s*.a' % (name, ver.major, ver.minor),
236 'libboost_%s-mt*.a' % (name),
237 'libboost_%s*.a' % (name)]
240 if (name ==
'python'):
241 python_ver = platform.python_version().split(
'.')
242 dynamic_search_paths = [
'libboost_%s-mt-py%s%s.%s' % (name, python_ver[0], python_ver[1], lib_suffix),
243 'libboost_%s-py%s%s.%s' % (name, python_ver[0], python_ver[1], lib_suffix)] + dynamic_search_paths
244 static_search_paths = [
'libboost_%s-mt-py%s%s.a' % (name, python_ver[0], python_ver[1]),
245 'libboost_%s-py%s%s.a' % (name, python_ver[0], python_ver[1])] + static_search_paths
247 search_paths = static_search_paths
if link_static
else dynamic_search_paths
252 raise BoostError(
'Could not locate library [%s], version %s' % (name, ver))
254 for p
in search_paths:
255 globstr = os.path.join(dir, p)
261 return os.path.basename(libs[0])
263 raise BoostError(
'Could not locate library [%s], version %s in lib directory [%s]' % (name, ver, dir))
267 if ver.is_system_install
or no_L_or_I:
270 return ' %s%s' % (prefix, ver.include_dir)
278 if not ver.is_default_search_location:
280 return ' -L%s -Wl,-rpath,%s' % (dir, dir)
291 return ' -l%s' % (os.path.splitext(lib)[0][len(
'lib'):])
309 if (ver.is_default_search_location
or no_L_or_I):
315 OPTIONS = [
'libs',
'include_dirs',
'lib_dirs',
'cflags',
'lflags',
'root',
'print_versions',
'version']
319 for k
in dir(options):
321 v = getattr(options, k)
323 raise BoostError(
'Only one option (excepting sysroot) is allowed at a time')
327 if (len(sys.argv) < 2):
330 parser = OptionParser()
331 parser.add_option(
'-l',
'--libs', dest=
'libs', type=
'string', help=
'')
332 parser.add_option(
'-i',
'--include_dirs', dest=
'include_dirs', action=
'store_true', default=
False, help=
'')
333 parser.add_option(
'-d',
'--lib_dirs', dest=
'lib_dirs', action=
'store_true', help=
'')
334 parser.add_option(
'-c',
'--cflags', dest=
'cflags', action=
'store_true', default=
False, help=
'')
335 parser.add_option(
'-f',
'--lflags', dest=
'lflags', type=
'string', help=
'')
336 parser.add_option(
'-r',
'--root', dest=
'root', action=
'store_true', default=
False, help=
'')
337 parser.add_option(
'-p',
'--print_versions', dest=
'print_versions', action=
'store_true', default=
False, help=
'')
338 parser.add_option(
'-v',
'--version', dest=
'version', action=
'store_true', default=
False, help=
'')
339 parser.add_option(
'-s',
'--sysroot', dest=
'sysroot', type=
'string', default=
'', help=
'Location of the system root (usually toolchain root).')
340 parser.add_option(
'-m',
'--multiarch', dest=
'multiarch', type=
'string', default=
'', help=
"Name of multiarch to search below 'lib' folder for libraries.")
342 (options, args) = parser.parse_args()
344 if (options.print_versions):
347 print(
'%s.%s.%s root=%s include_dir=%s' % (ver.major, ver.minor, ver.patch, ver.root, ver.include_dir))
358 print(
'%s.%s.%s root=%s include_dir=%s' % (ver.major, ver.minor, ver.patch, ver.root, ver.include_dir))
361 if ver.major < 1
or (ver.major == 1
and ver.minor < 37):
362 raise BoostError(
'Boost version %s.%s.%s does not meet the minimum requirements of boost 1.37.0' % (ver.major, ver.minor, ver.patch))
370 output =
libs(ver, options.libs.split(
','))
371 elif (options.include_dirs):
374 elif (options.lib_dirs):
377 elif (options.cflags):
380 elif (options.lflags):
382 output =
lflags(ver, options.lflags.split(
','))
386 print(output.strip())
389 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