FindQt.cmake 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindQt
  5. ------
  6. Searches for all installed versions of Qt3 or Qt4.
  7. This module cannot handle Qt5 or any later versions.
  8. For those, see :manual:`cmake-qt(7)`.
  9. This module exists for the :command:`find_package` command only if
  10. policy :policy:`CMP0084` is not set to ``NEW``.
  11. This module should only be used if your project can work with multiple
  12. versions of Qt. If not, you should just directly use FindQt4 or
  13. FindQt3. If multiple versions of Qt are found on the machine, then
  14. The user must set the option DESIRED_QT_VERSION to the version they
  15. want to use. If only one version of qt is found on the machine, then
  16. the DESIRED_QT_VERSION is set to that version and the matching FindQt3
  17. or FindQt4 module is included. Once the user sets DESIRED_QT_VERSION,
  18. then the FindQt3 or FindQt4 module is included.
  19. ::
  20. QT_REQUIRED if this is set to TRUE then if CMake can
  21. not find Qt4 or Qt3 an error is raised
  22. and a message is sent to the user.
  23. ::
  24. DESIRED_QT_VERSION OPTION is created
  25. QT4_INSTALLED is set to TRUE if qt4 is found.
  26. QT3_INSTALLED is set to TRUE if qt3 is found.
  27. #]=======================================================================]
  28. if(_findqt_testing)
  29. set(_findqt_included TRUE)
  30. return()
  31. endif()
  32. # look for signs of qt3 installations
  33. file(GLOB GLOB_TEMP_VAR /usr/lib*/qt-3*/bin/qmake /usr/lib*/qt3*/bin/qmake)
  34. if(GLOB_TEMP_VAR)
  35. set(QT3_INSTALLED TRUE)
  36. endif()
  37. set(GLOB_TEMP_VAR)
  38. file(GLOB GLOB_TEMP_VAR /usr/local/qt-x11-commercial-3*/bin/qmake)
  39. if(GLOB_TEMP_VAR)
  40. set(QT3_INSTALLED TRUE)
  41. endif()
  42. set(GLOB_TEMP_VAR)
  43. file(GLOB GLOB_TEMP_VAR /usr/local/lib/qt3/bin/qmake)
  44. if(GLOB_TEMP_VAR)
  45. set(QT3_INSTALLED TRUE)
  46. endif()
  47. set(GLOB_TEMP_VAR)
  48. # look for qt4 installations
  49. file(GLOB GLOB_TEMP_VAR /usr/local/qt-x11-commercial-4*/bin/qmake)
  50. if(GLOB_TEMP_VAR)
  51. set(QT4_INSTALLED TRUE)
  52. endif()
  53. set(GLOB_TEMP_VAR)
  54. file(GLOB GLOB_TEMP_VAR /usr/local/Trolltech/Qt-4*/bin/qmake)
  55. if(GLOB_TEMP_VAR)
  56. set(QT4_INSTALLED TRUE)
  57. endif()
  58. set(GLOB_TEMP_VAR)
  59. file(GLOB GLOB_TEMP_VAR /usr/local/lib/qt4/bin/qmake)
  60. if(GLOB_TEMP_VAR)
  61. set(QT4_INSTALLED TRUE)
  62. endif()
  63. set(GLOB_TEMP_VAR)
  64. if (Qt_FIND_VERSION)
  65. if (Qt_FIND_VERSION MATCHES "^([34])(\\.[0-9]+.*)?$")
  66. set(DESIRED_QT_VERSION ${CMAKE_MATCH_1})
  67. else ()
  68. 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.")
  69. endif ()
  70. endif ()
  71. # now find qmake
  72. find_program(QT_QMAKE_EXECUTABLE_FINDQT NAMES qmake PATHS "${QT_SEARCH_PATH}/bin" "$ENV{QTDIR}/bin")
  73. if(QT_QMAKE_EXECUTABLE_FINDQT)
  74. exec_program(${QT_QMAKE_EXECUTABLE_FINDQT} ARGS "-query QT_VERSION"
  75. OUTPUT_VARIABLE QTVERSION)
  76. if(QTVERSION MATCHES "4")
  77. set(QT_QMAKE_EXECUTABLE ${QT_QMAKE_EXECUTABLE_FINDQT} CACHE PATH "Qt4 qmake program.")
  78. set(QT4_INSTALLED TRUE)
  79. endif()
  80. if(QTVERSION MATCHES "Unknown")
  81. set(QT3_INSTALLED TRUE)
  82. endif()
  83. endif()
  84. if(QT_QMAKE_EXECUTABLE_FINDQT)
  85. exec_program( ${QT_QMAKE_EXECUTABLE_FINDQT}
  86. ARGS "-query QT_INSTALL_HEADERS"
  87. OUTPUT_VARIABLE qt_headers )
  88. endif()
  89. find_file( QT4_QGLOBAL_H_FILE qglobal.h
  90. "${QT_SEARCH_PATH}/Qt/include"
  91. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\4.0.0;InstallDir]/include/Qt"
  92. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Versions\\4.0.0;InstallDir]/include/Qt"
  93. ${qt_headers}/Qt
  94. $ENV{QTDIR}/include/Qt
  95. /usr/lib/qt/include/Qt
  96. /usr/share/qt4/include/Qt
  97. /usr/local/include/X11/qt4/Qt
  98. C:/Progra~1/qt/include/Qt
  99. PATH_SUFFIXES qt/include/Qt include/Qt)
  100. if(QT4_QGLOBAL_H_FILE)
  101. set(QT4_INSTALLED TRUE)
  102. endif()
  103. find_file( QT3_QGLOBAL_H_FILE qglobal.h
  104. "${QT_SEARCH_PATH}/Qt/include"
  105. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]/include/Qt"
  106. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]/include/Qt"
  107. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]/include/Qt"
  108. C:/Qt/3.3.3Educational/include
  109. $ENV{QTDIR}/include
  110. /usr/include/qt3/Qt
  111. /usr/share/qt3/include
  112. /usr/local/include/X11/qt3
  113. C:/Progra~1/qt/include
  114. PATH_SUFFIXES qt/include include/qt3)
  115. if(QT3_QGLOBAL_H_FILE)
  116. set(QT3_INSTALLED TRUE)
  117. endif()
  118. if(QT3_INSTALLED AND QT4_INSTALLED AND NOT DESIRED_QT_VERSION)
  119. # force user to pick if we have both
  120. set(DESIRED_QT_VERSION 0 CACHE STRING "Pick a version of Qt to use: 3 or 4")
  121. else()
  122. # if only one found then pick that one
  123. if(QT3_INSTALLED AND NOT DESIRED_QT_VERSION EQUAL 4)
  124. set(DESIRED_QT_VERSION 3 CACHE STRING "Pick a version of Qt to use: 3 or 4")
  125. endif()
  126. if(QT4_INSTALLED AND NOT DESIRED_QT_VERSION EQUAL 3)
  127. set(DESIRED_QT_VERSION 4 CACHE STRING "Pick a version of Qt to use: 3 or 4")
  128. endif()
  129. endif()
  130. if(DESIRED_QT_VERSION EQUAL 3)
  131. set(Qt3_FIND_REQUIRED ${Qt_FIND_REQUIRED})
  132. set(Qt3_FIND_QUIETLY ${Qt_FIND_QUIETLY})
  133. include(${CMAKE_CURRENT_LIST_DIR}/FindQt3.cmake)
  134. endif()
  135. if(DESIRED_QT_VERSION EQUAL 4)
  136. set(Qt4_FIND_REQUIRED ${Qt_FIND_REQUIRED})
  137. set(Qt4_FIND_QUIETLY ${Qt_FIND_QUIETLY})
  138. include(${CMAKE_CURRENT_LIST_DIR}/FindQt4.cmake)
  139. endif()
  140. if(NOT QT3_INSTALLED AND NOT QT4_INSTALLED)
  141. if(QT_REQUIRED)
  142. message(SEND_ERROR "CMake was unable to find any Qt versions, put qmake in your path, or set QT_QMAKE_EXECUTABLE.")
  143. endif()
  144. else()
  145. if(NOT QT_FOUND AND NOT DESIRED_QT_VERSION)
  146. if(QT_REQUIRED)
  147. message(SEND_ERROR "Multiple versions of Qt found please set DESIRED_QT_VERSION")
  148. else()
  149. message("Multiple versions of Qt found please set DESIRED_QT_VERSION")
  150. endif()
  151. endif()
  152. if(NOT QT_FOUND AND DESIRED_QT_VERSION)
  153. if(QT_REQUIRED)
  154. 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.")
  155. else()
  156. 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.")
  157. endif()
  158. endif()
  159. endif()
  160. mark_as_advanced(QT3_QGLOBAL_H_FILE QT4_QGLOBAL_H_FILE QT_QMAKE_EXECUTABLE_FINDQT)