FindQt.cmake 6.1 KB

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