FindQt.cmake 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file LICENSE.rst or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindQt
  5. ------
  6. .. deprecated:: 3.14
  7. This module is available only if policy :policy:`CMP0084` is not set to
  8. ``NEW``. It supports only Qt3 and Qt4. For Qt5 or later versions see
  9. :manual:`cmake-qt(7)`.
  10. Finds an installed version of Qt3 or Qt4:
  11. .. code-block:: cmake
  12. find_package(Qt [...])
  13. Qt is a cross-platform application development framework for creating
  14. graphical user interfaces and applications.
  15. Use this module only if the project can work with both Qt3 and Qt4
  16. versions. If a specific version is required, use :module:`FindQt4` or
  17. :module:`FindQt3` module directly.
  18. Behavior:
  19. * If multiple Qt versions are found, the user must set the preferred major
  20. Qt version with the ``DESIRED_QT_VERSION`` variable.
  21. * If only one Qt version is found, then the ``DESIRED_QT_VERSION`` is set
  22. automatically.
  23. * Once the ``DESIRED_QT_VERSION`` variable is set, the corresponding
  24. :module:`FindQt3` or :module:`FindQt4` module is included.
  25. Result Variables
  26. ^^^^^^^^^^^^^^^^
  27. This module defines the following variables:
  28. ``QT4_INSTALLED``
  29. ``TRUE`` if Qt4 is found.
  30. ``QT3_INSTALLED``
  31. ``TRUE`` if Qt3 is found.
  32. Hints
  33. ^^^^^
  34. ``QT_REQUIRED``
  35. If this variable is set to ``TRUE`` before calling ``find_package(Qt)``,
  36. CMake will raise an error if neither Qt3 nor Qt4 is found.
  37. ``DESIRED_QT_VERSION``
  38. Specifies the Qt major version to use. Can be either ``3``, ``4``, or empty,
  39. to search for version automatically.
  40. Examples
  41. ^^^^^^^^
  42. Finding Qt3 or Qt4 version:
  43. .. code-block:: cmake
  44. find_package(Qt)
  45. #]=======================================================================]
  46. if(_findqt_testing)
  47. set(_findqt_included TRUE)
  48. return()
  49. endif()
  50. # look for signs of qt3 installations
  51. file(GLOB GLOB_TEMP_VAR /usr/lib*/qt-3*/bin/qmake /usr/lib*/qt3*/bin/qmake)
  52. if(GLOB_TEMP_VAR)
  53. set(QT3_INSTALLED TRUE)
  54. endif()
  55. set(GLOB_TEMP_VAR)
  56. file(GLOB GLOB_TEMP_VAR /usr/local/qt-x11-commercial-3*/bin/qmake)
  57. if(GLOB_TEMP_VAR)
  58. set(QT3_INSTALLED TRUE)
  59. endif()
  60. set(GLOB_TEMP_VAR)
  61. file(GLOB GLOB_TEMP_VAR /usr/local/lib/qt3/bin/qmake)
  62. if(GLOB_TEMP_VAR)
  63. set(QT3_INSTALLED TRUE)
  64. endif()
  65. set(GLOB_TEMP_VAR)
  66. # look for qt4 installations
  67. file(GLOB GLOB_TEMP_VAR /usr/local/qt-x11-commercial-4*/bin/qmake)
  68. if(GLOB_TEMP_VAR)
  69. set(QT4_INSTALLED TRUE)
  70. endif()
  71. set(GLOB_TEMP_VAR)
  72. file(GLOB GLOB_TEMP_VAR /usr/local/Trolltech/Qt-4*/bin/qmake)
  73. if(GLOB_TEMP_VAR)
  74. set(QT4_INSTALLED TRUE)
  75. endif()
  76. set(GLOB_TEMP_VAR)
  77. file(GLOB GLOB_TEMP_VAR /usr/local/lib/qt4/bin/qmake)
  78. if(GLOB_TEMP_VAR)
  79. set(QT4_INSTALLED TRUE)
  80. endif()
  81. set(GLOB_TEMP_VAR)
  82. if (Qt_FIND_VERSION)
  83. if (Qt_FIND_VERSION MATCHES "^([34])(\\.[0-9]+.*)?$")
  84. set(DESIRED_QT_VERSION ${CMAKE_MATCH_1})
  85. else ()
  86. message(FATAL_ERROR "FindQt was called with invalid version '${Qt_FIND_VERSION}'. Only Qt major versions 3 or 4 are supported. If you do not need to support both Qt3 and Qt4 in your source consider calling find_package(Qt3) or find_package(Qt4) instead of find_package(Qt) instead.")
  87. endif ()
  88. endif ()
  89. # now find qmake
  90. find_program(QT_QMAKE_EXECUTABLE_FINDQT NAMES qmake PATHS "${QT_SEARCH_PATH}/bin" "$ENV{QTDIR}/bin")
  91. if(QT_QMAKE_EXECUTABLE_FINDQT)
  92. execute_process(COMMAND ${QT_QMAKE_EXECUTABLE_FINDQT} -query QT_VERSION
  93. OUTPUT_VARIABLE QTVERSION)
  94. if(QTVERSION MATCHES "4")
  95. set(QT_QMAKE_EXECUTABLE ${QT_QMAKE_EXECUTABLE_FINDQT} CACHE PATH "Qt4 qmake program.")
  96. set(QT4_INSTALLED TRUE)
  97. endif()
  98. if(QTVERSION MATCHES "Unknown")
  99. set(QT3_INSTALLED TRUE)
  100. endif()
  101. endif()
  102. if(QT_QMAKE_EXECUTABLE_FINDQT)
  103. execute_process(COMMAND ${QT_QMAKE_EXECUTABLE_FINDQT}
  104. -query QT_INSTALL_HEADERS
  105. OUTPUT_VARIABLE qt_headers )
  106. endif()
  107. find_file( QT4_QGLOBAL_H_FILE qglobal.h
  108. "${QT_SEARCH_PATH}/Qt/include"
  109. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\4.0.0;InstallDir]/include/Qt"
  110. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Versions\\4.0.0;InstallDir]/include/Qt"
  111. ${qt_headers}/Qt
  112. $ENV{QTDIR}/include/Qt
  113. /usr/lib/qt/include/Qt
  114. /usr/share/qt4/include/Qt
  115. /usr/local/include/X11/qt4/Qt
  116. C:/Progra~1/qt/include/Qt
  117. PATH_SUFFIXES qt/include/Qt include/Qt)
  118. if(QT4_QGLOBAL_H_FILE)
  119. set(QT4_INSTALLED TRUE)
  120. endif()
  121. find_file( QT3_QGLOBAL_H_FILE qglobal.h
  122. "${QT_SEARCH_PATH}/Qt/include"
  123. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]/include/Qt"
  124. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]/include/Qt"
  125. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]/include/Qt"
  126. C:/Qt/3.3.3Educational/include
  127. $ENV{QTDIR}/include
  128. /usr/include/qt3/Qt
  129. /usr/share/qt3/include
  130. /usr/local/include/X11/qt3
  131. C:/Progra~1/qt/include
  132. PATH_SUFFIXES qt/include include/qt3)
  133. if(QT3_QGLOBAL_H_FILE)
  134. set(QT3_INSTALLED TRUE)
  135. endif()
  136. if(QT3_INSTALLED AND QT4_INSTALLED AND NOT DESIRED_QT_VERSION)
  137. # force user to pick if we have both
  138. set(DESIRED_QT_VERSION 0 CACHE STRING "Pick a version of Qt to use: 3 or 4")
  139. else()
  140. # if only one found then pick that one
  141. if(QT3_INSTALLED AND NOT DESIRED_QT_VERSION EQUAL 4)
  142. set(DESIRED_QT_VERSION 3 CACHE STRING "Pick a version of Qt to use: 3 or 4")
  143. endif()
  144. if(QT4_INSTALLED AND NOT DESIRED_QT_VERSION EQUAL 3)
  145. set(DESIRED_QT_VERSION 4 CACHE STRING "Pick a version of Qt to use: 3 or 4")
  146. endif()
  147. endif()
  148. if(DESIRED_QT_VERSION EQUAL 3)
  149. set(Qt3_FIND_REQUIRED ${Qt_FIND_REQUIRED})
  150. set(Qt3_FIND_QUIETLY ${Qt_FIND_QUIETLY})
  151. include(${CMAKE_CURRENT_LIST_DIR}/FindQt3.cmake)
  152. endif()
  153. if(DESIRED_QT_VERSION EQUAL 4)
  154. set(Qt4_FIND_REQUIRED ${Qt_FIND_REQUIRED})
  155. set(Qt4_FIND_QUIETLY ${Qt_FIND_QUIETLY})
  156. include(${CMAKE_CURRENT_LIST_DIR}/FindQt4.cmake)
  157. endif()
  158. if(NOT QT3_INSTALLED AND NOT QT4_INSTALLED)
  159. if(QT_REQUIRED)
  160. message(SEND_ERROR "CMake was unable to find any Qt versions, put qmake in your path, or set QT_QMAKE_EXECUTABLE.")
  161. endif()
  162. else()
  163. if(NOT QT_FOUND AND NOT DESIRED_QT_VERSION)
  164. if(QT_REQUIRED)
  165. message(SEND_ERROR "Multiple versions of Qt found please set DESIRED_QT_VERSION")
  166. else()
  167. message("Multiple versions of Qt found please set DESIRED_QT_VERSION")
  168. endif()
  169. endif()
  170. if(NOT QT_FOUND AND DESIRED_QT_VERSION)
  171. if(QT_REQUIRED)
  172. message(FATAL_ERROR "CMake was unable to find Qt version: ${DESIRED_QT_VERSION}. Set advanced values QT_QMAKE_EXECUTABLE and QT${DESIRED_QT_VERSION}_QGLOBAL_H_FILE, if those are set then QT_QT_LIBRARY or QT_LIBRARY_DIR.")
  173. else()
  174. message( "CMake was unable to find desired Qt version: ${DESIRED_QT_VERSION}. Set advanced values QT_QMAKE_EXECUTABLE and QT${DESIRED_QT_VERSION}_QGLOBAL_H_FILE.")
  175. endif()
  176. endif()
  177. endif()
  178. mark_as_advanced(QT3_QGLOBAL_H_FILE QT4_QGLOBAL_H_FILE QT_QMAKE_EXECUTABLE_FINDQT)