FindQt3.cmake 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindQt3
  5. -------
  6. Locate Qt include paths and libraries
  7. This module defines:
  8. ::
  9. QT_INCLUDE_DIR - where to find qt.h, etc.
  10. QT_LIBRARIES - the libraries to link against to use Qt.
  11. QT_DEFINITIONS - definitions to use when
  12. compiling code that uses Qt.
  13. QT_FOUND - If false, don't try to use Qt.
  14. QT_VERSION_STRING - the version of Qt found
  15. If you need the multithreaded version of Qt, set QT_MT_REQUIRED to
  16. TRUE
  17. Also defined, but not for general use are:
  18. ::
  19. QT_MOC_EXECUTABLE, where to find the moc tool.
  20. QT_UIC_EXECUTABLE, where to find the uic tool.
  21. QT_QT_LIBRARY, where to find the Qt library.
  22. QT_QTMAIN_LIBRARY, where to find the qtmain
  23. library. This is only required by Qt3 on Windows.
  24. #]=======================================================================]
  25. # These are around for backwards compatibility
  26. # they will be set
  27. # QT_WRAP_CPP, set true if QT_MOC_EXECUTABLE is found
  28. # QT_WRAP_UI set true if QT_UIC_EXECUTABLE is found
  29. # If Qt4 has already been found, fail.
  30. if(QT4_FOUND)
  31. if(Qt3_FIND_REQUIRED)
  32. message( FATAL_ERROR "Qt3 and Qt4 cannot be used together in one project.")
  33. else()
  34. if(NOT Qt3_FIND_QUIETLY)
  35. message( STATUS "Qt3 and Qt4 cannot be used together in one project.")
  36. endif()
  37. return()
  38. endif()
  39. endif()
  40. file(GLOB GLOB_PATHS /usr/lib/qt-3*)
  41. foreach(GLOB_PATH ${GLOB_PATHS})
  42. list(APPEND GLOB_PATHS_BIN "${GLOB_PATH}/bin")
  43. endforeach()
  44. find_path(QT_INCLUDE_DIR qt.h
  45. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]/include/Qt"
  46. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]/include/Qt"
  47. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]/include/Qt"
  48. $ENV{QTDIR}/include
  49. ${GLOB_PATHS}
  50. /usr/share/qt3/include
  51. C:/Progra~1/qt/include
  52. /usr/local/include/X11/qt3
  53. PATH_SUFFIXES lib/qt/include lib/qt3/include include/qt include/qt3 qt/include qt3/include
  54. )
  55. # if qglobal.h is not in the qt_include_dir then set
  56. # QT_INCLUDE_DIR to NOTFOUND
  57. if(NOT EXISTS ${QT_INCLUDE_DIR}/qglobal.h)
  58. set(QT_INCLUDE_DIR QT_INCLUDE_DIR-NOTFOUND CACHE PATH "path to Qt3 include directory" FORCE)
  59. endif()
  60. if(QT_INCLUDE_DIR)
  61. #extract the version string from qglobal.h
  62. file(STRINGS ${QT_INCLUDE_DIR}/qglobal.h QGLOBAL_H REGEX "#define[\t ]+QT_VERSION_STR[\t ]+\"[0-9]+.[0-9]+.[0-9]+[a-z]*\"")
  63. string(REGEX REPLACE ".*\"([0-9]+.[0-9]+.[0-9]+[a-z]*)\".*" "\\1" qt_version_str "${QGLOBAL_H}")
  64. unset(QGLOBAL_H)
  65. # Under windows the qt library (MSVC) has the format qt-mtXYZ where XYZ is the
  66. # version X.Y.Z, so we need to remove the dots from version
  67. string(REGEX REPLACE "\\." "" qt_version_str_lib "${qt_version_str}")
  68. set(QT_VERSION_STRING "${qt_version_str}")
  69. endif()
  70. file(GLOB GLOB_PATHS_LIB /usr/lib/qt-3*/lib/)
  71. if (QT_MT_REQUIRED)
  72. find_library(QT_QT_LIBRARY
  73. NAMES
  74. qt-mt qt-mt${qt_version_str_lib} qt-mtnc${qt_version_str_lib}
  75. qt-mtedu${qt_version_str_lib} qt-mt230nc qt-mtnc321 qt-mt3
  76. PATHS
  77. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]"
  78. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]"
  79. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]"
  80. ENV QTDIR
  81. ${GLOB_PATHS_LIB}
  82. /usr/share/qt3
  83. C:/Progra~1/qt
  84. PATH_SUFFIXES
  85. lib lib/qt lib/qt3 qt qt3 qt/lib qt3/lib
  86. )
  87. else ()
  88. find_library(QT_QT_LIBRARY
  89. NAMES
  90. qt qt-${qt_version_str_lib} qt-edu${qt_version_str_lib}
  91. qt-mt qt-mt${qt_version_str_lib} qt-mtnc${qt_version_str_lib}
  92. qt-mtedu${qt_version_str_lib} qt-mt230nc qt-mtnc321 qt-mt3
  93. PATHS
  94. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]"
  95. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]"
  96. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]"
  97. ENV QTDIR
  98. ${GLOB_PATHS_LIB}
  99. /usr/share/qt3
  100. C:/Progra~1/qt/lib
  101. PATH_SUFFIXES
  102. lib lib/qt lib/qt3 qt qt3 qt/lib qt3/lib
  103. )
  104. endif ()
  105. find_library(QT_QASSISTANTCLIENT_LIBRARY
  106. NAMES qassistantclient
  107. PATHS
  108. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]"
  109. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]"
  110. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]"
  111. ENV QTDIR
  112. ${GLOB_PATHS_LIB}
  113. /usr/share/qt3
  114. C:/Progra~1/qt
  115. PATH_SUFFIXES
  116. lib lib/qt lib/qt3 qt qt3 qt/lib qt3/lib
  117. )
  118. # Qt 3 should prefer QTDIR over the PATH
  119. find_program(QT_MOC_EXECUTABLE
  120. NAMES moc-qt3 moc3 moc3-mt moc
  121. HINTS
  122. ENV QTDIR
  123. PATHS
  124. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]/include/Qt"
  125. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]/include/Qt"
  126. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]/include/Qt"
  127. ${GLOB_PATHS_BIN}
  128. /usr/share/qt3
  129. C:/Progra~1/qt
  130. PATH_SUFFIXES
  131. bin lib/qt lib/qt3 qt qt3 qt/bin qt3/bin lib/qt/bin lib/qt3/bin
  132. )
  133. if(QT_MOC_EXECUTABLE)
  134. set ( QT_WRAP_CPP "YES")
  135. endif()
  136. # Qt 3 should prefer QTDIR over the PATH
  137. find_program(QT_UIC_EXECUTABLE
  138. NAMES uic-qt3 uic3 uic3-mt uic
  139. HINTS
  140. ENV QTDIR
  141. PATHS
  142. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]/include/Qt"
  143. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]/include/Qt"
  144. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]/include/Qt"
  145. ${GLOB_PATHS_BIN}
  146. /usr/share/qt3
  147. C:/Progra~1/qt
  148. PATH_SUFFIXES
  149. bin lib/qt lib/qt3 qt qt3 qt/bin qt3/bin lib/qt/bin lib/qt3/bin
  150. )
  151. if(QT_UIC_EXECUTABLE)
  152. set ( QT_WRAP_UI "YES")
  153. endif()
  154. if (WIN32)
  155. find_library(QT_QTMAIN_LIBRARY qtmain
  156. HINTS
  157. ENV QTDIR
  158. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]"
  159. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]"
  160. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]"
  161. PATHS
  162. "$ENV{ProgramFiles}/qt"
  163. "C:/Program Files/qt"
  164. PATH_SUFFIXES
  165. lib
  166. DOC "This Library is only needed by and included with Qt3 on MSWindows. It should be NOTFOUND, undefined or IGNORE otherwise."
  167. )
  168. endif ()
  169. #support old QT_MIN_VERSION if set, but not if version is supplied by find_package()
  170. if(NOT Qt3_FIND_VERSION AND QT_MIN_VERSION)
  171. set(Qt3_FIND_VERSION ${QT_MIN_VERSION})
  172. endif()
  173. # if the include a library are found then we have it
  174. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  175. FIND_PACKAGE_HANDLE_STANDARD_ARGS(Qt3
  176. REQUIRED_VARS QT_QT_LIBRARY QT_INCLUDE_DIR QT_MOC_EXECUTABLE
  177. VERSION_VAR QT_VERSION_STRING)
  178. set(QT_FOUND ${QT3_FOUND} )
  179. if(QT_FOUND)
  180. set( QT_LIBRARIES ${QT_LIBRARIES} ${QT_QT_LIBRARY} )
  181. set( QT_DEFINITIONS "")
  182. if (WIN32 AND NOT CYGWIN)
  183. if (QT_QTMAIN_LIBRARY)
  184. # for version 3
  185. set (QT_DEFINITIONS -DQT_DLL -DQT_THREAD_SUPPORT -DNO_DEBUG)
  186. set (QT_LIBRARIES imm32.lib ${QT_QT_LIBRARY} ${QT_QTMAIN_LIBRARY} )
  187. set (QT_LIBRARIES ${QT_LIBRARIES} winmm wsock32)
  188. else ()
  189. # for version 2
  190. set (QT_LIBRARIES imm32.lib ws2_32.lib ${QT_QT_LIBRARY} )
  191. endif ()
  192. else ()
  193. set (QT_LIBRARIES ${QT_QT_LIBRARY} )
  194. set (QT_DEFINITIONS -DQT_SHARED -DQT_NO_DEBUG)
  195. if(QT_QT_LIBRARY MATCHES "qt-mt")
  196. set (QT_DEFINITIONS ${QT_DEFINITIONS} -DQT_THREAD_SUPPORT -D_REENTRANT)
  197. endif()
  198. endif ()
  199. if (QT_QASSISTANTCLIENT_LIBRARY)
  200. set (QT_LIBRARIES ${QT_QASSISTANTCLIENT_LIBRARY} ${QT_LIBRARIES})
  201. endif ()
  202. # Backwards compatibility for CMake1.4 and 1.2
  203. set (QT_MOC_EXE ${QT_MOC_EXECUTABLE} )
  204. set (QT_UIC_EXE ${QT_UIC_EXECUTABLE} )
  205. # for unix add X11 stuff
  206. if(UNIX)
  207. find_package(X11)
  208. if (X11_FOUND)
  209. set (QT_LIBRARIES ${QT_LIBRARIES} ${X11_LIBRARIES})
  210. endif ()
  211. if (CMAKE_DL_LIBS)
  212. set (QT_LIBRARIES ${QT_LIBRARIES} ${CMAKE_DL_LIBS})
  213. endif ()
  214. endif()
  215. if(QT_QT_LIBRARY MATCHES "qt-mt")
  216. find_package(Threads)
  217. set(QT_LIBRARIES ${QT_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
  218. endif()
  219. endif()
  220. if(QT_MOC_EXECUTABLE)
  221. execute_process(COMMAND ${QT_MOC_EXECUTABLE} "-v"
  222. OUTPUT_VARIABLE QTVERSION_MOC
  223. ERROR_QUIET)
  224. endif()
  225. if(QT_UIC_EXECUTABLE)
  226. execute_process(COMMAND ${QT_UIC_EXECUTABLE} "-version"
  227. OUTPUT_VARIABLE QTVERSION_UIC
  228. ERROR_QUIET)
  229. endif()
  230. set(_QT_UIC_VERSION_3 FALSE)
  231. if("${QTVERSION_UIC}" MATCHES " 3.")
  232. set(_QT_UIC_VERSION_3 TRUE)
  233. endif()
  234. set(_QT_MOC_VERSION_3 FALSE)
  235. if("${QTVERSION_MOC}" MATCHES " 3.")
  236. set(_QT_MOC_VERSION_3 TRUE)
  237. endif()
  238. set(QT_WRAP_CPP FALSE)
  239. if (QT_MOC_EXECUTABLE AND _QT_MOC_VERSION_3)
  240. set ( QT_WRAP_CPP TRUE)
  241. endif ()
  242. set(QT_WRAP_UI FALSE)
  243. if (QT_UIC_EXECUTABLE AND _QT_UIC_VERSION_3)
  244. set ( QT_WRAP_UI TRUE)
  245. endif ()
  246. mark_as_advanced(
  247. QT_INCLUDE_DIR
  248. QT_QT_LIBRARY
  249. QT_QTMAIN_LIBRARY
  250. QT_QASSISTANTCLIENT_LIBRARY
  251. QT_UIC_EXECUTABLE
  252. QT_MOC_EXECUTABLE
  253. QT_WRAP_CPP
  254. QT_WRAP_UI
  255. )