FindQt.cmake 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #.rst:
  2. # FindQt
  3. # ------
  4. #
  5. # Searches for all installed versions of Qt.
  6. #
  7. # This should only be used if your project can work with multiple
  8. # versions of Qt. If not, you should just directly use FindQt4 or
  9. # FindQt3. If multiple versions of Qt are found on the machine, then
  10. # The user must set the option DESIRED_QT_VERSION to the version they
  11. # want to use. If only one version of qt is found on the machine, then
  12. # the DESIRED_QT_VERSION is set to that version and the matching FindQt3
  13. # or FindQt4 module is included. Once the user sets DESIRED_QT_VERSION,
  14. # then the FindQt3 or FindQt4 module is included.
  15. #
  16. # This module can only detect and switch between Qt versions 3 and 4. It
  17. # cannot handle Qt5 or any later versions.
  18. #
  19. # ::
  20. #
  21. # QT_REQUIRED if this is set to TRUE then if CMake can
  22. # not find Qt4 or Qt3 an error is raised
  23. # and a message is sent to the user.
  24. #
  25. #
  26. #
  27. # ::
  28. #
  29. # DESIRED_QT_VERSION OPTION is created
  30. # QT4_INSTALLED is set to TRUE if qt4 is found.
  31. # QT3_INSTALLED is set to TRUE if qt3 is found.
  32. #=============================================================================
  33. # Copyright 2001-2009 Kitware, Inc.
  34. #
  35. # Distributed under the OSI-approved BSD License (the "License");
  36. # see accompanying file Copyright.txt for details.
  37. #
  38. # This software is distributed WITHOUT ANY WARRANTY; without even the
  39. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  40. # See the License for more information.
  41. #=============================================================================
  42. # (To distribute this file outside of CMake, substitute the full
  43. # License text for the above reference.)
  44. # look for signs of qt3 installations
  45. file(GLOB GLOB_TEMP_VAR /usr/lib*/qt-3*/bin/qmake /usr/lib*/qt3*/bin/qmake)
  46. if(GLOB_TEMP_VAR)
  47. set(QT3_INSTALLED TRUE)
  48. endif()
  49. set(GLOB_TEMP_VAR)
  50. file(GLOB GLOB_TEMP_VAR /usr/local/qt-x11-commercial-3*/bin/qmake)
  51. if(GLOB_TEMP_VAR)
  52. set(QT3_INSTALLED TRUE)
  53. endif()
  54. set(GLOB_TEMP_VAR)
  55. file(GLOB GLOB_TEMP_VAR /usr/local/lib/qt3/bin/qmake)
  56. if(GLOB_TEMP_VAR)
  57. set(QT3_INSTALLED TRUE)
  58. endif()
  59. set(GLOB_TEMP_VAR)
  60. # look for qt4 installations
  61. file(GLOB GLOB_TEMP_VAR /usr/local/qt-x11-commercial-4*/bin/qmake)
  62. if(GLOB_TEMP_VAR)
  63. set(QT4_INSTALLED TRUE)
  64. endif()
  65. set(GLOB_TEMP_VAR)
  66. file(GLOB GLOB_TEMP_VAR /usr/local/Trolltech/Qt-4*/bin/qmake)
  67. if(GLOB_TEMP_VAR)
  68. set(QT4_INSTALLED TRUE)
  69. endif()
  70. set(GLOB_TEMP_VAR)
  71. file(GLOB GLOB_TEMP_VAR /usr/local/lib/qt4/bin/qmake)
  72. if(GLOB_TEMP_VAR)
  73. set(QT4_INSTALLED TRUE)
  74. endif()
  75. set(GLOB_TEMP_VAR)
  76. if (Qt_FIND_VERSION)
  77. if (Qt_FIND_VERSION MATCHES "^([34])(\\.[0-9]+.*)?$")
  78. set(DESIRED_QT_VERSION ${CMAKE_MATCH_1})
  79. else ()
  80. 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.")
  81. endif ()
  82. endif ()
  83. # now find qmake
  84. find_program(QT_QMAKE_EXECUTABLE_FINDQT NAMES qmake PATHS "${QT_SEARCH_PATH}/bin" "$ENV{QTDIR}/bin")
  85. if(QT_QMAKE_EXECUTABLE_FINDQT)
  86. exec_program(${QT_QMAKE_EXECUTABLE_FINDQT} ARGS "-query QT_VERSION"
  87. OUTPUT_VARIABLE QTVERSION)
  88. if(QTVERSION MATCHES "4")
  89. set(QT_QMAKE_EXECUTABLE ${QT_QMAKE_EXECUTABLE_FINDQT} CACHE PATH "Qt4 qmake program.")
  90. set(QT4_INSTALLED TRUE)
  91. endif()
  92. if(QTVERSION MATCHES "Unknown")
  93. set(QT3_INSTALLED TRUE)
  94. endif()
  95. endif()
  96. if(QT_QMAKE_EXECUTABLE_FINDQT)
  97. exec_program( ${QT_QMAKE_EXECUTABLE_FINDQT}
  98. ARGS "-query QT_INSTALL_HEADERS"
  99. OUTPUT_VARIABLE qt_headers )
  100. endif()
  101. find_file( QT4_QGLOBAL_H_FILE qglobal.h
  102. "${QT_SEARCH_PATH}/Qt/include"
  103. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\4.0.0;InstallDir]/include/Qt"
  104. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Versions\\4.0.0;InstallDir]/include/Qt"
  105. ${qt_headers}/Qt
  106. $ENV{QTDIR}/include/Qt
  107. /usr/local/qt/include/Qt
  108. /usr/local/include/Qt
  109. /usr/lib/qt/include/Qt
  110. /usr/include/Qt
  111. /usr/share/qt4/include/Qt
  112. /usr/local/include/X11/qt4/Qt
  113. C:/Progra~1/qt/include/Qt )
  114. if(QT4_QGLOBAL_H_FILE)
  115. set(QT4_INSTALLED TRUE)
  116. endif()
  117. find_file( QT3_QGLOBAL_H_FILE qglobal.h
  118. "${QT_SEARCH_PATH}/Qt/include"
  119. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]/include/Qt"
  120. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]/include/Qt"
  121. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]/include/Qt"
  122. C:/Qt/3.3.3Educational/include
  123. $ENV{QTDIR}/include
  124. /usr/include/qt3/Qt
  125. /usr/local/qt/include
  126. /usr/local/include
  127. /usr/lib/qt/include
  128. /usr/include
  129. /usr/share/qt3/include
  130. /usr/local/include/X11/qt3
  131. C:/Progra~1/qt/include
  132. /usr/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)