Merge topic 'cpack-innosetup-linux'
[kiteware-cmake.git] / Modules / FindQt.cmake
blob604f8e3adb0f6e3b66eb11d77f2e07d390882d5c
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:
5 FindQt
6 ------
8 .. deprecated:: 3.14
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 #]=======================================================================]
40 if(_findqt_testing)
41   set(_findqt_included TRUE)
42   return()
43 endif()
45 # look for signs of qt3 installations
46 file(GLOB GLOB_TEMP_VAR /usr/lib*/qt-3*/bin/qmake /usr/lib*/qt3*/bin/qmake)
47 if(GLOB_TEMP_VAR)
48   set(QT3_INSTALLED TRUE)
49 endif()
50 set(GLOB_TEMP_VAR)
52 file(GLOB GLOB_TEMP_VAR /usr/local/qt-x11-commercial-3*/bin/qmake)
53 if(GLOB_TEMP_VAR)
54   set(QT3_INSTALLED TRUE)
55 endif()
56 set(GLOB_TEMP_VAR)
58 file(GLOB GLOB_TEMP_VAR /usr/local/lib/qt3/bin/qmake)
59 if(GLOB_TEMP_VAR)
60   set(QT3_INSTALLED TRUE)
61 endif()
62 set(GLOB_TEMP_VAR)
64 # look for qt4 installations
65 file(GLOB GLOB_TEMP_VAR /usr/local/qt-x11-commercial-4*/bin/qmake)
66 if(GLOB_TEMP_VAR)
67   set(QT4_INSTALLED TRUE)
68 endif()
69 set(GLOB_TEMP_VAR)
71 file(GLOB GLOB_TEMP_VAR /usr/local/Trolltech/Qt-4*/bin/qmake)
72 if(GLOB_TEMP_VAR)
73   set(QT4_INSTALLED TRUE)
74 endif()
75 set(GLOB_TEMP_VAR)
77 file(GLOB GLOB_TEMP_VAR /usr/local/lib/qt4/bin/qmake)
78 if(GLOB_TEMP_VAR)
79   set(QT4_INSTALLED TRUE)
80 endif()
81 set(GLOB_TEMP_VAR)
83 if (Qt_FIND_VERSION)
84   if (Qt_FIND_VERSION MATCHES "^([34])(\\.[0-9]+.*)?$")
85     set(DESIRED_QT_VERSION ${CMAKE_MATCH_1})
86   else ()
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.")
88   endif ()
89 endif ()
91 # now find qmake
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)
99   endif()
100   if(QTVERSION MATCHES "Unknown")
101     set(QT3_INSTALLED TRUE)
102   endif()
103 endif()
105 if(QT_QMAKE_EXECUTABLE_FINDQT)
106   execute_process(COMMAND ${QT_QMAKE_EXECUTABLE_FINDQT}
107     -query QT_INSTALL_HEADERS
108     OUTPUT_VARIABLE qt_headers )
109 endif()
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"
115   ${qt_headers}/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)
125 endif()
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
133   $ENV{QTDIR}/include
134   /usr/include/qt3/Qt
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)
142 endif()
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")
147 else()
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")
151   endif()
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")
154   endif()
155 endif()
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)
161 endif()
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)
166 endif()
168 if(NOT QT3_INSTALLED AND NOT QT4_INSTALLED)
169   if(QT_REQUIRED)
170     message(SEND_ERROR "CMake was unable to find any Qt versions, put qmake in your path, or set QT_QMAKE_EXECUTABLE.")
171   endif()
172 else()
173   if(NOT QT_FOUND AND NOT DESIRED_QT_VERSION)
174     if(QT_REQUIRED)
175       message(SEND_ERROR "Multiple versions of Qt found please set DESIRED_QT_VERSION")
176     else()
177       message("Multiple versions of Qt found please set DESIRED_QT_VERSION")
178     endif()
179   endif()
180   if(NOT QT_FOUND AND DESIRED_QT_VERSION)
181     if(QT_REQUIRED)
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.")
183     else()
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.")
185     endif()
186   endif()
187 endif()
188 mark_as_advanced(QT3_QGLOBAL_H_FILE QT4_QGLOBAL_H_FILE QT_QMAKE_EXECUTABLE_FINDQT)