Configuring qmake's Environment
Propertiesqmake has a system of persistant information, this allows you to set a variable in qmake once, and each time qmake is invoked this value can be queried. Use the following to set a property in qmake: qmake -set VARIABLE VALUE To retrieve this information back from qmake you can do: qmake -query VARIABLE qmake -query #queries all current VARIABLE/VALUE pairs.. This information will be saved into a QSettings object (meaning it will be stored in different places for different platforms). As VARIABLE is versioned as well, you can set one value in an older version of qmake, and newer versions will retrieve this value, however if you -set VARIABLE into a newer version of qmake the older version will not use this value. You can however query a specific version of a variable if you prefix that version of qmake to VARIABLE, as in: qmake -query "1.06a/VARIABLE" qmake also has the notion of builtin properties, for example you can query the installation of Qt for this version of qmake with the QT_INSTALL_PREFIX property: qmake -query "QT_INSTALL_PREFIX" These builtin properties cannot have a version prefixed to them as they are not versioned and each qmake will have its own notion of these values. The list below outlines the builtin properties:
Finally, these values can be queried in a project file with a special notation such as: QMAKE_VERS = $$[QMAKE_VERSION] QMAKESPECqmake requires a platform and compiler description file which contains many default values used to generate appropriate Makefiles. The standard Qt distribution comes with many of these files, located in the mkspecs subdirectory of the Qt installation. The QMAKESPEC environment variable can contain any of the following:
Note: the QMAKESPEC path will automatically be added to the INCLUDEPATH system variable. INSTALLSIt is common on Unix to be able to install from the same utility as you build with (e.g make install). For this qmake has introduce the concept of an install set. The notation for this is quite simple, first you fill in an "object" in qmake for example: documentation.path = /usr/local/program/doc documentation.files = docs/* In this way you are telling qmake several things about this install, first that you plan to install to /usr/local/program/doc (the path member), second that you plan to copy everything in the docs directory. Once this is done you may insert it in the install list: INSTALLS += documentation Now qmake will take over making sure the correct things are copied to the specified places. If however you require greater control you may use the extra member of the object: unix:documentation.extra = create_docs; mv master.doc toc.doc Then qmake will run the things in extra (this is of course platform specific, so you may need to test for your platform first, this case we test for unix). Then it will do the normal processings of the files member. Finally if you appened a builtin install to INSTALLS qmake (and do not specify a files or extra member) will decide what needs to be copied for you, currently the only supported builtin is target: target.path = /usr/local/myprogram INSTALLS += target With this qmake will know what you plan need copied, and do this for you. Cache FileThe cache file (mentioned above in the options) is a special file qmake will read to find settings not specified in the qmake.conf file, the .pro file, or the command line. If -nocache is not specified, qmake will try to find a file called .qmake.cache in parent directories. If it fails to find this file, it will silently ignore this step of processing. Library DependenciesOften when linking against a library qmake relies on the underlying platform to know what other libraries this library links against, and lets the platform pull them in. In many cases, however, this is not sufficent. For example when statically linking a library there are no libraries linked against, and therefore no dependencies to those libraries are created - however an application that later links against this library will need to know where to find the symbols that the linked in library will require. To help with this situation qmake will follow a library's dependencies when it feels appropriate, however this behaviour must be enabled in qmake. To enable requires two steps. First, you must enable it in the library - to do this you must tell qmake to save information about this library: CONFIG += create_prl This is only relevant to the lib template, and will be ignored for all others. When this option is enabled qmake will create a file (called a .prl file) which will save some meta information about the library. This metafile is itself just a qmake project file, but with all internal variables. You are free to view this file, and if deleted qmake will know to recreate it when necesary (either when the .pro file is later read, or if a dependent library (described below) has changed). When installing this library (by using target in INSTALLS, above) qmake will automatically copy the .prl file to your install path. The second step to enabling this processing is to turn on reading of the meta information created above: CONFIG += link_prl When this is turned on qmake will process all libraries linked to, and find their meta information. With this meta information qmake will figure out what is relevant to linking, specifically it will add to your list of DEFINES as well as LIBS. Once qmake has processed this file, it will then look through the newly introduced LIBS and find their dependent .prl files, and continue until all libraries have been resolved. At this point the Makefile is created as usual, and the libraries are linked explicity against your program. The internals of the .prl file are left closed so they can easily change later. It is not designed to be changed by hand however, and should only be created by qmake - these .prl files should also not be transfered from operating system to operating system as they may be platform dependent (like a Makefile). File ExtensionsUnder normal circumstances qmake will try to use appropriate file extensions for your platform. There may be times, however, that you would like to override the behavior of these extensions. To do this, you must modify builtin variables in your .pro file, which will in turn changes qmake's interpretation of these files. You may do this as: QMAKE_EXT_MOC = .mymoc The variables are as follows:
All the above accept just the first value, so you must assign to it one value that will be used through your Makefile. There are two variables that accept a list of values, they are:
Customizing Makefile Outputqmake often tries to be all things to all build tools, this is often less than ideal when you really need to run special platform dependent commands. This can be achieved with specific instructions to the different qmake backends. The interfaces to customizing the Makefile are done through "objects" as in other places in qmake. The notation for this is quite simple, first you fill in an "object" in qmake for example: mytarget.target = .buildfile mytarget.commands = touch $$mytarget.target mytarget.depends = mytarget2 mytarget2.commands = @echo Building $$mytarget.target The information above defines a qmake target called mytarget which contains a Makefile target called .buildfile, .buildfile is generated by 'touch .buildfile', and finally that this Makefile target depends on the qmake target mytarget2. Additionally we've defined the qmake target mytarget2 which simply echo's something to stdout. The final step to making use of the above is to instruct qmake that this is actually an object used by the target building parts of qmake by: QMAKE_EXTRA_TARGETS += mytarget mytarget2 This is all you need to do to actually build custom targets in qmake, of course you may want to tie one of these targets to actually building the qmake build target. To do this, you simply need to include your Makefile target in the list of PRE_TARGETDEPS. For convenience there is also a method of customizing projects for generic new compilers (or even preprocessors). new_moc.output = moc_${QMAKE_FILE_BASE}.cpp new_moc.commands = moc ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT} new_moc.depend_command = g++ -E -M ${QMAKE_FILE_NAME} | sed "s,^.*: ,," new_moc.input = NEW_HEADERS QMAKE_EXTRA_COMPILERS += new_moc With this you can create a new moc for qmake, the commands will be executed over all arguments given to a NEW_HEADERS variable (from the input variable), and write to output (and automatically hand this filename to the compiler to be linked into your target). Additionally qmake will execute depend_command to generate dependency information and place this in the project as well. These commands can easily be placed into a cache file, and subsequent .pro files can give several arguments to NEW_HEADERS. [Previous: qmake Function Reference] [Contents] [Next: qmake Advanced Usage] |
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 4.0 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com