1 # Copyright 2002-2006 Vladimir Prus
2 # Copyright 2005 Alo Sarv
3 # Copyright 2005-2012 Juergen Hunold
5 # Distributed under the Boost Software License, Version 1.0. (See
6 # accompanying file LICENSE_1_0.txt or copy at
7 # http://www.boost.org/LICENSE_1_0.txt)
9 # Qt5 library support module
11 # The module attempts to auto-detect QT installation location from QTDIR
12 # environment variable; failing that, installation location can be passed as
15 # toolset.using qt5 : /usr/local/Trolltech/Qt-5.0.0 ;
17 # The module supports code generation from .ui and .qrc files, as well as
18 # running the moc preprocessor on headers. Note that you must list all your
19 # moc-able headers in sources.
23 # exe myapp : myapp.cpp myapp.h myapp.ui myapp.qrc
24 # /qt5//QtGui /qt5//QtNetwork ;
26 # It's also possible to run moc on cpp sources:
30 # exe myapp : myapp.cpp [ cast _ moccable-cpp : myapp.cpp ] /qt5//QtGui ;
32 # When moccing source file myapp.cpp you need to include "myapp.moc" from
33 # myapp.cpp. When moccing .h files, the output of moc will be automatically
34 # compiled and linked in, you don't need any includes.
36 # This is consistent with Qt guidelines:
37 # http://qt-project.org/doc/qt-5.0/moc.html
39 # The .qrc processing utility supports various command line option (see
40 # http://qt-project.org/doc/qt-5.0/rcc.html for a complete list). The
41 # module provides default arguments for the "output file" and
42 # "initialization function name" options. Other options can be set through
43 # the <rccflags> build property. E.g. if you wish the compression settings
44 # to be more aggressive than the defaults, you can apply them too all .qrc
47 # project my-qt-project :
49 # <rccflags>"-compress 9 -threshold 10"
52 # Of course, this property can also be specified on individual targets.
59 import "class" : new ;
62 import toolset : flags ;
64 import virtual-target ;
67 # The Qt version used for requirements
68 # Valid are <qt>5.0 or <qt>5.1.0
69 # Auto-detection via qmake sets '<qt>major.minor.patch'
70 feature.feature qt5 : : propagated ;
73 # $TODO: figure out how to declare this only once
74 # feature.feature rccflags : : free ;
76 project.initialize $(__name__) ;
79 # Save the project so that we tolerate 'import + using' combo.
80 .project = [ project.current ] ;
82 # Helper utils for easy debug output
83 if [ MATCH (--debug-configuration) : [ modules.peek : ARGV ] ]
85 .debug-configuration = TRUE ;
88 local rule debug-message ( message * )
90 if $(.debug-configuration) = TRUE
92 ECHO notice\: "[qt5-cfg]" $(message) ;
96 # Capture qmake output line by line
97 local rule read-output ( content )
102 local << = "([^$(nl)]*)[$(nl)](.*)" ;
103 local line+ = [ MATCH "$(<<)" : "$(content)" ] ;
106 lines += $(line+[1]) ;
107 line+ = [ MATCH "$(<<)" : "$(line+[2])" ] ;
112 # Capture Qt version from qmake
113 local rule check-version ( bin_prefix )
115 full-cmd = $(bin_prefix)"/qmake -v" ;
116 debug-message Running '$(full-cmd)' ;
117 local output = [ SHELL $(full-cmd) ] ;
118 for line in [ read-output $(output) ]
120 # Parse the output to get all the results.
121 if [ MATCH "QMake" : $(line) ]
123 # Skip first line of output
127 temp = [ MATCH "([0-9]*)\\.([0-9]*)\\.([0-9]*)" : $(line) ] ;
133 # Validate the version string and extract the major/minor part we care about.
135 local rule split-version ( version )
137 local major-minor = [ MATCH "^([0-9]+)\.([0-9]+)(.*)$" : $(version) : 1 2 3 ] ;
138 if ! $(major-minor[2]) || $(major-minor[3])
140 ECHO "Warning: 'using qt' expects a two part (major, minor) version number; got" $(version) instead ;
142 # Add a zero to account for the missing digit if necessary.
146 return $(major-minor[1]) $(major-minor[2]) ;
149 # Initialize the QT support module.
151 # - 'prefix' parameter tells where Qt is installed.
152 # - 'version' optional version of Qt, else autodetected via 'qmake -v'
153 # - 'condition' optional requirements
154 # - 'namespace' optional support for configure -qtnamespace
155 # - 'infix' optional support for configure -qtlibinfix
156 # - 'full_bin' optional full path to Qt binaries (qmake,moc,uic,rcc)
157 # - 'full_inc' optional full path to Qt top-level include directory
158 # - 'full_lib' optional full path to Qt library directory
159 rule init ( prefix : version ? : condition * : namespace ? : infix ? : full_bin ? : full_inc ? : full_lib ? )
161 project.push-current $(.project) ;
163 debug-message "==== Configuring Qt ... ====" ;
164 for local v in version prefix condition namespace infix full_bin full_inc full_lib
168 debug-message " user-specified $(v):" '$($(v))' ;
172 # Needed as default value
173 .prefix = $(prefix) ;
175 # pre-build paths to detect reinitializations changes
176 local inc_prefix lib_prefix bin_prefix ;
179 inc_prefix = $(full_inc) ;
183 inc_prefix = $(prefix)/include ;
187 lib_prefix = $(full_lib) ;
191 lib_prefix = $(prefix)/lib ;
195 bin_prefix = $(full_bin) ;
199 bin_prefix = $(prefix)/bin ;
202 # Globally needed variables
203 .incprefix = $(inc_prefix) ;
204 .libprefix = $(lib_prefix) ;
205 .binprefix = $(bin_prefix) ;
209 # Make sure this is initialised only once
210 .initialized = true ;
212 # Generates cpp files from header files using "moc" tool
213 generators.register-standard qt5.moc : H : CPP(moc_%) : <allow>qt5 ;
215 # The OBJ result type is a fake, 'H' will be really produced. See
216 # comments on the generator class, defined below the 'init' function.
217 generators.register [ new uic-5-generator qt5.uic : UI : OBJ :
220 # The OBJ result type is a fake here too.
221 generators.register [ new moc-h-5-generator
222 qt5.moc.inc : MOCCABLE5_CPP : OBJ : <allow>qt5 ] ;
224 generators.register [ new moc-inc-5-generator
225 qt5.moc.inc : MOCCABLE5_H : OBJ : <allow>qt5 ] ;
227 # Generates .cpp files from .qrc files.
228 generators.register-standard qt5.rcc : QRC : CPP(qrc_%) : <allow>qt5 ;
230 # dependency scanner for wrapped files.
231 type.set-scanner QRC : qrc-5-scanner ;
233 # Save value of first occurring prefix
234 .PREFIX = $(prefix) ;
239 major-minor = [ split-version $(version) ] ;
240 version = $(major-minor:J=.) ;
244 version = [ check-version $(bin_prefix) ] ;
247 version = $(version:J=.) ;
249 debug-message Detected version '$(version)' ;
252 local target-requirements = $(condition) ;
254 # Add the version, if any, to the target requirements.
257 if ! $(version) in [ feature.values qt5 ]
259 feature.extend qt5 : $(version) ;
261 target-requirements += <qt5>$(version:E=default) ;
264 local target-os = [ feature.get-values target-os : $(condition) ] ;
267 target-os ?= [ feature.defaults target-os ] ;
268 target-os = $(target-os:G=) ;
269 target-requirements += <target-os>$(target-os) ;
272 # Build exact requirements for the tools
273 local tools-requirements = $(target-requirements:J=/) ;
275 debug-message "Details of this Qt configuration:" ;
276 debug-message " prefix: " '$(prefix:E=<empty>)' ;
277 debug-message " binary path: " '$(bin_prefix:E=<empty>)' ;
278 debug-message " include path:" '$(inc_prefix:E=<empty>)' ;
279 debug-message " library path:" '$(lib_prefix:E=<empty>)' ;
280 debug-message " target requirements:" '$(target-requirements)' ;
281 debug-message " tool requirements: " '$(tools-requirements)' ;
283 # setup the paths for the tools
284 toolset.flags qt5.moc .BINPREFIX $(tools-requirements) : $(bin_prefix) ;
285 toolset.flags qt5.rcc .BINPREFIX $(tools-requirements) : $(bin_prefix) ;
286 toolset.flags qt5.uic .BINPREFIX $(tools-requirements) : $(bin_prefix) ;
288 # TODO: 2009-02-12: Better support for directories
289 # Most likely needed are separate getters for: include,libraries,binaries and sources.
290 toolset.flags qt5.directory .PREFIX $(tools-requirements) : $(prefix) ;
292 # Test for a buildable Qt.
293 if [ glob $(.prefix)/Jamroot ]
297 # this will declare QtCore (and qtmain on <target-os>windows)
298 add-shared-library QtCore ;
301 # Setup common pre-built Qt.
302 # Special setup for QtCore on which everything depends
304 local link = [ feature.get-values link : $(condition) ] ;
306 local usage-requirements =
307 <include>$(.incprefix)
308 <library-path>$(.libprefix)
314 usage-requirements += <dll-path>$(.libprefix) ;
315 usage-requirements += <target-os>windows:<dll-path>$(.binprefix) ;
320 # debug versions on unix have to be built
321 # separately and therefore have no suffix.
322 .infix_version = "" ;
325 # Control flag for auto-configuration of the debug libraries.
326 # This setup requires Qt 'configure -debug-and-release'.
327 # Only available on some platforms.
328 # ToDo: 2009-02-12: Maybe throw this away and
329 # require separate setup with <variant>debug as condition.
330 .have_separate_debug = FALSE ;
332 # Setup other platforms
333 if $(target-os) in windows cygwin
335 .have_separate_debug = TRUE ;
337 # On NT, the libs have "d" suffix in debug builds.
338 .suffix_debug = "d" ;
340 .infix_version = "5" ;
342 # On Windows we must link against the qtmain library
346 <name>qtmain$(.suffix_debug)
348 $(target-requirements)
355 $(target-requirements)
358 else if $(target-os) = darwin
360 # On MacOS X, both debug and release libraries are available.
361 .suffix_debug = "_debug" ;
363 .have_separate_debug = TRUE ;
369 alias qtmain : : $(target-requirements) ;
370 .infix_version = "5" ;
375 <name>Qt$(.infix_version)Core
376 $(target-requirements)
378 : # usage-requirements
381 <include>$(.incprefix)/QtCore
382 $(usage-requirements)
385 if $(.have_separate_debug) = TRUE
387 debug-message Configure debug libraries with suffix '$(.suffix_debug)' ;
391 <name>Qt$(.infix_version)Core$(.suffix_debug)
393 $(target-requirements)
395 : # usage-requirements
397 <include>$(.incprefix)/QtCore
398 $(usage-requirements)
403 if [ glob $(.incprefix)/QtAngle ]
405 # Setup support of ANGLE builds.
409 $(target-requirements)
411 : # usage-requirements
412 <define>QT_OPENGL_ES_2
413 <define>QT_OPENGL_ES_2_ANGLE
414 <include>$(.incprefix)/QtAngle
415 $(usage-requirements)
423 $(target-requirements)
427 # Initialising the remaining libraries is canonical
428 # parameters 'module' : 'depends-on' : 'usage-define' : 'requirements' : 'include'
429 # 'include' only for non-canonical include paths.
430 add-shared-library QtGui : QtCore QtAngle : QT_GUI_LIB : $(target-requirements) ;
431 add-shared-library QtWidgets : QtGui : QT_WIDGETS_LIB : $(target-requirements) ;
432 add-shared-library QtNetwork : QtCore : QT_NETWORK_LIB : $(target-requirements) ;
433 add-shared-library QtSql : QtCore : QT_SQL_LIB : $(target-requirements) ;
434 add-shared-library QtXml : QtCore : QT_XML_LIB : $(target-requirements) ;
435 add-shared-library QtPrintSupport : QtGui : QT_PRINTSUPPORT_LIB : $(target-requirements) ;
436 add-shared-library QtConcurrent : QtCore : QT_CONCURRENT_LIB : $(target-requirements) ;
438 add-shared-library QtPositioning : QtCore : QT_POSITIONING_LIB : $(target-requirements) ;
440 add-shared-library QtOpenGL : QtGui : QT_OPENGL_LIB : $(target-requirements) ;
441 add-shared-library QtSvg : QtXml QtOpenGL : QT_SVG_LIB : $(target-requirements) ;
443 add-shared-library QtTest : QtCore : : $(target-requirements) ;
445 # Qt designer library et. al.
446 add-shared-library QtDesigner : QtGui QtXml : : $(target-requirements) ;
447 add-shared-library QtDesignerComponents : QtGui QtXml : : $(target-requirements) ;
448 add-static-library QtUiTools : QtGui QtXml : $(target-requirements) ;
451 add-shared-library QtDBus : QtXml : : $(target-requirements) ;
453 # Script-Engine and Tools
454 add-shared-library QtScript : QtGui QtXml : QT_SCRIPT_LIB : $(target-requirements) ;
455 add-shared-library QtScriptTools : QtScript : QT_SCRIPTTOOLS_LIB : $(target-requirements) ;
458 add-shared-library QtWebKit : QtGui : QT_WEBKIT_LIB : $(target-requirements) ;
459 add-shared-library QtWebKitWidgets : QtGui : QT_WEBKITWIDGETS_LIB : $(target-requirements) ;
462 add-shared-library QtMultimedia : QtGui : QT_MULTIMEDIA_LIB : $(target-requirements) ;
463 add-shared-library QtMultimediaWidgets : QtMultimedia : QT_MULTIMEDIAWIDGETS_LIB : $(target-requirements) ;
466 add-shared-library QtXmlPatterns : QtNetwork : QT_XMLPATTERNS_LIB : $(target-requirements) ;
469 add-shared-library QtHelp : QtGui QtSql QtXml : : $(target-requirements) ;
470 add-shared-library QtCLucene : QCore QtSql QtXml : : $(target-requirements) ;
473 add-shared-library QtQml : QtCore QtNetwork QtGui : QT_QML_LIB : $(target-requirements) ;
474 add-shared-library QtQuick : QtQml : QT_QUICK_LIB : $(target-requirements) ;
475 add-shared-library QtQuickParticles : QtQml : : $(target-requirements) ;
476 add-shared-library QtQuickTest : QtQml : : $(target-requirements) ;
478 add-shared-library QtSerialPort : QtCore : QT_SERIALPORT_LIB : $(target-requirements) ;
480 # QtLocation (since 5.4)
481 add-shared-library QtLocation : QtQuick QtPositioning : QT_LOCATION_LIB : $(target-requirements) ;
483 # Webengine support (since 5.4)
484 add-shared-library QtWebEngine : QtGui : QT_WEBENGINE_LIB : $(target-requirements) ;
485 add-shared-library QtWebEngineCore : QtWebEngine : QT_WEBENGINECORE_LIB : $(target-requirements) ;
486 add-shared-library QtWebEngineWidgets : QtWebEngineCore QtWidgets : QT_WEBENGINEWIDGETS_LIB : $(target-requirements) ;
488 add-shared-library QtWebChannel : QtQml : QT_WEBCHANNEL_LIB : $(target-requirements) ;
489 add-shared-library QtWebSockets : QtNetwork : QT_WEBSOCKETS_LIB : $(target-requirements) ;
491 add-shared-library QtWebView : QtWebEngineCore QtWebChannel : QT_WEBVIEW_LIB : $(target-requirements) ;
493 # Qt3d libraries (since 5.6)
494 add-shared-library Qt3DCore : QtGui : QT_3DCORE_LIB : $(target-requirements) ;
495 add-shared-library Qt3DRender : Qt3DCore QtConcurrent : QT_3DRENDER_LIB : $(target-requirements) ;
496 add-shared-library Qt3DLogic : Qt3DCore : QT_3DLOGIC_LIB : $(target-requirements) ;
497 add-shared-library Qt3DInput : Qt3DRender : QT_3DINPUT_LIB : $(target-requirements) ;
499 # QtCharts (since 5.7)
500 add-shared-library QtCharts : QtWidgets : QT_CHARTS_LIB : $(target-requirements) ;
502 # 3D data visualization (since 5.7)
503 add-shared-library QtDataVisualization : QtGui : QT_DATAVISUALIZATION_LIB : $(target-requirements) ;
505 # In-App purchase API (since 5.7)
506 add-shared-library QtPurchasing : QtCore : QT_PURCHASING_LIB : $(target-requirements) ;
508 # Qt Connectivity (since 5.3)
509 add-shared-library QtBluetooth : QtCore : QT_BLUETOOTH_LIB : $(target-requirements) ;
510 add-shared-library QtNfc : QtCore : QT_NFC_LIB : $(target-requirements) ;
512 # Gamepad (since 5.7)
513 add-shared-library QtGamepad : QtCore : QT_GAMEPAD_LIB : $(target-requirements) ;
515 # SCXML state machine (since 5.7)
516 add-shared-library QtScxml : QtCore : QT_SCXML_LIB : $(target-requirements) ;
518 # Tech Preview QtQuick
519 # SerialBus (since 5.7)
520 add-shared-library QtSerialBus : QtCore : QT_SERIALBUS_LIB : $(target-requirements) ;
522 # Platform dependent libraries
523 # Regular expression support
524 add-shared-library QtV8 : QtCore : : $(target-requirements) ;
526 # QML-Engine version1
527 add-shared-library QtDeclarative : QtXml : : $(target-requirements) ;
529 debug-message "==== Configured Qt-$(version) ====" ;
531 project.pop-current ;
536 return $(.initialized) ;
541 # This custom generator is needed because in QT5, UI files are translated only
542 # into H files, and no C++ files are created. Further, the H files need not be
543 # passed via MOC. The header is used only via inclusion. If we define a standard
544 # UI -> H generator, Boost.Build will run MOC on H, and then compile the
545 # resulting cpp. It will give a warning, since output from moc will be empty.
547 # This generator is declared with a UI -> OBJ signature, so it gets invoked when
548 # linking generator tries to convert sources to OBJ, but it produces target of
549 # type H. This is non-standard, but allowed. That header won't be mocced.
551 class uic-5-generator : generator
553 rule __init__ ( * : * )
555 generator.__init__ $(1) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ;
558 rule run ( project name ? : property-set : sources * )
562 name = [ $(sources[0]).name ] ;
566 local a = [ new action $(sources[1]) : qt5.uic : $(property-set) ] ;
568 # The 'ui_' prefix is to match qmake's default behavior.
569 local target = [ new file-target ui_$(name) : H : $(project) : $(a) ] ;
571 local r = [ virtual-target.register $(target) ] ;
573 # Since this generator will return a H target, the linking generator
574 # won't use it at all, and won't set any dependency on it. However, we
575 # need the target to be seen by bjam, so that dependency from sources to
576 # this generated header is detected -- if jam does not know about this
577 # target, it won't do anything.
578 DEPENDS all : [ $(r).actualize ] ;
585 class moc-h-5-generator : generator
587 rule __init__ ( * : * )
589 generator.__init__ $(1) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ;
592 rule run ( project name ? : property-set : sources * )
594 if ! $(sources[2]) && [ $(sources[1]).type ] = MOCCABLE5_CPP
596 name = [ $(sources[0]).name ] ;
599 local a = [ new action $(sources[1]) : qt5.moc.inc :
602 local target = [ new file-target $(name) : MOC : $(project) : $(a)
605 local r = [ virtual-target.register $(target) ] ;
607 # Since this generator will return a H target, the linking generator
608 # won't use it at all, and won't set any dependency on it. However,
609 # we need the target to be seen by bjam, so that dependency from
610 # sources to this generated header is detected -- if jam does not
611 # know about this target, it won't do anything.
612 DEPENDS all : [ $(r).actualize ] ;
620 class moc-inc-5-generator : generator
622 rule __init__ ( * : * )
624 generator.__init__ $(1) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ;
627 rule run ( project name ? : property-set : sources * )
629 if ! $(sources[2]) && [ $(sources[1]).type ] = MOCCABLE5_H
631 name = [ $(sources[0]).name ] ;
634 local a = [ new action $(sources[1]) : qt5.moc.inc :
637 local target = [ new file-target moc_$(name) : CPP : $(project) :
640 # Since this generator will return a H target, the linking generator
641 # won't use it at all, and won't set any dependency on it. However,
642 # we need the target to be seen by bjam, so that dependency from
643 # sources to this generated header is detected -- if jam does not
644 # know about this target, it won't do anything.
645 DEPENDS all : [ $(target).actualize ] ;
647 return [ virtual-target.register $(target) ] ;
653 # Query the installation directory. This is needed in at least two scenarios.
654 # First, when re-using sources from the Qt-Tree. Second, to "install" custom Qt
655 # plugins to the Qt-Tree.
662 # Add a shared Qt library.
663 rule add-shared-library ( lib-name : depends-on * : usage-defines * : requirements * : include ? )
665 add-library $(lib-name) : $(.infix_version) : $(depends-on) : $(usage-defines) : $(requirements) : $(include) ;
668 # Add a static Qt library.
669 rule add-static-library ( lib-name : depends-on * : usage-defines * : requirements * : include ? )
671 add-library $(lib-name) : $(.infix_version) : $(depends-on) : $(usage-defines) : $(requirements) : $(include) ;
675 # Static libs are unversioned, whereas shared libs have the major number as suffix.
676 # Creates both release and debug versions on platforms where both are enabled by Qt configure.
678 # - lib-name Qt library Name
679 # - version Qt major number used as shared library suffix (QtCore5.so)
680 # - depends-on other Qt libraries
681 # - usage-defines those are set by qmake, so set them when using this library
682 # - requirements additional requirements
683 # - include non-canonical include path. The canonical path is $(.incprefix)/$(lib-name).
684 rule add-library ( lib-name : version ? : depends-on * : usage-defines * : requirements * : include ? )
689 # Eveything will be setup there
691 : $(.prefix)//$(lib-name)
699 real_include ?= $(include) ;
700 real_include ?= $(lib-name) ;
702 local real_name = [ MATCH ^Qt(.*) : $(lib-name) ] ;
708 <name>Qt$(version)$(real_name)
711 : # usage-requirements
712 <define>$(usage-defines)
713 <include>$(.incprefix)/$(real_include)
716 if $(.have_separate_debug) = TRUE
722 <name>Qt$(version)$(real_name)$(.suffix_debug)
726 : # usage-requirements
727 <define>$(usage-defines)
728 <include>$(.incprefix)/$(real_include)
733 # Make library explicit so that a simple <use>qt5 will not bring in everything.
734 # And some components like QtDBus/Phonon may not be available on all platforms.
735 explicit $(lib-name) ;
738 # Use $(.BINPREFIX[-1]) for the paths as several tools-requirements can match.
739 # The exact match is the last one.
741 # Get <include> and <defines> from current toolset.
742 flags qt5.moc INCLUDES <include> ;
743 flags qt5.moc DEFINES <define> ;
745 # need a newline for expansion of DEFINES and INCLUDES in the response file.
749 # Processes headers to create Qt MetaObject information. Qt5-moc has its
750 # c++-parser, so pass INCLUDES and DEFINES.
751 # We use response file with one INCLUDE/DEFINE per line
755 $(.BINPREFIX[-1])/moc $(>) -o $(<) @"@($(<).rsp:E=-D$(DEFINES)$(.nl) -I$(INCLUDES:T)$(.nl))"
758 # When moccing files for include only, we don't need -f, otherwise the generated
759 # code will include the .cpp and we'll get duplicated symbols.
763 $(.BINPREFIX[-1])/moc $(>) -o $(<) @"@($(<).rsp:E=-D$(DEFINES)$(.nl) -I$(INCLUDES:T)$(.nl))"
767 # Get extra options for RCC
768 flags qt5.rcc RCC_OPTIONS <rccflags> ;
770 # Generates source files from resource files.
774 $(.BINPREFIX[-1])/rcc $(>) -name $(>:B) $(RCC_OPTIONS) -o $(<)
778 # Generates user-interface source from .ui files.
782 $(.BINPREFIX[-1])/uic $(>) -o $(<)
786 # Scanner for .qrc files. Look for the CDATA section of the <file> tag. Ignore
787 # the "alias" attribute. See http://doc.trolltech.com/qt/resources.html for
788 # detailed documentation of the Qt Resource System.
790 class qrc-5-scanner : common-scanner
794 return "<file.*>(.*)</file>" ;
799 # Wrapped files are "included".
800 scanner.register qrc-5-scanner : include ;