Spec-Zone.ru › CMake 3.7

FindQt4

Поиск и использование Qt4

Этот модуль предназначен для поиска Qt4. Самый важный вопрос заключается в том, доступен ли qmake Qt4 через системный путь. Этот qmake используется для обнаружения практически всего остального. Этот модуль определяет ряд IMPORTED целевых объектов, макросов и переменных.

Типичное использование может выглядеть так:

set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(Qt4 4.4.3 REQUIRED QtGui QtXml)
add_executable(myexe main.cpp)
target_link_libraries(myexe Qt4::QtGui Qt4::QtXml)

Примечание

При использовании IMPORTED целевых объектов статическая библиотека qtmain.lib автоматически подключается к Windows для WIN32 исполняемых файлов. Чтобы отключить это глобально, установите переменную QT4_NO_LINK_QTMAIN перед поиском Qt4. Чтобы отключить это для конкретного исполняемого файла, установите свойство целевого объекта QT4_NO_LINK_QTMAIN на значение TRUE для этого исполняемого файла.

Инструменты построения Qt

Qt полагается на некоторые интегрированные инструменты для генерации кода, такие как moc для генерации метаобъектного кода, ``uic`` для макета и заполнения виджетов и rcc для генерации содержимого виртуальной файловой системы. Эти инструменты могут быть автоматически вызваны cmake(1), если выполнены соответствующие условия. Дополнительная информация приведена в cmake-qt(7).

Макросы Qt

В некоторых случаях может потребоваться или быть полезным вызов инструментов построения Qt более ручным способом. Для таких целей доступны несколько макросов для добавления целевых объектов.

macro QT4_WRAP_CPP(outfiles inputfile ... [TARGET tgt] OPTIONS ...)
      create moc code from a list of files containing Qt class with
      the Q_OBJECT declaration.  Per-directory preprocessor definitions
      are also added.  If the <tgt> is specified, the
      INTERFACE_INCLUDE_DIRECTORIES and INTERFACE_COMPILE_DEFINITIONS from
      the <tgt> are passed to moc.  Options may be given to moc, such as
      those found when executing "moc -help".
macro QT4_WRAP_UI(outfiles inputfile ... OPTIONS ...)
      create code from a list of Qt designer ui files.
      Options may be given to uic, such as those found
      when executing "uic -help"
macro QT4_ADD_RESOURCES(outfiles inputfile ... OPTIONS ...)
      create code from a list of Qt resource files.
      Options may be given to rcc, such as those found
      when executing "rcc -help"
macro QT4_GENERATE_MOC(inputfile outputfile [TARGET tgt])
      creates a rule to run moc on infile and create outfile.
      Use this if for some reason QT4_WRAP_CPP() isn't appropriate, e.g.
      because you need a custom filename for the moc file or something
      similar.  If the <tgt> is specified, the
      INTERFACE_INCLUDE_DIRECTORIES and INTERFACE_COMPILE_DEFINITIONS from
      the <tgt> are passed to moc.
macro QT4_ADD_DBUS_INTERFACE(outfiles interface basename)
      Create the interface header and implementation files with the
      given basename from the given interface xml file and add it to
      the list of sources.

      You can pass additional parameters to the qdbusxml2cpp call by setting
      properties on the input file:

      INCLUDE the given file will be included in the generate interface header

      CLASSNAME the generated class is named accordingly

      NO_NAMESPACE the generated class is not wrapped in a namespace
macro QT4_ADD_DBUS_INTERFACES(outfiles inputfile ... )
      Create the interface header and implementation files
      for all listed interface xml files.
      The basename will be automatically determined from the name
      of the xml file.

      The source file properties described for
      QT4_ADD_DBUS_INTERFACE also apply here.
macro QT4_ADD_DBUS_ADAPTOR(outfiles xmlfile parentheader parentclassname
                           [basename] [classname])
      create a dbus adaptor (header and implementation file) from the xml file
      describing the interface, and add it to the list of sources. The adaptor
      forwards the calls to a parent class, defined in parentheader and named
      parentclassname. The name of the generated files will be
      <basename>adaptor.{cpp,h} where basename defaults to the basename of the
      xml file.
      If <classname> is provided, then it will be used as the classname of the
      adaptor itself.
macro QT4_GENERATE_DBUS_INTERFACE( header [interfacename] OPTIONS ...)
      generate the xml interface file from the given header.
      If the optional argument interfacename is omitted, the name of the
      interface file is constructed from the basename of the header with
      the suffix .xml appended.
      Options may be given to qdbuscpp2xml, such as those found when
      executing "qdbuscpp2xml --help"
macro QT4_CREATE_TRANSLATION( qm_files directories ... sources ...
                              ts_files ... OPTIONS ...)
      out: qm_files
      in:  directories sources ts_files
      options: flags to pass to lupdate, such as -extensions to specify
      extensions for a directory scan.
      generates commands to create .ts (vie lupdate) and .qm
      (via lrelease) - files from directories and/or sources. The ts files are
      created and/or updated in the source tree (unless given with full paths).
      The qm files are generated in the build tree.
      Updating the translations can be done by adding the qm_files
      to the source list of your library/executable, so they are
      always updated, or by adding a custom target to control when
      they get updated/generated.
macro QT4_ADD_TRANSLATION( qm_files ts_files ... )
      out: qm_files
      in:  ts_files
      generates commands to create .qm from .ts - files. The generated
      filenames can be found in qm_files. The ts_files
      must exist and are not updated in any way.
macro QT4_AUTOMOC(sourcefile1 sourcefile2 ... [TARGET tgt])
      The qt4_automoc macro is obsolete.  Use the CMAKE_AUTOMOC feature instead.
      This macro is still experimental.
      It can be used to have moc automatically handled.
      So if you have the files foo.h and foo.cpp, and in foo.h a
      a class uses the Q_OBJECT macro, moc has to run on it. If you don't
      want to use QT4_WRAP_CPP() (which is reliable and mature), you can insert
      #include "foo.moc"
      in foo.cpp and then give foo.cpp as argument to QT4_AUTOMOC(). This will
      scan all listed files at cmake-time for such included moc files and if it
      finds them cause a rule to be generated to run moc at build time on the
      accompanying header file foo.h.
      If a source file has the SKIP_AUTOMOC property set it will be ignored by
      this macro.
      If the <tgt> is specified, the INTERFACE_INCLUDE_DIRECTORIES and
      INTERFACE_COMPILE_DEFINITIONS from the <tgt> are passed to moc.
function QT4_USE_MODULES( target [link_type] modules...)
       This function is obsolete. Use target_link_libraries with IMPORTED targets
       instead.
       Make <target> use the <modules> from Qt. Using a Qt module means
       to link to the library, add the relevant include directories for the
       module, and add the relevant compiler defines for using the module.
       Modules are roughly equivalent to components of Qt4, so usage would be
       something like:
        qt4_use_modules(myexe Core Gui Declarative)
       to use QtCore, QtGui and QtDeclarative. The optional <link_type> argument
       can be specified as either LINK_PUBLIC or LINK_PRIVATE to specify the
       same argument to the target_link_libraries call.

Целевые объекты IMPORTS

Конкретная библиотека Qt может быть использована с помощью соответствующего IMPORTED целевого объекта вместе с командой target_link_libraries():

target_link_libraries(myexe Qt4::QtGui Qt4::QtXml)

Использование целевого объекта таким образом заставляет :cmake(1)` использовать соответствующие каталоги включения и определения компиляции для целевого объекта при компиляции myexe.

Целевые объекты учитывают свои зависимости, поэтому, например, нет необходимости указывать Qt4::QtCore, если указана другая библиотека Qt, и нет необходимости указывать Qt4::QtGui, если указана Qt4::QtDeclarative. Проверить существование целевых объектов можно обычным способом, используя команду if(TARGET).

Набор инструментов Qt может содержать библиотеки как для отладки, так и для релизной сборки. cmake(1) выберет соответствующую версию в зависимости от конфигурации сборки.

Qt4::QtCore
Целевой объект QtCore
Qt4::QtGui
Целевой объект QtGui
Qt4::Qt3Support
Целевой объект Qt3Support
Qt4::QtAssistant
Целевой объект QtAssistant
Qt4::QtAssistantClient
Целевой объект QtAssistantClient
Qt4::QAxContainer
Целевой объект QAxContainer (только Windows)
Qt4::QAxServer
Целевой объект QAxServer (только Windows)
Qt4::QtDBus
Целевой объект QtDBus
Qt4::QtDeclarative
Целевой объект QtDeclarative
Qt4::QtDesigner
Целевой объект QtDesigner
Qt4::QtDesignerComponents
Целевой объект QtDesignerComponents
Qt4::QtHelp
Целевой объект QtHelp
Qt4::QtMotif
Целевой объект QtMotif
Qt4::QtMultimedia
Целевой объект QtMultimedia
Qt4::QtNetwork
Целевой объект QtNetwork
Qt4::QtNsPLugin
Целевой объект QtNsPLugin
Qt4::QtOpenGL
Целевой объект QtOpenGL
Qt4::QtScript
Целевой объект QtScript
Qt4::QtScriptTools
Целевой объект QtScriptTools
Qt4::QtSql
Целевой объект QtSql
Qt4::QtSvg
Целевой объект QtSvg
Qt4::QtTest
Целевой объект QtTest
Qt4::QtUiTools
Целевой объект QtUiTools
Qt4::QtWebKit
Целевой объект QtWebKit
Qt4::QtXml
Целевой объект QtXml
Qt4::QtXmlPatterns
Целевой объект QtXmlPatterns
Qt4::phonon
Целевой объект phonon

Переменные результатов

Ниже представлен подробный список переменных, которые задаёт FindQt4.cmake.
Qt4_FOUND
Если ложь, не пытаться использовать Qt 4.
QT_FOUND
Если ложь, не пытаться использовать Qt. Эта переменная используется только для совместимости.
QT4_FOUND
Если ложь, не пытаться использовать Qt 4. Эта переменная используется только для совместимости.
QT_VERSION_MAJOR
Главная версия найденного Qt.
QT_VERSION_MINOR
Дополнительная версия найденного Qt.
QT_VERSION_PATCH
Вспомогательная версия найденного Qt.

© 2000–2019 Kitware, Inc. and Contributors
Licensed under the BSD 3-clause License.
https://cmake.org/cmake/help/v3.7/module/FindQt4.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API