QT5.3 下的CMAKE MANUAL
来源:互联网 发布:苹果手机网络卡怎么办 编辑:程序博客网 时间:2024/06/09 18:55
CMake is a tool that helps simplify the build process for development projects across different platforms. CMake automates the generation of buildsystems such as Makefiles and Visual Studio project files.CMake is a 3rd party tool with its own documentation. The rest of this manual details the specifics of how to use Qt 5 with CMake. The minimum version required to use Qt5 is CMake 2.8.3, but 2.8.11 is recommended.Getting StartedThe first requirement when using CMake is to use find_package to locate the libraries and header files shipped with Qt. These libraries and header files can then be used to build libraries and applications based on Qt.The recommended way to use Qt libraries and headers with CMake 2.8.11 is to use the target_link_libraries command. In CMake 2.8.11 and later versions, this command automatically adds appropriate include directories, compile definitions, the position-independent-code flag, and links to the qtmain.lib library on Windows.To build a helloworld GUI executable, typical usage would be:cmake_minimum_required(VERSION 2.8.11)project(testproject)# Find includes in corresponding build directoriesset(CMAKE_INCLUDE_CURRENT_DIR ON)# Instruct CMake to run moc automatically when needed.set(CMAKE_AUTOMOC ON)# Find the QtWidgets libraryfind_package(Qt5Widgets)# Tell CMake to create the helloworld executableadd_executable(helloworld WIN32 main.cpp)# Use the Widgets module from Qt 5.target_link_libraries(helloworld Qt5::Widgets)Note that setting the minimum required CMake version to 2.8.11 is required for automatic linking to the qtmain.lib library on Windows.In order for find_package to be successful, Qt 5 must be found below the CMAKE_PREFIX_PATH, or the Qt5_DIR must be set in the CMake cache to the location of the Qt5WidgetsConfig.cmake file. The easiest way to use CMake is to set the CMAKE_PREFIX_PATH environment variable to the install prefix of Qt 5.The CMAKE_AUTOMOC setting runs moc automatically when required. For more on this feature see the CMake AUTOMOC documentationImported targetsImported targets are created for each Qt module. Imported target names should be preferred instead of using a variable like Qt5_LIBRARIES in CMake commands such as target_link_libraries. The actual path to the library can be obtained using the LOCATION property:find_package(Qt5Core)get_target_property(QtCore_location Qt5::Core LOCATION)Note however that it is rare to require the full location to the library in CMake code. Most CMake APIs are aware of imported targets and can automatically use them instead of the full path.Each module in Qt 5 has a library target with the naming convention Qt5:: which can be used for this purpose.Imported targets are created with the configurations Qt was configured with. That is, if Qt was configured with the -debug switch, an imported target with the configuration DEBUG will be created. If Qt was configured with the -release switch an imported target with the configuration RELEASE will be created. If Qt was configured with the -debug-and-release switch (the default on windows), then imported targets will be created with both RELEASE and DEBUG configurations.If your project has custom CMake build configurations, it may be necessary to set a mapping from your custom configuration to either the debug or release Qt configuration.find_package(Qt5Core)set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-arcs -ftest-coverage")# set up a mapping so that the Release configuration for the Qt imported target is# used in the COVERAGE CMake configuration.set_target_properties(Qt5::Core PROPERTIES MAP_IMPORTED_CONFIG_COVERAGE "RELEASE")Plugins are also available as IMPORTED targets in CMake. The Qt Network, Qt SQL, Qt GUI, and Qt Widgets modules have plugins associated. They provide a list of plugins in the Qt5_PLUGINS variable.foreach(plugin ${Qt5Network_PLUGINS}) get_target_property(_loc ${plugin} LOCATION) message("Plugin ${plugin} is at location ${_loc}")endforeach()Using Qt 5 with CMake older than 2.8
0 0
- QT5.3 下的CMAKE MANUAL
- Qt5下通过CMake创建CTK插件的步骤
- 用cmake构建基于qt5.8.0的qt5项目
- Qt5 By CMake
- Qt5.7 CMake
- windows下cmake的使用
- Windows下CMake的使用
- cmake编译QT5串口通信
- 用CMake构建Qt5项目
- Win7平台下 opencv2.4.11+CMake+Qt5.8.0 开发环境配置
- Ubuntu下Cmake的安装以及Cmake的使用
- ubuntu下安装cmake以及cmake的简单使用
- Cuda 5.5 + Qt5 + opencv 2.4.8 使用cmake+vs2012编译GPU加速的opencv
- opencv + Qt5.5 + cmake(你遇到的问题,我知道)
- OpenCV3.2+Qt5.8.0+Win10配置和使用----(2)CMake的安装
- Ubuntu下安装最新版本的CMake
- Ubuntu下安装最新版本的CMake
- Ubuntu下安装最新版本的CMake
- Python 字典(Dictionary)
- 移动设备,屏幕自适应问题解决方法
- jsp页面中JSTL/EL标签引用java后台静态static字段的方法总结
- linux内核源码“双向链表list_head”续
- java 学习写架构必会几大技术点
- QT5.3 下的CMAKE MANUAL
- struts2和CKFinder的整合(java版)
- poj 3070(矩阵快速幂)
- 【POJ】3279 Fliptile(十字变换搜索+二进制枚举)
- Constraints
- Python 日期和时间
- 一款经典简洁的CSS滑动门代码
- Android.mk的用法和基础
- HTML5比较成熟的技术