Imported Upstream version 2.8.11.2
[platform/upstream/cmake.git] / Modules / FindQt.cmake
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 #=============================================================================
21 # Copyright 2001-2009 Kitware, Inc.
22 #
23 # Distributed under the OSI-approved BSD License (the "License");
24 # see accompanying file Copyright.txt for details.
25 #
26 # This software is distributed WITHOUT ANY WARRANTY; without even the
27 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
28 # See the License for more information.
29 #=============================================================================
30 # (To distribute this file outside of CMake, substitute the full
31 #  License text for the above reference.)
32
33 # look for signs of qt3 installations
34 file(GLOB GLOB_TEMP_VAR /usr/lib*/qt-3*/bin/qmake /usr/lib*/qt3*/bin/qmake)
35 if(GLOB_TEMP_VAR)
36   set(QT3_INSTALLED TRUE)
37 endif()
38 set(GLOB_TEMP_VAR)
39
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
46 file(GLOB GLOB_TEMP_VAR /usr/local/lib/qt3/bin/qmake)
47 if(GLOB_TEMP_VAR)
48   set(QT3_INSTALLED TRUE)
49 endif()
50 set(GLOB_TEMP_VAR)
51
52 # look for qt4 installations
53 file(GLOB GLOB_TEMP_VAR /usr/local/qt-x11-commercial-4*/bin/qmake)
54 if(GLOB_TEMP_VAR)
55   set(QT4_INSTALLED TRUE)
56 endif()
57 set(GLOB_TEMP_VAR)
58
59 file(GLOB GLOB_TEMP_VAR /usr/local/Trolltech/Qt-4*/bin/qmake)
60 if(GLOB_TEMP_VAR)
61   set(QT4_INSTALLED TRUE)
62 endif()
63 set(GLOB_TEMP_VAR)
64
65 file(GLOB GLOB_TEMP_VAR /usr/local/lib/qt4/bin/qmake)
66 if(GLOB_TEMP_VAR)
67   set(QT4_INSTALLED TRUE)
68 endif()
69 set(GLOB_TEMP_VAR)
70
71 if (Qt_FIND_VERSION)
72   set(DESIRED_QT_VERSION "${Qt_FIND_VERSION}")
73 endif ()
74
75 # now find qmake
76 find_program(QT_QMAKE_EXECUTABLE_FINDQT NAMES qmake PATHS "${QT_SEARCH_PATH}/bin" "$ENV{QTDIR}/bin")
77 if(QT_QMAKE_EXECUTABLE_FINDQT)
78   exec_program(${QT_QMAKE_EXECUTABLE_FINDQT} ARGS "-query QT_VERSION"
79     OUTPUT_VARIABLE QTVERSION)
80   if(QTVERSION MATCHES "4.*")
81     set(QT_QMAKE_EXECUTABLE ${QT_QMAKE_EXECUTABLE_FINDQT} CACHE PATH "Qt4 qmake program.")
82     set(QT4_INSTALLED TRUE)
83   endif()
84   if(QTVERSION MATCHES "Unknown")
85     set(QT3_INSTALLED TRUE)
86   endif()
87 endif()
88
89 if(QT_QMAKE_EXECUTABLE_FINDQT)
90   exec_program( ${QT_QMAKE_EXECUTABLE_FINDQT}
91     ARGS "-query QT_INSTALL_HEADERS"
92     OUTPUT_VARIABLE qt_headers )
93 endif()
94
95 find_file( QT4_QGLOBAL_H_FILE qglobal.h
96   "${QT_SEARCH_PATH}/Qt/include"
97   "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\4.0.0;InstallDir]/include/Qt"
98   "[HKEY_CURRENT_USER\\Software\\Trolltech\\Versions\\4.0.0;InstallDir]/include/Qt"
99   ${qt_headers}/Qt
100   $ENV{QTDIR}/include/Qt
101   /usr/local/qt/include/Qt
102   /usr/local/include/Qt
103   /usr/lib/qt/include/Qt
104   /usr/include/Qt
105   /usr/share/qt4/include/Qt
106   /usr/local/include/X11/qt4/Qt
107   C:/Progra~1/qt/include/Qt )
108
109 if(QT4_QGLOBAL_H_FILE)
110   set(QT4_INSTALLED TRUE)
111 endif()
112
113 find_file( QT3_QGLOBAL_H_FILE qglobal.h
114   "${QT_SEARCH_PATH}/Qt/include"
115  "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]/include/Qt"
116   "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]/include/Qt"
117   "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]/include/Qt"
118   C:/Qt/3.3.3Educational/include
119   $ENV{QTDIR}/include
120   /usr/include/qt3/Qt
121   /usr/local/qt/include
122   /usr/local/include
123   /usr/lib/qt/include
124   /usr/include
125   /usr/share/qt3/include
126   /usr/local/include/X11/qt3
127   C:/Progra~1/qt/include
128   /usr/include/qt3 )
129
130 if(QT3_QGLOBAL_H_FILE)
131   set(QT3_INSTALLED TRUE)
132 endif()
133
134 if(QT3_INSTALLED AND QT4_INSTALLED AND NOT DESIRED_QT_VERSION)
135   # force user to pick if we have both
136   set(DESIRED_QT_VERSION 0 CACHE STRING "Pick a version of Qt to use: 3 or 4")
137 else()
138   # if only one found then pick that one
139   if(QT3_INSTALLED AND NOT DESIRED_QT_VERSION EQUAL 4)
140     set(DESIRED_QT_VERSION 3 CACHE STRING "Pick a version of Qt to use: 3 or 4")
141   endif()
142   if(QT4_INSTALLED AND NOT DESIRED_QT_VERSION EQUAL 3)
143     set(DESIRED_QT_VERSION 4 CACHE STRING "Pick a version of Qt to use: 3 or 4")
144   endif()
145 endif()
146
147 if(DESIRED_QT_VERSION MATCHES 3)
148   set(Qt3_FIND_REQUIRED ${Qt_FIND_REQUIRED})
149   set(Qt3_FIND_QUIETLY  ${Qt_FIND_QUIETLY})
150   include(${CMAKE_CURRENT_LIST_DIR}/FindQt3.cmake)
151 endif()
152 if(DESIRED_QT_VERSION MATCHES 4)
153   set(Qt4_FIND_REQUIRED ${Qt_FIND_REQUIRED})
154   set(Qt4_FIND_QUIETLY  ${Qt_FIND_QUIETLY})
155   include(${CMAKE_CURRENT_LIST_DIR}/FindQt4.cmake)
156 endif()
157
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_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_FILE.")
175     endif()
176   endif()
177 endif()
178 mark_as_advanced(QT3_QGLOBAL_H_FILE QT4_QGLOBAL_H_FILE QT_QMAKE_EXECUTABLE_FINDQT)