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.

200 lines
6.4KB

  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{QTDIR} STREQUAL "" AND QT_VERSION STREQUAL "3" )
  43. set( QT_PREFIX_DIR "$ENV{QTDIR}" )
  44. qt_message( " QT_PREFIX_DIR is set to QTDIR" )
  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 QT_INCLUDE_DIR )
  52. if( QT_PREFIX_DIR STREQUAL "/usr" )
  53. set( QT_INCLUDE_DIR "${QT_PREFIX_DIR}/include/qt${QT_VERSION}" )
  54. else( )
  55. set( QT_INCLUDE_DIR "${QT_PREFIX_DIR}/include" )
  56. endif( )
  57. endif( )
  58. qt_message( " QT_INCLUDE_DIR: ${QT_INCLUDE_DIR}" )
  59. # qt library path
  60. if( NOT DEFINED QT_LIBRARY_DIR )
  61. set( QT_LIBRARY_DIR "${QT_PREFIX_DIR}/lib${LIB_SUFFIX}" )
  62. if( QT_VERSION STREQUAL "4" )
  63. if( NOT EXISTS "${QT_LIBRARY_DIR}/libQtGui.so" )
  64. if( EXISTS "${QT_LIBRARY_DIR}/qt4/libQtGui.so" )
  65. set( QT_LIBRARY_DIR "${QT_PREFIX_DIR}/lib${LIB_SUFFIX}/qt4" )
  66. endif( )
  67. endif( )
  68. endif( )
  69. endif( )
  70. qt_message( " QT_LIBRARY_DIR: ${QT_LIBRARY_DIR}" )
  71. # qt library name
  72. if( NOT DEFINED QT_LIBRARIES )
  73. if( QT_VERSION STREQUAL "3" )
  74. set( QT_LIBRARIES qt-mt )
  75. elseif( QT_VERSION STREQUAL "4" )
  76. set( QT_LIBRARIES QtCore QtGui )
  77. endif( )
  78. endif( )
  79. # qt tools
  80. if( NOT DEFINED QT_BINARY_DIR )
  81. set( QT_BINARY_DIR "${QT_PREFIX_DIR}/bin" )
  82. endif( )
  83. qt_message( " QT_BINARY_DIR : ${QT_BINARY_DIR}" )
  84. # find moc
  85. if( DEFINED MOC_EXECUTABLE )
  86. if( IS_DIRECTORY "${MOC_EXECUTABLE}" OR NOT EXISTS "${MOC_EXECUTABLE}" )
  87. tde_message_fatal( "moc was NOT found.\n MOC_EXECUTABLE may not be set correctly." )
  88. endif( )
  89. else( )
  90. if( QT_VERSION STREQUAL "3" )
  91. find_program( MOC_EXECUTABLE NAMES moc-qt3 moc HINTS "${QT_BINARY_DIR}" )
  92. elseif( QT_VERSION STREQUAL "4" )
  93. find_program( MOC_EXECUTABLE NAMES moc-qt4 moc HINTS "${QT_BINARY_DIR}" )
  94. endif( )
  95. if( NOT MOC_EXECUTABLE )
  96. tde_message_fatal( "moc was NOT found.\n Please check if your Qt${QT_VERSION} is correctly installed." )
  97. endif( )
  98. endif( )
  99. # attempt to run moc, to check which qt version is using
  100. execute_process( COMMAND ${MOC_EXECUTABLE} -v ERROR_VARIABLE __output
  101. RESULT_VARIABLE __result ERROR_STRIP_TRAILING_WHITESPACE )
  102. if( __result EQUAL 1 )
  103. string( REGEX MATCH "^.*Qt (.+)\\)$" __dummy "${__output}" )
  104. set( __version "${CMAKE_MATCH_1}" )
  105. if( NOT __version )
  106. tde_message_fatal( "Invalid response from moc:\n ${__output}" )
  107. endif( )
  108. else( )
  109. tde_message_fatal( "Unable to run moc!\n Qt${VERSION} are correctly installed?\n LD_LIBRARY_PATH are correctly set?" )
  110. endif( )
  111. qt_message( " MOC_EXECUTABLE: ${MOC_EXECUTABLE} (using Qt ${CMAKE_MATCH_1})" )
  112. if( QT_VERSION STREQUAL "3" AND NOT "${CMAKE_MATCH_1}" VERSION_LESS "4" )
  113. tde_message_fatal( "Strange, you want Qt3, but your moc using Qt4." )
  114. elseif( QT_VERSION STREQUAL "4" AND "${CMAKE_MATCH_1}" VERSION_LESS "4" )
  115. tde_message_fatal( "Strange, you want Qt4, but your moc using Qt3." )
  116. endif( )
  117. # find uic (only for Qt3)
  118. if( QT_VERSION STREQUAL "3" )
  119. if( DEFINED UIC_EXECUTABLE )
  120. if( IS_DIRECTORY "${UIC_EXECUTABLE}" OR NOT EXISTS "${UIC_EXECUTABLE}" )
  121. tde_message_fatal( "uic was NOT found.\n MOC_EXECUTABLE may not be set correctly" )
  122. endif( )
  123. else( )
  124. find_program( UIC_EXECUTABLE NAMES uic-qt3 uic HINTS "${QT_BINARY_DIR}" )
  125. if( NOT UIC_EXECUTABLE )
  126. tde_message_fatal( "uic was NOT found.\n Please check if your Qt${QT_VERSION} is correctly installed." )
  127. endif( )
  128. endif( )
  129. qt_message( " UIC_EXECUTABLE: ${UIC_EXECUTABLE}" )
  130. endif( )
  131. # definitions
  132. if( QT_VERSION STREQUAL "3" )
  133. set( QT_DEFINITIONS "-DQT_NO_ASCII_CAST -DQT_CLEAN_NAMESPACE -DQT_NO_STL -DQT_NO_COMPAT -DQT_NO_TRANSLATION -DQT_THREAD_SUPPORT -D_REENTRANT" )
  134. elseif( QT_VERSION STREQUAL "4" )
  135. set( QT_DEFINITIONS "-DQT_NO_ASCII_CAST -DQT_CLEAN_NAMESPACE -DQT_NO_STL -DQT_NO_COMPAT -DQT_NO_TRANSLATION -DQT_THREAD_SUPPORT -D_REENTRANT" )
  136. endif( )
  137. tde_save( CMAKE_REQUIRED_INCLUDES CMAKE_REQUIRED_LIBRARIES )
  138. set( CMAKE_REQUIRED_INCLUDES ${QT_INCLUDE_DIR} )
  139. set( CMAKE_REQUIRED_LIBRARIES -L${QT_LIBRARY_DIR} ${QT_LIBRARIES} )
  140. # check if Qt3 is usable
  141. if( QT_VERSION STREQUAL "3" )
  142. check_cxx_source_compiles("
  143. #include <qapplication.h>
  144. int main(int argc, char **argv) { QApplication app(argc, argv); return 0; } "
  145. HAVE_USABLE_QT${QT_VERSION} )
  146. # check if Qt4 is usable
  147. elseif( QT_VERSION STREQUAL "4" )
  148. check_cxx_source_compiles("
  149. #include <QtGui/QApplication>
  150. int main(int argc, char **argv) { QApplication app(argc, argv); return 0; } "
  151. HAVE_USABLE_QT${QT_VERSION} )
  152. endif( )
  153. if( NOT HAVE_USABLE_QT${QT_VERSION} )
  154. tde_message_fatal( "Unable to build a simple Qt${QT_VERSION} test." )
  155. endif( )
  156. # check if Qt3 is patched for compatibility with TQt
  157. if( QT_VERSION STREQUAL "3" )
  158. check_cxx_source_compiles("
  159. #include <qobjectlist.h>
  160. #include <qobject.h>
  161. int main(int, char**) { QObject::objectTreesListObject(); return 0; } "
  162. HAVE_PATCHED_QT3 )
  163. if( NOT HAVE_PATCHED_QT3 )
  164. tde_message_fatal( "Your Qt3 is not patched for compatibility with tqtinterface." )
  165. endif( )
  166. endif( )
  167. tde_restore( CMAKE_REQUIRED_INCLUDES CMAKE_REQUIRED_LIBRARIES )