jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

693 lines
20KB

  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. # Thomas Nagy, 2006-2010 (ita)
  4. """
  5. Tool Description
  6. ================
  7. This tool helps with finding Qt4 tools and libraries,
  8. and also provides syntactic sugar for using Qt4 tools.
  9. The following snippet illustrates the tool usage::
  10. def options(opt):
  11. opt.load('compiler_cxx qt4')
  12. def configure(conf):
  13. conf.load('compiler_cxx qt4')
  14. def build(bld):
  15. bld(
  16. features = 'qt4 cxx cxxprogram',
  17. uselib = 'QTCORE QTGUI QTOPENGL QTSVG',
  18. source = 'main.cpp textures.qrc aboutDialog.ui',
  19. target = 'window',
  20. )
  21. Here, the UI description and resource files will be processed
  22. to generate code.
  23. Usage
  24. =====
  25. Load the "qt4" tool.
  26. You also need to edit your sources accordingly:
  27. - the normal way of doing things is to have your C++ files
  28. include the .moc file.
  29. This is regarded as the best practice (and provides much faster
  30. compilations).
  31. It also implies that the include paths have beenset properly.
  32. - to have the include paths added automatically, use the following::
  33. from waflib.TaskGen import feature, before_method, after_method
  34. @feature('cxx')
  35. @after_method('process_source')
  36. @before_method('apply_incpaths')
  37. def add_includes_paths(self):
  38. incs = set(self.to_list(getattr(self, 'includes', '')))
  39. for x in self.compiled_tasks:
  40. incs.add(x.inputs[0].parent.path_from(self.path))
  41. self.includes = list(incs)
  42. Note: another tool provides Qt processing that does not require
  43. .moc includes, see 'playground/slow_qt/'.
  44. A few options (--qt{dir,bin,...}) and environment variables
  45. (QT4_{ROOT,DIR,MOC,UIC,XCOMPILE}) allow finer tuning of the tool,
  46. tool path selection, etc; please read the source for more info.
  47. """
  48. try:
  49. from xml.sax import make_parser
  50. from xml.sax.handler import ContentHandler
  51. except ImportError:
  52. has_xml = False
  53. ContentHandler = object
  54. else:
  55. has_xml = True
  56. import os, sys
  57. from waflib.Tools import cxx
  58. from waflib import Task, Utils, Options, Errors, Context
  59. from waflib.TaskGen import feature, after_method, extension
  60. from waflib.Configure import conf
  61. from waflib import Logs
  62. MOC_H = ['.h', '.hpp', '.hxx', '.hh']
  63. """
  64. File extensions associated to the .moc files
  65. """
  66. EXT_RCC = ['.qrc']
  67. """
  68. File extension for the resource (.qrc) files
  69. """
  70. EXT_UI = ['.ui']
  71. """
  72. File extension for the user interface (.ui) files
  73. """
  74. EXT_QT4 = ['.cpp', '.cc', '.cxx', '.C']
  75. """
  76. File extensions of C++ files that may require a .moc processing
  77. """
  78. QT4_LIBS = "QtCore QtGui QtUiTools QtNetwork QtOpenGL QtSql QtSvg QtTest QtXml QtXmlPatterns QtWebKit Qt3Support QtHelp QtScript QtDeclarative QtDesigner"
  79. class qxx(Task.classes['cxx']):
  80. """
  81. Each C++ file can have zero or several .moc files to create.
  82. They are known only when the files are scanned (preprocessor)
  83. To avoid scanning the c++ files each time (parsing C/C++), the results
  84. are retrieved from the task cache (bld.node_deps/bld.raw_deps).
  85. The moc tasks are also created *dynamically* during the build.
  86. """
  87. def __init__(self, *k, **kw):
  88. Task.Task.__init__(self, *k, **kw)
  89. self.moc_done = 0
  90. def runnable_status(self):
  91. """
  92. Compute the task signature to make sure the scanner was executed. Create the
  93. moc tasks by using :py:meth:`waflib.Tools.qt4.qxx.add_moc_tasks` (if necessary),
  94. then postpone the task execution (there is no need to recompute the task signature).
  95. """
  96. if self.moc_done:
  97. return Task.Task.runnable_status(self)
  98. else:
  99. for t in self.run_after:
  100. if not t.hasrun:
  101. return Task.ASK_LATER
  102. self.add_moc_tasks()
  103. return Task.Task.runnable_status(self)
  104. def create_moc_task(self, h_node, m_node):
  105. """
  106. If several libraries use the same classes, it is possible that moc will run several times (Issue 1318)
  107. It is not possible to change the file names, but we can assume that the moc transformation will be identical,
  108. and the moc tasks can be shared in a global cache.
  109. The defines passed to moc will then depend on task generator order. If this is not acceptable, then
  110. use the tool slow_qt4 instead (and enjoy the slow builds... :-( )
  111. """
  112. try:
  113. moc_cache = self.generator.bld.moc_cache
  114. except AttributeError:
  115. moc_cache = self.generator.bld.moc_cache = {}
  116. try:
  117. return moc_cache[h_node]
  118. except KeyError:
  119. tsk = moc_cache[h_node] = Task.classes['moc'](env=self.env, generator=self.generator)
  120. tsk.set_inputs(h_node)
  121. tsk.set_outputs(m_node)
  122. if self.generator:
  123. self.generator.tasks.append(tsk)
  124. # direct injection in the build phase (safe because called from the main thread)
  125. gen = self.generator.bld.producer
  126. gen.outstanding.insert(0, tsk)
  127. gen.total += 1
  128. return tsk
  129. def moc_h_ext(self):
  130. try:
  131. ext = Options.options.qt_header_ext.split()
  132. except AttributeError:
  133. pass
  134. if not ext:
  135. ext = MOC_H
  136. return ext
  137. def add_moc_tasks(self):
  138. """
  139. Create the moc tasks by looking in ``bld.raw_deps[self.uid()]``
  140. """
  141. node = self.inputs[0]
  142. bld = self.generator.bld
  143. try:
  144. # compute the signature once to know if there is a moc file to create
  145. self.signature()
  146. except KeyError:
  147. # the moc file may be referenced somewhere else
  148. pass
  149. else:
  150. # remove the signature, it must be recomputed with the moc task
  151. delattr(self, 'cache_sig')
  152. include_nodes = [node.parent] + self.generator.includes_nodes
  153. moctasks = []
  154. mocfiles = set([])
  155. for d in bld.raw_deps.get(self.uid(), []):
  156. if not d.endswith('.moc'):
  157. continue
  158. # process that base.moc only once
  159. if d in mocfiles:
  160. continue
  161. mocfiles.add(d)
  162. # find the source associated with the moc file
  163. h_node = None
  164. base2 = d[:-4]
  165. for x in include_nodes:
  166. for e in self.moc_h_ext():
  167. h_node = x.find_node(base2 + e)
  168. if h_node:
  169. break
  170. if h_node:
  171. m_node = h_node.change_ext('.moc')
  172. break
  173. else:
  174. # foo.cpp -> foo.cpp.moc
  175. for k in EXT_QT4:
  176. if base2.endswith(k):
  177. for x in include_nodes:
  178. h_node = x.find_node(base2)
  179. if h_node:
  180. break
  181. if h_node:
  182. m_node = h_node.change_ext(k + '.moc')
  183. break
  184. if not h_node:
  185. raise Errors.WafError('No source found for %r which is a moc file' % d)
  186. # create the moc task
  187. task = self.create_moc_task(h_node, m_node)
  188. moctasks.append(task)
  189. # simple scheduler dependency: run the moc task before others
  190. self.run_after.update(set(moctasks))
  191. self.moc_done = 1
  192. class trans_update(Task.Task):
  193. """Update a .ts files from a list of C++ files"""
  194. run_str = '${QT_LUPDATE} ${SRC} -ts ${TGT}'
  195. color = 'BLUE'
  196. Task.update_outputs(trans_update)
  197. class XMLHandler(ContentHandler):
  198. """
  199. Parser for *.qrc* files
  200. """
  201. def __init__(self):
  202. self.buf = []
  203. self.files = []
  204. def startElement(self, name, attrs):
  205. if name == 'file':
  206. self.buf = []
  207. def endElement(self, name):
  208. if name == 'file':
  209. self.files.append(str(''.join(self.buf)))
  210. def characters(self, cars):
  211. self.buf.append(cars)
  212. @extension(*EXT_RCC)
  213. def create_rcc_task(self, node):
  214. "Create rcc and cxx tasks for *.qrc* files"
  215. rcnode = node.change_ext('_rc.cpp')
  216. self.create_task('rcc', node, rcnode)
  217. cpptask = self.create_task('cxx', rcnode, rcnode.change_ext('.o'))
  218. try:
  219. self.compiled_tasks.append(cpptask)
  220. except AttributeError:
  221. self.compiled_tasks = [cpptask]
  222. return cpptask
  223. @extension(*EXT_UI)
  224. def create_uic_task(self, node):
  225. "hook for uic tasks"
  226. uictask = self.create_task('ui4', node)
  227. uictask.outputs = [self.path.find_or_declare(self.env['ui_PATTERN'] % node.name[:-3])]
  228. @extension('.ts')
  229. def add_lang(self, node):
  230. """add all the .ts file into self.lang"""
  231. self.lang = self.to_list(getattr(self, 'lang', [])) + [node]
  232. @feature('qt4')
  233. @after_method('apply_link')
  234. def apply_qt4(self):
  235. """
  236. Add MOC_FLAGS which may be necessary for moc::
  237. def build(bld):
  238. bld.program(features='qt4', source='main.cpp', target='app', use='QTCORE')
  239. The additional parameters are:
  240. :param lang: list of translation files (\*.ts) to process
  241. :type lang: list of :py:class:`waflib.Node.Node` or string without the .ts extension
  242. :param update: whether to process the C++ files to update the \*.ts files (use **waf --translate**)
  243. :type update: bool
  244. :param langname: if given, transform the \*.ts files into a .qrc files to include in the binary file
  245. :type langname: :py:class:`waflib.Node.Node` or string without the .qrc extension
  246. """
  247. if getattr(self, 'lang', None):
  248. qmtasks = []
  249. for x in self.to_list(self.lang):
  250. if isinstance(x, str):
  251. x = self.path.find_resource(x + '.ts')
  252. qmtasks.append(self.create_task('ts2qm', x, x.change_ext('.qm')))
  253. if getattr(self, 'update', None) and Options.options.trans_qt4:
  254. cxxnodes = [a.inputs[0] for a in self.compiled_tasks] + [
  255. a.inputs[0] for a in self.tasks if getattr(a, 'inputs', None) and a.inputs[0].name.endswith('.ui')]
  256. for x in qmtasks:
  257. self.create_task('trans_update', cxxnodes, x.inputs)
  258. if getattr(self, 'langname', None):
  259. qmnodes = [x.outputs[0] for x in qmtasks]
  260. rcnode = self.langname
  261. if isinstance(rcnode, str):
  262. rcnode = self.path.find_or_declare(rcnode + '.qrc')
  263. t = self.create_task('qm2rcc', qmnodes, rcnode)
  264. k = create_rcc_task(self, t.outputs[0])
  265. self.link_task.inputs.append(k.outputs[0])
  266. lst = []
  267. for flag in self.to_list(self.env['CXXFLAGS']):
  268. if len(flag) < 2: continue
  269. f = flag[0:2]
  270. if f in ('-D', '-I', '/D', '/I'):
  271. if (f[0] == '/'):
  272. lst.append('-' + flag[1:])
  273. else:
  274. lst.append(flag)
  275. self.env.append_value('MOC_FLAGS', lst)
  276. @extension(*EXT_QT4)
  277. def cxx_hook(self, node):
  278. """
  279. Re-map C++ file extensions to the :py:class:`waflib.Tools.qt4.qxx` task.
  280. """
  281. return self.create_compiled_task('qxx', node)
  282. class rcc(Task.Task):
  283. """
  284. Process *.qrc* files
  285. """
  286. color = 'BLUE'
  287. run_str = '${QT_RCC} -name ${tsk.rcname()} ${SRC[0].abspath()} ${RCC_ST} -o ${TGT}'
  288. ext_out = ['.h']
  289. def rcname(self):
  290. return os.path.splitext(self.inputs[0].name)[0]
  291. def scan(self):
  292. """Parse the *.qrc* files"""
  293. if not has_xml:
  294. Logs.error('no xml support was found, the rcc dependencies will be incomplete!')
  295. return ([], [])
  296. parser = make_parser()
  297. curHandler = XMLHandler()
  298. parser.setContentHandler(curHandler)
  299. fi = open(self.inputs[0].abspath(), 'r')
  300. try:
  301. parser.parse(fi)
  302. finally:
  303. fi.close()
  304. nodes = []
  305. names = []
  306. root = self.inputs[0].parent
  307. for x in curHandler.files:
  308. nd = root.find_resource(x)
  309. if nd: nodes.append(nd)
  310. else: names.append(x)
  311. return (nodes, names)
  312. class moc(Task.Task):
  313. """
  314. Create *.moc* files
  315. """
  316. color = 'BLUE'
  317. run_str = '${QT_MOC} ${MOC_FLAGS} ${MOCCPPPATH_ST:INCPATHS} ${MOCDEFINES_ST:DEFINES} ${SRC} ${MOC_ST} ${TGT}'
  318. def keyword(self):
  319. return "Creating"
  320. def __str__(self):
  321. return self.outputs[0].path_from(self.generator.bld.launch_node())
  322. class ui4(Task.Task):
  323. """
  324. Process *.ui* files
  325. """
  326. color = 'BLUE'
  327. run_str = '${QT_UIC} ${SRC} -o ${TGT}'
  328. ext_out = ['.h']
  329. class ts2qm(Task.Task):
  330. """
  331. Create *.qm* files from *.ts* files
  332. """
  333. color = 'BLUE'
  334. run_str = '${QT_LRELEASE} ${QT_LRELEASE_FLAGS} ${SRC} -qm ${TGT}'
  335. class qm2rcc(Task.Task):
  336. """
  337. Transform *.qm* files into *.rc* files
  338. """
  339. color = 'BLUE'
  340. after = 'ts2qm'
  341. def run(self):
  342. """Create a qrc file including the inputs"""
  343. txt = '\n'.join(['<file>%s</file>' % k.path_from(self.outputs[0].parent) for k in self.inputs])
  344. code = '<!DOCTYPE RCC><RCC version="1.0">\n<qresource>\n%s\n</qresource>\n</RCC>' % txt
  345. self.outputs[0].write(code)
  346. def configure(self):
  347. """
  348. Besides the configuration options, the environment variable QT4_ROOT may be used
  349. to give the location of the qt4 libraries (absolute path).
  350. The detection will use the program *pkg-config* through :py:func:`waflib.Tools.config_c.check_cfg`
  351. """
  352. self.find_qt4_binaries()
  353. self.set_qt4_libs_to_check()
  354. self.set_qt4_defines()
  355. self.find_qt4_libraries()
  356. self.add_qt4_rpath()
  357. self.simplify_qt4_libs()
  358. @conf
  359. def find_qt4_binaries(self):
  360. env = self.env
  361. opt = Options.options
  362. qtdir = getattr(opt, 'qtdir', '')
  363. qtbin = getattr(opt, 'qtbin', '')
  364. paths = []
  365. if qtdir:
  366. qtbin = os.path.join(qtdir, 'bin')
  367. # the qt directory has been given from QT4_ROOT - deduce the qt binary path
  368. if not qtdir:
  369. qtdir = os.environ.get('QT4_ROOT', '')
  370. qtbin = os.environ.get('QT4_BIN', None) or os.path.join(qtdir, 'bin')
  371. if qtbin:
  372. paths = [qtbin]
  373. # no qtdir, look in the path and in /usr/local/Trolltech
  374. if not qtdir:
  375. paths = os.environ.get('PATH', '').split(os.pathsep)
  376. paths.append('/usr/share/qt4/bin/')
  377. try:
  378. lst = Utils.listdir('/usr/local/Trolltech/')
  379. except OSError:
  380. pass
  381. else:
  382. if lst:
  383. lst.sort()
  384. lst.reverse()
  385. # keep the highest version
  386. qtdir = '/usr/local/Trolltech/%s/' % lst[0]
  387. qtbin = os.path.join(qtdir, 'bin')
  388. paths.append(qtbin)
  389. # at the end, try to find qmake in the paths given
  390. # keep the one with the highest version
  391. cand = None
  392. prev_ver = ['4', '0', '0']
  393. for qmk in ('qmake-qt4', 'qmake4', 'qmake'):
  394. try:
  395. qmake = self.find_program(qmk, path_list=paths)
  396. except self.errors.ConfigurationError:
  397. pass
  398. else:
  399. try:
  400. version = self.cmd_and_log(qmake + ['-query', 'QT_VERSION']).strip()
  401. except self.errors.WafError:
  402. pass
  403. else:
  404. if version:
  405. new_ver = version.split('.')
  406. if new_ver > prev_ver:
  407. cand = qmake
  408. prev_ver = new_ver
  409. if cand:
  410. self.env.QMAKE = cand
  411. else:
  412. self.fatal('Could not find qmake for qt4')
  413. qtbin = self.cmd_and_log(self.env.QMAKE + ['-query', 'QT_INSTALL_BINS']).strip() + os.sep
  414. def find_bin(lst, var):
  415. if var in env:
  416. return
  417. for f in lst:
  418. try:
  419. ret = self.find_program(f, path_list=paths)
  420. except self.errors.ConfigurationError:
  421. pass
  422. else:
  423. env[var]=ret
  424. break
  425. find_bin(['uic-qt3', 'uic3'], 'QT_UIC3')
  426. find_bin(['uic-qt4', 'uic'], 'QT_UIC')
  427. if not env.QT_UIC:
  428. self.fatal('cannot find the uic compiler for qt4')
  429. self.start_msg('Checking for uic version')
  430. uicver = self.cmd_and_log(env.QT_UIC + ["-version"], output=Context.BOTH)
  431. uicver = ''.join(uicver).strip()
  432. uicver = uicver.replace('Qt User Interface Compiler ','').replace('User Interface Compiler for Qt', '')
  433. self.end_msg(uicver)
  434. if uicver.find(' 3.') != -1:
  435. self.fatal('this uic compiler is for qt3, add uic for qt4 to your path')
  436. find_bin(['moc-qt4', 'moc'], 'QT_MOC')
  437. find_bin(['rcc-qt4', 'rcc'], 'QT_RCC')
  438. find_bin(['lrelease-qt4', 'lrelease'], 'QT_LRELEASE')
  439. find_bin(['lupdate-qt4', 'lupdate'], 'QT_LUPDATE')
  440. env['UIC3_ST']= '%s -o %s'
  441. env['UIC_ST'] = '%s -o %s'
  442. env['MOC_ST'] = '-o'
  443. env['ui_PATTERN'] = 'ui_%s.h'
  444. env['QT_LRELEASE_FLAGS'] = ['-silent']
  445. env.MOCCPPPATH_ST = '-I%s'
  446. env.MOCDEFINES_ST = '-D%s'
  447. @conf
  448. def find_qt4_libraries(self):
  449. qtlibs = getattr(Options.options, 'qtlibs', None) or os.environ.get("QT4_LIBDIR", None)
  450. if not qtlibs:
  451. try:
  452. qtlibs = self.cmd_and_log(self.env.QMAKE + ['-query', 'QT_INSTALL_LIBS']).strip()
  453. except Errors.WafError:
  454. qtdir = self.cmd_and_log(self.env.QMAKE + ['-query', 'QT_INSTALL_PREFIX']).strip() + os.sep
  455. qtlibs = os.path.join(qtdir, 'lib')
  456. self.msg('Found the Qt4 libraries in', qtlibs)
  457. qtincludes = os.environ.get("QT4_INCLUDES", None) or self.cmd_and_log(self.env.QMAKE + ['-query', 'QT_INSTALL_HEADERS']).strip()
  458. env = self.env
  459. if not 'PKG_CONFIG_PATH' in os.environ:
  460. os.environ['PKG_CONFIG_PATH'] = '%s:%s/pkgconfig:/usr/lib/qt4/lib/pkgconfig:/opt/qt4/lib/pkgconfig:/usr/lib/qt4/lib:/opt/qt4/lib' % (qtlibs, qtlibs)
  461. try:
  462. if os.environ.get("QT4_XCOMPILE", None):
  463. raise self.errors.ConfigurationError()
  464. self.check_cfg(atleast_pkgconfig_version='0.1')
  465. except self.errors.ConfigurationError:
  466. for i in self.qt4_vars:
  467. uselib = i.upper()
  468. if Utils.unversioned_sys_platform() == "darwin":
  469. # Since at least qt 4.7.3 each library locates in separate directory
  470. frameworkName = i + ".framework"
  471. qtDynamicLib = os.path.join(qtlibs, frameworkName, i)
  472. if os.path.exists(qtDynamicLib):
  473. env.append_unique('FRAMEWORK_' + uselib, i)
  474. self.msg('Checking for %s' % i, qtDynamicLib, 'GREEN')
  475. else:
  476. self.msg('Checking for %s' % i, False, 'YELLOW')
  477. env.append_unique('INCLUDES_' + uselib, os.path.join(qtlibs, frameworkName, 'Headers'))
  478. elif env.DEST_OS != "win32":
  479. qtDynamicLib = os.path.join(qtlibs, "lib" + i + ".so")
  480. qtStaticLib = os.path.join(qtlibs, "lib" + i + ".a")
  481. if os.path.exists(qtDynamicLib):
  482. env.append_unique('LIB_' + uselib, i)
  483. self.msg('Checking for %s' % i, qtDynamicLib, 'GREEN')
  484. elif os.path.exists(qtStaticLib):
  485. env.append_unique('LIB_' + uselib, i)
  486. self.msg('Checking for %s' % i, qtStaticLib, 'GREEN')
  487. else:
  488. self.msg('Checking for %s' % i, False, 'YELLOW')
  489. env.append_unique('LIBPATH_' + uselib, qtlibs)
  490. env.append_unique('INCLUDES_' + uselib, qtincludes)
  491. env.append_unique('INCLUDES_' + uselib, os.path.join(qtincludes, i))
  492. else:
  493. # Release library names are like QtCore4
  494. for k in ("lib%s.a", "lib%s4.a", "%s.lib", "%s4.lib"):
  495. lib = os.path.join(qtlibs, k % i)
  496. if os.path.exists(lib):
  497. env.append_unique('LIB_' + uselib, i + k[k.find("%s") + 2 : k.find('.')])
  498. self.msg('Checking for %s' % i, lib, 'GREEN')
  499. break
  500. else:
  501. self.msg('Checking for %s' % i, False, 'YELLOW')
  502. env.append_unique('LIBPATH_' + uselib, qtlibs)
  503. env.append_unique('INCLUDES_' + uselib, qtincludes)
  504. env.append_unique('INCLUDES_' + uselib, os.path.join(qtincludes, i))
  505. # Debug library names are like QtCore4d
  506. uselib = i.upper() + "_debug"
  507. for k in ("lib%sd.a", "lib%sd4.a", "%sd.lib", "%sd4.lib"):
  508. lib = os.path.join(qtlibs, k % i)
  509. if os.path.exists(lib):
  510. env.append_unique('LIB_' + uselib, i + k[k.find("%s") + 2 : k.find('.')])
  511. self.msg('Checking for %s' % i, lib, 'GREEN')
  512. break
  513. else:
  514. self.msg('Checking for %s' % i, False, 'YELLOW')
  515. env.append_unique('LIBPATH_' + uselib, qtlibs)
  516. env.append_unique('INCLUDES_' + uselib, qtincludes)
  517. env.append_unique('INCLUDES_' + uselib, os.path.join(qtincludes, i))
  518. else:
  519. for i in self.qt4_vars_debug + self.qt4_vars:
  520. self.check_cfg(package=i, args='--cflags --libs', mandatory=False)
  521. @conf
  522. def simplify_qt4_libs(self):
  523. # the libpaths make really long command-lines
  524. # remove the qtcore ones from qtgui, etc
  525. env = self.env
  526. def process_lib(vars_, coreval):
  527. for d in vars_:
  528. var = d.upper()
  529. if var == 'QTCORE':
  530. continue
  531. value = env['LIBPATH_'+var]
  532. if value:
  533. core = env[coreval]
  534. accu = []
  535. for lib in value:
  536. if lib in core:
  537. continue
  538. accu.append(lib)
  539. env['LIBPATH_'+var] = accu
  540. process_lib(self.qt4_vars, 'LIBPATH_QTCORE')
  541. process_lib(self.qt4_vars_debug, 'LIBPATH_QTCORE_DEBUG')
  542. @conf
  543. def add_qt4_rpath(self):
  544. # rpath if wanted
  545. env = self.env
  546. if getattr(Options.options, 'want_rpath', False):
  547. def process_rpath(vars_, coreval):
  548. for d in vars_:
  549. var = d.upper()
  550. value = env['LIBPATH_'+var]
  551. if value:
  552. core = env[coreval]
  553. accu = []
  554. for lib in value:
  555. if var != 'QTCORE':
  556. if lib in core:
  557. continue
  558. accu.append('-Wl,--rpath='+lib)
  559. env['RPATH_'+var] = accu
  560. process_rpath(self.qt4_vars, 'LIBPATH_QTCORE')
  561. process_rpath(self.qt4_vars_debug, 'LIBPATH_QTCORE_DEBUG')
  562. @conf
  563. def set_qt4_libs_to_check(self):
  564. if not hasattr(self, 'qt4_vars'):
  565. self.qt4_vars = QT4_LIBS
  566. self.qt4_vars = Utils.to_list(self.qt4_vars)
  567. if not hasattr(self, 'qt4_vars_debug'):
  568. self.qt4_vars_debug = [a + '_debug' for a in self.qt4_vars]
  569. self.qt4_vars_debug = Utils.to_list(self.qt4_vars_debug)
  570. @conf
  571. def set_qt4_defines(self):
  572. if sys.platform != 'win32':
  573. return
  574. for x in self.qt4_vars:
  575. y = x[2:].upper()
  576. self.env.append_unique('DEFINES_%s' % x.upper(), 'QT_%s_LIB' % y)
  577. self.env.append_unique('DEFINES_%s_DEBUG' % x.upper(), 'QT_%s_LIB' % y)
  578. def options(opt):
  579. """
  580. Command-line options
  581. """
  582. opt.add_option('--want-rpath', action='store_true', default=False, dest='want_rpath', help='enable the rpath for qt libraries')
  583. opt.add_option('--header-ext',
  584. type='string',
  585. default='',
  586. help='header extension for moc files',
  587. dest='qt_header_ext')
  588. for i in 'qtdir qtbin qtlibs'.split():
  589. opt.add_option('--'+i, type='string', default='', dest=i)
  590. opt.add_option('--translate', action="store_true", help="collect translation strings", dest="trans_qt4", default=False)