FindQt3.cmake 9.1 KB
Newer Older
1 2 3
# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.

4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#[=======================================================================[.rst:
FindQt3
-------

Locate Qt include paths and libraries

This module defines:

::

  QT_INCLUDE_DIR    - where to find qt.h, etc.
  QT_LIBRARIES      - the libraries to link against to use Qt.
  QT_DEFINITIONS    - definitions to use when
                      compiling code that uses Qt.
  QT_FOUND          - If false, don't try to use Qt.
  QT_VERSION_STRING - the version of Qt found



If you need the multithreaded version of Qt, set QT_MT_REQUIRED to
TRUE

Also defined, but not for general use are:

::

  QT_MOC_EXECUTABLE, where to find the moc tool.
  QT_UIC_EXECUTABLE, where to find the uic tool.
  QT_QT_LIBRARY, where to find the Qt library.
  QT_QTMAIN_LIBRARY, where to find the qtmain
   library. This is only required by Qt3 on Windows.
#]=======================================================================]
36

37
# These are around for backwards compatibility
38
# they will be set
39 40
#  QT_WRAP_CPP, set true if QT_MOC_EXECUTABLE is found
#  QT_WRAP_UI set true if QT_UIC_EXECUTABLE is found
41

42
# If Qt4 has already been found, fail.
43 44 45
if(QT4_FOUND)
  if(Qt3_FIND_REQUIRED)
    message( FATAL_ERROR "Qt3 and Qt4 cannot be used together in one project.")
46
  else()
47 48
    if(NOT Qt3_FIND_QUIETLY)
      message( STATUS    "Qt3 and Qt4 cannot be used together in one project.")
49
    endif()
50
    return()
51 52
  endif()
endif()
53 54


55 56 57
file(GLOB GLOB_PATHS /usr/lib/qt-3*)
foreach(GLOB_PATH ${GLOB_PATHS})
  list(APPEND GLOB_PATHS_BIN "${GLOB_PATH}/bin")
58
endforeach()
59
find_path(QT_INCLUDE_DIR qt.h
60 61 62
  "[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"
63
  $ENV{QTDIR}/include
64
  ${GLOB_PATHS}
65 66
  /usr/share/qt3/include
  C:/Progra~1/qt/include
67
  /usr/local/include/X11/qt3
68
  PATH_SUFFIXES lib/qt/include lib/qt3/include include/qt include/qt3 qt/include qt3/include
69 70
  )

71 72
# if qglobal.h is not in the qt_include_dir then set
# QT_INCLUDE_DIR to NOTFOUND
73 74
if(NOT EXISTS ${QT_INCLUDE_DIR}/qglobal.h)
  set(QT_INCLUDE_DIR QT_INCLUDE_DIR-NOTFOUND CACHE PATH "path to Qt3 include directory" FORCE)
75
endif()
76

77
if(QT_INCLUDE_DIR)
78
  #extract the version string from qglobal.h
79
  file(STRINGS ${QT_INCLUDE_DIR}/qglobal.h QGLOBAL_H REGEX "#define[\t ]+QT_VERSION_STR[\t ]+\"[0-9]+.[0-9]+.[0-9]+[a-z]*\"")
80
  string(REGEX REPLACE ".*\"([0-9]+.[0-9]+.[0-9]+[a-z]*)\".*" "\\1" qt_version_str "${QGLOBAL_H}")
81
  unset(QGLOBAL_H)
82 83 84

  # Under windows the qt library (MSVC) has the format qt-mtXYZ where XYZ is the
  # version X.Y.Z, so we need to remove the dots from version
85 86
  string(REGEX REPLACE "\\." "" qt_version_str_lib "${qt_version_str}")
  set(QT_VERSION_STRING "${qt_version_str}")
87
endif()
88

89 90 91
file(GLOB GLOB_PATHS_LIB /usr/lib/qt-3*/lib/)
if (QT_MT_REQUIRED)
  find_library(QT_QT_LIBRARY
92 93
    NAMES
    qt-mt qt-mt${qt_version_str_lib} qt-mtnc${qt_version_str_lib}
94
    qt-mtedu${qt_version_str_lib} qt-mt230nc qt-mtnc321 qt-mt3
95
    PATHS
96 97 98 99 100 101 102 103
      "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]"
      "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]"
      "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]"
      ENV QTDIR
      ${GLOB_PATHS_LIB}
      /usr/share/qt3
      C:/Progra~1/qt
    PATH_SUFFIXES
104
      lib lib/qt lib/qt3 qt qt3 qt/lib qt3/lib
105 106
    )

107
else ()
108
  find_library(QT_QT_LIBRARY
109 110
    NAMES
    qt qt-${qt_version_str_lib} qt-edu${qt_version_str_lib}
111
    qt-mt qt-mt${qt_version_str_lib} qt-mtnc${qt_version_str_lib}
112
    qt-mtedu${qt_version_str_lib} qt-mt230nc qt-mtnc321 qt-mt3
113
    PATHS
114 115 116 117 118 119 120 121
      "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]"
      "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]"
      "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]"
      ENV QTDIR
      ${GLOB_PATHS_LIB}
      /usr/share/qt3
      C:/Progra~1/qt/lib
    PATH_SUFFIXES
122
      lib lib/qt lib/qt3 qt qt3 qt/lib qt3/lib
123
    )
124
endif ()
125 126


127
find_library(QT_QASSISTANTCLIENT_LIBRARY
128 129
  NAMES qassistantclient
  PATHS
130 131 132 133 134 135 136 137
    "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]"
    "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]"
    "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]"
    ENV QTDIR
    ${GLOB_PATHS_LIB}
    /usr/share/qt3
    C:/Progra~1/qt
  PATH_SUFFIXES
138
    lib lib/qt lib/qt3 qt qt3 qt/lib qt3/lib
139 140
  )

141
# Qt 3 should prefer QTDIR over the PATH
142
find_program(QT_MOC_EXECUTABLE
143
  NAMES moc-qt3 moc3 moc3-mt moc
144
  HINTS
145
    ENV QTDIR
146
  PATHS
Bill Hoffman's avatar
Bill Hoffman committed
147 148 149 150
  "[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"
  ${GLOB_PATHS_BIN}
151 152 153
    /usr/share/qt3
    C:/Progra~1/qt
  PATH_SUFFIXES
154
    bin lib/qt lib/qt3 qt qt3 qt/bin qt3/bin lib/qt/bin lib/qt3/bin
155 156
  )

157 158
if(QT_MOC_EXECUTABLE)
  set ( QT_WRAP_CPP "YES")
159
endif()
160

161
# Qt 3 should prefer QTDIR over the PATH
162
find_program(QT_UIC_EXECUTABLE
163
  NAMES uic-qt3 uic3 uic3-mt uic
164
  HINTS
165
    ENV QTDIR
166
  PATHS
Bill Hoffman's avatar
Bill Hoffman committed
167 168 169 170
  "[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"
  ${GLOB_PATHS_BIN}
171 172 173
    /usr/share/qt3
    C:/Progra~1/qt
  PATH_SUFFIXES
174
    bin lib/qt lib/qt3 qt qt3 qt/bin qt3/bin lib/qt/bin lib/qt3/bin
175 176
  )

177 178
if(QT_UIC_EXECUTABLE)
  set ( QT_WRAP_UI "YES")
179
endif()
180

181 182
if (WIN32)
  find_library(QT_QTMAIN_LIBRARY qtmain
183
    HINTS
184 185 186 187
      ENV QTDIR
      "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]"
      "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]"
      "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]"
188
    PATHS
189 190
      "$ENV{ProgramFiles}/qt"
      "C:/Program Files/qt"
191 192
    PATH_SUFFIXES
      lib
193 194
    DOC "This Library is only needed by and included with Qt3 on MSWindows. It should be NOTFOUND, undefined or IGNORE otherwise."
    )
195
endif ()
196

197
#support old QT_MIN_VERSION if set, but not if version is supplied by find_package()
198 199
if(NOT Qt3_FIND_VERSION AND QT_MIN_VERSION)
  set(Qt3_FIND_VERSION ${QT_MIN_VERSION})
200
endif()
201 202

# if the include a library are found then we have it
203
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
204 205 206
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Qt3
                                  REQUIRED_VARS QT_QT_LIBRARY QT_INCLUDE_DIR QT_MOC_EXECUTABLE
                                  VERSION_VAR QT_VERSION_STRING)
207
set(QT_FOUND ${QT3_FOUND} )
208

209 210 211
if(QT_FOUND)
  set( QT_LIBRARIES ${QT_LIBRARIES} ${QT_QT_LIBRARY} )
  set( QT_DEFINITIONS "")
212

213 214
  if (WIN32 AND NOT CYGWIN)
    if (QT_QTMAIN_LIBRARY)
215
      # for version 3
216 217 218
      set (QT_DEFINITIONS -DQT_DLL -DQT_THREAD_SUPPORT -DNO_DEBUG)
      set (QT_LIBRARIES imm32.lib ${QT_QT_LIBRARY} ${QT_QTMAIN_LIBRARY} )
      set (QT_LIBRARIES ${QT_LIBRARIES} winmm wsock32)
219
    else ()
220
      # for version 2
221
      set (QT_LIBRARIES imm32.lib ws2_32.lib ${QT_QT_LIBRARY} )
222 223
    endif ()
  else ()
224
    set (QT_LIBRARIES ${QT_QT_LIBRARY} )
225

226 227 228
    set (QT_DEFINITIONS -DQT_SHARED -DQT_NO_DEBUG)
    if(QT_QT_LIBRARY MATCHES "qt-mt")
      set (QT_DEFINITIONS ${QT_DEFINITIONS} -DQT_THREAD_SUPPORT -D_REENTRANT)
229
    endif()
230

231
  endif ()
232

233 234
  if (QT_QASSISTANTCLIENT_LIBRARY)
    set (QT_LIBRARIES ${QT_QASSISTANTCLIENT_LIBRARY} ${QT_LIBRARIES})
235
  endif ()
236

237
  # Backwards compatibility for CMake1.4 and 1.2
238 239
  set (QT_MOC_EXE ${QT_MOC_EXECUTABLE} )
  set (QT_UIC_EXE ${QT_UIC_EXECUTABLE} )
240
  # for unix add X11 stuff
241 242 243 244
  if(UNIX)
    find_package(X11)
    if (X11_FOUND)
      set (QT_LIBRARIES ${QT_LIBRARIES} ${X11_LIBRARIES})
245
    endif ()
246 247
    if (CMAKE_DL_LIBS)
      set (QT_LIBRARIES ${QT_LIBRARIES} ${CMAKE_DL_LIBS})
248 249
    endif ()
  endif()
250 251 252
  if(QT_QT_LIBRARY MATCHES "qt-mt")
    find_package(Threads)
    set(QT_LIBRARIES ${QT_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
253 254
  endif()
endif()
255

256 257
if(QT_MOC_EXECUTABLE)
  execute_process(COMMAND ${QT_MOC_EXECUTABLE} "-v"
258 259
                  OUTPUT_VARIABLE QTVERSION_MOC
                  ERROR_QUIET)
260
endif()
261 262
if(QT_UIC_EXECUTABLE)
  execute_process(COMMAND ${QT_UIC_EXECUTABLE} "-version"
263 264
                  OUTPUT_VARIABLE QTVERSION_UIC
                  ERROR_QUIET)
265
endif()
266

267
set(_QT_UIC_VERSION_3 FALSE)
268
if("${QTVERSION_UIC}" MATCHES " 3.")
269
  set(_QT_UIC_VERSION_3 TRUE)
270
endif()
271

272
set(_QT_MOC_VERSION_3 FALSE)
273
if("${QTVERSION_MOC}" MATCHES " 3.")
274
  set(_QT_MOC_VERSION_3 TRUE)
275
endif()
276

277 278 279
set(QT_WRAP_CPP FALSE)
if (QT_MOC_EXECUTABLE AND _QT_MOC_VERSION_3)
  set ( QT_WRAP_CPP TRUE)
280
endif ()
281

282 283 284
set(QT_WRAP_UI FALSE)
if (QT_UIC_EXECUTABLE AND _QT_UIC_VERSION_3)
  set ( QT_WRAP_UI TRUE)
285
endif ()
286

287
mark_as_advanced(
288 289 290 291 292 293 294 295
  QT_INCLUDE_DIR
  QT_QT_LIBRARY
  QT_QTMAIN_LIBRARY
  QT_QASSISTANTCLIENT_LIBRARY
  QT_UIC_EXECUTABLE
  QT_MOC_EXECUTABLE
  QT_WRAP_CPP
  QT_WRAP_UI
296
  )