Updates will be applied on October 27th between 12pm - 12:45pm EDT (UTC-0400). Gitlab may be slow during the maintenance window.

FindQt.cmake 6.59 KB
Newer Older
1
2
3
4
5
6
#.rst:
# FindQt
# ------
#
# Searches for all installed versions of Qt.
#
7
# This should only be used if your project can work with multiple
8
9
10
11
12
13
14
15
# versions of Qt.  If not, you should just directly use FindQt4 or
# FindQt3.  If multiple versions of Qt are found on the machine, then
# The user must set the option DESIRED_QT_VERSION to the version they
# want to use.  If only one version of qt is found on the machine, then
# the DESIRED_QT_VERSION is set to that version and the matching FindQt3
# or FindQt4 module is included.  Once the user sets DESIRED_QT_VERSION,
# then the FindQt3 or FindQt4 module is included.
#
16
17
18
# This module can only detect and switch between Qt versions 3 and 4. It
# cannot handle Qt5 or any later versions.
#
19
20
21
22
23
24
25
26
27
28
29
30
31
# ::
#
#   QT_REQUIRED if this is set to TRUE then if CMake can
#               not find Qt4 or Qt3 an error is raised
#               and a message is sent to the user.
#
#
#
# ::
#
#   DESIRED_QT_VERSION OPTION is created
#   QT4_INSTALLED is set to TRUE if qt4 is found.
#   QT3_INSTALLED is set to TRUE if qt3 is found.
32

33
34
35
36
37
38
39
40
41
42
#=============================================================================
# Copyright 2001-2009 Kitware, Inc.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
43
# (To distribute this file outside of CMake, substitute the full
44
#  License text for the above reference.)
45

46
# look for signs of qt3 installations
47
file(GLOB GLOB_TEMP_VAR /usr/lib*/qt-3*/bin/qmake /usr/lib*/qt3*/bin/qmake)
48
49
if(GLOB_TEMP_VAR)
  set(QT3_INSTALLED TRUE)
50
endif()
51
set(GLOB_TEMP_VAR)
52

53
54
55
file(GLOB GLOB_TEMP_VAR /usr/local/qt-x11-commercial-3*/bin/qmake)
if(GLOB_TEMP_VAR)
  set(QT3_INSTALLED TRUE)
56
endif()
57
set(GLOB_TEMP_VAR)
58

Amit Kulkarni's avatar
Amit Kulkarni committed
59
60
61
62
63
64
file(GLOB GLOB_TEMP_VAR /usr/local/lib/qt3/bin/qmake)
if(GLOB_TEMP_VAR)
  set(QT3_INSTALLED TRUE)
endif()
set(GLOB_TEMP_VAR)

65
# look for qt4 installations
66
67
68
file(GLOB GLOB_TEMP_VAR /usr/local/qt-x11-commercial-4*/bin/qmake)
if(GLOB_TEMP_VAR)
  set(QT4_INSTALLED TRUE)
69
endif()
70
set(GLOB_TEMP_VAR)
71

72
73
74
file(GLOB GLOB_TEMP_VAR /usr/local/Trolltech/Qt-4*/bin/qmake)
if(GLOB_TEMP_VAR)
  set(QT4_INSTALLED TRUE)
75
endif()
76
set(GLOB_TEMP_VAR)
77

Amit Kulkarni's avatar
Amit Kulkarni committed
78
79
80
81
82
83
file(GLOB GLOB_TEMP_VAR /usr/local/lib/qt4/bin/qmake)
if(GLOB_TEMP_VAR)
  set(QT4_INSTALLED TRUE)
endif()
set(GLOB_TEMP_VAR)

84
if (Qt_FIND_VERSION)
85
86
87
88
89
  if (Qt_FIND_VERSION MATCHES "^([34])(\\.[0-9]+.*)?$")
    set(DESIRED_QT_VERSION ${CMAKE_MATCH_1})
  else ()
    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.")
  endif ()
90
91
endif ()

92
# now find qmake
93
94
95
find_program(QT_QMAKE_EXECUTABLE_FINDQT NAMES qmake PATHS "${QT_SEARCH_PATH}/bin" "$ENV{QTDIR}/bin")
if(QT_QMAKE_EXECUTABLE_FINDQT)
  exec_program(${QT_QMAKE_EXECUTABLE_FINDQT} ARGS "-query QT_VERSION"
96
    OUTPUT_VARIABLE QTVERSION)
97
  if(QTVERSION MATCHES "4")
98
    set(QT_QMAKE_EXECUTABLE ${QT_QMAKE_EXECUTABLE_FINDQT} CACHE PATH "Qt4 qmake program.")
99
    set(QT4_INSTALLED TRUE)
100
  endif()
101
102
  if(QTVERSION MATCHES "Unknown")
    set(QT3_INSTALLED TRUE)
103
104
  endif()
endif()
105

106
107
if(QT_QMAKE_EXECUTABLE_FINDQT)
  exec_program( ${QT_QMAKE_EXECUTABLE_FINDQT}
108
    ARGS "-query QT_INSTALL_HEADERS"
109
    OUTPUT_VARIABLE qt_headers )
110
endif()
111

112
find_file( QT4_QGLOBAL_H_FILE qglobal.h
113
114
  "${QT_SEARCH_PATH}/Qt/include"
  "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\4.0.0;InstallDir]/include/Qt"
115
  "[HKEY_CURRENT_USER\\Software\\Trolltech\\Versions\\4.0.0;InstallDir]/include/Qt"
116
117
118
119
120
121
122
  ${qt_headers}/Qt
  $ENV{QTDIR}/include/Qt
  /usr/local/qt/include/Qt
  /usr/local/include/Qt
  /usr/lib/qt/include/Qt
  /usr/include/Qt
  /usr/share/qt4/include/Qt
Amit Kulkarni's avatar
Amit Kulkarni committed
123
  /usr/local/include/X11/qt4/Qt
124
  C:/Progra~1/qt/include/Qt )
125

126
127
if(QT4_QGLOBAL_H_FILE)
  set(QT4_INSTALLED TRUE)
128
endif()
129

130
find_file( QT3_QGLOBAL_H_FILE qglobal.h
131
  "${QT_SEARCH_PATH}/Qt/include"
132
133
134
 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]/include/Qt"
  "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]/include/Qt"
  "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]/include/Qt"
135
136
137
138
139
140
141
142
  C:/Qt/3.3.3Educational/include
  $ENV{QTDIR}/include
  /usr/include/qt3/Qt
  /usr/local/qt/include
  /usr/local/include
  /usr/lib/qt/include
  /usr/include
  /usr/share/qt3/include
Amit Kulkarni's avatar
Amit Kulkarni committed
143
  /usr/local/include/X11/qt3
144
145
146
  C:/Progra~1/qt/include
  /usr/include/qt3 )

147
148
if(QT3_QGLOBAL_H_FILE)
  set(QT3_INSTALLED TRUE)
149
endif()
150

151
if(QT3_INSTALLED AND QT4_INSTALLED AND NOT DESIRED_QT_VERSION)
152
  # force user to pick if we have both
153
  set(DESIRED_QT_VERSION 0 CACHE STRING "Pick a version of Qt to use: 3 or 4")
154
else()
155
  # if only one found then pick that one
156
  if(QT3_INSTALLED AND NOT DESIRED_QT_VERSION EQUAL 4)
157
    set(DESIRED_QT_VERSION 3 CACHE STRING "Pick a version of Qt to use: 3 or 4")
158
  endif()
159
  if(QT4_INSTALLED AND NOT DESIRED_QT_VERSION EQUAL 3)
160
    set(DESIRED_QT_VERSION 4 CACHE STRING "Pick a version of Qt to use: 3 or 4")
161
162
  endif()
endif()
163

164
if(DESIRED_QT_VERSION EQUAL 3)
165
166
  set(Qt3_FIND_REQUIRED ${Qt_FIND_REQUIRED})
  set(Qt3_FIND_QUIETLY  ${Qt_FIND_QUIETLY})
167
  include(${CMAKE_CURRENT_LIST_DIR}/FindQt3.cmake)
168
endif()
169
if(DESIRED_QT_VERSION EQUAL 4)
170
171
  set(Qt4_FIND_REQUIRED ${Qt_FIND_REQUIRED})
  set(Qt4_FIND_QUIETLY  ${Qt_FIND_QUIETLY})
172
  include(${CMAKE_CURRENT_LIST_DIR}/FindQt4.cmake)
173
endif()
174

175
176
if(NOT QT3_INSTALLED AND NOT QT4_INSTALLED)
  if(QT_REQUIRED)
177
    message(SEND_ERROR "CMake was unable to find any Qt versions, put qmake in your path, or set QT_QMAKE_EXECUTABLE.")
178
179
  endif()
else()
180
181
  if(NOT QT_FOUND AND NOT DESIRED_QT_VERSION)
    if(QT_REQUIRED)
182
      message(SEND_ERROR "Multiple versions of Qt found please set DESIRED_QT_VERSION")
183
    else()
184
      message("Multiple versions of Qt found please set DESIRED_QT_VERSION")
185
186
    endif()
  endif()
187
188
  if(NOT QT_FOUND AND DESIRED_QT_VERSION)
    if(QT_REQUIRED)
189
      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.")
190
    else()
191
      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.")
192
193
194
    endif()
  endif()
endif()
195
mark_as_advanced(QT3_QGLOBAL_H_FILE QT4_QGLOBAL_H_FILE QT_QMAKE_EXECUTABLE_FINDQT)