FindQt.cmake 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. # searches for all installed versions of QT.
  2. # This should only be used if your project can work with multiple
  3. # versions of QT. If not, you should just directly use FindQt4 or FindQt3.
  4. #
  5. # If multiple versions of QT are found on the machine, then
  6. # The user must set the option DESIRED_QT_VERSION to the version
  7. # they want to use. If only one version of qt is found on the machine,
  8. # then the DESIRED_QT_VERSION is set to that version and the
  9. # matching FindQt3 or FindQt4 module is included.
  10. # Once the user sets DESIRED_QT_VERSION, then the FindQt3 or FindQt4 module
  11. # is included.
  12. #
  13. # QT_REQUIRED if this is set to TRUE then if cmake can not find QT4 or QT3
  14. # an error is raised and a message is sent to the user.
  15. # DESIRED_QT_VERSION OPTION is created
  16. # QT4_INSTALLED is set to TRUE if qt4 is found.
  17. # QT3_INSTALLED is set to TRUE if qt3 is found.
  18. # look for signs of qt3 installations
  19. FILE(GLOB GLOB_TEMP_VAR /usr/lib/qt-3*/bin/qmake)
  20. IF(GLOB_TEMP_VAR)
  21. SET(QT3_INSTALLED TRUE)
  22. ENDIF(GLOB_TEMP_VAR)
  23. SET(GLOB_TEMP_VAR)
  24. FILE(GLOB GLOB_TEMP_VAR /usr/local/qt-x11-commercial-3*/bin/qmake)
  25. IF(GLOB_TEMP_VAR)
  26. SET(QT3_INSTALLED TRUE)
  27. ENDIF(GLOB_TEMP_VAR)
  28. SET(GLOB_TEMP_VAR)
  29. # look for qt4 installations
  30. FILE(GLOB GLOB_TEMP_VAR /usr/local/qt-x11-commercial-4*/bin/qmake)
  31. IF(GLOB_TEMP_VAR)
  32. SET(QT4_INSTALLED TRUE)
  33. ENDIF(GLOB_TEMP_VAR)
  34. SET(GLOB_TEMP_VAR)
  35. FILE(GLOB GLOB_TEMP_VAR /usr/local/Trolltech/Qt-4*/bin/qmake)
  36. IF(GLOB_TEMP_VAR)
  37. SET(QT4_INSTALLED TRUE)
  38. ENDIF(GLOB_TEMP_VAR)
  39. SET(GLOB_TEMP_VAR)
  40. # now find qmake
  41. FIND_PROGRAM(QT_QMAKE_EXECUTABLE_FINDQT NAMES qmake PATHS "${QT_SEARCH_PATH}/bin" "$ENV{QTDIR}/bin")
  42. IF(QT_QMAKE_EXECUTABLE_FINDQT)
  43. EXEC_PROGRAM(${QT_QMAKE_EXECUTABLE_FINDQT} ARGS "-query QT_VERSION"
  44. OUTPUT_VARIABLE QTVERSION)
  45. IF(QTVERSION MATCHES "4.*")
  46. SET(QT4_INSTALLED TRUE)
  47. ENDIF(QTVERSION MATCHES "4.*")
  48. IF(QTVERSION MATCHES "Unknown")
  49. SET(QT3_INSTALLED TRUE)
  50. ENDIF(QTVERSION MATCHES "Unknown")
  51. ENDIF(QT_QMAKE_EXECUTABLE_FINDQT)
  52. IF(QT_QMAKE_EXECUTABLE_FINDQT)
  53. EXEC_PROGRAM( ${QT_QMAKE_EXECUTABLE_FINDQT}
  54. ARGS "-query QT_INSTALL_HEADERS"
  55. OUTPUT_VARIABLE qt_headers )
  56. ENDIF(QT_QMAKE_EXECUTABLE)
  57. FIND_FILE( QT4_QGLOBAL_H_FILE qglobal.h
  58. "${QT_SEARCH_PATH}/Qt/include"
  59. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\4.0.0;InstallDir]/include/Qt"
  60. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Versions\\4.0.0;InstallDir]/include/Qt"
  61. ${qt_headers}/Qt
  62. $ENV{QTDIR}/include/Qt
  63. /usr/local/qt/include/Qt
  64. /usr/local/include/Qt
  65. /usr/lib/qt/include/Qt
  66. /usr/include/Qt
  67. /usr/share/qt4/include/Qt
  68. C:/Progra~1/qt/include/Qt )
  69. IF(QT4_QGLOBAL_H_FILE)
  70. SET(QT4_INSTALLED TRUE)
  71. ENDIF(QT4_QGLOBAL_H_FILE)
  72. FIND_FILE( QT3_QGLOBAL_H_FILE qglobal.h
  73. "${QT_SEARCH_PATH}/Qt/include"
  74. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]/include/Qt"
  75. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]/include/Qt"
  76. "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]/include/Qt"
  77. C:/Qt/3.3.3Educational/include
  78. $ENV{QTDIR}/include
  79. /usr/include/qt3/Qt
  80. /usr/local/qt/include
  81. /usr/local/include
  82. /usr/lib/qt/include
  83. /usr/include
  84. /usr/share/qt3/include
  85. C:/Progra~1/qt/include
  86. /usr/include/qt3 )
  87. IF(QT3_QGLOBAL_H_FILE)
  88. SET(QT3_INSTALLED TRUE)
  89. ENDIF(QT3_QGLOBAL_H_FILE)
  90. IF(QT3_INSTALLED AND QT4_INSTALLED )
  91. # force user to pick if we have both
  92. SET(DESIRED_QT_VERSION 0 CACHE STRING "Pick a version of QT to use: 3 or 4")
  93. ELSE(QT3_INSTALLED AND QT4_INSTALLED )
  94. # if only one found then pick that one
  95. IF(QT3_INSTALLED)
  96. SET(DESIRED_QT_VERSION 3 CACHE STRING "Pick a version of QT to use: 3 or 4")
  97. ENDIF(QT3_INSTALLED)
  98. IF(QT4_INSTALLED)
  99. SET(DESIRED_QT_VERSION 4 CACHE STRING "Pick a version of QT to use: 3 or 4")
  100. ENDIF(QT4_INSTALLED)
  101. ENDIF(QT3_INSTALLED AND QT4_INSTALLED )
  102. IF(DESIRED_QT_VERSION MATCHES 3)
  103. INCLUDE(FindQt3)
  104. ENDIF(DESIRED_QT_VERSION MATCHES 3)
  105. IF(DESIRED_QT_VERSION MATCHES 4)
  106. INCLUDE(FindQt4)
  107. ENDIF(DESIRED_QT_VERSION MATCHES 4)
  108. IF(NOT QT3_INSTALLED AND NOT QT4_INSTALLED)
  109. IF(QT_REQUIRED)
  110. MESSAGE(SEND_ERROR "CMake was unable to find any QT versions, put qmake in your path, or set QT_QMAKE_EXECUTABLE.")
  111. ENDIF(QT_REQUIRED)
  112. ELSE(NOT QT3_INSTALLED AND NOT QT4_INSTALLED)
  113. IF(NOT QT_FOUND AND NOT DESIRED_QT_VERSION)
  114. IF(QT_REQUIRED)
  115. MESSAGE(SEND_ERROR "Multiple versions of QT found please set DESIRED_QT_VERSION")
  116. ELSE(QT_REQUIRED)
  117. MESSAGE("Multiple versions of QT found please set DESIRED_QT_VERSION")
  118. ENDIF(QT_REQUIRED)
  119. ENDIF(NOT QT_FOUND AND NOT DESIRED_QT_VERSION)
  120. IF(NOT QT_FOUND AND DESIRED_QT_VERSION)
  121. IF(QT_REQUIRED)
  122. MESSAGE(SEND_ERROR "CMake was unable to find QT version: ${DESIRED_QT_VERSION}. Set advanced values QT_QMAKE_EXECUTABLE and QT${DESIRED_QT_VERSION}_QGLOBAL_FILE, if those are set then QT_QT_LIBRARY or QT_LIBRARY_DIR.")
  123. ELSE(QT_REQUIRED)
  124. MESSAGE( "CMake was unable to find desired QT version: ${DESIRED_QT_VERSION}. Set advanced values QT_QMAKE_EXECUTABLE and QT${DESIRED_QT_VERSION}_QGLOBAL_FILE.")
  125. ENDIF(QT_REQUIRED)
  126. ENDIF(NOT QT_FOUND AND DESIRED_QT_VERSION)
  127. ENDIF(NOT QT3_INSTALLED AND NOT QT4_INSTALLED)
  128. MARK_AS_ADVANCED(QT3_QGLOBAL_H_FILE QT4_QGLOBAL_H_FILE QT_QMAKE_EXECUTABLE_FINDQT)