1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
4 #[=======================================================================[.rst:
9 This module is available only if policy :policy:`CMP0084` is not set to ``NEW``.
11 Searches for all installed versions of Qt3 or Qt4.
13 This module cannot handle Qt5 or any later versions.
14 For those, see :manual:`cmake-qt(7)`.
16 This module should only be used if your project can work with multiple
17 versions of Qt. If not, you should just directly use FindQt4 or
18 FindQt3. If multiple versions of Qt are found on the machine, then
19 The user must set the option DESIRED_QT_VERSION to the version they
20 want to use. If only one version of qt is found on the machine, then
21 the DESIRED_QT_VERSION is set to that version and the matching FindQt3
22 or FindQt4 module is included. Once the user sets DESIRED_QT_VERSION,
23 then the FindQt3 or FindQt4 module is included.
27 QT_REQUIRED if this is set to TRUE then if CMake can
28 not find Qt4 or Qt3 an error is raised
29 and a message is sent to the user.
35 DESIRED_QT_VERSION OPTION is created
36 QT4_INSTALLED is set to TRUE if qt4 is found.
37 QT3_INSTALLED is set to TRUE if qt3 is found.
38 #]=======================================================================]
41 set(_findqt_included TRUE)
45 # look for signs of qt3 installations
46 file(GLOB GLOB_TEMP_VAR /usr/lib*/qt-3*/bin/qmake /usr/lib*/qt3*/bin/qmake)
48 set(QT3_INSTALLED TRUE)
52 file(GLOB GLOB_TEMP_VAR /usr/local/qt-x11-commercial-3*/bin/qmake)
54 set(QT3_INSTALLED TRUE)
58 file(GLOB GLOB_TEMP_VAR /usr/local/lib/qt3/bin/qmake)
60 set(QT3_INSTALLED TRUE)
64 # look for qt4 installations
65 file(GLOB GLOB_TEMP_VAR /usr/local/qt-x11-commercial-4*/bin/qmake)
67 set(QT4_INSTALLED TRUE)
71 file(GLOB GLOB_TEMP_VAR /usr/local/Trolltech/Qt-4*/bin/qmake)
73 set(QT4_INSTALLED TRUE)
77 file(GLOB GLOB_TEMP_VAR /usr/local/lib/qt4/bin/qmake)
79 set(QT4_INSTALLED TRUE)
84 if (Qt_FIND_VERSION MATCHES "^([34])(\\.[0-9]+.*)?$")
85 set(DESIRED_QT_VERSION ${CMAKE_MATCH_1})
87 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.")
92 find_program(QT_QMAKE_EXECUTABLE_FINDQT NAMES qmake PATHS "${QT_SEARCH_PATH}/bin" "$ENV{QTDIR}/bin")
93 if(QT_QMAKE_EXECUTABLE_FINDQT)
94 execute_process(COMMAND ${QT_QMAKE_EXECUTABLE_FINDQT} -query QT_VERSION
95 OUTPUT_VARIABLE QTVERSION)
96 if(QTVERSION MATCHES "4")
97 set(QT_QMAKE_EXECUTABLE ${QT_QMAKE_EXECUTABLE_FINDQT} CACHE PATH "Qt4 qmake program.")
98 set(QT4_INSTALLED TRUE)
100 if(QTVERSION MATCHES "Unknown")
101 set(QT3_INSTALLED TRUE)
105 if(QT_QMAKE_EXECUTABLE_FINDQT)
106 execute_process(COMMAND ${QT_QMAKE_EXECUTABLE_FINDQT}
107 -query QT_INSTALL_HEADERS
108 OUTPUT_VARIABLE qt_headers )
111 find_file( QT4_QGLOBAL_H_FILE qglobal.h
112 "${QT_SEARCH_PATH}/Qt/include"
113 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\4.0.0;InstallDir]/include/Qt"
114 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Versions\\4.0.0;InstallDir]/include/Qt"
116 $ENV{QTDIR}/include/Qt
117 /usr/lib/qt/include/Qt
118 /usr/share/qt4/include/Qt
119 /usr/local/include/X11/qt4/Qt
120 C:/Progra~1/qt/include/Qt
121 PATH_SUFFIXES qt/include/Qt include/Qt)
123 if(QT4_QGLOBAL_H_FILE)
124 set(QT4_INSTALLED TRUE)
127 find_file( QT3_QGLOBAL_H_FILE qglobal.h
128 "${QT_SEARCH_PATH}/Qt/include"
129 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]/include/Qt"
130 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]/include/Qt"
131 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]/include/Qt"
132 C:/Qt/3.3.3Educational/include
135 /usr/share/qt3/include
136 /usr/local/include/X11/qt3
137 C:/Progra~1/qt/include
138 PATH_SUFFIXES qt/include include/qt3)
140 if(QT3_QGLOBAL_H_FILE)
141 set(QT3_INSTALLED TRUE)
144 if(QT3_INSTALLED AND QT4_INSTALLED AND NOT DESIRED_QT_VERSION)
145 # force user to pick if we have both
146 set(DESIRED_QT_VERSION 0 CACHE STRING "Pick a version of Qt to use: 3 or 4")
148 # if only one found then pick that one
149 if(QT3_INSTALLED AND NOT DESIRED_QT_VERSION EQUAL 4)
150 set(DESIRED_QT_VERSION 3 CACHE STRING "Pick a version of Qt to use: 3 or 4")
152 if(QT4_INSTALLED AND NOT DESIRED_QT_VERSION EQUAL 3)
153 set(DESIRED_QT_VERSION 4 CACHE STRING "Pick a version of Qt to use: 3 or 4")
157 if(DESIRED_QT_VERSION EQUAL 3)
158 set(Qt3_FIND_REQUIRED ${Qt_FIND_REQUIRED})
159 set(Qt3_FIND_QUIETLY ${Qt_FIND_QUIETLY})
160 include(${CMAKE_CURRENT_LIST_DIR}/FindQt3.cmake)
162 if(DESIRED_QT_VERSION EQUAL 4)
163 set(Qt4_FIND_REQUIRED ${Qt_FIND_REQUIRED})
164 set(Qt4_FIND_QUIETLY ${Qt_FIND_QUIETLY})
165 include(${CMAKE_CURRENT_LIST_DIR}/FindQt4.cmake)
168 if(NOT QT3_INSTALLED AND NOT QT4_INSTALLED)
170 message(SEND_ERROR "CMake was unable to find any Qt versions, put qmake in your path, or set QT_QMAKE_EXECUTABLE.")
173 if(NOT QT_FOUND AND NOT DESIRED_QT_VERSION)
175 message(SEND_ERROR "Multiple versions of Qt found please set DESIRED_QT_VERSION")
177 message("Multiple versions of Qt found please set DESIRED_QT_VERSION")
180 if(NOT QT_FOUND AND DESIRED_QT_VERSION)
182 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.")
184 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.")
188 mark_as_advanced(QT3_QGLOBAL_H_FILE QT4_QGLOBAL_H_FILE QT_QMAKE_EXECUTABLE_FINDQT)