The Trinity Qt Interface
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ConfigureChecks.cmake 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. #################################################
  2. #
  3. # (C) 2010-2011 Serghei Amelian
  4. # serghei (DOT) amelian (AT) gmail.com
  5. #
  6. # Improvements and feedback are welcome
  7. #
  8. # This file is released under GPL >= 2
  9. #
  10. #################################################
  11. macro( qt_message )
  12. message( STATUS "${ARGN}" )
  13. endmacro( )
  14. if( (WITH_QT3 OR USE_QT3) AND (WITH_QT4 OR USE_QT4) )
  15. tde_message_fatal( "Options WITH_QT3 and WITH_QT4 are mutually exclusive." )
  16. endif( )
  17. if( WITH_QT3 OR USE_QT3 )
  18. set( QT_VERSION "3" )
  19. elseif( WITH_QT4 OR USE_QT4 )
  20. set( QT_VERSION "4" )
  21. message( AUTHOR_WARNING
  22. " ------------------------------------------------------------- \n"
  23. " *** NOTE *** \n"
  24. " \n"
  25. " The code for the TQt interface based on Qt4 is not maintained \n"
  26. " and the result can cause unexpected problems.\n"
  27. " \n"
  28. " It is not recommended to build a TQt interface based on Qt4!\n"
  29. " ------------------------------------------------------------- \n"
  30. )
  31. endif()
  32. if( NOT DEFINED QT_VERSION )
  33. tde_message_fatal( "You must select a Qt version, like this:\n \n cmake -DQT_VERSION=3 [arguments...]\n or\n cmake -DUSE_QT3=ON [arguments...]" )
  34. endif( )
  35. if( NOT (QT_VERSION STREQUAL "3" OR QT_VERSION STREQUAL "4") )
  36. tde_message_fatal( "You have chosen an invalid version.\n QT_VERSION should be 3 or 4." )
  37. else( )
  38. qt_message( "Checking for Qt${QT_VERSION}..." )
  39. endif( )
  40. # qt prefix directory
  41. if( NOT DEFINED QT_PREFIX_DIR )
  42. if( NOT $ENV{TQTDIR} STREQUAL "" AND QT_VERSION STREQUAL "3" )
  43. set( QT_PREFIX_DIR "$ENV{TQTDIR}" )
  44. qt_message( " QT_PREFIX_DIR is set to TQTDIR" )
  45. else( )
  46. set( QT_PREFIX_DIR "/usr" )
  47. endif( )
  48. endif( )
  49. qt_message( " QT_PREFIX_DIR : ${QT_PREFIX_DIR}" )
  50. # qt headers
  51. if( NOT DEFINED TQT_INCLUDE_DIR )
  52. if( QT_PREFIX_DIR STREQUAL "/usr" )
  53. if( EXISTS "${QT_PREFIX_DIR}/include/tqt${QT_VERSION}" )
  54. set( TQT_INCLUDE_DIR "${QT_PREFIX_DIR}/include/tqt${QT_VERSION}" )
  55. else( )
  56. set( TQT_INCLUDE_DIR "${QT_PREFIX_DIR}/include/qt${QT_VERSION}" )
  57. endif( )
  58. else( )
  59. set( TQT_INCLUDE_DIR "${QT_PREFIX_DIR}/include" )
  60. endif( )
  61. endif( )
  62. qt_message( " TQT_INCLUDE_DIR: ${TQT_INCLUDE_DIR}" )
  63. # detect native tqt
  64. if( EXISTS "${TQT_INCLUDE_DIR}/ntqglobal.h" )
  65. set( HAVE_REAL_TQT ON CACHE BOOL "Native TQt3 detected" )
  66. qt_message( "Native TQt3 detected" )
  67. else( )
  68. qt_message( "Qt3 detected" )
  69. endif( )
  70. # qt library path
  71. if( NOT DEFINED TQT_LIBRARY_DIR )
  72. set( TQT_LIBRARY_DIR "${QT_PREFIX_DIR}/lib${LIB_SUFFIX}" )
  73. if( QT_VERSION STREQUAL "4" )
  74. if( NOT EXISTS "${TQT_LIBRARY_DIR}/libQtGui.so" )
  75. if( EXISTS "${TQT_LIBRARY_DIR}/qt4/libQtGui.so" )
  76. set( TQT_LIBRARY_DIR "${QT_PREFIX_DIR}/lib${LIB_SUFFIX}/qt4" )
  77. endif( )
  78. endif( )
  79. endif( )
  80. endif( )
  81. qt_message( " TQT_LIBRARY_DIR: ${TQT_LIBRARY_DIR}" )
  82. # qt library name
  83. if( NOT DEFINED TQT_LIBRARIES )
  84. if( QT_VERSION STREQUAL "3" )
  85. set( TQT_LIBRARIES qt-mt )
  86. elseif( QT_VERSION STREQUAL "4" )
  87. set( TQT_LIBRARIES QtCore QtGui )
  88. endif( )
  89. endif( )
  90. # qt tools
  91. if( NOT DEFINED QT_BINARY_DIR )
  92. set( QT_BINARY_DIR "${QT_PREFIX_DIR}/bin" )
  93. endif( )
  94. qt_message( " QT_BINARY_DIR : ${QT_BINARY_DIR}" )
  95. # find moc
  96. if( DEFINED MOC_EXECUTABLE )
  97. if( IS_DIRECTORY "${MOC_EXECUTABLE}" OR NOT EXISTS "${MOC_EXECUTABLE}" )
  98. tde_message_fatal( "moc was NOT found.\n MOC_EXECUTABLE may not be set correctly." )
  99. endif( )
  100. else( )
  101. if( QT_VERSION STREQUAL "3" )
  102. find_program( MOC_EXECUTABLE NAMES tqmoc moc-qt3 moc HINTS "${QT_BINARY_DIR}" )
  103. elseif( QT_VERSION STREQUAL "4" )
  104. find_program( MOC_EXECUTABLE NAMES moc-qt4 moc HINTS "${QT_BINARY_DIR}" )
  105. endif( )
  106. if( NOT MOC_EXECUTABLE )
  107. tde_message_fatal( "moc was NOT found.\n Please check if your Qt${QT_VERSION} is correctly installed." )
  108. endif( )
  109. endif( )
  110. # attempt to run moc, to check which qt version is using
  111. execute_process( COMMAND ${MOC_EXECUTABLE} -v ERROR_VARIABLE __output
  112. RESULT_VARIABLE __result ERROR_STRIP_TRAILING_WHITESPACE )
  113. if( __result EQUAL 1 )
  114. string( REGEX MATCH "^.*Qt (.+)\\)$" __dummy "${__output}" )
  115. set( __version "${CMAKE_MATCH_1}" )
  116. if( NOT __version )
  117. tde_message_fatal( "Invalid response from moc:\n ${__output}" )
  118. endif( )
  119. else( )
  120. tde_message_fatal( "Unable to run moc!\n Qt${VERSION} are correctly installed?\n LD_LIBRARY_PATH are correctly set?" )
  121. endif( )
  122. qt_message( " MOC_EXECUTABLE: ${MOC_EXECUTABLE} (using Qt ${CMAKE_MATCH_1})" )
  123. if( QT_VERSION STREQUAL "3" AND NOT "${CMAKE_MATCH_1}" VERSION_LESS "4" )
  124. tde_message_fatal( "Strange, you want Qt3, but your moc using Qt4." )
  125. elseif( QT_VERSION STREQUAL "4" AND "${CMAKE_MATCH_1}" VERSION_LESS "4" )
  126. tde_message_fatal( "Strange, you want Qt4, but your moc using Qt3." )
  127. endif( )
  128. # find uic (only for Qt3)
  129. if( QT_VERSION STREQUAL "3" )
  130. if( DEFINED UIC_EXECUTABLE )
  131. if( IS_DIRECTORY "${UIC_EXECUTABLE}" OR NOT EXISTS "${UIC_EXECUTABLE}" )
  132. tde_message_fatal( "uic was NOT found.\n MOC_EXECUTABLE may not be set correctly" )
  133. endif( )
  134. else( )
  135. find_program( UIC_EXECUTABLE NAMES tquic uic-qt3 uic HINTS "${QT_BINARY_DIR}" )
  136. if( NOT UIC_EXECUTABLE )
  137. tde_message_fatal( "uic was NOT found.\n Please check if your Qt${QT_VERSION} is correctly installed." )
  138. endif( )
  139. endif( )
  140. qt_message( " UIC_EXECUTABLE: ${UIC_EXECUTABLE}" )
  141. endif( )
  142. # definitions
  143. if( QT_VERSION STREQUAL "3" )
  144. if( HAVE_REAL_TQT )
  145. set( QT_DEFINITIONS "-DTQT_NO_ASCII_CAST -DTQT_NO_STL -DTQT_NO_COMPAT -DTQT_NO_TRANSLATION -DTQT_THREAD_SUPPORT -D_REENTRANT" )
  146. else( )
  147. set( QT_DEFINITIONS "-DQT_NO_ASCII_CAST -DQT_NO_STL -DQT_NO_COMPAT -DQT_NO_TRANSLATION -DQT_THREAD_SUPPORT -D_REENTRANT" )
  148. endif( )
  149. elseif( QT_VERSION STREQUAL "4" )
  150. set( QT_DEFINITIONS "-DQT_NO_ASCII_CAST -DQT_NO_STL -DQT_NO_COMPAT -DQT_NO_TRANSLATION -DQT_THREAD_SUPPORT -D_REENTRANT" )
  151. endif( )
  152. tde_save( CMAKE_REQUIRED_INCLUDES CMAKE_REQUIRED_LIBRARIES )
  153. set( CMAKE_REQUIRED_INCLUDES ${TQT_INCLUDE_DIR} )
  154. set( CMAKE_REQUIRED_LIBRARIES -L${TQT_LIBRARY_DIR} ${TQT_LIBRARIES} )
  155. # check if Qt3 is usable
  156. if( QT_VERSION STREQUAL "3" )
  157. check_cxx_source_compiles("
  158. #include <qapplication.h>
  159. int main(int argc, char **argv) { QApplication app(argc, argv); return 0; } "
  160. HAVE_USABLE_QT${QT_VERSION} )
  161. if( NOT HAVE_USABLE_QT${QT_VERSION} )
  162. # Unset the Qt detection variable
  163. unset( HAVE_USABLE_QT${QT_VERSION} CACHE )
  164. # Reset libraries
  165. set( TQT_LIBRARIES tqt-mt )
  166. set( CMAKE_REQUIRED_LIBRARIES -L${TQT_LIBRARY_DIR} ${TQT_LIBRARIES} )
  167. qt_message( "Looking for native TQt3..." )
  168. check_cxx_source_compiles("
  169. #include <ntqapplication.h>
  170. int main(int argc, char **argv) { TQApplication app(argc, argv); return 0; } "
  171. HAVE_USABLE_QT${QT_VERSION} )
  172. endif( )
  173. # check if Qt4 is usable
  174. elseif( QT_VERSION STREQUAL "4" )
  175. check_cxx_source_compiles("
  176. #include <QtGui/QApplication>
  177. int main(int argc, char **argv) { QApplication app(argc, argv); return 0; } "
  178. HAVE_USABLE_QT${QT_VERSION} )
  179. endif( )
  180. if( NOT HAVE_USABLE_QT${QT_VERSION} )
  181. tde_message_fatal( "Unable to build a simple Qt${QT_VERSION} test." )
  182. endif( )
  183. # check if Qt3 is patched for compatibility with TQt
  184. if( QT_VERSION STREQUAL "3" )
  185. check_cxx_source_compiles("
  186. #include <qobjectlist.h>
  187. #include <qobject.h>
  188. int main(int, char**) { QObject::objectTreesListObject(); return 0; } "
  189. HAVE_PATCHED_QT3 )
  190. if( NOT HAVE_PATCHED_QT3 )
  191. # Unset the Qt detection variable
  192. unset( HAVE_PATCHED_QT3 CACHE )
  193. # Reset libraries
  194. set( TQT_LIBRARIES tqt-mt )
  195. set( CMAKE_REQUIRED_LIBRARIES -L${TQT_LIBRARY_DIR} ${TQT_LIBRARIES} )
  196. qt_message( "Looking for patched native TQt3..." )
  197. check_cxx_source_compiles("
  198. #include <ntqobjectlist.h>
  199. #include <ntqobject.h>
  200. int main(int, char**) { TQObject::objectTreesListObject(); return 0; } "
  201. HAVE_PATCHED_QT3 )
  202. endif( )
  203. if( NOT HAVE_PATCHED_QT3 )
  204. tde_message_fatal( "Your Qt3 is not patched for compatibility with tqtinterface." )
  205. endif( )
  206. endif( )
  207. tde_restore( CMAKE_REQUIRED_INCLUDES CMAKE_REQUIRED_LIBRARIES )