FindQt.cmake 6.0 KB

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