1CMAKE-QT(7) CMake CMAKE-QT(7)
2
3
4
6 cmake-qt - CMake Qt Features Reference
7
9 CMake can find and use Qt 4 and Qt 5 libraries. The Qt 4 libraries are
10 found by the FindQt4 find-module shipped with CMake, whereas the Qt 5
11 libraries are found using “Config-file Packages” shipped with Qt 5. See
12 cmake-packages(7) for more information about CMake packages, and see
13 the Qt cmake manual for your Qt version.
14
15 Qt 4 and Qt 5 may be used together in the same CMake buildsystem:
16
17 cmake_minimum_required(VERSION 3.8.0 FATAL_ERROR)
18
19 project(Qt4And5)
20
21 set(CMAKE_AUTOMOC ON)
22
23 find_package(Qt5 COMPONENTS Widgets DBus REQUIRED)
24 add_executable(publisher publisher.cpp)
25 target_link_libraries(publisher Qt5::Widgets Qt5::DBus)
26
27 find_package(Qt4 REQUIRED)
28 add_executable(subscriber subscriber.cpp)
29 target_link_libraries(subscriber Qt4::QtGui Qt4::QtDBus)
30
31 A CMake target may not link to both Qt 4 and Qt 5. A diagnostic is
32 issued if this is attempted or results from transitive target depen‐
33 dency evaluation.
34
36 Qt relies on some bundled tools for code generation, such as moc for
37 meta-object code generation, uic for widget layout and population, and
38 rcc for virtual filesystem content generation. These tools may be
39 automatically invoked by cmake(1) if the appropriate conditions are
40 met. The automatic tool invocation may be used with both Qt 4 and Qt
41 5.
42
43 The tools are executed as part of a synthesized custom target generated
44 by CMake. Target dependencies may be added to that custom target by
45 adding them to the AUTOGEN_TARGET_DEPENDS target property.
46
47 AUTOMOC
48 The AUTOMOC target property controls whether cmake(1) inspects the C++
49 files in the target to determine if they require moc to be run, and to
50 create rules to execute moc at the appropriate time.
51
52 If a macro from AUTOMOC_MACRO_NAMES is found in a header file, moc will
53 be run on the file. The result will be put into a file named according
54 to moc_<basename>.cpp. If the macro is found in a C++ implementation
55 file, the moc output will be put into a file named according to <base‐
56 name>.moc, following the Qt conventions. The <basename>.moc must be
57 included by the user in the C++ implementation file with a preprocessor
58 #include.
59
60 Included moc_*.cpp and *.moc files will be generated in the <AUTO‐
61 GEN_BUILD_DIR>/include directory which is automatically added to the
62 target’s INCLUDE_DIRECTORIES.
63
64 · This differs from CMake 3.7 and below; see their documentation for
65 det