2
0
mirror of https://github.com/boostorg/build.git synced 2026-02-17 13:42:14 +00:00
Files
build/v2/tools/qt4.jam
Vladimir Prus ec673c840f Add the "ui_" prefix to the header the uic generates, to match
qmake's behaviour.

Thanks to Ryan Winter for the hint.


[SVN r31033]
2005-09-19 07:48:36 +00:00

294 lines
9.6 KiB
Plaintext

# Copyright 2002 Vladimir Prus
# Copyright 2005 Alo Sarv
# Distributed under the Boost Software License, Version 1.0. (See
# accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
# Qt4 library support module
#
# The module attempts to auto-detect QT installation location from QTDIR
# environment variable; failing that, installation location can be passed as
# argument:
#
# toolset.using qt4 : /usr/local/Trolltech/Qt-4.0.0 ;
#
# The module supports code generation from .ui and .qrc files, as well as
# running the moc preprocessor on headers. Note that you must list all your
# moc-able headers in sources.
#
# Example:
#
# exe myapp : myapp.cpp myapp.h myapp.ui myapp.qrc
# /qt4//QtGui /qt4//QtNetwork ;
#
# It's also possible to run moc on cpp sources:
#
# import cast ;
#
# exe myapp : myapp.cpp [ cast _ moccable-cpp : myapp.cpp ] /qt4//QtGui ;
#
# When moccing source file myapp.cpp you need to include "myapp.moc" from
# myapp.cpp. When moccing .h files, the output of moc will be automatically
# compiled and linked in, you don't need any includes.
#
# This is consistent with Qt guidelines:
# http://doc.trolltech.com/4.0/moc.html
import modules ;
import feature ;
import errors ;
import type ;
import "class" : new ;
import generators ;
import project ;
import toolset : flags ;
import os ;
import virtual-target ;
project.initialize $(__name__) ;
project qt4 ;
# Initialized the QT support module. The 'prefix' parameter
# tells where QT is installed. When not given, environmental
# variable QTDIR should be set.
rule init ( prefix ? )
{
if ! $(prefix)
{
prefix = [ modules.peek : QTDIR ] ;
if ! $(prefix)
{
errors.error
"QT installation prefix not given and QTDIR variable is empty" ;
}
}
if $(.initialized)
{
if $(prefix) != $(.prefix)
{
errors.error
"Attempt the reinitialize QT with different installation prefix" ;
}
}
else
{
.initialized = true ;
.prefix = $(prefix) ;
# Generates cpp files from header files using "moc" tool
generators.register-standard qt4.moc : H : CPP(moc_%) ;
# The OBJ result type is a fake, 'H' will be really produces.
# See comments on the generator calss, defined below
# the 'init' function.
generators.register [ new uic-h-generator qt4.uic-h : UI : OBJ ] ;
# The OBJ result type is a fake here too.
generators.register [ new moc-h-generator
qt.moc.cpp : MOCCABLE_CPP : OBJ ] ;
# Generates .cpp file from qrc file
generators.register-standard qt4.rcc : QRC : CPP(qrc_%) ;
local usage-requirements =
<include>$(.prefix)/include
<library-path>$(.prefix)/lib
<dll-path>$(.prefix)/lib ;
local suffix ;
if [ os.name ] = NT
{
# On NT, the libs have "4" suffix, and "d" suffix in debug builds
# Also, on NT we must link against qtmain library (for WinMain)
suffix_version = "4" ;
suffix_debug = "d" ;
lib qtmain : : <name>qtmain$(suffix_debug) <variant>debug ;
lib qtmain : : <name>qtmain <variant>release ;
main = qtmain ;
}
else
{
# On X11, debug versions of libs have "_debug" suffix
suffix_version = "" ;
suffix_debug = "_debug" ;
}
lib QtCore : $(main)
: <name>QtCore$(suffix_version) <variant>release
:
: <include>$(.prefix)/include/QtCore $(usage-requirements)
;
lib QtCore : $(main)
: <name>QtCore$(suffix_debug)$(suffix_version) <variant>debug
:
: <include>$(.prefix)/include/QtCore $(usage-requirements) ;
lib QtGui : QtCore
: <name>QtGui$(suffix_version) <variant>release
:
: <include>$(.prefix)/include/QtGui <user-interface>gui ;
lib QtGui : QtCore
: <name>QtGui$(suffix_debug)$(suffix_version) <variant>debug
:
: <include>$(.prefix)/include/QtGui <user-interface>gui ;
lib QtNetwork : QtCore
: <name>QtNetwork$(suffix_version) <variant>release
:
: <include>$(.prefix)/include/QtNetwork ;
lib QtNetwork : QtCore
: <name>QtNetwork$(suffix_debug)$(suffix_version) <variant>debug
:
: <include>$(.prefix)/include/QtNetwork ;
lib Qt3Support : QtCore
: <name>Qt3Support$(suffix_version) <variant>release
:
: <include>$(.prefix)/include/Qt3Support ;
lib Qt3Support : QtCore
: <name>Qt3Support$(suffix_debug)$(suffix_version) <variant>debug
:
: <include>$(.prefix)/include/Qt3Support ;
lib QtOpenGL : QtCore
: <name>QtOpenGL$(suffix_version) <variant>release
:
: <include>$(.prefix)/include/QtOpenGL ;
lib QtOpenGL : QtCore
: <name>QtOpenGL$(suffix_debug)$(suffix_version) <variant>debug
:
: <include>$(.prefix)/include/QtOpenGL ;
lib QtSql : QtCore
: <name>QtSql$(suffix_version) <variant>release
:
: <include>$(.prefix)/include/QtSql ;
lib QtSql : QtCore
: <name>QtSql$(suffix_debug)$(suffix_version) <variant>debug
:
: <include>$(.prefix)/include/QtSql ;
lib QtXml : QtCore
: <name>QtXml$(suffix_version) <variant>release
:
: <include>$(.prefix)/include/QtXml ;
lib QtXml : QtCore
: <name>QtXml$(suffix_debug)$(suffix_version) <variant>debug
:
: <include>$(.prefix)/include/QtXml ;
}
}
# This custom generator is needed because it QT4, UI files are translated
# only in H files, and no C++ files are created. Further, the H files
# need not be passed via MOC. The header is used only via inclusion.
# If we define standard UI -> H generator, Boost.Build will run
# MOC on H, and the compile resulting cpp. It will give a warning, since
# output from moc will be empty.
#
# This generator is declared with UI -> OBJ signature, so it's
# invoked when linking generator tries to convert sources to OBJ,
# but it produces target of type H. This is non-standard, but allowed.
# That header won't be mocced.
#
class uic-h-generator : generator
{
rule __init__ ( * : * )
{
generator.__init__ $(1) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ;
}
rule run ( project name ? : property-set : sources * )
{
if ! $(name)
{
name = [ $(sources[0]).name ] ;
name = $(name:B) ;
}
local a = [ new action $(sources[1]) : qt4.uic-h :
$(property-set) ] ;
# The 'ui_' prefix is to match qmake's default behavior.
local target = [
new file-target ui_$(name) : H : $(project) : $(a) ] ;
# Since this generator will return H target, the linking generator
# won't use it at all, and won't set any dependency on it.
# However, we need to target to be seen by bjam, so that dependency
# from sources to this generated header is detected -- if jam does
# not know about this target, it won't do anything.
DEPENDS all : [ $(target).actualize ] ;
return [ virtual-target.register $(target) ] ;
}
}
class moc-h-generator : generator
{
rule __init__ ( * : * )
{
generator.__init__ $(1) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ;
}
rule run ( project name ? : property-set : sources * )
{
if ! $(sources[2]) && [ $(sources[1]).type ] = MOCCABLE_CPP
{
name = [ $(sources[0]).name ] ;
name = $(name:B) ;
local a = [ new action $(sources[1]) : qt4.moc.cpp :
$(property-set) ] ;
local target = [
new file-target $(name) : MOC : $(project) : $(a) ] ;
# Since this generator will return H target, the linking generator
# won't use it at all, and won't set any dependency on it.
# However, we need to target to be seen by bjam, so that dependency
# from sources to this generated header is detected -- if jam does
# not know about this target, it won't do anything.
DEPENDS all : [ $(target).actualize ] ;
return [ virtual-target.register $(target) ] ;
}
}
}
# Query the installation directory
# This is needed in at least two scenarios
# First, when re-using sources from the Qt-Tree.
# Second, to "install" custom Qt plugins to the Qt-Tree.
rule directory
{
return $(.prefix) ;
}
# Get <include> and <defines> from current toolset
flags qt4.moc INCLUDES <include> ;
flags qt4.moc DEFINES <define> ;
# Processes headers to create Qt MetaObject information
# Qt4-moc has its c++-parser, so pass INCLUDES and DEFINES.
actions moc
{
$(.prefix)/bin/moc -I$(INCLUDES) -I$(DEFINES) -f $(>) -o $(<)
}
# When moccing .cpp files, we don't need -f, otherwise generated
# code will include .cpp and we'll get duplicated symbols.
actions moc.cpp
{
$(.prefix)/bin/moc -I$(INCLUDES) -I$(DEFINES) $(>) -o $(<)
}
# Generates source files from resource files
actions rcc
{
$(.prefix)/bin/rcc $(>) -name $(>:B) -o $(<)
}
# Generates user-interface source from .ui files
actions uic-h
{
$(.prefix)/bin/uic $(>) -o $(<)
}