From aa06972a708d3559eae667dd9484edadf722d73c Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Mon, 20 Jun 2016 18:37:43 +0200 Subject: [PATCH 08/22] gr-qtgui: Allow build with Qt4 or Qt5 (default) Signed-off-by: Paul Cercueil --- gr-qtgui/CMakeLists.txt | 27 ++++++++++++++++++++------- gr-qtgui/examples/c++/CMakeLists.txt | 11 ++++++++--- gr-qtgui/include/gnuradio/qtgui/form_menus.h | 4 ++++ gr-qtgui/lib/CMakeLists.txt | 14 ++++++++++---- 4 files changed, 42 insertions(+), 14 deletions(-) --- a/gr-qtgui/CMakeLists.txt +++ b/gr-qtgui/CMakeLists.txt @@ -22,14 +22,27 @@ ######################################################################## include(GrBoost) -find_package(Qt5Widgets) - -find_package(Qwt) - find_package(PythonLibs 2) include(GrPython) -GR_PYTHON_CHECK_MODULE("PyQt5" PyQt5 True PYQT5_FOUND) + +set(DESIRED_QT_VERSION 5 CACHE STRING "The Qt version to use (4 or 5)") +set_property(CACHE DESIRED_QT_VERSION PROPERTY STRINGS 4 5) + +if (DESIRED_QT_VERSION MATCHES 4) + find_package(Qt4 COMPONENTS QtCore QtGui) + set(QT_FOUND ${Qt4_FOUND}) + include(GrSetupQt4) +else() + find_package(Qt5Widgets) + set(QT_FOUND ${Qt5Widgets_FOUND}) + set(QT_LIBRARIES ${Qt5Widgets_LIBRARIES}) + set(QT_INCLUDE_DIRS ${Qt5Widgets_INCLUDE_DIRS}) +endif() + +GR_PYTHON_CHECK_MODULE("PyQt${DESIRED_QT_VERSION}" PyQt${DESIRED_QT_VERSION} True PYQT${DESIRED_QT_VERSION}_FOUND) + +find_package(Qwt) ######################################################################## # Register component @@ -37,13 +50,13 @@ include(GrComponent) if(NOT CMAKE_CROSSCOMPILING) set(qt_gui_python_deps - PYQT5_FOUND + PYQT${DESIRED_QT_VERSION}_FOUND ) endif(NOT CMAKE_CROSSCOMPILING) GR_REGISTER_COMPONENT("gr-qtgui" ENABLE_GR_QTGUI Boost_FOUND - Qt5Widgets_FOUND + QT_FOUND QWT_FOUND ENABLE_VOLK ENABLE_GNURADIO_RUNTIME --- a/gr-qtgui/examples/c++/CMakeLists.txt +++ b/gr-qtgui/examples/c++/CMakeLists.txt @@ -24,7 +24,7 @@ ${GR_BLOCKS_INCLUDE_DIRS} ${GR_FFT_INCLUDE_DIRS} ${GNURADIO_RUNTIME_INCLUDE_DIRS} - ${Qt5Widgets_INCLUDE_DIRS} + ${QT_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ) @@ -36,10 +36,15 @@ gnuradio-fft gnuradio-runtime ${QWT_LIBRARY_DIRS} - ${Qt5Widgets_LIBRARIES} + ${QT_LIBRARIES} ) -QT5_WRAP_CPP(qtgui_moc_sources display_qt.h) +if (${DESIRED_QT_VERSION} MATCHES 4) + QT4_WRAP_CPP(qtgui_moc_sources display_qt.h) +else() + QT5_WRAP_CPP(qtgui_moc_sources display_qt.h) +endif() + add_executable(display_qt display_qt.cc ${qtgui_moc_sources}) target_link_libraries(display_qt ${QTGUI_LIBRARIES}) --- a/gr-qtgui/include/gnuradio/qtgui/form_menus.h +++ b/gr-qtgui/include/gnuradio/qtgui/form_menus.h @@ -28,7 +28,11 @@ #include #include #include + +#if QT_VERSION >= 0x050000 #include +#endif + #include #include #include --- a/gr-qtgui/lib/CMakeLists.txt +++ b/gr-qtgui/lib/CMakeLists.txt @@ -45,8 +45,14 @@ ${qtgui_mod_includedir}/VectorDisplayPlot.h edit_box_msg_impl.h ) -QT5_WRAP_CPP(qtgui_moc_sources ${qtgui_moc_hdrs}) -QT5_WRAP_UI(qtgui_ui_hdrs spectrumdisplayform.ui) + +if (${DESIRED_QT_VERSION} MATCHES 4) + QT4_WRAP_CPP(qtgui_moc_sources ${qtgui_moc_hdrs}) + QT4_WRAP_UI(qtgui_ui_hdrs spectrumdisplayform.ui) +else() + QT5_WRAP_CPP(qtgui_moc_sources ${qtgui_moc_hdrs}) + QT5_WRAP_UI(qtgui_ui_hdrs spectrumdisplayform.ui) +endif() #FIXME the sources expect .ui.h, but the macros generate ui_foo.h #avoid changing the sources by generating the header with the include @@ -127,7 +133,7 @@ ${GNURADIO_RUNTIME_INCLUDE_DIRS} ${VOLK_INCLUDE_DIRS} ${QWT_INCLUDE_DIRS} - ${Qt5Widgets_INCLUDE_DIRS} + ${QT_INCLUDE_DIRS} ${FFTW3F_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS} @@ -154,7 +160,7 @@ gnuradio-filter ${VOLK_LIBRARIES} ${QWT_LIBRARIES} - ${Qt5Widgets_LIBRARIES} + ${QT_LIBRARIES} ${FFTW3F_LIBRARIES} ) if (WIN32)