青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

Error

C++博客 首頁 新隨筆 聯(lián)系 聚合 管理
  217 Posts :: 61 Stories :: 32 Comments :: 0 Trackbacks

#實際上是調(diào)用cmake安裝目錄\share\cmake-2.8\Modules\FindQt4.cmake
#設(shè)置好一批預(yù)定義的東東
FIND_PACKAGE(Qt4 REQUIRED)

# 不解釋
SET(helloworld_SOURCES main.cpp hellowindow.cpp)
SET(helloworld_HEADERS hellowindow.h)

#處理helloworld_HEADERS中的MOC宏,處理結(jié)果生成在helloworld_HEADERS_MOC
QT4_WRAP_CPP(helloworld_HEADERS_MOC ${helloworld_HEADERS})

#添加QT頭文件和宏
INCLUDE(${QT_USE_FILE})
ADD_DEFINITIONS(${QT_DEFINITIONS})






**********************************************

Using CMake to Build Qt Projects

Written by: Johan Thelin

Qt comes with the QMake tool for handling cross platform building issues. However, there are other build systems available such as autotools, SCons and CMake. These tools meet different criterias, for example external dependencies.

When the KDE project shifted from Qt 3 to Qt 4 the project changed build tool from autotools to CMake. This has given CMake a special position in the Qt world &emdash; both from the number of users point and from a feature support and quality point. Seen from a workflow point of view, Qt Creator supports CMake since version 1.1 (1.3 if you want to use a Microsoft toolchain).

A Basic Example

In this article we will focus on CMake itself, and how to use it in conjunction with Qt. To do this, let's start with an overview of a simple, but typical CMake-based project. As you can tell from the listing below, the project consists of some source files and a text file.

$ ls CMakeLists.txt hellowindow.cpp hellowindow.h main.cpp 

Basically, the CMakeLists.txt file replaces the projectfile used by QMake. To build the project, create a build directory and run cmake and then make from there. The reason for creating a build directory is that CMake has been built with out-of-source building in mind from the very start. It is possible to configure QMake to place intermediate files outside the source, but it requires extra steps. With CMake, it is the default.

$ mkdir build $ cd build $ cmake .. && make 


CMake building a basic project.

The argument given to CMake refers to the directory where the CMakeLists.txt file resides. This file controls the whole build process. In order to fully understand it, it is important to recognize how the build process looks. The figure below shows how the user files: sources, headers, forms and resource files are processed by the various Qt code generators before joining the standard C++ compilation flow. Since QMake was designed to handle this flow, it hides all the details of this flow.


The Qt build system.

When using CMake, the intermediate steps must be handled explicitly. This means that headers with Q_OBJECT macros must be run through moc, user interface forms must be processed by uic and resource files must pass through rcc.

In the example that we started with the world is slightly easier, though. It is limited to a single header file that needs to meet moc. But first, the CMakeLists.txt defines a project name and includes the Qt4 package as a required component.

PROJECT(helloworld) FIND_PACKAGE(Qt4 REQUIRED) 

Then all sources involved in the build process are assigned to two variables. The SET command assigns the variable listed first with the values that follow. The names, helloworld_SOURCES and helloworld_HEADERS, is by convention. You can name them either way you like.

SET(helloworld_SOURCES main.cpp hellowindow.cpp) SET(helloworld_HEADERS hellowindow.h) 

Notice that the headers only include the headers that needs to be processed by moc. All other headers can be left out of the CMakeLists.txt file. This also implicates that if you add a Q_OBJECT macro to any of your classes you must ensure that it is listed here.

To invoke moc, the macro QT4_WRAP_CPP is used. It assigns the names of the resulting files to the variable listed first. In this case the line looks as follows.

QT4_WRAP_CPP(helloworld_HEADERS_MOC ${helloworld_HEADERS}) 

What happens is that all headers are processed by moc and the names of the resulting source files are listed in the helloworld_HEADERS_MOC variable. Again, the variable name is by convention rather than forced.

In order to build a Qt application, the Qt include directories needs to be added as well as a range of defines need to be set. This is handled through the commands INCLUDE and ADD_DEFINITIONS.

INCLUDE(${QT_USE_FILE}) ADD_DEFINITIONS(${QT_DEFINITIONS}) 

Finally, CMake needs to know the name of the resulting executable and what to link it to. This is conveniently handled by by the commands ADD_EXECUTABLE and TARGET_LINK_LIBRARIES. Now CMake knows what to build, from what and through which steps.

ADD_EXECUTABLE(helloworld ${helloworld_SOURCES}      ${helloworld_HEADERS_MOC}) TARGET_LINK_LIBRARIES(helloworld ${QT_LIBRARIES}) 

When reviewing the listing above, it relies on a number of variables starting with QT_. These are generated by the Qt4 package. However, as a developer, you must explicitly refer to them as CMake is not build as tightly to suite Qt as QMake.

Adding More Qt

Moving beyond the initial example, we now look at a project with both resources and user interface forms. The resulting application will look quite similar to its predecessor, but all the magic takes place under the hood.

The CMakeLists.txt file start by naming the project and including the Qt4 package - the complete file can be downloaded as a source code package accompanying this article. Then all the input files are listed and assigned to their corresponding variables.

SET(helloworld_SOURCES main.cpp hellowindow.cpp) SET(helloworld_HEADERS hellowindow.h) SET(helloworld_FORMS hellowindow.ui) SET(helloworld_RESOURCES images.qrc) 

The new file types are then handled by QT4_WRAP_UI and QT4_ADD_RESOURCES. These macros operate in the same ways as QT4_WRAP_CPP. This means that the resulting files are assigned to variable given as the left-most argument. Notice that the header files generated by uic are needed as we need to build a dependency relationship between them and the final executable. Otherwise they will not be created.

QT4_WRAP_CPP(helloworld_HEADERS_MOC ${helloworld_HEADERS}) QT4_WRAP_UI(helloworld_FORMS_HEADERS ${helloworld_FORMS}) QT4_ADD_RESOURCES(helloworld_RESOURCES_RCC ${helloworld_RESOURCES}) 

All the resulting files are then added as dependencies to the ADD_EXECUTABLE macro. This includes the uic generated headerfiles. This establishes the dependency from the executable to the hellowindow.ui file through the intermediary ui_hellowindow.h header.

ADD_EXECUTABLE(helloworld ${helloworld_SOURCES}      ${helloworld_HEADERS_MOC}      ${helloworld_FORMS_HEADERS}      ${helloworld_RESOURCES_RCC}) 

Before this file can be used to build the project there is a small caveat to handle. As all intermediate files are generated outside the source tree, the header file generated by uic will not be located by the compiler. In order to handle this, the build directory needs to be added to the list of include directories.

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) 

With this line, all intermediary files will be available in the include path.

Qt Modules

Until now we have relied on the QtCore and QtGui modules. To be able to use more modules, the CMake environment must be tuned to enable them. By setting them to TRUE using the SET command, the included modules can be controlled.

For instance, to enable OpenGL support add the following line to your CMakeLists.txt.

SET(QT_USE_QTOPENGL TRUE) 

The most commonly used modules are controlled using the following variables.

  • QT_USE_QTNETWORK
  • QT_USE_QTOPENGL
  • QT_USE_QTSQL
  • QT_USE_QTXML
  • QT_USE_QTSVG
  • QT_USE_QTTEST
  • QT_USE_QTDBUS
  • QT_USE_QTSCRIPT
  • QT_USE_QTWEBKIT
  • QT_USE_QTXMLPATTERNS
  • QT_USE_PHONON

In addition to these, the variable QT_DONT_USE_QTGUI can be used to disable the use to QtGui. There is a similar variable to disable QtCore, but that is more to be feature complete than to actually add much useful value.

Added Value and Complexity

It is not as trivial to use CMake as QMake, but the rewards are more features. The most notable point when moving from QMake is CMake's built in support for out-of-source builds. It can really change habits, and thus make versioning code much easier.

It is also possible to add conditionals for various platforms and build scenarios. For instance, use different libraries for different platforms, as well as tuning the same project differently for different situations.

Other powerful features are the ability to generate multiple executables and libraries in one build as well as using said executables and libraries in the same build. This, in combination with the QtTest module can handle complex build situations from a single configuration.

The choice between CMake and QMake is really quite easy. For straight forward Qt projects, QMake is the obvious choice. When the build requirements passes the complexity threshold for QMake, CMake can take its place. With Qt Creator's support for CMake, the same tools can still be used.

posted on 2012-07-16 12:24 Enic 閱讀(2693) 評論(0)  編輯 收藏 引用 所屬分類: QT
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            美女尤物久久精品| 免费成人高清在线视频| 亚洲第一网站| 午夜精品视频一区| 夜久久久久久| 欧美高清视频在线| 久久五月激情| 国产综合久久久久久| 亚洲午夜视频在线观看| 一区二区免费看| 欧美成人高清| 亚洲国产精品久久| 伊人久久成人| 久久久亚洲综合| 久久综合色天天久久综合图片| 国产精品日韩精品| 亚洲视频网在线直播| 中文在线资源观看网站视频免费不卡| 免费亚洲一区| 亚洲高清资源| 日韩午夜电影在线观看| 欧美激情bt| 亚洲精品免费一二三区| 亚洲精品乱码视频 | 欧美激情一区二区三区高清视频| 国产亚洲人成a一在线v站| 亚洲一区二区三区视频播放| 亚洲欧美日韩国产另类专区| 国产精品yjizz| 亚洲永久免费| 久久久久久久久久久久久女国产乱 | 久久九九热免费视频| 国产日韩欧美不卡| 欧美一区二区视频观看视频| 久久久无码精品亚洲日韩按摩| 国内精品视频久久| 久久久一区二区| 亚洲国产精品黑人久久久| 亚洲日本欧美| 欧美午夜精品久久久久久人妖| 亚洲一区二区高清| 欧美亚洲视频在线观看| 国内精品久久久久久久影视麻豆| 久久国产精品电影| 欧美国产日韩精品免费观看| 日韩亚洲精品在线| 国产精品www网站| 欧美在线观看网址综合| 欧美高清自拍一区| 亚洲午夜小视频| 国产亚洲福利| 欧美大秀在线观看| 亚洲一区二区三区四区五区黄 | 久久免费偷拍视频| 亚洲国产日韩一区| 欧美亚洲一区二区在线观看| 黄色成人精品网站| 欧美日韩国产综合视频在线观看中文 | 欧美激情中文字幕一区二区| 亚洲视频二区| 免费在线日韩av| 亚洲无线视频| 亚洲福利一区| 国产精品一区二区视频| 欧美大学生性色视频| 亚洲男人的天堂在线观看| 免费久久精品视频| 亚洲自拍偷拍麻豆| 亚洲激情在线激情| 国产性猛交xxxx免费看久久| 欧美精品 国产精品| 欧美伊人精品成人久久综合97| 亚洲黄色免费电影| 久久精品国产久精国产爱| 99在线视频精品| 精品成人一区二区三区| 国产精品久久久久久户外露出| 美国十次了思思久久精品导航| 亚洲视频中文字幕| 亚洲国产小视频在线观看| 久久精品欧美| 亚洲欧美一区二区在线观看| 亚洲精品日产精品乱码不卡| 黄色av成人| 国产欧美一区二区在线观看| 欧美日韩国产在线播放| 免费日韩av片| 久久久激情视频| 亚久久调教视频| 亚洲视频欧美视频| 一区二区高清在线观看| 最新日韩精品| 亚洲二区视频| 欧美国产日韩精品| 欧美电影资源| 欧美成人精品一区二区| 久久婷婷av| 久久亚裔精品欧美| 久久久久久九九九九| 欧美一级一区| 欧美在线免费一级片| 午夜精品久久久久久| 亚洲在线观看免费视频| 在线视频日韩精品| 亚洲一本大道在线| 亚洲午夜精品久久| 亚洲一区二区三区视频| 亚洲一区在线观看免费观看电影高清| 日韩亚洲欧美成人一区| 亚洲毛片网站| 亚洲视频中文字幕| 亚洲免费在线视频| 欧美在线视屏| 久久亚洲欧美| 欧美二区不卡| 日韩视频在线观看国产| 日韩视频不卡中文| 亚洲无限av看| 香蕉久久夜色精品国产使用方法| 欧美一级欧美一级在线播放| 久久爱www久久做| 久久综合999| 欧美人成网站| 国产精品美女www爽爽爽| 国产亚洲一区二区三区| 影音先锋亚洲一区| 亚洲美女视频| 先锋影音国产精品| 久久影视精品| 亚洲精品国产精品国自产观看| 亚洲最新视频在线播放| 亚洲欧美在线一区| 老司机午夜精品| 欧美午夜宅男影院在线观看| 国产免费亚洲高清| 亚洲国产99| 亚洲一区二区三区高清| 久久久久久穴| 亚洲理论在线| 欧美一区二区三区视频在线| 免费成人高清| 国产精品看片资源| 亚洲国产高清视频| 亚洲男人的天堂在线| 久久伊人精品天天| av成人老司机| 久久久一本精品99久久精品66| 欧美区二区三区| 国一区二区在线观看| 一本色道久久综合亚洲精品小说| 欧美一区二区三区在线观看| 亚洲电影下载| 欧美与欧洲交xxxx免费观看| 欧美激情2020午夜免费观看| 国产亚洲精品高潮| 中文无字幕一区二区三区| 久久精品亚洲精品| 一区二区三区色| 免费观看成人| 国模一区二区三区| 亚洲一区二区久久| 亚洲高清网站| 久久久久国色av免费观看性色| 欧美性久久久| 亚洲精品国产精品国自产观看浪潮| 欧美一级视频精品观看| 亚洲美女诱惑| 欧美成年人网站| 黑人中文字幕一区二区三区| 亚洲欧美国产高清| 亚洲日本欧美天堂| 美玉足脚交一区二区三区图片| 国产精品日韩欧美| 亚洲一区精彩视频| 亚洲乱码国产乱码精品精可以看| 久久久国产精品一区| 国产日韩精品视频一区| 亚洲欧美在线观看| 亚洲最新在线| 欧美日韩国产成人| 99精品欧美一区| 亚洲激情视频在线播放| 久热精品视频| 91久久精品日日躁夜夜躁国产| 久久久国产精品亚洲一区 | 国产精品欧美久久久久无广告| 日韩一级精品视频在线观看| 欧美国产日韩视频| 欧美freesex8一10精品| 91久久中文| 亚洲国产精品免费| 欧美精品一区二区在线观看| 亚洲精品一区二区网址| 亚洲激情二区| 欧美日韩一区二区三区在线视频| 日韩一区二区精品| 一本色道久久加勒比88综合| 欧美日韩国产在线一区| 亚洲视频免费在线观看| 中国成人亚色综合网站|