STYLE: Nightly Version update
[cmake.git] / Modules / FindQt.cmake
blob39523e231c44e4d5f141db2160aa02aafa521f45
1 # Locate Qt include paths and libraries
3 # This module defines
4 # QT_INCLUDE_DIR, where to find qt.h, etc.
5 # QT_LIBRARIES, the libraries to link against to use Qt.
6 # QT_DEFINITIONS, definitions to use when 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 library. This is only required by Qt3 on Windows.
17 # These are around for backwards compatibility 
18 # they will be set
19 # QT_WRAP_CPP, set true if QT_MOC_EXECUTABLE is found
20 # QT_WRAP_UI set true if QT_UIC_EXECUTABLE is found
23 FIND_PATH(QT_INCLUDE_DIR qt.h
24   $ENV{QTDIR}/include
25   /usr/local/qt/include
26   /usr/local/include
27   /usr/lib/qt/include
28   /usr/include/qt
29   /usr/include
30   /usr/share/qt3/include
31   C:/Progra~1/qt/include
32   /usr/include/qt3
33   )
35 IF(QT_INCLUDE_DIR)
36   #extract the version string from qglobal.h
37   FILE(READ ${QT_INCLUDE_DIR}/qglobal.h QGLOBAL_H)
38   STRING(REGEX MATCH "#define[\t ]+QT_VERSION_STR[\t ]+\"([0-9]+.[0-9]+.[0-9]+)\"" QGLOBAL_H "${QGLOBAL_H}")
39   STRING(REGEX REPLACE ".*\"([0-9]+.[0-9]+.[0-9]+)\".*" "\\1" QGLOBAL_H "${QGLOBAL_H}")
41   # Under windows the qt library (MSVC) has the format qt-mtXYZ where XYZ is the
42   # version X.Y.Z, so we need to remove the dots from version
43   STRING(REGEX REPLACE "\\." "" qt_version_str_lib "${QGLOBAL_H}")
44 ELSE(QT_INCLUDE_DIR)
45 ENDIF(QT_INCLUDE_DIR)
48 IF (QT_MT_REQUIRED)
49    FIND_LIBRARY(QT_QT_LIBRARY
50         NAMES qt-mt qt-mt${qt_version_str_lib} qt-mt230nc
51         PATHS
52         $ENV{QTDIR}/lib
53         /usr/local/qt/lib
54         /usr/local/lib
55         /usr/lib/qt/lib
56         /usr/lib
57         /usr/share/qt3/lib
58         C:/Progra~1/qt/lib
59      )
61 ELSE (QT_MT_REQUIRED)
62   FIND_LIBRARY(QT_QT_LIBRARY
63     NAMES qt qt-${qt_version_str_lib} qt-mt qt-mt230nc
64     PATHS
65     $ENV{QTDIR}/lib
66     /usr/local/qt/lib
67     /usr/local/lib
68     /usr/lib/qt/lib
69     /usr/lib
70     /usr/share/qt3/lib
71     C:/Progra~1/qt/lib
72     )
73 ENDIF (QT_MT_REQUIRED)
75 IF(QT_QT_LIBRARY)
76 ELSE(QT_QT_LIBRARY)
77 ENDIF(QT_QT_LIBRARY)
80 FIND_LIBRARY(QT_QASSISTANTCLIENT_LIBRARY
81   NAMES qassistantclient
82   PATHS
83   $ENV{QTDIR}/lib
84   /usr/local/qt/lib
85   /usr/local/lib
86   /usr/lib
87   /usr/share/qt3/lib
88   C:/Progra~1/qt/lib
89   )
91 FIND_PROGRAM(QT_MOC_EXECUTABLE 
92   NAMES moc moc-qt3
93   PATHS
94   $ENV{QTDIR}/bin 
95   /usr/local/qt/bin
96   /usr/lib/qt/bin
97   /usr/share/qt3/bin
98   C:/Progra~1/qt/bin
99   )
101 IF(QT_MOC_EXECUTABLE)
102    SET ( QT_WRAP_CPP "YES")
103 ELSE(QT_MOC_EXECUTABLE)
104 ENDIF(QT_MOC_EXECUTABLE)
106 FIND_PROGRAM(QT_UIC_EXECUTABLE uic
107   $ENV{QTDIR}/bin 
108   /usr/local/qt/bin
109   /usr/lib/qt/bin
110   /usr/share/qt3/bin
111   C:/Progra~1/qt/bin
114 IF(QT_UIC_EXECUTABLE)
115    SET ( QT_WRAP_UI "YES")
116 ELSE(QT_UIC_EXECUTABLE)
117 ENDIF(QT_UIC_EXECUTABLE)
119 IF (WIN32)
120   FIND_LIBRARY(QT_QTMAIN_LIBRARY qtmain
121     $ENV{QTDIR}/lib C:/Progra~1/qt/lib
122     DOC "This Library is only needed by and included with Qt3 on MSWindows. It should be NOTFOUND, undefined or IGNORE otherwise."
123     )
124 ENDIF (WIN32)
127 IF (QT_MIN_VERSION)
129   STRING(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" qt_major_vers "${qt_version_str}")
130   STRING(REGEX REPLACE "[0-9]+\\.([0-9]+)\\.[0-9]+" "\\1" qt_minor_vers "${qt_version_str}")
131   STRING(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" qt_patch_vers "${qt_version_str}")
132   
133   #now parse the parts of the user given version string into variables 
134   STRING(REGEX MATCH "^[0-9]+\\.[0-9]+\\.[0-9]+$" req_qt_major_vers "${QT_MIN_VERSION}")
135   IF (NOT req_qt_major_vers)
136     MESSAGE( FATAL_ERROR "Invalid Qt version string given: \"${QT_MIN_VERSION}\", expected e.g. \"3.1.5\"")
137   ENDIF (NOT req_qt_major_vers)
138   
139   STRING(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" req_qt_major_vers "${QT_MIN_VERSION}")
140   STRING(REGEX REPLACE "[0-9]+\\.([0-9])+\\.[0-9]+" "\\1" req_qt_minor_vers "${QT_MIN_VERSION}")
141   STRING(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" req_qt_patch_vers "${QT_MIN_VERSION}")
142   
143   # req = "6.5.4", qt = "3.2.1"
144   
145   IF (req_qt_major_vers GREATER qt_major_vers)                  # (6 > 3) ?
146     MESSAGE(  FATAL_ERROR "Qt major version not matched (required: ${QT_MIN_VERSION}, found: ${qt_version_str})")            # yes
147   ELSE  (req_qt_major_vers GREATER qt_major_vers)               # no
148     IF (req_qt_major_vers LESS qt_major_vers)                  # (6 < 3) ?
149       SET( QT_VERSION_BIG_ENOUGH "YES" )                      # yes
150     ELSE (req_qt_major_vers LESS qt_major_vers)                # ( 6==3) ?
151       IF (req_qt_minor_vers GREATER qt_minor_vers)            # (5>2) ?
152         MESSAGE(  FATAL_ERROR "Qt minor version not matched (required: ${QT_MIN_VERSION}, found: ${qt_version_str})")      # yes
153       ELSE (req_qt_minor_vers GREATER qt_minor_vers)          # no
154         IF (req_qt_minor_vers LESS qt_minor_vers)            # (5<2) ?
155           SET( QT_VERSION_BIG_ENOUGH "YES" )                # yes
156         ELSE (req_qt_minor_vers LESS qt_minor_vers)          # (5==2)
157           IF (req_qt_patch_vers GREATER qt_patch_vers)      # (4>1) ?
158             MESSAGE( FATAL_ERROR "Qt patch level not matched (required: ${QT_MIN_VERSION}, found: ${qt_version_str})")  # yes
159           ELSE (req_qt_patch_vers GREATER qt_patch_vers)    # (4>1) ?
160             SET( QT_VERSION_BIG_ENOUGH "YES" )             # yes
161           ENDIF (req_qt_patch_vers GREATER qt_patch_vers)   # (4>1) ?
162         ENDIF (req_qt_minor_vers LESS qt_minor_vers)
163       ENDIF (req_qt_minor_vers GREATER qt_minor_vers)
164     ENDIF (req_qt_major_vers LESS qt_major_vers)
165   ENDIF (req_qt_major_vers GREATER qt_major_vers)
166 ENDIF (QT_MIN_VERSION)
168 # if the include a library are found then we have it
169 IF(QT_INCLUDE_DIR)
170   IF(QT_QT_LIBRARY)
171     SET( QT_FOUND "YES" )
172   ENDIF(QT_QT_LIBRARY)
173 ENDIF(QT_INCLUDE_DIR)
174    
175 IF(QT_FOUND)
176   SET( QT_LIBRARIES ${QT_LIBRARIES} ${QT_QT_LIBRARY} )
177   SET( QT_DEFINITIONS "")
178   
179   IF (WIN32 AND NOT CYGWIN)
180     IF (QT_QTMAIN_LIBRARY)
181       # for version 3
182       SET (QT_DEFINITIONS "-DQT_DLL -DQT_THREAD_SUPPORT -DNO_DEBUG")
183       SET (QT_LIBRARIES imm32.lib ${QT_QT_LIBRARY} ${QT_QTMAIN_LIBRARY} )
184       SET (QT_LIBRARIES ${QT_LIBRARIES} winmm wsock32)
185     ELSE (QT_QTMAIN_LIBRARY)
186       # for version 2
187       SET (QT_LIBRARIES imm32.lib ws2_32.lib ${QT_QT_LIBRARY} )
188     ENDIF (QT_QTMAIN_LIBRARY)
189   ELSE (WIN32 AND NOT CYGWIN)
190     SET (QT_LIBRARIES ${QT_QT_LIBRARY} )
191     
192     SET (QT_DEFINITIONS "-DQT_SHARED -DQT_NO_DEBUG")
193     IF(QT_QT_LIBRARY MATCHES "qt-mt")
194       SET (QT_DEFINITIONS ${QT_DEFINITIONS} -DQT_THREAD_SUPPORT -D_REENTRANT)
195     ENDIF(QT_QT_LIBRARY MATCHES "qt-mt")
196     
197   ENDIF (WIN32 AND NOT CYGWIN)
198   
199   IF (QT_QASSISTANTCLIENT_LIBRARY)
200     SET (QT_LIBRARIES ${QT_QASSISTANTCLIENT_LIBRARY} ${QT_LIBRARIES})
201   ENDIF (QT_QASSISTANTCLIENT_LIBRARY)
202   
203   # Backwards compatibility for CMake1.4 and 1.2
204   SET (QT_MOC_EXE ${QT_MOC_EXECUTABLE} )
205   SET (QT_UIC_EXE ${QT_UIC_EXECUTABLE} )
206   # for unix add X11 stuff
207   IF(UNIX)
208     FIND_PACKAGE(X11)
209     IF (X11_FOUND)
210       SET (QT_LIBRARIES ${QT_LIBRARIES} ${X11_LIBRARIES})
211     ENDIF (X11_FOUND)
212     IF (CMAKE_DL_LIBS)
213       SET (QT_LIBRARIES ${QT_LIBRARIES} ${CMAKE_DL_LIBS})
214     ENDIF (CMAKE_DL_LIBS)
215   ENDIF(UNIX)
216   IF(QT_QT_LIBRARY MATCHES "qt-mt")
217     FIND_PACKAGE(Threads)
218     SET(QT_LIBRARIES ${QT_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
219   ENDIF(QT_QT_LIBRARY MATCHES "qt-mt")
220 ENDIF(QT_FOUND)
223 IF (QT_MOC_EXECUTABLE)   
224   SET ( QT_WRAP_CPP "YES")   
225 ENDIF (QT_MOC_EXECUTABLE)   
226     
227 IF (QT_UIC_EXECUTABLE)   
228   SET ( QT_WRAP_UI "YES")   
229 ENDIF (QT_UIC_EXECUTABLE)   
230   
233 MARK_AS_ADVANCED(
234   QT_INCLUDE_DIR
235   QT_QT_LIBRARY
236   QT_QTMAIN_LIBRARY
237   QT_QASSISTANTCLIENT_LIBRARY
238   QT_UIC_EXECUTABLE
239   QT_MOC_EXECUTABLE
240   QT_WRAP_CPP
241   QT_WRAP_UI
242   )