1 # - Locate Qt include paths and libraries
3 # QT_INCLUDE_DIR - where to find qt.h, etc.
4 # QT_LIBRARIES - the libraries to link against to use Qt.
5 # QT_DEFINITIONS - definitions to use when
6 # compiling code that uses Qt.
7 # QT_FOUND - If false, don't try to use Qt.
9 # If you need the multithreaded version of Qt, set QT_MT_REQUIRED to TRUE
11 # Also defined, but not for general use are:
12 # QT_MOC_EXECUTABLE, where to find the moc tool.
13 # QT_UIC_EXECUTABLE, where to find the uic tool.
14 # QT_QT_LIBRARY, where to find the Qt library.
15 # QT_QTMAIN_LIBRARY, where to find the qtmain
16 # library. This is only required by Qt3 on Windows.
18 # These are around for backwards compatibility
20 # QT_WRAP_CPP, set true if QT_MOC_EXECUTABLE is found
21 # QT_WRAP_UI set true if QT_UIC_EXECUTABLE is found
23 # If Qt4 has already been found, fail.
26 MESSAGE( FATAL_ERROR "Qt3 and Qt4 cannot be used together in one project.")
27 ELSE(Qt3_FIND_REQUIRED)
28 IF(NOT Qt3_FIND_QUIETLY)
29 MESSAGE( STATUS "Qt3 and Qt4 cannot be used together in one project.")
30 ENDIF(NOT Qt3_FIND_QUIETLY)
32 ENDIF(Qt3_FIND_REQUIRED)
36 FILE(GLOB GLOB_PATHS_BIN /usr/lib/qt-3*/bin/)
37 FIND_PATH(QT_INCLUDE_DIR qt.h
38 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]/include/Qt"
39 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]/include/Qt"
40 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]/include/Qt"
47 /usr/share/qt3/include
48 C:/Progra~1/qt/include
52 # if qglobal.h is not in the qt_include_dir then set
53 # QT_INCLUDE_DIR to NOTFOUND
54 IF(NOT EXISTS ${QT_INCLUDE_DIR}/qglobal.h)
55 SET(QT_INCLUDE_DIR QT_INCLUDE_DIR-NOTFOUND CACHE PATH "path to Qt3 include directory" FORCE)
56 ENDIF(NOT EXISTS ${QT_INCLUDE_DIR}/qglobal.h)
59 #extract the version string from qglobal.h
60 FILE(READ ${QT_INCLUDE_DIR}/qglobal.h QGLOBAL_H)
61 STRING(REGEX MATCH "#define[\t ]+QT_VERSION_STR[\t ]+\"([0-9]+.[0-9]+.[0-9]+)\"" QGLOBAL_H "${QGLOBAL_H}")
62 STRING(REGEX REPLACE ".*\"([0-9]+.[0-9]+.[0-9]+)\".*" "\\1" qt_version_str "${QGLOBAL_H}")
64 # Under windows the qt library (MSVC) has the format qt-mtXYZ where XYZ is the
65 # version X.Y.Z, so we need to remove the dots from version
66 STRING(REGEX REPLACE "\\." "" qt_version_str_lib "${qt_version_str}")
69 FILE(GLOB GLOB_PATHS_LIB /usr/lib/qt-3*/lib/)
71 FIND_LIBRARY(QT_QT_LIBRARY
73 qt-mt qt-mt${qt_version_str_lib} qt-mtnc${qt_version_str_lib}
74 qt-mtedu${qt_version_str_lib} qt-mt230nc qt-mtnc321 qt-mt3
76 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]/lib"
77 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]/lib"
78 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]/lib"
90 FIND_LIBRARY(QT_QT_LIBRARY
92 qt qt-${qt_version_str_lib} qt-edu${qt_version_str_lib}
93 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
96 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]/lib"
97 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]/lib"
98 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]/lib"
108 ENDIF (QT_MT_REQUIRED)
111 FIND_LIBRARY(QT_QASSISTANTCLIENT_LIBRARY
112 NAMES qassistantclient
114 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]/lib"
115 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]/lib"
116 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]/lib"
126 # qt 3 should prefer QTDIR over the PATH
127 FIND_PROGRAM(QT_MOC_EXECUTABLE
132 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]/include/Qt"
133 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]/include/Qt"
134 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]/include/Qt"
145 IF(QT_MOC_EXECUTABLE)
146 SET ( QT_WRAP_CPP "YES")
147 ENDIF(QT_MOC_EXECUTABLE)
149 # qt 3 should prefer QTDIR over the PATH
150 FIND_PROGRAM(QT_UIC_EXECUTABLE uic
154 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]/include/Qt"
155 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]/include/Qt"
156 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]/include/Qt"
166 IF(QT_UIC_EXECUTABLE)
167 SET ( QT_WRAP_UI "YES")
168 ENDIF(QT_UIC_EXECUTABLE)
171 FIND_LIBRARY(QT_QTMAIN_LIBRARY qtmain
172 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]/lib"
173 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]/lib"
174 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]/lib"
175 "$ENV{ProgramFiles}/qt/lib"
176 $ENV{QTDIR}/lib "C:/Program Files/qt/lib"
177 DOC "This Library is only needed by and included with Qt3 on MSWindows. It should be NOTFOUND, undefined or IGNORE otherwise."
184 STRING(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" qt_major_vers "${qt_version_str}")
185 STRING(REGEX REPLACE "[0-9]+\\.([0-9]+)\\.[0-9]+" "\\1" qt_minor_vers "${qt_version_str}")
186 STRING(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" qt_patch_vers "${qt_version_str}")
188 #now parse the parts of the user given version string into variables
189 STRING(REGEX MATCH "^[0-9]+\\.[0-9]+\\.[0-9]+$" req_qt_major_vers "${QT_MIN_VERSION}")
190 IF (NOT req_qt_major_vers)
191 error_message( "Invalid Qt version string given: \"${QT_MIN_VERSION}\", expected e.g. \"3.1.5\"")
192 ENDIF (NOT req_qt_major_vers)
194 STRING(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" req_qt_major_vers "${QT_MIN_VERSION}")
195 STRING(REGEX REPLACE "[0-9]+\\.([0-9])+\\.[0-9]+" "\\1" req_qt_minor_vers "${QT_MIN_VERSION}")
196 STRING(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" req_qt_patch_vers "${QT_MIN_VERSION}")
198 # req = "6.5.4", qt = "3.2.1"
199 MACRO(error_message msg)
201 MESSAGE( FATAL_ERROR ${msg})
203 MESSAGE( STATUS ${msg})
205 ENDMACRO(error_message)
207 IF (req_qt_major_vers GREATER qt_major_vers) # (6 > 3) ?
208 ERROR_MESSAGE( "Qt major version not matched (required: ${QT_MIN_VERSION}, found: ${qt_version_str})") # yes
209 ELSE (req_qt_major_vers GREATER qt_major_vers) # no
210 IF (req_qt_major_vers LESS qt_major_vers) # (6 < 3) ?
211 SET( QT_VERSION_BIG_ENOUGH "YES" ) # yes
212 ELSE (req_qt_major_vers LESS qt_major_vers) # ( 6==3) ?
213 IF (req_qt_minor_vers GREATER qt_minor_vers) # (5>2) ?
214 ERROR_MESSAGE( "Qt minor version not matched (required: ${QT_MIN_VERSION}, found: ${qt_version_str})") # yes
215 ELSE (req_qt_minor_vers GREATER qt_minor_vers) # no
216 IF (req_qt_minor_vers LESS qt_minor_vers) # (5<2) ?
217 SET( QT_VERSION_BIG_ENOUGH "YES" ) # yes
218 ELSE (req_qt_minor_vers LESS qt_minor_vers) # (5==2)
219 IF (req_qt_patch_vers GREATER qt_patch_vers) # (4>1) ?
220 ERROR_MESSAGE( "Qt patch level not matched (required: ${QT_MIN_VERSION}, found: ${qt_version_str})") # yes
221 ELSE (req_qt_patch_vers GREATER qt_patch_vers) # (4>1) ?
222 SET( QT_VERSION_BIG_ENOUGH "YES" ) # yes
223 ENDIF (req_qt_patch_vers GREATER qt_patch_vers) # (4>1) ?
224 ENDIF (req_qt_minor_vers LESS qt_minor_vers)
225 ENDIF (req_qt_minor_vers GREATER qt_minor_vers)
226 ENDIF (req_qt_major_vers LESS qt_major_vers)
227 ENDIF (req_qt_major_vers GREATER qt_major_vers)
228 ENDIF (QT_MIN_VERSION)
230 # if the include a library are found then we have it
231 IF(QT_INCLUDE_DIR AND QT_QT_LIBRARY)
232 SET( QT_FOUND "YES" )
233 ENDIF(QT_INCLUDE_DIR AND QT_QT_LIBRARY)
236 SET( QT_LIBRARIES ${QT_LIBRARIES} ${QT_QT_LIBRARY} )
237 SET( QT_DEFINITIONS "")
239 IF (WIN32 AND NOT CYGWIN)
240 IF (QT_QTMAIN_LIBRARY)
242 SET (QT_DEFINITIONS -DQT_DLL -DQT_THREAD_SUPPORT -DNO_DEBUG)
243 SET (QT_LIBRARIES imm32.lib ${QT_QT_LIBRARY} ${QT_QTMAIN_LIBRARY} )
244 SET (QT_LIBRARIES ${QT_LIBRARIES} winmm wsock32)
245 ELSE (QT_QTMAIN_LIBRARY)
247 SET (QT_LIBRARIES imm32.lib ws2_32.lib ${QT_QT_LIBRARY} )
248 ENDIF (QT_QTMAIN_LIBRARY)
249 ELSE (WIN32 AND NOT CYGWIN)
250 SET (QT_LIBRARIES ${QT_QT_LIBRARY} )
252 SET (QT_DEFINITIONS -DQT_SHARED -DQT_NO_DEBUG)
253 IF(QT_QT_LIBRARY MATCHES "qt-mt")
254 SET (QT_DEFINITIONS ${QT_DEFINITIONS} -DQT_THREAD_SUPPORT -D_REENTRANT)
255 ENDIF(QT_QT_LIBRARY MATCHES "qt-mt")
257 ENDIF (WIN32 AND NOT CYGWIN)
259 IF (QT_QASSISTANTCLIENT_LIBRARY)
260 SET (QT_LIBRARIES ${QT_QASSISTANTCLIENT_LIBRARY} ${QT_LIBRARIES})
261 ENDIF (QT_QASSISTANTCLIENT_LIBRARY)
263 # Backwards compatibility for CMake1.4 and 1.2
264 SET (QT_MOC_EXE ${QT_MOC_EXECUTABLE} )
265 SET (QT_UIC_EXE ${QT_UIC_EXECUTABLE} )
266 # for unix add X11 stuff
270 SET (QT_LIBRARIES ${QT_LIBRARIES} ${X11_LIBRARIES})
273 SET (QT_LIBRARIES ${QT_LIBRARIES} ${CMAKE_DL_LIBS})
274 ENDIF (CMAKE_DL_LIBS)
276 IF(QT_QT_LIBRARY MATCHES "qt-mt")
277 FIND_PACKAGE(Threads)
278 SET(QT_LIBRARIES ${QT_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
279 ENDIF(QT_QT_LIBRARY MATCHES "qt-mt")
282 EXEC_PROGRAM(${QT_MOC_EXECUTABLE} ARGS "-v" OUTPUT_VARIABLE QTVERSION_MOC)
283 EXEC_PROGRAM(${QT_UIC_EXECUTABLE} ARGS "-version" OUTPUT_VARIABLE QTVERSION_UIC)
285 SET(_QT_UIC_VERSION_3 FALSE)
286 IF("${QTVERSION_UIC}" MATCHES ".* 3..*")
287 SET(_QT_UIC_VERSION_3 TRUE)
288 ENDIF("${QTVERSION_UIC}" MATCHES ".* 3..*")
290 SET(_QT_MOC_VERSION_3 FALSE)
291 IF("${QTVERSION_MOC}" MATCHES ".* 3..*")
292 SET(_QT_MOC_VERSION_3 TRUE)
293 ENDIF("${QTVERSION_MOC}" MATCHES ".* 3..*")
295 SET(QT_WRAP_CPP FALSE)
296 IF (QT_MOC_EXECUTABLE AND _QT_MOC_VERSION_3)
297 SET ( QT_WRAP_CPP TRUE)
298 ENDIF (QT_MOC_EXECUTABLE AND _QT_MOC_VERSION_3)
300 SET(QT_WRAP_UI FALSE)
301 IF (QT_UIC_EXECUTABLE AND _QT_UIC_VERSION_3)
302 SET ( QT_WRAP_UI TRUE)
303 ENDIF (QT_UIC_EXECUTABLE AND _QT_UIC_VERSION_3)
309 QT_QASSISTANTCLIENT_LIBRARY