From 1490f9ea119dba0c29fa193619ade3ef4eda2ad5 Mon Sep 17 00:00:00 2001 From: samelian Date: Sun, 27 Mar 2011 21:56:52 +0000 Subject: [PATCH] [cmake] reworked tqtinterface build system git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kde-common@1226235 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- cmake/modules/FindQt.cmake | 213 ------------------------------ cmake/modules/FindTDE.cmake | 2 +- cmake/modules/FindTQt.cmake | 95 ++++++++----- cmake/modules/TDEMacros.cmake | 12 +- cmake/modules/TDESetupPaths.cmake | 2 +- cmake/modules/tde_uic.cmake | 6 +- 6 files changed, 73 insertions(+), 257 deletions(-) delete mode 100644 cmake/modules/FindQt.cmake diff --git a/cmake/modules/FindQt.cmake b/cmake/modules/FindQt.cmake deleted file mode 100644 index 3aa2b5b..0000000 --- a/cmake/modules/FindQt.cmake +++ /dev/null @@ -1,213 +0,0 @@ -################################################# -# -# (C) 2010 Serghei Amelian -# serghei (DOT) amelian (AT) gmail.com -# -# Improvements and feedback are welcome -# -# This file is released under GPL >= 2 -# -################################################# - -macro( __tde_internal_find_qt_program __progname __output ) - find_program( ${__output} - NAMES ${__progname} - HINTS ${QTDIR}/bin $ENV{QTDIR}/bin - PATHS ${BINDIR} ) - if( NOT ${__output} ) - tde_message_fatal( "${__progname} are NOT found.\n Please check if Qt are correctly installed." ) - endif( NOT ${__output} ) -endmacro( __tde_internal_find_qt_program ) - -option( AUTODETECT_QT_DIRS "Attempt to autodetect Qt location and version [EXPERIMENTAL]" OFF ) -option( WITH_QT3 "Use TQt for Qt3" ON ) -option( WITH_QT4 "Use TQt for Qt4 [EXPERIMENTAL]" OFF ) - -if( NOT QT_FOUND ) - -# See if TQt for Qt4 is available -# HACK HACK HACK -# This detection relies on the fact that TQt for Qt3 utilizes TQt.pc, -# whereas TQt for Qt4 utilizes tqt.pc -# Please find a better way to do this! -pkg_search_module( TQT tqt ) - -if( TQT_FOUND ) - set( WITH_QT3 "OFF" ) - set (WITH_QT4 "ON" ) -endif() - -if( WITH_QT4 ) - # Set a default if not manually set - if ( NOT QT_INCLUDE_DIRS ) - set( QT_INCLUDE_DIRS "/usr/include/qt4" ) - endif ( NOT QT_INCLUDE_DIRS ) - if ( NOT QT_LIBRARY_DIRS ) - set( QT_LIBRARY_DIRS "/usr/lib" ) - endif ( NOT QT_LIBRARY_DIRS ) - - # we search for moc only if is not already set (by user or previous run of cmake) - if( NOT QT_MOC_EXECUTABLE ) - __tde_internal_find_qt_program( moc QT_MOC_EXECUTABLE ) - endif( NOT QT_MOC_EXECUTABLE ) - - message( STATUS "checking for 'Qt4'") - - # we run moc, to check which qt version is using - execute_process( - COMMAND ${QT_MOC_EXECUTABLE} -v - ERROR_VARIABLE __output - RESULT_VARIABLE __result - ERROR_STRIP_TRAILING_WHITESPACE ) - - # parse moc response, to extract Qt version - if( __result EQUAL 1 ) - string( REGEX MATCH "^.*Qt (.+)\\)$" __dummy "${__output}" ) - set( __version "${CMAKE_MATCH_1}" ) - if( NOT __version ) - tde_message_fatal( "Invalid response from moc:\n ${__output}" ) - endif( NOT __version ) - else( __result EQUAL 1 ) - tde_message_fatal( "Unable to run moc!\n Qt are correctly installed?\n LD_LIBRARY_PATH are correctly set?" ) - endif( __result EQUAL 1 ) - - # search for uic - __tde_internal_find_qt_program( uic-tqt QT_UIC_EXECUTABLE ) - - # try to find path to qt.h - # we assume that this path is Qt's include path - find_path( QT_INCLUDE_DIRS Qt/qconfig.h - ${QT_INCLUDE_DIRS} - ${QTDIR}/include - $ENV{QTDIR}/include ) - - if( NOT QT_INCLUDE_DIRS ) - - tde_message_fatal( - "Unable to find qconfig.h! - Qt are correctly installed? - Try to set QT_INCLUDE_DIRS manually. - Example: cmake -DQT_INCLUDE_DIRS=/usr/qt/4/include" ) - - endif( NOT QT_INCLUDE_DIRS ) - - # try to find libQtCore.so - # we assume that this is Qt's libraries path - find_path( QT_LIBRARY_DIRS libQtCore.so - ${QT_LIBRARY_DIRS} - ${QTDIR}/lib - $ENV{QTDIR}/lib ) - - if( NOT QT_LIBRARY_DIRS ) - - tde_message_fatal( - "Unable to find libQtCore.so! - Qt are correctly installed? - Try to set QT_LIBRARY_DIRS manually. - Example: cmake -DQT_LIBRARY_DIRS=/usr/qt/4/lib" ) - - endif( NOT QT_LIBRARY_DIRS ) - - message( STATUS " found Qt, version ${__version}" ) - include_directories( ${QT_INCLUDE_DIRS} ) - set( QT_FOUND true CACHE INTERNAL QT_FOUND FORCE ) - set( QT_LIBRARIES "QtCore QtGui" CACHE INTERNAL QT_LIBRARIES FORCE ) - set( QT_DEFINITIONS "-DQT_NO_ASCII_CAST -DQT_CLEAN_NAMESPACE -DQT_NO_STL -DQT_NO_COMPAT -DQT_NO_TRANSLATION -DQT_THREAD_SUPPORT -D_REENTRANT" CACHE INTERNAL QT_DEFINITIONS FORCE ) - -endif( WITH_QT4 ) - -if( WITH_QT3 ) - # Set a default if not manually set - if ( AUTODETECT_QT_DIRS ) - if ( NOT QT_INCLUDE_DIRS ) - set( QT_INCLUDE_DIRS "/usr/include/qt3" ) - endif ( NOT QT_INCLUDE_DIRS ) - if ( NOT QT_LIBRARY_DIRS ) - set( QT_LIBRARY_DIRS "/usr/lib" ) - endif ( NOT QT_LIBRARY_DIRS ) - endif ( AUTODETECT_QT_DIRS ) - - # we search for moc only if is not already set (by user or previous run of cmake) - if( NOT QT_MOC_EXECUTABLE ) - __tde_internal_find_qt_program( moc QT_MOC_EXECUTABLE ) - endif( NOT QT_MOC_EXECUTABLE ) - - message( STATUS "checking for 'Qt3'") - - # we run moc, to check which qt version is using - execute_process( - COMMAND ${QT_MOC_EXECUTABLE} -v - ERROR_VARIABLE __output - RESULT_VARIABLE __result - ERROR_STRIP_TRAILING_WHITESPACE ) - - # parse moc response, to extract Qt version - if( __result EQUAL 1 ) - string( REGEX MATCH "^.*Qt (.+)\\)$" __dummy "${__output}" ) - set( __version "${CMAKE_MATCH_1}" ) - if( NOT __version ) - tde_message_fatal( "Invalid response from moc:\n ${__output}" ) - endif( NOT __version ) - else( __result EQUAL 1 ) - tde_message_fatal( "Unable to run moc!\n Qt are correctly installed?\n LD_LIBRARY_PATH are correctly set?" ) - endif( __result EQUAL 1 ) - - # search for uic - __tde_internal_find_qt_program( uic QT_UIC_EXECUTABLE ) - - # try to find path to qt.h - # we assume that this path is Qt's include path - find_path( QT_INCLUDE_DIRS qt.h - ${QT_INCLUDE_DIRS} - ${QTDIR}/include - $ENV{QTDIR}/include ) - - if( NOT QT_INCLUDE_DIRS ) - - tde_message_fatal( - "Unable to find qt.h! - Qt are correctly installed? - Try to set QT_INCLUDE_DIRS manually. - Example: cmake -DQT_INCLUDE_DIRS=/usr/qt/3/include" ) - - endif( NOT QT_INCLUDE_DIRS ) - - # try to find libqt-mt.so - # we assume that this is Qt's libraries path - find_path( QT_LIBRARY_DIRS libqt-mt.so - ${QT_LIBRARY_DIRS} - ${QTDIR}/lib - $ENV{QTDIR}/lib ) - - if( NOT QT_LIBRARY_DIRS ) - - tde_message_fatal( - "Unable to find libqt-mt.so! - Qt are correctly installed? - Try to set QT_LIBRARY_DIRS manually. - Example: cmake -DQT_LIBRARY_DIRS=/usr/qt/3/lib" ) - - endif( NOT QT_LIBRARY_DIRS ) - - # check if Qt3 is patched for compatibility with TQt - tde_save( CMAKE_REQUIRED_INCLUDES CMAKE_REQUIRED_LIBRARIES ) - set( CMAKE_REQUIRED_INCLUDES ${QT_INCLUDE_DIRS} ) - set( CMAKE_REQUIRED_LIBRARIES -L${QT_LIBRARY_DIRS} qt-mt ) - check_cxx_source_compiles(" - #include - #include - int main(int, char**) { QObject::objectTreesListObject(); return 0; } " - HAVE_PATCHED_QT3 ) - tde_restore( CMAKE_REQUIRED_INCLUDES CMAKE_REQUIRED_LIBRARIES ) - if( NOT HAVE_PATCHED_QT3 ) - tde_message_fatal( "Your Qt3 is not patched for compatibility with tqtinterface" ) - endif() - - message( STATUS " found patched Qt, version ${__version}" ) - set( QT_FOUND true CACHE INTERNAL QT_FOUND FORCE ) - set( QT_LIBRARIES "qt-mt" CACHE INTERNAL QT_LIBRARIES FORCE ) - set( QT_DEFINITIONS "-DQT_NO_ASCII_CAST -DQT_CLEAN_NAMESPACE -DQT_NO_STL -DQT_NO_COMPAT -DQT_NO_TRANSLATION -DQT_THREAD_SUPPORT -D_REENTRANT" CACHE INTERNAL QT_DEFINITIONS FORCE ) - -endif( WITH_QT3 ) - -endif( NOT QT_FOUND ) diff --git a/cmake/modules/FindTDE.cmake b/cmake/modules/FindTDE.cmake index 8809178..ab7592d 100644 --- a/cmake/modules/FindTDE.cmake +++ b/cmake/modules/FindTDE.cmake @@ -1,6 +1,6 @@ ################################################# # -# (C) 2010 Serghei Amelian +# (C) 2010-2011 Serghei Amelian # serghei (DOT) amelian (AT) gmail.com # # Improvements and feedback are welcome diff --git a/cmake/modules/FindTQt.cmake b/cmake/modules/FindTQt.cmake index 9e7d559..657a844 100644 --- a/cmake/modules/FindTQt.cmake +++ b/cmake/modules/FindTQt.cmake @@ -1,6 +1,6 @@ ################################################# # -# (C) 2010 Serghei Amelian +# (C) 2010-2011 Serghei Amelian # serghei (DOT) amelian (AT) gmail.com # # Improvements and feedback are welcome @@ -9,44 +9,73 @@ # ################################################# -if( WITH_QT4 ) +macro( tqt_message ) + message( STATUS "${ARGN}" ) +endmacro( ) -pkg_search_module( TQT tqt ) +pkg_search_module( TQT TQt ) if( NOT TQT_FOUND ) - tde_message_fatal( "Unable to find TQt for Qt4!\n Try adding the directory in which the tqt.pc file is located\nto the PKG_CONFIG_PATH variable." ) -endif() + tde_message_fatal( "Unable to find TQt!\n Try adding the directory in which the TQt.pc file is located\nto the PKG_CONFIG_PATH variable." ) +endif( ) -# under Qt4 the standard moc is used -if( NOT TQT_TMOC_EXECUTABLE ) - find_program( TQT_TMOC_EXECUTABLE - NAMES moc - HINTS ${TQTDIR}/bin $ENV{TQTDIR}/bin - PATHS ${BINDIR} ) -endif( NOT TQT_TMOC_EXECUTABLE ) +# tmoc_executable +execute_process( + COMMAND pkg-config TQt --variable=tmoc_executable + OUTPUT_VARIABLE TMOC_EXECUTABLE OUTPUT_STRIP_TRAILING_WHITESPACE ) -if ( TQT_LIBRARIES ) - set( TQT_LIBRARIES "${TQT_LIBRARIES} -lQtCore -lQtGui" CACHE INTERNAL TQT_LIBRARIES FORCE ) -else ( TQT_LIBRARIES ) - set( TQT_LIBRARIES "QtCore -lQtGui" CACHE INTERNAL TQT_LIBRARIES FORCE ) -endif ( TQT_LIBRARIES ) +if( TMOC_EXECUTABLE ) + tqt_message( " tmoc path: ${TMOC_EXECUTABLE}" ) +else( ) + tde_message_fatal( "Path to tmoc is not set.\n TQt is correctly installed?" ) +endif( ) -endif( WITH_QT4 ) -if( WITH_QT3 ) +# moc_executable +execute_process( + COMMAND pkg-config TQt --variable=moc_executable + OUTPUT_VARIABLE MOC_EXECUTABLE OUTPUT_STRIP_TRAILING_WHITESPACE ) -pkg_search_module( TQT TQt ) +if( MOC_EXECUTABLE ) + tqt_message( " moc path: ${MOC_EXECUTABLE}" ) +else( ) + tde_message_fatal( "Path to moc is not set.\n TQt is correctly installed?" ) +endif( ) -if( NOT TQT_FOUND ) - tde_message_fatal( "Unable to find TQt for Qt3!\n Try adding the directory in which the TQt.pc file is located\nto the PKG_CONFIG_PATH variable." ) -endif() - -# for Qt3, find tmoc, a simple TQt wrapper around the standard moc -if( NOT TQT_TMOC_EXECUTABLE ) - find_program( TQT_TMOC_EXECUTABLE - NAMES tmoc - HINTS ${TQTDIR}/bin $ENV{TQTDIR}/bin - PATHS ${BINDIR} ) -endif( NOT TQT_TMOC_EXECUTABLE ) - -endif( WITH_QT3 ) \ No newline at end of file + +# uic_executable +execute_process( + COMMAND pkg-config TQt --variable=uic_executable + OUTPUT_VARIABLE UIC_EXECUTABLE OUTPUT_STRIP_TRAILING_WHITESPACE ) + +if( UIC_EXECUTABLE ) + tqt_message( " uic path: ${UIC_EXECUTABLE}" ) +else( ) + tde_message_fatal( "Path to uic is not set.\n TQt is correctly installed?" ) +endif( ) + + +# check if TQt is usable +tde_save( CMAKE_REQUIRED_INCLUDES CMAKE_REQUIRED_LIBRARIES ) +set( CMAKE_REQUIRED_INCLUDES ${TQT_INCLUDE_DIRS} ) +foreach( _dirs ${TQT_LIBRARY_DIRS} ) + list( APPEND CMAKE_REQUIRED_LIBRARIES "-L${_dirs}" ) +endforeach() +list( APPEND CMAKE_REQUIRED_LIBRARIES ${TQT_LIBRARIES} ) + +check_cxx_source_compiles(" + #include + int main(int argc, char **argv) { TQApplication app(argc, argv); return 0; } " + HAVE_USABLE_TQT ) + +if( NOT HAVE_USABLE_TQT ) + tde_message_fatal( "Unable to build a simple TQt test." ) +endif( ) + +tde_restore( CMAKE_REQUIRED_INCLUDES CMAKE_REQUIRED_LIBRARIES ) + + +# TQT_CXX_FLAGS +foreach( _flag ${TQT_CFLAGS_OTHER} ) + set( TQT_CXX_FLAGS "${TQT_CXX_FLAGS} ${_flag}" ) +endforeach() diff --git a/cmake/modules/TDEMacros.cmake b/cmake/modules/TDEMacros.cmake index 9474e3c..bbb0cd9 100644 --- a/cmake/modules/TDEMacros.cmake +++ b/cmake/modules/TDEMacros.cmake @@ -1,6 +1,6 @@ ################################################# # -# (C) 2010 Serghei Amelian +# (C) 2010-2011 Serghei Amelian # serghei (DOT) amelian (AT) gmail.com # # Improvements and feedback are welcome @@ -207,11 +207,11 @@ macro( tde_add_ui_files _sources ) add_custom_command( OUTPUT ${_ui_basename}.h ${_ui_basename}.cpp COMMAND ${CMAKE_COMMAND} - -DQT_UIC_EXECUTABLE:FILEPATH=${QT_UIC_EXECUTABLE} + -DUIC_EXECUTABLE:FILEPATH=${UIC_EXECUTABLE} -DTDE_QTPLUGINS_DIR:FILEPATH=${TDE_QTPLUGINS_DIR} -DUI_FILE:FILEPATH=${_ui_absolute_path} -P ${CMAKE_MODULE_PATH}/tde_uic.cmake - COMMAND ${QT_MOC_EXECUTABLE} ${_ui_basename}.h >> ${_ui_basename}.cpp + COMMAND ${MOC_EXECUTABLE} ${_ui_basename}.h >> ${_ui_basename}.cpp DEPENDS ${_ui_absolute_path} ) endforeach( _ui_file ) @@ -227,10 +227,10 @@ macro( tde_moc _sources ) get_filename_component( _input_file "${_input_file}" ABSOLUTE ) get_filename_component( _basename ${_input_file} NAME_WE ) - set( _output_file "${_basename}.moc.cpp" ) + set( _output_file "${_basename}.moc" ) add_custom_command( OUTPUT ${_output_file} COMMAND - ${TQT_TMOC_EXECUTABLE} ${_input_file} -o ${_output_file} + ${TMOC_EXECUTABLE} ${_input_file} -o ${_output_file} DEPENDS ${_input_file} ) list( APPEND ${_sources} ${_output_file} ) @@ -286,7 +286,7 @@ macro( tde_automoc ) # moc-ing header add_custom_command( OUTPUT ${_moc_file} - COMMAND ${TQT_TMOC_EXECUTABLE} ${_header_file} -o ${_moc_file} + COMMAND ${TMOC_EXECUTABLE} ${_header_file} -o ${_moc_file} DEPENDS ${_header_file} ) # create dependency between source file and moc file diff --git a/cmake/modules/TDESetupPaths.cmake b/cmake/modules/TDESetupPaths.cmake index b717118..409a7b9 100644 --- a/cmake/modules/TDESetupPaths.cmake +++ b/cmake/modules/TDESetupPaths.cmake @@ -1,6 +1,6 @@ ################################################# # -# (C) 2010 Serghei Amelian +# (C) 2010-2011 Serghei Amelian # serghei (DOT) amelian (AT) gmail.com # # Improvements and feedback are welcome diff --git a/cmake/modules/tde_uic.cmake b/cmake/modules/tde_uic.cmake index 9f04776..a545828 100644 --- a/cmake/modules/tde_uic.cmake +++ b/cmake/modules/tde_uic.cmake @@ -1,6 +1,6 @@ ################################################# # -# (C) 2010 Serghei Amelian +# (C) 2010-2011 Serghei Amelian # serghei (DOT) amelian (AT) gmail.com # # Improvements and feedback are welcome @@ -16,7 +16,7 @@ set( local_ui_file ${_ui_basename}.ui ) configure_file( ${UI_FILE} ${local_ui_file} COPYONLY ) execute_process( COMMAND tqt-replace ${local_ui_file} ) -execute_process( COMMAND ${QT_UIC_EXECUTABLE} +execute_process( COMMAND ${UIC_EXECUTABLE} -nounload -tr tr2i18n ${local_ui_file} OUTPUT_VARIABLE _ui_h_content ) @@ -31,7 +31,7 @@ if( TDE_QTPLUGINS_DIR ) set( L -L ${TDE_QTPLUGINS_DIR} ) endif( ) -execute_process( COMMAND ${QT_UIC_EXECUTABLE} +execute_process( COMMAND ${UIC_EXECUTABLE} -nounload -tr tr2i18n ${L} -impl ${_ui_basename}.h