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

Error

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

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

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

#處理helloworld_HEADERS中的MOC宏,處理結果生成在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>
            亚洲图片在区色| 欧美一区二视频| 欧美日本在线看| 99re热这里只有精品视频| 亚洲国产精品久久久久| 美女主播视频一区| 99热免费精品| 亚洲嫩草精品久久| 在线观看国产日韩| 亚洲精品乱码久久久久久久久| 欧美**字幕| 亚洲一区二区三区高清| 亚洲一区欧美| 在线观看的日韩av| 亚洲精品欧美日韩| 国产区日韩欧美| 亚洲激情视频| 午夜在线视频观看日韩17c| 国产区二精品视| 欧美多人爱爱视频网站| 欧美国产日韩二区| 亚洲欧美在线免费观看| 欧美一区二区三区免费视| 亚洲激情电影中文字幕| 亚洲免费不卡| 亚洲精品欧美| 欧美国产亚洲视频| 性欧美长视频| 你懂的国产精品永久在线| 亚洲免费视频成人| 米奇777在线欧美播放| 亚洲天堂成人| 久久香蕉国产线看观看av| 亚洲欧洲一区二区天堂久久 | 亚洲国产精品综合| 日韩一级大片| 亚洲福利在线观看| 在线一区二区三区四区| 亚洲国产二区| 羞羞答答国产精品www一本| 亚洲另类黄色| 久久福利资源站| 午夜在线播放视频欧美| 欧美精品色综合| 老司机精品导航| 国产美女精品免费电影| 亚洲人午夜精品| 亚洲国产视频直播| 午夜免费日韩视频| 亚洲伊人色欲综合网| 免费成人av在线看| 免费看av成人| 国产一区二区无遮挡| 亚洲色图在线视频| 亚洲视频免费观看| 欧美精品一区二区三区高清aⅴ| 蜜臀av性久久久久蜜臀aⅴ| 国产精品永久在线| 亚洲综合二区| 午夜国产精品影院在线观看| 欧美色视频一区| 日韩写真视频在线观看| 中国av一区| 欧美日韩在线播放一区| 亚洲人成啪啪网站| 一区二区三区不卡视频在线观看| 免费日本视频一区| 亚洲丰满少妇videoshd| 亚洲成人直播| 美女国产精品| 亚洲欧洲精品成人久久奇米网 | 国产精品成人在线| 99热这里只有精品8| 一区二区三区鲁丝不卡| 欧美日韩国产限制| 亚洲一区图片| 久久久国产91| 亚洲国产99精品国自产| 欧美bbbxxxxx| 在线亚洲电影| 欧美一区二区三区免费视频| 国产一区深夜福利| 久久久久久久一区二区| 欧美国产视频一区二区| 夜夜嗨av一区二区三区| 国产精品人成在线观看免费 | 欧美福利视频网站| 亚洲免费激情| 国产精品欧美日韩| 久久久久久久高潮| 最新成人av在线| 香港久久久电影| 国模精品一区二区三区| 久久偷窥视频| 99天天综合性| 久久综合伊人| 亚洲视频 欧洲视频| 国产日韩欧美电影在线观看| 久久www成人_看片免费不卡| 亚洲国产成人av在线| 亚洲欧美日韩国产一区二区三区 | 欧美日韩一区二| 亚洲欧美日韩精品久久亚洲区 | 亚洲精品日韩综合观看成人91 | 亚洲福利视频免费观看| 欧美日韩伦理在线| 欧美在线黄色| 一本大道久久精品懂色aⅴ| 久久人人九九| 一区二区三区不卡视频在线观看 | 亚洲伊人观看| 91久久久久| 国产亚洲欧美一区二区三区| 欧美精品一区二区蜜臀亚洲| 性欧美xxxx视频在线观看| 亚洲免费电影在线| 欧美wwwwww| 久久gogo国模裸体人体| 日韩午夜黄色| 亚洲第一在线综合在线| 国产精品久久久久影院亚瑟| 免费成年人欧美视频| 欧美在线视频一区二区三区| 夜色激情一区二区| 亚洲国产一区二区三区高清| 久久一区二区三区超碰国产精品| 亚洲欧美日本另类| 日韩午夜av在线| 亚洲欧洲中文日韩久久av乱码| 国内外成人在线视频| 国产日韩欧美成人| 国产精品久久毛片a| 欧美日韩在线一区二区| 欧美成人dvd在线视频| 久久精品一区二区三区中文字幕 | 午夜在线成人av| 一区二区三区高清| 最新中文字幕亚洲| 亚洲黄页一区| 最新热久久免费视频| 亚洲国产免费| 欧美大片在线看免费观看| 久久久久欧美精品| 久久不射中文字幕| 久久久久久久成人| 久久久久久久久久久一区| 午夜精品一区二区三区在线视| 亚洲一区激情| 欧美一区二区视频免费观看| 亚洲欧美制服另类日韩| 欧美一区二区免费| 久久琪琪电影院| 麻豆精品视频在线观看视频| 蜜月aⅴ免费一区二区三区| 久久综合狠狠综合久久激情| 欧美成人综合| 国产精品乱码人人做人人爱| 欧美色视频一区| 国产精品黄视频| 国产一区二区三区自拍| 激情亚洲网站| 亚洲美女一区| 午夜精品久久久久久| 久久一区二区三区超碰国产精品| 免费久久99精品国产| 91久久综合| 先锋影音一区二区三区| 久久精品国产亚洲一区二区三区 | 一本大道久久a久久综合婷婷 | 亚洲视频在线播放| 亚洲欧美区自拍先锋| 久久久久久久久久码影片| 欧美成人免费全部| 国产精品看片你懂得| 精品电影在线观看| 亚洲最新色图| 欧美在线在线| 亚洲电影免费观看高清完整版在线观看| 欧美成人在线影院| 亚洲一级免费视频| 久久理论片午夜琪琪电影网| 欧美久久在线| 狠狠色狠狠色综合人人| 亚洲免费精彩视频| 久久久久久久91| 亚洲美女一区| 久久九九国产| 国产精品久久久久一区二区三区共| 黑人中文字幕一区二区三区| 一区二区高清在线| 免费中文字幕日韩欧美| 一本色道久久综合亚洲二区三区| 欧美中文字幕在线| 欧美网站大全在线观看| 亚洲国产老妈| 久久美女性网| 亚洲天堂av在线免费观看| 欧美成人四级电影| 经典三级久久| 久久久久久亚洲精品杨幂换脸|