ENH: fix bug where sharedforward would not work if there was a space in the path...
[cmake.git] / Modules / FindQt3.cmake
blobdcfaad30c2cbff8075f7be8d56a8fdf1096daf09
1 # - Locate Qt include paths and libraries
2 # This module defines:
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
19 # they will be set
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.
24 IF(QT4_FOUND)
25   IF(Qt3_FIND_REQUIRED)
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)
31     RETURN()
32   ENDIF(Qt3_FIND_REQUIRED)
33 ENDIF(QT4_FOUND)
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"
41   $ENV{QTDIR}/include
42   ${GLOB_PATHS_BIN}
43   /usr/local/qt/include
44   /usr/lib/qt/include
45   /usr/lib/qt3/include
46   /usr/include/qt
47   /usr/share/qt3/include
48   C:/Progra~1/qt/include
49   /usr/include/qt3
50   )
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)
58 IF(QT_INCLUDE_DIR)
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}")
67 ENDIF(QT_INCLUDE_DIR)
69 FILE(GLOB GLOB_PATHS_LIB /usr/lib/qt-3*/lib/)
70 IF (QT_MT_REQUIRED)
71   FIND_LIBRARY(QT_QT_LIBRARY
72     NAMES
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
75     PATHS
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"
79     $ENV{QTDIR}/lib
80     ${GLOB_PATHS_LIB}
81     /usr/local/qt/lib
82     /usr/lib/qt/lib
83     /usr/lib/qt3/lib
84     /usr/lib/qt3/lib64
85     /usr/share/qt3/lib
86     C:/Progra~1/qt/lib
87     )
89 ELSE (QT_MT_REQUIRED)
90   FIND_LIBRARY(QT_QT_LIBRARY
91     NAMES
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
95     PATHS
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"
99     $ENV{QTDIR}/lib
100     ${GLOB_PATHS_LIB}
101     /usr/local/qt/lib
102     /usr/lib/qt/lib
103     /usr/lib/qt3/lib
104     /usr/lib/qt3/lib64
105     /usr/share/qt3/lib
106     C:/Progra~1/qt/lib
107     )
108 ENDIF (QT_MT_REQUIRED)
111 FIND_LIBRARY(QT_QASSISTANTCLIENT_LIBRARY
112   NAMES qassistantclient
113   PATHS
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"
117   $ENV{QTDIR}/lib
118   ${GLOB_PATHS_LIB}
119   /usr/local/qt/lib
120   /usr/lib/qt3/lib
121   /usr/lib/qt3/lib64
122   /usr/share/qt3/lib
123   C:/Progra~1/qt/lib
124   )
126 # qt 3 should prefer QTDIR over the PATH
127 FIND_PROGRAM(QT_MOC_EXECUTABLE
128   NAMES moc moc-qt3
129   HINTS
130   $ENV{QTDIR}/bin
131   PATHS
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"
135   $ENV{QTDIR}/bin
136   ${GLOB_PATHS_BIN}
137   /usr/local/qt/bin
138   /usr/lib/qt/bin
139   /usr/lib/qt3/bin
140   /usr/share/qt3/bin
141   C:/Progra~1/qt/bin
142   /usr/X11R6/bin
143   )
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
151   HINTS
152   $ENV{QTDIR}/bin
153   PATHS
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"
157   ${GLOB_PATHS_BIN}
158   /usr/local/qt/bin
159   /usr/lib/qt/bin
160   /usr/lib/qt3/bin
161   /usr/share/qt3/bin
162   C:/Progra~1/qt/bin
163   /usr/X11R6/bin
164   )
166 IF(QT_UIC_EXECUTABLE)
167   SET ( QT_WRAP_UI "YES")
168 ENDIF(QT_UIC_EXECUTABLE)
170 IF (WIN32)
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."
178     )
179 ENDIF (WIN32)
182 IF (QT_MIN_VERSION)
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)
200     IF(QT3_REQUIRED)
201       MESSAGE( FATAL_ERROR ${msg})
202     ELSE(QT3_REQUIRED)
203       MESSAGE( STATUS ${msg})
204     ENDIF(QT3_REQUIRED)
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)
235 IF(QT_FOUND)
236   SET( QT_LIBRARIES ${QT_LIBRARIES} ${QT_QT_LIBRARY} )
237   SET( QT_DEFINITIONS "")
239   IF (WIN32 AND NOT CYGWIN)
240     IF (QT_QTMAIN_LIBRARY)
241       # for version 3
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)
246       # for version 2
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
267   IF(UNIX)
268     FIND_PACKAGE(X11)
269     IF (X11_FOUND)
270       SET (QT_LIBRARIES ${QT_LIBRARIES} ${X11_LIBRARIES})
271     ENDIF (X11_FOUND)
272     IF (CMAKE_DL_LIBS)
273       SET (QT_LIBRARIES ${QT_LIBRARIES} ${CMAKE_DL_LIBS})
274     ENDIF (CMAKE_DL_LIBS)
275   ENDIF(UNIX)
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")
280 ENDIF(QT_FOUND)
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)
305 MARK_AS_ADVANCED(
306   QT_INCLUDE_DIR
307   QT_QT_LIBRARY
308   QT_QTMAIN_LIBRARY
309   QT_QASSISTANTCLIENT_LIBRARY
310   QT_UIC_EXECUTABLE
311   QT_MOC_EXECUTABLE
312   QT_WRAP_CPP
313   QT_WRAP_UI
314   )