1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
4 #[=======================================================================[.rst:
11 This module can be used to find Qt4. The most important issue is that
12 the Qt4 qmake is available via the system path. This qmake is then
13 used to detect basically everything else. This module defines a
14 number of :prop_tgt:`IMPORTED` targets, macros and variables.
16 Typical usage could be something like:
21 set(CMAKE_INCLUDE_CURRENT_DIR ON)
22 find_package(Qt4 4.4.3 REQUIRED QtGui QtXml)
23 add_executable(myexe main.cpp)
24 target_link_libraries(myexe Qt4::QtGui Qt4::QtXml)
28 When using :prop_tgt:`IMPORTED` targets, the qtmain.lib static library is
29 automatically linked on Windows for :prop_tgt:`WIN32 <WIN32_EXECUTABLE>`
30 executables. To disable that globally, set the
31 ``QT4_NO_LINK_QTMAIN`` variable before finding Qt4. To disable that
32 for a particular executable, set the ``QT4_NO_LINK_QTMAIN`` target
33 property to ``TRUE`` on the executable.
38 Qt relies on some bundled tools for code generation, such as ``moc`` for
39 meta-object code generation, ``uic`` for widget layout and population,
40 and ``rcc`` for virtual filesystem content generation. These tools may be
41 automatically invoked by :manual:`cmake(1)` if the appropriate conditions
42 are met. See :manual:`cmake-qt(7)` for more.
47 In some cases it can be necessary or useful to invoke the Qt build tools in a
48 more-manual way. Several macros are available to add targets for such uses.
52 macro QT4_WRAP_CPP(outfiles inputfile ... [TARGET tgt] OPTIONS ...)
53 create moc code from a list of files containing Qt class with
54 the Q_OBJECT declaration. Per-directory preprocessor definitions
55 are also added. If the <tgt> is specified, the
56 INTERFACE_INCLUDE_DIRECTORIES and INTERFACE_COMPILE_DEFINITIONS from
57 the <tgt> are passed to moc. Options may be given to moc, such as
58 those found when executing "moc -help".
63 macro QT4_WRAP_UI(outfiles inputfile ... OPTIONS ...)
64 create code from a list of Qt designer ui files.
65 Options may be given to uic, such as those found
66 when executing "uic -help"
71 macro QT4_ADD_RESOURCES(outfiles inputfile ... OPTIONS ...)
72 create code from a list of Qt resource files.
73 Options may be given to rcc, such as those found
74 when executing "rcc -help"
79 macro QT4_GENERATE_MOC(inputfile outputfile [TARGET tgt])
80 creates a rule to run moc on infile and create outfile.
81 Use this if for some reason QT4_WRAP_CPP() isn't appropriate, e.g.
82 because you need a custom filename for the moc file or something
83 similar. If the <tgt> is specified, the
84 INTERFACE_INCLUDE_DIRECTORIES and INTERFACE_COMPILE_DEFINITIONS from
85 the <tgt> are passed to moc.
90 macro QT4_ADD_DBUS_INTERFACE(outfiles interface basename)
91 Create the interface header and implementation files with the
92 given basename from the given interface xml file and add it to
95 You can pass additional parameters to the qdbusxml2cpp call by setting
96 properties on the input file:
98 INCLUDE the given file will be included in the generate interface header
100 CLASSNAME the generated class is named accordingly
102 NO_NAMESPACE the generated class is not wrapped in a namespace
107 macro QT4_ADD_DBUS_INTERFACES(outfiles inputfile ... )
108 Create the interface header and implementation files
109 for all listed interface xml files.
110 The basename will be automatically determined from the name
113 The source file properties described for
114 QT4_ADD_DBUS_INTERFACE also apply here.
119 macro QT4_ADD_DBUS_ADAPTOR(outfiles xmlfile parentheader parentclassname
120 [basename] [classname])
121 create a dbus adaptor (header and implementation file) from the xml file
122 describing the interface, and add it to the list of sources. The adaptor
123 forwards the calls to a parent class, defined in parentheader and named
124 parentclassname. The name of the generated files will be
125 <basename>adaptor.{cpp,h} where basename defaults to the basename of the
127 If <classname> is provided, then it will be used as the classname of the
133 macro QT4_GENERATE_DBUS_INTERFACE( header [interfacename] OPTIONS ...)
134 generate the xml interface file from the given header.
135 If the optional argument interfacename is omitted, the name of the
136 interface file is constructed from the basename of the header with
137 the suffix .xml appended.
138 Options may be given to qdbuscpp2xml, such as those found when
139 executing "qdbuscpp2xml --help"
144 macro QT4_CREATE_TRANSLATION( qm_files directories ... sources ...
145 ts_files ... OPTIONS ...)
147 in: directories sources ts_files
148 options: flags to pass to lupdate, such as -extensions to specify
149 extensions for a directory scan.
150 generates commands to create .ts (via lupdate) and .qm
151 (via lrelease) - files from directories and/or sources. The ts files are
152 created and/or updated in the source tree (unless given with full paths).
153 The qm files are generated in the build tree.
154 Updating the translations can be done by adding the qm_files
155 to the source list of your library/executable, so they are
156 always updated, or by adding a custom target to control when
157 they get updated/generated.
162 macro QT4_ADD_TRANSLATION( qm_files ts_files ... )
165 generates commands to create .qm from .ts - files. The generated
166 filenames can be found in qm_files. The ts_files
167 must exist and are not updated in any way.
172 macro QT4_AUTOMOC(sourcefile1 sourcefile2 ... [TARGET tgt])
173 The qt4_automoc macro is obsolete. Use the CMAKE_AUTOMOC feature instead.
174 This macro is still experimental.
175 It can be used to have moc automatically handled.
176 So if you have the files foo.h and foo.cpp, and in foo.h a
177 a class uses the Q_OBJECT macro, moc has to run on it. If you don't
178 want to use QT4_WRAP_CPP() (which is reliable and mature), you can insert
180 in foo.cpp and then give foo.cpp as argument to QT4_AUTOMOC(). This will
181 scan all listed files at cmake-time for such included moc files and if it
182 finds them cause a rule to be generated to run moc at build time on the
183 accompanying header file foo.h.
184 If a source file has the SKIP_AUTOMOC property set it will be ignored by
186 If the <tgt> is specified, the INTERFACE_INCLUDE_DIRECTORIES and
187 INTERFACE_COMPILE_DEFINITIONS from the <tgt> are passed to moc.
192 function QT4_USE_MODULES( target [link_type] modules...)
193 This function is obsolete. Use target_link_libraries with IMPORTED targets
195 Make <target> use the <modules> from Qt. Using a Qt module means
196 to link to the library, add the relevant include directories for the
197 module, and add the relevant compiler defines for using the module.
198 Modules are roughly equivalent to components of Qt4, so usage would be
200 qt4_use_modules(myexe Core Gui Declarative)
201 to use QtCore, QtGui and QtDeclarative. The optional <link_type> argument
202 can be specified as either LINK_PUBLIC or LINK_PRIVATE to specify the
203 same argument to the target_link_libraries call.
209 A particular Qt library may be used by using the corresponding
210 :prop_tgt:`IMPORTED` target with the :command:`target_link_libraries`
213 .. code-block:: cmake
215 target_link_libraries(myexe Qt4::QtGui Qt4::QtXml)
217 Using a target in this way causes :cmake(1)` to use the appropriate include
218 directories and compile definitions for the target when compiling ``myexe``.
220 Targets are aware of their dependencies, so for example it is not necessary
221 to list ``Qt4::QtCore`` if another Qt library is listed, and it is not
222 necessary to list ``Qt4::QtGui`` if ``Qt4::QtDeclarative`` is listed.
223 Targets may be tested for existence in the usual way with the
224 :command:`if(TARGET)` command.
226 The Qt toolkit may contain both debug and release libraries.
227 :manual:`cmake(1)` will choose the appropriate version based on the build
235 The Qt3Support target
237 The QtAssistant target
238 ``Qt4::QtAssistantClient``
239 The QtAssistantClient target
240 ``Qt4::QAxContainer``
241 The QAxContainer target (Windows only)
243 The QAxServer target (Windows only)
246 ``Qt4::QtDeclarative``
247 The QtDeclarative target
249 The QtDesigner target
250 ``Qt4::QtDesignerComponents``
251 The QtDesignerComponents target
256 ``Qt4::QtMultimedia``
257 The QtMultimedia target
261 The QtNsPLugin target
266 ``Qt4::QtScriptTools``
267 The QtScriptTools target
280 ``Qt4::QtXmlPatterns``
281 The QtXmlPatterns target
288 Below is a detailed list of variables that FindQt4.cmake sets.
291 If false, don't try to use Qt 4.
293 If false, don't try to use Qt. This variable is for compatibility only.
295 If false, don't try to use Qt 4. This variable is for compatibility only.
297 The major version of Qt found.
299 The minor version of Qt found.
301 The patch version of Qt found.
302 #]=======================================================================]
304 # Use find_package( Qt4 COMPONENTS ... ) to enable modules
305 if( Qt4_FIND_COMPONENTS )
306 foreach( component ${Qt4_FIND_COMPONENTS} )
307 string( TOUPPER ${component} _COMPONENT )
308 set( QT_USE_${_COMPONENT} 1 )
311 # To make sure we don't use QtCore or QtGui when not in COMPONENTS
312 if(NOT QT_USE_QTCORE)
313 set( QT_DONT_USE_QTCORE 1 )
317 set( QT_DONT_USE_QTGUI 1 )
322 # If Qt3 has already been found, fail.
324 if(Qt4_FIND_REQUIRED)
325 message( FATAL_ERROR "Qt3 and Qt4 cannot be used together in one project. If switching to Qt4, the CMakeCache.txt needs to be cleaned.")
327 if(NOT Qt4_FIND_QUIETLY)
328 message( STATUS "Qt3 and Qt4 cannot be used together in one project. If switching to Qt4, the CMakeCache.txt needs to be cleaned.")
335 include(${CMAKE_CURRENT_LIST_DIR}/CheckCXXSymbolExists.cmake)
336 include(${CMAKE_CURRENT_LIST_DIR}/MacroAddFileDependencies.cmake)
337 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
338 include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake)
340 set(QT_USE_FILE ${CMAKE_ROOT}/Modules/UseQt4.cmake)
342 set( QT_DEFINITIONS "")
344 # convenience macro for dealing with debug/release library names
345 macro (_QT4_ADJUST_LIB_VARS _camelCaseBasename)
347 string(TOUPPER "${_camelCaseBasename}" basename)
349 # The name of the imported targets, i.e. the prefix "Qt4::" must not change,
350 # since it is stored in EXPORT-files as name of a required library. If the name would change
351 # here, this would lead to the imported Qt4-library targets not being resolved by cmake anymore.
352 if (QT_${basename}_LIBRARY_RELEASE OR QT_${basename}_LIBRARY_DEBUG)
354 if(NOT TARGET Qt4::${_camelCaseBasename})
355 add_library(Qt4::${_camelCaseBasename} UNKNOWN IMPORTED )
357 if (QT_${basename}_LIBRARY_RELEASE)
358 set_property(TARGET Qt4::${_camelCaseBasename} APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
359 set(_location "${QT_${basename}_LIBRARY_RELEASE}")
360 if(QT_USE_FRAMEWORKS AND EXISTS ${_location}/${_camelCaseBasename})
361 set_property(TARGET Qt4::${_camelCaseBasename} PROPERTY IMPORTED_LOCATION_RELEASE "${_location}/${_camelCaseBasename}" )
363 set_property(TARGET Qt4::${_camelCaseBasename} PROPERTY IMPORTED_LOCATION_RELEASE "${_location}" )
367 if (QT_${basename}_LIBRARY_DEBUG)
368 set_property(TARGET Qt4::${_camelCaseBasename} APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
369 set(_location "${QT_${basename}_LIBRARY_DEBUG}")
370 if(QT_USE_FRAMEWORKS AND EXISTS ${_location}/${_camelCaseBasename})
371 set_property(TARGET Qt4::${_camelCaseBasename} PROPERTY IMPORTED_LOCATION_DEBUG "${_location}/${_camelCaseBasename}" )
373 set_property(TARGET Qt4::${_camelCaseBasename} PROPERTY IMPORTED_LOCATION_DEBUG "${_location}" )
376 set_property(TARGET Qt4::${_camelCaseBasename} PROPERTY
377 INTERFACE_INCLUDE_DIRECTORIES
378 "${QT_${basename}_INCLUDE_DIR}"
380 string(REGEX REPLACE "^QT" "" _stemname ${basename})
381 set_property(TARGET Qt4::${_camelCaseBasename} PROPERTY
382 INTERFACE_COMPILE_DEFINITIONS
383 "QT_${_stemname}_LIB"
387 # If QT_USE_IMPORTED_TARGETS is enabled, the QT_QTFOO_LIBRARY variables are set to point at these
388 # imported targets. This works better in general, and is also in almost all cases fully
389 # backward compatible. The only issue is when a project A which had this enabled then exports its
390 # libraries via export or export_library_dependencies(). In this case the libraries from project
391 # A will depend on the imported Qt targets, and the names of these imported targets will be stored
392 # in the dependency files on disk. This means when a project B then uses project A, these imported
393 # targets must be created again, otherwise e.g. "Qt4__QtCore" will be interpreted as name of a
394 # library file on disk, and not as a target, and linking will fail:
395 if(QT_USE_IMPORTED_TARGETS)
396 set(QT_${basename}_LIBRARY Qt4::${_camelCaseBasename} )
397 set(QT_${basename}_LIBRARIES Qt4::${_camelCaseBasename} )
400 # if the release- as well as the debug-version of the library have been found:
401 if (QT_${basename}_LIBRARY_DEBUG AND QT_${basename}_LIBRARY_RELEASE)
402 # if the generator is multi-config or if CMAKE_BUILD_TYPE is set for
403 # single-config generators, set optimized and debug libraries
404 get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
405 if(_isMultiConfig OR CMAKE_BUILD_TYPE)
406 set(QT_${basename}_LIBRARY optimized ${QT_${basename}_LIBRARY_RELEASE} debug ${QT_${basename}_LIBRARY_DEBUG})
408 # For single-config generators where CMAKE_BUILD_TYPE has no value,
409 # just use the release libraries
410 set(QT_${basename}_LIBRARY ${QT_${basename}_LIBRARY_RELEASE} )
412 set(QT_${basename}_LIBRARIES optimized ${QT_${basename}_LIBRARY_RELEASE} debug ${QT_${basename}_LIBRARY_DEBUG})
415 # if only the release version was found, set the debug variable also to the release version
416 if (QT_${basename}_LIBRARY_RELEASE AND NOT QT_${basename}_LIBRARY_DEBUG)
417 set(QT_${basename}_LIBRARY_DEBUG ${QT_${basename}_LIBRARY_RELEASE})
418 set(QT_${basename}_LIBRARY ${QT_${basename}_LIBRARY_RELEASE})
419 set(QT_${basename}_LIBRARIES ${QT_${basename}_LIBRARY_RELEASE})
422 # if only the debug version was found, set the release variable also to the debug version
423 if (QT_${basename}_LIBRARY_DEBUG AND NOT QT_${basename}_LIBRARY_RELEASE)
424 set(QT_${basename}_LIBRARY_RELEASE ${QT_${basename}_LIBRARY_DEBUG})
425 set(QT_${basename}_LIBRARY ${QT_${basename}_LIBRARY_DEBUG})
426 set(QT_${basename}_LIBRARIES ${QT_${basename}_LIBRARY_DEBUG})
429 # put the value in the cache:
430 set(QT_${basename}_LIBRARY ${QT_${basename}_LIBRARY} CACHE STRING "The Qt ${basename} library" FORCE)
434 set(QT_${basename}_FOUND 1)
438 set(QT_${basename}_LIBRARY "" CACHE STRING "The Qt ${basename} library" FORCE)
442 if (QT_${basename}_INCLUDE_DIR)
443 #add the include directory to QT_INCLUDES
444 set(QT_INCLUDES "${QT_${basename}_INCLUDE_DIR}" ${QT_INCLUDES})
447 # Make variables changeable to the advanced user
448 mark_as_advanced(QT_${basename}_LIBRARY QT_${basename}_LIBRARY_RELEASE QT_${basename}_LIBRARY_DEBUG QT_${basename}_INCLUDE_DIR)
451 function(_QT4_QUERY_QMAKE VAR RESULT)
452 execute_process(COMMAND "${QT_QMAKE_EXECUTABLE}" -query ${VAR}
453 RESULT_VARIABLE return_code
454 OUTPUT_VARIABLE output
455 OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE)
457 file(TO_CMAKE_PATH "${output}" output)
458 set(${RESULT} ${output} PARENT_SCOPE)
462 function(_QT4_GET_VERSION_COMPONENTS VERSION RESULT_MAJOR RESULT_MINOR RESULT_PATCH)
463 string(REGEX REPLACE "^([0-9]+)\\.[0-9]+\\.[0-9]+.*" "\\1" QT_VERSION_MAJOR "${QTVERSION}")
464 string(REGEX REPLACE "^[0-9]+\\.([0-9]+)\\.[0-9]+.*" "\\1" QT_VERSION_MINOR "${QTVERSION}")
465 string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" QT_VERSION_PATCH "${QTVERSION}")
467 set(${RESULT_MAJOR} ${QT_VERSION_MAJOR} PARENT_SCOPE)
468 set(${RESULT_MINOR} ${QT_VERSION_MINOR} PARENT_SCOPE)
469 set(${RESULT_PATCH} ${QT_VERSION_PATCH} PARENT_SCOPE)
472 function(_QT4_FIND_QMAKE QMAKE_NAMES QMAKE_RESULT VERSION_RESULT)
473 list(LENGTH QMAKE_NAMES QMAKE_NAMES_LEN)
474 if(${QMAKE_NAMES_LEN} EQUAL 0)
477 list(GET QMAKE_NAMES 0 QMAKE_NAME)
479 get_filename_component(qt_install_version "[HKEY_CURRENT_USER\\Software\\trolltech\\Versions;DefaultQtVersion]" NAME)
481 find_program(QT_QMAKE_EXECUTABLE NAMES ${QMAKE_NAME}
484 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Versions\\${qt_install_version};InstallDir]"
486 DOC "The qmake executable for the Qt installation to use"
490 if (QT_QMAKE_EXECUTABLE)
491 _qt4_query_qmake(QT_VERSION QTVERSION)
492 _qt4_get_version_components("${QTVERSION}" major minor patch)
495 if (NOT QT_QMAKE_EXECUTABLE OR NOT "${major}" EQUAL 4)
496 set(curr_qmake "${QT_QMAKE_EXECUTABLE}")
497 set(curr_qt_version "${QTVERSION}")
499 set(QT_QMAKE_EXECUTABLE NOTFOUND CACHE FILEPATH "" FORCE)
500 list(REMOVE_AT QMAKE_NAMES 0)
501 _qt4_find_qmake("${QMAKE_NAMES}" QMAKE QTVERSION)
503 _qt4_get_version_components("${QTVERSION}" major minor patch)
504 if (NOT ${major} EQUAL 4)
505 # Restore possibly found qmake and it's version; these are used later
506 # in error message if incorrect version is found
507 set(QT_QMAKE_EXECUTABLE "${curr_qmake}" CACHE FILEPATH "" FORCE)
508 set(QTVERSION "${curr_qt_version}")
514 set(${QMAKE_RESULT} "${QT_QMAKE_EXECUTABLE}" PARENT_SCOPE)
515 set(${VERSION_RESULT} "${QTVERSION}" PARENT_SCOPE)
519 set(QT4_INSTALLED_VERSION_TOO_OLD FALSE)
521 set(_QT4_QMAKE_NAMES qmake qmake4 qmake-qt4 qmake-mac)
522 _qt4_find_qmake("${_QT4_QMAKE_NAMES}" QT_QMAKE_EXECUTABLE QTVERSION)
524 if (QT_QMAKE_EXECUTABLE AND
525 QTVERSION VERSION_GREATER 3 AND QTVERSION VERSION_LESS 5)
528 # Qt5CoreConfig sets QT_MOC_EXECUTABLE as a non-cache variable to the Qt 5
529 # path to moc. Unset that variable when Qt 4 and 5 are used together, so
530 # that when find_program looks for moc, it is not set to the Qt 5 version.
531 # If FindQt4 has already put the Qt 4 path in the cache, the unset()
532 # command 'unhides' the (correct) cache variable.
533 unset(QT_MOC_EXECUTABLE)
535 if (QT_QMAKE_EXECUTABLE_LAST)
536 string(COMPARE NOTEQUAL "${QT_QMAKE_EXECUTABLE_LAST}" "${QT_QMAKE_EXECUTABLE}" QT_QMAKE_CHANGED)
538 set(QT_QMAKE_EXECUTABLE_LAST "${QT_QMAKE_EXECUTABLE}" CACHE INTERNAL "" FORCE)
540 _qt4_get_version_components("${QTVERSION}" QT_VERSION_MAJOR QT_VERSION_MINOR QT_VERSION_PATCH)
542 # ask qmake for the mkspecs directory
543 # we do this first because QT_LIBINFIX might be set
544 if (NOT QT_MKSPECS_DIR OR QT_QMAKE_CHANGED)
545 _qt4_query_qmake(QMAKE_MKSPECS qt_mkspecs_dirs)
546 # do not replace : on windows as it might be a drive letter
547 # and windows should already use ; as a separator
549 string(REPLACE ":" ";" qt_mkspecs_dirs "${qt_mkspecs_dirs}")
552 find_path(QT_MKSPECS_DIR NAMES qconfig.pri
553 HINTS ${qt_mkspecs_dirs}
554 PATH_SUFFIXES mkspecs share/qt4/mkspecs
555 DOC "The location of the Qt mkspecs containing qconfig.pri")
558 if(EXISTS "${QT_MKSPECS_DIR}/qconfig.pri")
559 file(READ ${QT_MKSPECS_DIR}/qconfig.pri _qconfig_FILE_contents)
560 string(REGEX MATCH "QT_CONFIG[^\n]+" QT_QCONFIG "${_qconfig_FILE_contents}")
561 string(REGEX MATCH "CONFIG[^\n]+" QT_CONFIG "${_qconfig_FILE_contents}")
562 string(REGEX MATCH "EDITION[^\n]+" QT_EDITION "${_qconfig_FILE_contents}")
563 string(REGEX MATCH "QT_LIBINFIX[^\n]+" _qconfig_qt_libinfix "${_qconfig_FILE_contents}")
564 string(REGEX REPLACE "QT_LIBINFIX *= *([^\n]*)" "\\1" QT_LIBINFIX "${_qconfig_qt_libinfix}")
566 if("${QT_EDITION}" MATCHES "DesktopLight")
567 set(QT_EDITION_DESKTOPLIGHT 1)
570 # ask qmake for the library dir as a hint, then search for QtCore library and use that as a reference for finding the
571 # others and for setting QT_LIBRARY_DIR
572 if (NOT (QT_QTCORE_LIBRARY_RELEASE OR QT_QTCORE_LIBRARY_DEBUG) OR QT_QMAKE_CHANGED)
573 _qt4_query_qmake(QT_INSTALL_LIBS QT_LIBRARY_DIR_TMP)
574 set(QT_QTCORE_LIBRARY_RELEASE NOTFOUND)
575 set(QT_QTCORE_LIBRARY_DEBUG NOTFOUND)
576 find_library(QT_QTCORE_LIBRARY_RELEASE
577 NAMES QtCore${QT_LIBINFIX} QtCore${QT_LIBINFIX}4
578 HINTS ${QT_LIBRARY_DIR_TMP}
581 find_library(QT_QTCORE_LIBRARY_DEBUG
582 NAMES QtCore${QT_LIBINFIX}_debug QtCore${QT_LIBINFIX}d QtCore${QT_LIBINFIX}d4
583 HINTS ${QT_LIBRARY_DIR_TMP}
587 if(NOT QT_QTCORE_LIBRARY_RELEASE AND NOT QT_QTCORE_LIBRARY_DEBUG)
588 find_library(QT_QTCORE_LIBRARY_RELEASE
589 NAMES QtCore${QT_LIBINFIX} QtCore${QT_LIBINFIX}4
590 HINTS ${QT_LIBRARY_DIR_TMP}
592 find_library(QT_QTCORE_LIBRARY_DEBUG
593 NAMES QtCore${QT_LIBINFIX}_debug QtCore${QT_LIBINFIX}d QtCore${QT_LIBINFIX}d4
594 HINTS ${QT_LIBRARY_DIR_TMP}
598 # try dropping a hint if trying to use Visual Studio with Qt built by MinGW
599 if(NOT QT_QTCORE_LIBRARY_RELEASE AND MSVC)
600 if(EXISTS ${QT_LIBRARY_DIR_TMP}/libqtmain.a)
601 message( FATAL_ERROR "It appears you're trying to use Visual Studio with Qt built by MinGW. Those compilers do not produce code compatible with each other.")
607 # set QT_LIBRARY_DIR based on location of QtCore found.
608 if(QT_QTCORE_LIBRARY_RELEASE)
609 get_filename_component(QT_LIBRARY_DIR_TMP "${QT_QTCORE_LIBRARY_RELEASE}" PATH)
610 set(QT_LIBRARY_DIR ${QT_LIBRARY_DIR_TMP} CACHE INTERNAL "Qt library dir" FORCE)
611 set(QT_QTCORE_FOUND 1)
612 elseif(QT_QTCORE_LIBRARY_DEBUG)
613 get_filename_component(QT_LIBRARY_DIR_TMP "${QT_QTCORE_LIBRARY_DEBUG}" PATH)
614 set(QT_LIBRARY_DIR ${QT_LIBRARY_DIR_TMP} CACHE INTERNAL "Qt library dir" FORCE)
615 set(QT_QTCORE_FOUND 1)
617 if(NOT Qt4_FIND_QUIETLY)
619 "${QT_QMAKE_EXECUTABLE} reported QT_INSTALL_LIBS as "
620 "\"${QT_LIBRARY_DIR_TMP}\" "
621 "but QtCore could not be found there. "
622 "Qt is NOT installed correctly for the target build environment.")
625 if(Qt4_FIND_REQUIRED)
626 message( FATAL_ERROR "Could NOT find QtCore.")
632 # ask qmake for the binary dir
633 if (NOT QT_BINARY_DIR OR QT_QMAKE_CHANGED)
634 _qt4_query_qmake(QT_INSTALL_BINS qt_bins)
635 set(QT_BINARY_DIR ${qt_bins} CACHE INTERNAL "" FORCE)
639 set(CMAKE_FIND_FRAMEWORK_OLD ${CMAKE_FIND_FRAMEWORK})
640 if (EXISTS ${QT_LIBRARY_DIR}/QtCore.framework)
641 set(QT_USE_FRAMEWORKS ON CACHE INTERNAL "" FORCE)
642 set(CMAKE_FIND_FRAMEWORK FIRST)
644 set(QT_USE_FRAMEWORKS OFF CACHE INTERNAL "" FORCE)
645 set(CMAKE_FIND_FRAMEWORK LAST)
649 # ask qmake for the include dir
650 if (QT_LIBRARY_DIR AND (NOT QT_QTCORE_INCLUDE_DIR OR NOT QT_HEADERS_DIR OR QT_QMAKE_CHANGED))
651 _qt4_query_qmake(QT_INSTALL_HEADERS qt_headers)
652 set(QT_QTCORE_INCLUDE_DIR NOTFOUND)
653 find_path(QT_QTCORE_INCLUDE_DIR QtCore
654 HINTS ${qt_headers} ${QT_LIBRARY_DIR}
655 PATH_SUFFIXES QtCore qt4/QtCore
658 if(NOT QT_QTCORE_INCLUDE_DIR)
659 find_path(QT_QTCORE_INCLUDE_DIR QtCore
660 HINTS ${qt_headers} ${QT_LIBRARY_DIR}
661 PATH_SUFFIXES QtCore qt4/QtCore
665 # Set QT_HEADERS_DIR based on finding QtCore header
666 if(QT_QTCORE_INCLUDE_DIR)
667 if(QT_USE_FRAMEWORKS)
668 set(QT_HEADERS_DIR "${qt_headers}" CACHE INTERNAL "" FORCE)
670 get_filename_component(qt_headers "${QT_QTCORE_INCLUDE_DIR}/../" ABSOLUTE)
671 set(QT_HEADERS_DIR "${qt_headers}" CACHE INTERNAL "" FORCE)
674 message("Warning: QT_QMAKE_EXECUTABLE reported QT_INSTALL_HEADERS as ${qt_headers}")
675 message("Warning: But QtCore couldn't be found. Qt must NOT be installed correctly.")
680 set(CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK_OLD})
683 # Set QT_INCLUDE_DIR based on QT_HEADERS_DIR
685 if(QT_USE_FRAMEWORKS)
686 # Qt/Mac frameworks has two include dirs.
687 # One is the framework include for which CMake will add a -F flag
688 # and the other is an include dir for non-framework Qt modules
689 set(QT_INCLUDE_DIR ${QT_HEADERS_DIR} ${QT_QTCORE_LIBRARY_RELEASE} )
691 set(QT_INCLUDE_DIR ${QT_HEADERS_DIR})
696 set( QT_INCLUDES ${QT_MKSPECS_DIR}/default ${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR})
699 # ask qmake for the documentation directory
700 if (QT_LIBRARY_DIR AND NOT QT_DOC_DIR OR QT_QMAKE_CHANGED)
701 _qt4_query_qmake(QT_INSTALL_DOCS qt_doc_dir)
702 set(QT_DOC_DIR ${qt_doc_dir} CACHE PATH "The location of the Qt docs" FORCE)
706 # ask qmake for the plugins directory
707 if (QT_LIBRARY_DIR AND NOT QT_PLUGINS_DIR OR QT_QMAKE_CHANGED)
708 _qt4_query_qmake(QT_INSTALL_PLUGINS qt_plugins_dir)
709 if(CMAKE_CROSSCOMPILING OR NOT qt_plugins_dir)
710 find_path(QT_PLUGINS_DIR
711 NAMES accessible bearer codecs designer graphicssystems iconengines imageformats inputmethods qmltooling script sqldrivers
712 HINTS ${qt_plugins_dir}
713 PATH_SUFFIXES plugins lib/qt4/plugins
714 DOC "The location of the Qt plugins")
716 set(QT_PLUGINS_DIR ${qt_plugins_dir} CACHE PATH "The location of the Qt plugins")
720 # ask qmake for the translations directory
721 if (QT_LIBRARY_DIR AND NOT QT_TRANSLATIONS_DIR OR QT_QMAKE_CHANGED)
722 _qt4_query_qmake(QT_INSTALL_TRANSLATIONS qt_translations_dir)
723 set(QT_TRANSLATIONS_DIR ${qt_translations_dir} CACHE PATH "The location of the Qt translations" FORCE)
726 # ask qmake for the imports directory
727 if (QT_LIBRARY_DIR AND NOT QT_IMPORTS_DIR OR QT_QMAKE_CHANGED)
728 _qt4_query_qmake(QT_INSTALL_IMPORTS qt_imports_dir)
729 if(CMAKE_CROSSCOMPILING OR NOT qt_imports_dir)
730 find_path(QT_IMPORTS_DIR NAMES Qt
731 HINTS ${qt_imports_dir}
732 PATH_SUFFIXES imports lib/qt4/imports
733 DOC "The location of the Qt imports")
735 set(QT_IMPORTS_DIR ${qt_imports_dir} CACHE PATH "The location of the Qt imports")
739 # Make variables changeable to the advanced user
740 mark_as_advanced( QT_LIBRARY_DIR QT_DOC_DIR QT_MKSPECS_DIR
741 QT_PLUGINS_DIR QT_TRANSLATIONS_DIR)
746 #############################################
748 # Find out what window system we're using
750 #############################################
751 cmake_push_check_state()
752 # Add QT_INCLUDE_DIR to CMAKE_REQUIRED_INCLUDES
753 list(APPEND CMAKE_REQUIRED_INCLUDES "${QT_INCLUDE_DIR}")
754 set(CMAKE_REQUIRED_QUIET ${Qt4_FIND_QUIETLY})
755 # Check for Window system symbols (note: only one should end up being set)
756 CHECK_CXX_SYMBOL_EXISTS(Q_WS_X11 "QtCore/qglobal.h" Q_WS_X11)
757 CHECK_CXX_SYMBOL_EXISTS(Q_WS_WIN "QtCore/qglobal.h" Q_WS_WIN)
758 CHECK_CXX_SYMBOL_EXISTS(Q_WS_QWS "QtCore/qglobal.h" Q_WS_QWS)
759 CHECK_CXX_SYMBOL_EXISTS(Q_WS_MAC "QtCore/qglobal.h" Q_WS_MAC)
762 unset(QT_MAC_USE_COCOA CACHE)
764 CHECK_CXX_SYMBOL_EXISTS(QT_MAC_USE_COCOA "QtCore/qconfig.h" QT_MAC_USE_COCOA)
767 if (QT_QTCOPY_REQUIRED)
768 CHECK_CXX_SYMBOL_EXISTS(QT_IS_QTCOPY "QtCore/qglobal.h" QT_KDE_QT_COPY)
769 if (NOT QT_IS_QTCOPY)
770 message(FATAL_ERROR "qt-copy is required, but hasn't been found")
774 cmake_pop_check_state()
776 #############################################
780 ########################################
782 # Setting the INCLUDE-Variables
784 ########################################
786 set(QT_MODULES QtGui Qt3Support QtSvg QtScript QtTest QtUiTools
787 QtHelp QtWebKit QtXmlPatterns phonon QtNetwork QtMultimedia
788 QtNsPlugin QtOpenGL QtSql QtXml QtDesigner QtDBus QtScriptTools
792 set(QT_MODULES ${QT_MODULES} QtMotif)
796 foreach(QT_MODULE ${QT_MODULES})
797 string(TOUPPER ${QT_MODULE} _upper_qt_module)
798 set(QT_${_upper_qt_module}_INCLUDE_DIR NOTFOUND)
799 set(QT_${_upper_qt_module}_LIBRARY_RELEASE NOTFOUND)
800 set(QT_${_upper_qt_module}_LIBRARY_DEBUG NOTFOUND)
802 set(QT_QTDESIGNERCOMPONENTS_INCLUDE_DIR NOTFOUND)
803 set(QT_QTDESIGNERCOMPONENTS_LIBRARY_RELEASE NOTFOUND)
804 set(QT_QTDESIGNERCOMPONENTS_LIBRARY_DEBUG NOTFOUND)
805 set(QT_QTASSISTANTCLIENT_INCLUDE_DIR NOTFOUND)
806 set(QT_QTASSISTANTCLIENT_LIBRARY_RELEASE NOTFOUND)
807 set(QT_QTASSISTANTCLIENT_LIBRARY_DEBUG NOTFOUND)
808 set(QT_QTASSISTANT_INCLUDE_DIR NOTFOUND)
809 set(QT_QTASSISTANT_LIBRARY_RELEASE NOTFOUND)
810 set(QT_QTASSISTANT_LIBRARY_DEBUG NOTFOUND)
811 set(QT_QTCLUCENE_LIBRARY_RELEASE NOTFOUND)
812 set(QT_QTCLUCENE_LIBRARY_DEBUG NOTFOUND)
813 set(QT_QAXCONTAINER_INCLUDE_DIR NOTFOUND)
814 set(QT_QAXCONTAINER_LIBRARY_RELEASE NOTFOUND)
815 set(QT_QAXCONTAINER_LIBRARY_DEBUG NOTFOUND)
816 set(QT_QAXSERVER_INCLUDE_DIR NOTFOUND)
817 set(QT_QAXSERVER_LIBRARY_RELEASE NOTFOUND)
818 set(QT_QAXSERVER_LIBRARY_DEBUG NOTFOUND)
820 set(QT_QTMAIN_LIBRARY_DEBUG NOTFOUND)
821 set(QT_QTMAIN_LIBRARY_RELEASE NOTFOUND)
825 foreach(QT_MODULE ${QT_MODULES})
826 string(TOUPPER ${QT_MODULE} _upper_qt_module)
827 find_path(QT_${_upper_qt_module}_INCLUDE_DIR ${QT_MODULE}
829 ${QT_HEADERS_DIR}/${QT_MODULE}
830 ${QT_LIBRARY_DIR}/${QT_MODULE}.framework/Headers
831 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
833 # phonon doesn't seem consistent, let's try phonondefs.h for some
835 if(${QT_MODULE} STREQUAL "phonon")
836 find_path(QT_${_upper_qt_module}_INCLUDE_DIR phonondefs.h
838 ${QT_HEADERS_DIR}/${QT_MODULE}
839 ${QT_LIBRARY_DIR}/${QT_MODULE}.framework/Headers
840 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
846 set(QT_MODULES ${QT_MODULES} QAxContainer QAxServer)
847 # Set QT_AXCONTAINER_INCLUDE_DIR and QT_AXSERVER_INCLUDE_DIR
848 find_path(QT_QAXCONTAINER_INCLUDE_DIR ActiveQt
849 PATHS ${QT_HEADERS_DIR}/ActiveQt
850 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
852 find_path(QT_QAXSERVER_INCLUDE_DIR ActiveQt
853 PATHS ${QT_HEADERS_DIR}/ActiveQt
854 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
858 # Set QT_QTDESIGNERCOMPONENTS_INCLUDE_DIR
859 find_path(QT_QTDESIGNERCOMPONENTS_INCLUDE_DIR QDesignerComponents
861 ${QT_HEADERS_DIR}/QtDesigner
862 ${QT_LIBRARY_DIR}/QtDesigner.framework/Headers
863 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
866 # Set QT_QTASSISTANT_INCLUDE_DIR
867 find_path(QT_QTASSISTANT_INCLUDE_DIR QtAssistant
869 ${QT_HEADERS_DIR}/QtAssistant
870 ${QT_LIBRARY_DIR}/QtAssistant.framework/Headers
871 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
874 # Set QT_QTASSISTANTCLIENT_INCLUDE_DIR
875 find_path(QT_QTASSISTANTCLIENT_INCLUDE_DIR QAssistantClient
877 ${QT_HEADERS_DIR}/QtAssistant
878 ${QT_LIBRARY_DIR}/QtAssistant.framework/Headers
879 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
882 ########################################
884 # Setting the LIBRARY-Variables
886 ########################################
889 foreach(QT_MODULE ${QT_MODULES})
890 string(TOUPPER ${QT_MODULE} _upper_qt_module)
891 find_library(QT_${_upper_qt_module}_LIBRARY_RELEASE
892 NAMES ${QT_MODULE}${QT_LIBINFIX} ${QT_MODULE}${QT_LIBINFIX}4
893 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
895 find_library(QT_${_upper_qt_module}_LIBRARY_DEBUG
896 NAMES ${QT_MODULE}${QT_LIBINFIX}_debug ${QT_MODULE}${QT_LIBINFIX}d ${QT_MODULE}${QT_LIBINFIX}d4
897 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
899 if(QT_${_upper_qt_module}_LIBRARY_RELEASE MATCHES "/${QT_MODULE}\\.framework$")
900 if(NOT EXISTS "${QT_${_upper_qt_module}_LIBRARY_RELEASE}/${QT_MODULE}")
901 # Release framework library file does not exist... Force to NOTFOUND:
902 set(QT_${_upper_qt_module}_LIBRARY_RELEASE "QT_${_upper_qt_module}_LIBRARY_RELEASE-NOTFOUND" CACHE FILEPATH "Path to a library." FORCE)
905 if(QT_${_upper_qt_module}_LIBRARY_DEBUG MATCHES "/${QT_MODULE}\\.framework$")
906 if(NOT EXISTS "${QT_${_upper_qt_module}_LIBRARY_DEBUG}/${QT_MODULE}")
907 # Debug framework library file does not exist... Force to NOTFOUND:
908 set(QT_${_upper_qt_module}_LIBRARY_DEBUG "QT_${_upper_qt_module}_LIBRARY_DEBUG-NOTFOUND" CACHE FILEPATH "Path to a library." FORCE)
913 # QtUiTools is sometimes not in the same directory as the other found libraries
914 # e.g. on Mac, its never a framework like the others are
915 if(QT_QTCORE_LIBRARY_RELEASE AND NOT QT_QTUITOOLS_LIBRARY_RELEASE)
916 find_library(QT_QTUITOOLS_LIBRARY_RELEASE NAMES QtUiTools${QT_LIBINFIX} PATHS ${QT_LIBRARY_DIR})
919 # Set QT_QTDESIGNERCOMPONENTS_LIBRARY
920 find_library(QT_QTDESIGNERCOMPONENTS_LIBRARY_RELEASE NAMES QtDesignerComponents${QT_LIBINFIX} QtDesignerComponents${QT_LIBINFIX}4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
921 find_library(QT_QTDESIGNERCOMPONENTS_LIBRARY_DEBUG NAMES QtDesignerComponents${QT_LIBINFIX}_debug QtDesignerComponents${QT_LIBINFIX}d QtDesignerComponents${QT_LIBINFIX}d4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
923 # Set QT_QTMAIN_LIBRARY
925 find_library(QT_QTMAIN_LIBRARY_RELEASE NAMES qtmain${QT_LIBINFIX} PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
926 find_library(QT_QTMAIN_LIBRARY_DEBUG NAMES qtmain${QT_LIBINFIX}d PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
929 # Set QT_QTASSISTANTCLIENT_LIBRARY
930 find_library(QT_QTASSISTANTCLIENT_LIBRARY_RELEASE NAMES QtAssistantClient${QT_LIBINFIX} QtAssistantClient${QT_LIBINFIX}4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
931 find_library(QT_QTASSISTANTCLIENT_LIBRARY_DEBUG NAMES QtAssistantClient${QT_LIBINFIX}_debug QtAssistantClient${QT_LIBINFIX}d QtAssistantClient${QT_LIBINFIX}d4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
933 # Set QT_QTASSISTANT_LIBRARY
934 find_library(QT_QTASSISTANT_LIBRARY_RELEASE NAMES QtAssistantClient${QT_LIBINFIX} QtAssistantClient${QT_LIBINFIX}4 QtAssistant${QT_LIBINFIX} QtAssistant${QT_LIBINFIX}4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
935 find_library(QT_QTASSISTANT_LIBRARY_DEBUG NAMES QtAssistantClient${QT_LIBINFIX}_debug QtAssistantClient${QT_LIBINFIX}d QtAssistantClient${QT_LIBINFIX}d4 QtAssistant${QT_LIBINFIX}_debug QtAssistant${QT_LIBINFIX}d4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
937 # Set QT_QTHELP_LIBRARY
938 find_library(QT_QTCLUCENE_LIBRARY_RELEASE NAMES QtCLucene${QT_LIBINFIX} QtCLucene${QT_LIBINFIX}4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
939 find_library(QT_QTCLUCENE_LIBRARY_DEBUG NAMES QtCLucene${QT_LIBINFIX}_debug QtCLucene${QT_LIBINFIX}d QtCLucene${QT_LIBINFIX}d4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
940 if(Q_WS_MAC AND QT_QTCORE_LIBRARY_RELEASE AND NOT QT_QTCLUCENE_LIBRARY_RELEASE)
941 find_library(QT_QTCLUCENE_LIBRARY_RELEASE NAMES QtCLucene${QT_LIBINFIX} PATHS ${QT_LIBRARY_DIR})
945 ############################################
947 # Check the existence of the libraries.
949 ############################################
952 macro(_qt4_add_target_depends_internal _QT_MODULE _PROPERTY)
953 if (TARGET Qt4::${_QT_MODULE})
954 foreach(_DEPEND ${ARGN})
956 if (TARGET Qt4::Qt${_DEPEND})
957 list(APPEND _VALID_DEPENDS Qt4::Qt${_DEPEND})
960 set_property(TARGET Qt4::${_QT_MODULE} APPEND PROPERTY
970 macro(_qt4_add_target_depends _QT_MODULE)
971 if (TARGET Qt4::${_QT_MODULE})
972 get_target_property(_configs Qt4::${_QT_MODULE} IMPORTED_CONFIGURATIONS)
973 _qt4_add_target_depends_internal(${_QT_MODULE} INTERFACE_LINK_LIBRARIES ${ARGN})
974 foreach(_config ${_configs})
975 _qt4_add_target_depends_internal(${_QT_MODULE} IMPORTED_LINK_INTERFACE_LIBRARIES_${_config} ${ARGN})
981 macro(_qt4_add_target_private_depends _QT_MODULE)
982 if (TARGET Qt4::${_QT_MODULE})
983 get_target_property(_configs Qt4::${_QT_MODULE} IMPORTED_CONFIGURATIONS)
984 foreach(_config ${_configs})
985 _qt4_add_target_depends_internal(${_QT_MODULE} IMPORTED_LINK_DEPENDENT_LIBRARIES_${_config} ${ARGN})
992 # Set QT_xyz_LIBRARY variable and add
993 # library include path to QT_INCLUDES
994 _QT4_ADJUST_LIB_VARS(QtCore)
995 set_property(TARGET Qt4::QtCore APPEND PROPERTY
996 INTERFACE_INCLUDE_DIRECTORIES
997 "${QT_MKSPECS_DIR}/default"
1000 set_property(TARGET Qt4::QtCore APPEND PROPERTY
1001 INTERFACE_COMPILE_DEFINITIONS
1002 $<$<NOT:$<CONFIG:Debug>>:QT_NO_DEBUG>
1004 set_property(TARGET Qt4::QtCore PROPERTY
1005 INTERFACE_QT_MAJOR_VERSION 4
1007 set_property(TARGET Qt4::QtCore APPEND PROPERTY
1008 COMPATIBLE_INTERFACE_STRING QT_MAJOR_VERSION
1011 foreach(QT_MODULE ${QT_MODULES})
1012 _QT4_ADJUST_LIB_VARS(${QT_MODULE})
1013 _qt4_add_target_depends(${QT_MODULE} Core)
1016 _QT4_ADJUST_LIB_VARS(QtAssistant)
1017 _QT4_ADJUST_LIB_VARS(QtAssistantClient)
1018 _QT4_ADJUST_LIB_VARS(QtCLucene)
1019 _QT4_ADJUST_LIB_VARS(QtDesignerComponents)
1021 # platform dependent libraries
1023 _QT4_ADJUST_LIB_VARS(qtmain)
1025 _QT4_ADJUST_LIB_VARS(QAxServer)
1026 if(QT_QAXSERVER_FOUND)
1027 set_property(TARGET Qt4::QAxServer PROPERTY
1028 INTERFACE_QT4_NO_LINK_QTMAIN ON
1030 set_property(TARGET Qt4::QAxServer APPEND PROPERTY
1031 COMPATIBLE_INTERFACE_BOOL QT4_NO_LINK_QTMAIN)
1034 _QT4_ADJUST_LIB_VARS(QAxContainer)
1037 # Only public dependencies are listed here.
1038 # Eg, QtDBus links to QtXml, but users of QtDBus do not need to
1039 # link to QtXml because QtDBus only uses it internally, not in public
1041 # Everything depends on QtCore, but that is covered above already
1042 _qt4_add_target_depends(Qt3Support Sql Gui Network)
1043 if (TARGET Qt4::Qt3Support)
1044 # An additional define is required for QT3_SUPPORT
1045 set_property(TARGET Qt4::Qt3Support APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS QT3_SUPPORT)
1047 _qt4_add_target_depends(QtDeclarative Script Gui)
1048 _qt4_add_target_depends(QtDesigner Gui)
1049 _qt4_add_target_depends(QtHelp Gui)
1050 _qt4_add_target_depends(QtMultimedia Gui)
1051 _qt4_add_target_depends(QtOpenGL Gui)
1052 _qt4_add_target_depends(QtSvg Gui)
1053 _qt4_add_target_depends(QtWebKit Gui Network)
1055 _qt4_add_target_private_depends(Qt3Support Xml)
1056 if(QT_VERSION VERSION_GREATER 4.6)
1057 _qt4_add_target_private_depends(QtSvg Xml)
1059 _qt4_add_target_private_depends(QtDBus Xml)
1060 _qt4_add_target_private_depends(QtUiTools Xml Gui)
1061 _qt4_add_target_private_depends(QtHelp Sql Xml Network)
1062 _qt4_add_target_private_depends(QtXmlPatterns Network)
1063 _qt4_add_target_private_depends(QtScriptTools Gui)
1064 _qt4_add_target_private_depends(QtWebKit XmlPatterns)
1065 _qt4_add_target_private_depends(QtDeclarative XmlPatterns Svg Sql Gui)
1066 _qt4_add_target_private_depends(QtMultimedia Gui)
1067 _qt4_add_target_private_depends(QtOpenGL Gui)
1068 if(QT_QAXSERVER_FOUND)
1069 _qt4_add_target_private_depends(QAxServer Gui)
1071 if(QT_QAXCONTAINER_FOUND)
1072 _qt4_add_target_private_depends(QAxContainer Gui)
1074 _qt4_add_target_private_depends(phonon Gui)
1076 _qt4_add_target_private_depends(phonon DBus)
1079 if (WIN32 AND NOT QT4_NO_LINK_QTMAIN)
1080 set(_isExe $<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>)
1081 set(_isWin32 $<BOOL:$<TARGET_PROPERTY:WIN32_EXECUTABLE>>)
1082 set(_isNotExcluded $<NOT:$<BOOL:$<TARGET_PROPERTY:QT4_NO_LINK_QTMAIN>>>)
1083 set(_isPolicyNEW $<TARGET_POLICY:CMP0020>)
1084 get_target_property(_configs Qt4::QtCore IMPORTED_CONFIGURATIONS)
1085 set_property(TARGET Qt4::QtCore APPEND PROPERTY
1086 INTERFACE_LINK_LIBRARIES
1087 $<$<AND:${_isExe},${_isWin32},${_isNotExcluded},${_isPolicyNEW}>:Qt4::qtmain>
1089 foreach(_config ${_configs})
1090 set_property(TARGET Qt4::QtCore APPEND PROPERTY
1091 IMPORTED_LINK_INTERFACE_LIBRARIES_${_config}
1092 $<$<AND:${_isExe},${_isWin32},${_isNotExcluded},${_isPolicyNEW}>:Qt4::qtmain>
1098 unset(_isNotExcluded)
1102 #######################################
1104 # Check the executables of Qt
1107 #######################################
1110 if(QT_QMAKE_CHANGED)
1111 set(QT_UIC_EXECUTABLE NOTFOUND)
1112 set(QT_MOC_EXECUTABLE NOTFOUND)
1113 set(QT_UIC3_EXECUTABLE NOTFOUND)
1114 set(QT_RCC_EXECUTABLE NOTFOUND)
1115 set(QT_DBUSCPP2XML_EXECUTABLE NOTFOUND)
1116 set(QT_DBUSXML2CPP_EXECUTABLE NOTFOUND)
1117 set(QT_LUPDATE_EXECUTABLE NOTFOUND)
1118 set(QT_LRELEASE_EXECUTABLE NOTFOUND)
1119 set(QT_QCOLLECTIONGENERATOR_EXECUTABLE NOTFOUND)
1120 set(QT_DESIGNER_EXECUTABLE NOTFOUND)
1121 set(QT_LINGUIST_EXECUTABLE NOTFOUND)
1124 macro(_find_qt4_program VAR NAME)
1127 PATHS ${QT_BINARY_DIR}
1128 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
1130 if (${VAR} AND NOT TARGET ${NAME})
1131 add_executable(${NAME} IMPORTED)
1132 set_property(TARGET ${NAME} PROPERTY IMPORTED_LOCATION ${${VAR}})
1136 _find_qt4_program(QT_MOC_EXECUTABLE Qt4::moc moc-qt4 moc4 moc)
1137 _find_qt4_program(QT_UIC_EXECUTABLE Qt4::uic uic-qt4 uic4 uic)
1138 _find_qt4_program(QT_UIC3_EXECUTABLE Qt4::uic3 uic3)
1139 _find_qt4_program(QT_RCC_EXECUTABLE Qt4::rcc rcc)
1140 _find_qt4_program(QT_DBUSCPP2XML_EXECUTABLE Qt4::qdbuscpp2xml qdbuscpp2xml)
1141 _find_qt4_program(QT_DBUSXML2CPP_EXECUTABLE Qt4::qdbusxml2cpp qdbusxml2cpp)
1142 _find_qt4_program(QT_LUPDATE_EXECUTABLE Qt4::lupdate lupdate-qt4 lupdate4 lupdate)
1143 _find_qt4_program(QT_LRELEASE_EXECUTABLE Qt4::lrelease lrelease-qt4 lrelease4 lrelease)
1144 _find_qt4_program(QT_QCOLLECTIONGENERATOR_EXECUTABLE Qt4::qcollectiongenerator qcollectiongenerator-qt4 qcollectiongenerator)
1145 _find_qt4_program(QT_DESIGNER_EXECUTABLE Qt4::designer designer-qt4 designer4 designer)
1146 _find_qt4_program(QT_LINGUIST_EXECUTABLE Qt4::linguist linguist-qt4 linguist4 linguist)
1148 if (NOT TARGET Qt4::qmake)
1149 add_executable(Qt4::qmake IMPORTED)
1150 set_property(TARGET Qt4::qmake PROPERTY IMPORTED_LOCATION ${QT_QMAKE_EXECUTABLE})
1153 if (QT_MOC_EXECUTABLE)
1154 set(QT_WRAP_CPP "YES")
1157 if (QT_UIC_EXECUTABLE)
1158 set(QT_WRAP_UI "YES")
1163 mark_as_advanced( QT_UIC_EXECUTABLE QT_UIC3_EXECUTABLE QT_MOC_EXECUTABLE
1164 QT_RCC_EXECUTABLE QT_DBUSXML2CPP_EXECUTABLE QT_DBUSCPP2XML_EXECUTABLE
1165 QT_LUPDATE_EXECUTABLE QT_LRELEASE_EXECUTABLE QT_QCOLLECTIONGENERATOR_EXECUTABLE
1166 QT_DESIGNER_EXECUTABLE QT_LINGUIST_EXECUTABLE)
1169 # get the directory of the current file, used later on in the file
1170 get_filename_component( _qt4_current_dir "${CMAKE_CURRENT_LIST_FILE}" PATH)
1173 ###############################################
1175 # configuration/system dependent settings
1177 ###############################################
1179 include("${_qt4_current_dir}/Qt4ConfigDependentSettings.cmake")
1182 #######################################
1184 # Check the plugins of Qt
1186 #######################################
1188 set( QT_PLUGIN_TYPES accessible bearer codecs decorations designer gfxdrivers graphicssystems iconengines imageformats inputmethods mousedrivers phonon_backend script sqldrivers )
1190 set( QT_ACCESSIBLE_PLUGINS qtaccessiblecompatwidgets qtaccessiblewidgets )
1191 set( QT_BEARER_PLUGINS qcorewlanbearer qgenericbearer qnativewifibearer )
1192 set( QT_CODECS_PLUGINS qcncodecs qjpcodecs qkrcodecs qtwcodecs )
1193 set( QT_DECORATIONS_PLUGINS qdecorationdefault qdecorationwindows )
1194 set( QT_DESIGNER_PLUGINS arthurplugin containerextension customwidgetplugin phononwidgets qdeclarativeview qt3supportwidgets qwebview taskmenuextension worldtimeclockplugin )
1195 set( QT_GRAPHICSDRIVERS_PLUGINS qgfxtransformed qgfxvnc qscreenvfb )
1196 set( QT_GRAPHICSSYSTEMS_PLUGINS qglgraphicssystem qtracegraphicssystem )
1197 set( QT_ICONENGINES_PLUGINS qsvgicon )
1198 set( QT_IMAGEFORMATS_PLUGINS qgif qjpeg qmng qico qsvg qtiff qtga )
1199 set( QT_INPUTMETHODS_PLUGINS qimsw_multi )
1200 set( QT_MOUSEDRIVERS_PLUGINS qwstslibmousehandler )
1202 set( QT_PHONON_BACKEND_PLUGINS phonon_qt7 )
1204 set( QT_PHONON_BACKEND_PLUGINS phonon_ds9 )
1206 set( QT_SCRIPT_PLUGINS qtscriptdbus )
1207 set( QT_SQLDRIVERS_PLUGINS qsqldb2 qsqlibase qsqlite qsqlite2 qsqlmysql qsqloci qsqlodbc qsqlpsql qsqltds )
1209 set( QT_PHONON_PLUGINS ${QT_PHONON_BACKEND_PLUGINS} )
1210 set( QT_QT3SUPPORT_PLUGINS qtaccessiblecompatwidgets )
1211 set( QT_QTCORE_PLUGINS ${QT_BEARER_PLUGINS} ${QT_CODECS_PLUGINS} )
1212 set( QT_QTGUI_PLUGINS qtaccessiblewidgets ${QT_IMAGEFORMATS_PLUGINS} ${QT_DECORATIONS_PLUGINS} ${QT_GRAPHICSDRIVERS_PLUGINS} ${QT_GRAPHICSSYSTEMS_PLUGINS} ${QT_INPUTMETHODS_PLUGINS} ${QT_MOUSEDRIVERS_PLUGINS} )
1213 set( QT_QTSCRIPT_PLUGINS ${QT_SCRIPT_PLUGINS} )
1214 set( QT_QTSQL_PLUGINS ${QT_SQLDRIVERS_PLUGINS} )
1215 set( QT_QTSVG_PLUGINS qsvg qsvgicon )
1217 if(QT_QMAKE_CHANGED)
1218 foreach(QT_PLUGIN_TYPE ${QT_PLUGIN_TYPES})
1219 string(TOUPPER ${QT_PLUGIN_TYPE} _upper_qt_plugin_type)
1220 set(QT_${_upper_qt_plugin_type}_PLUGINS_DIR ${QT_PLUGINS_DIR}/${QT_PLUGIN_TYPE})
1221 foreach(QT_PLUGIN ${QT_${_upper_qt_plugin_type}_PLUGINS})
1222 string(TOUPPER ${QT_PLUGIN} _upper_qt_plugin)
1223 unset(QT_${_upper_qt_plugin}_LIBRARY_RELEASE CACHE)
1224 unset(QT_${_upper_qt_plugin}_LIBRARY_DEBUG CACHE)
1225 unset(QT_${_upper_qt_plugin}_LIBRARY CACHE)
1226 unset(QT_${_upper_qt_plugin}_PLUGIN_RELEASE CACHE)
1227 unset(QT_${_upper_qt_plugin}_PLUGIN_DEBUG CACHE)
1228 unset(QT_${_upper_qt_plugin}_PLUGIN CACHE)
1233 # find_library works better than find_file but we need to set prefixes to only match plugins
1234 foreach(QT_PLUGIN_TYPE ${QT_PLUGIN_TYPES})
1235 string(TOUPPER ${QT_PLUGIN_TYPE} _upper_qt_plugin_type)
1236 set(QT_${_upper_qt_plugin_type}_PLUGINS_DIR ${QT_PLUGINS_DIR}/${QT_PLUGIN_TYPE})
1237 foreach(QT_PLUGIN ${QT_${_upper_qt_plugin_type}_PLUGINS})
1238 string(TOUPPER ${QT_PLUGIN} _upper_qt_plugin)
1240 find_library(QT_${_upper_qt_plugin}_LIBRARY_RELEASE
1241 NAMES ${QT_PLUGIN}${QT_LIBINFIX} ${QT_PLUGIN}${QT_LIBINFIX}4
1242 PATHS ${QT_${_upper_qt_plugin_type}_PLUGINS_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
1244 find_library(QT_${_upper_qt_plugin}_LIBRARY_DEBUG
1245 NAMES ${QT_PLUGIN}${QT_LIBINFIX}_debug ${QT_PLUGIN}${QT_LIBINFIX}d ${QT_PLUGIN}${QT_LIBINFIX}d4
1246 PATHS ${QT_${_upper_qt_plugin_type}_PLUGINS_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
1248 _QT4_ADJUST_LIB_VARS(${QT_PLUGIN})
1250 # find_library works easier/better than find_file but we need to set suffixes to only match plugins
1251 set(CMAKE_FIND_LIBRARY_SUFFIXES_DEFAULT ${CMAKE_FIND_LIBRARY_SUFFIXES})
1252 set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_SHARED_MODULE_SUFFIX} ${CMAKE_SHARED_LIBRARY_SUFFIX})
1253 find_library(QT_${_upper_qt_plugin}_PLUGIN_RELEASE
1254 NAMES ${QT_PLUGIN}${QT_LIBINFIX} ${QT_PLUGIN}${QT_LIBINFIX}4
1255 PATHS ${QT_${_upper_qt_plugin_type}_PLUGINS_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
1257 find_library(QT_${_upper_qt_plugin}_PLUGIN_DEBUG
1258 NAMES ${QT_PLUGIN}${QT_LIBINFIX}_debug ${QT_PLUGIN}${QT_LIBINFIX}d ${QT_PLUGIN}${QT_LIBINFIX}d4
1259 PATHS ${QT_${_upper_qt_plugin_type}_PLUGINS_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
1261 mark_as_advanced(QT_${_upper_qt_plugin}_PLUGIN_RELEASE QT_${_upper_qt_plugin}_PLUGIN_DEBUG)
1262 set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_DEFAULT})
1268 ######################################
1270 # Macros for building Qt files
1272 ######################################
1274 include("${_qt4_current_dir}/Qt4Macros.cmake")
1278 #support old QT_MIN_VERSION if set, but not if version is supplied by find_package()
1279 if(NOT Qt4_FIND_VERSION AND QT_MIN_VERSION)
1280 set(Qt4_FIND_VERSION ${QT_MIN_VERSION})
1283 if( Qt4_FIND_COMPONENTS )
1285 # if components specified in find_package(), make sure each of those pieces were found
1286 set(_QT4_FOUND_REQUIRED_VARS QT_QMAKE_EXECUTABLE QT_MOC_EXECUTABLE QT_RCC_EXECUTABLE QT_INCLUDE_DIR QT_LIBRARY_DIR)
1287 foreach( component ${Qt4_FIND_COMPONENTS} )
1288 string( TOUPPER ${component} _COMPONENT )
1289 if(${_COMPONENT} STREQUAL "QTMAIN")
1291 set(_QT4_FOUND_REQUIRED_VARS ${_QT4_FOUND_REQUIRED_VARS} QT_${_COMPONENT}_LIBRARY)
1294 set(_QT4_FOUND_REQUIRED_VARS ${_QT4_FOUND_REQUIRED_VARS} QT_${_COMPONENT}_INCLUDE_DIR QT_${_COMPONENT}_LIBRARY)
1298 if(Qt4_FIND_COMPONENTS MATCHES QtGui)
1299 set(_QT4_FOUND_REQUIRED_VARS ${_QT4_FOUND_REQUIRED_VARS} QT_UIC_EXECUTABLE)
1304 # if no components specified, we'll make a default set of required variables to say Qt is found
1305 set(_QT4_FOUND_REQUIRED_VARS QT_QMAKE_EXECUTABLE QT_MOC_EXECUTABLE QT_RCC_EXECUTABLE QT_UIC_EXECUTABLE QT_INCLUDE_DIR
1306 QT_LIBRARY_DIR QT_QTCORE_LIBRARY)
1310 if (NOT QT_VERSION_MAJOR EQUAL 4)
1311 set(VERSION_MSG "Found unsuitable Qt version \"${QTVERSION}\" from ${QT_QMAKE_EXECUTABLE}")
1312 set(Qt4_FOUND FALSE)
1313 if(Qt4_FIND_REQUIRED)
1314 message( FATAL_ERROR "${VERSION_MSG}, this code requires Qt 4.x")
1316 if(NOT Qt4_FIND_QUIETLY)
1317 message( STATUS "${VERSION_MSG}")
1321 if (CMAKE_FIND_PACKAGE_NAME STREQUAL "Qt")
1322 # FindQt include()'s this module. It's an old pattern, but rather than
1323 # trying to suppress this from outside the module (which is then sensitive
1324 # to the contents, detect the case in this module and suppress it
1326 set(FPHSA_NAME_MISMATCHED 1)
1328 FIND_PACKAGE_HANDLE_STANDARD_ARGS(Qt4 FOUND_VAR Qt4_FOUND
1329 REQUIRED_VARS ${_QT4_FOUND_REQUIRED_VARS}
1330 VERSION_VAR QTVERSION
1332 unset(FPHSA_NAME_MISMATCHED)
1335 #######################################
1337 # compatibility settings
1339 #######################################
1340 # Backwards compatibility for CMake1.4 and 1.2
1341 set (QT_MOC_EXE ${QT_MOC_EXECUTABLE} )
1342 set (QT_UIC_EXE ${QT_UIC_EXECUTABLE} )
1343 set( QT_QT_LIBRARY "")
1344 set(QT4_FOUND ${Qt4_FOUND})
1345 set(QT_FOUND ${Qt4_FOUND})