Skip to content

Commit

Permalink
CMakeLists.txt: adjust cmake build rules for Qt6 support
Browse files Browse the repository at this point in the history
Check for the availability of Qt5 as well as Qt6. Prefer Qt5 for
backwards compatibility, but accept when only Qt6 is available.
This unbreaks Mac OSX 12 builds with homebrew.

This change is based on work that was submitted by Dominik Sliwa
<dominik@sliwa.io>.

It is assumed that failed tests for timestamps to text conversion
(the format_time_minutes() routine) and Qt widgets not being thread
safe are issues that do reproduce more often on the Mac platform
but are independent from Qt6 support. These issues will be dealt with
separately.
  • Loading branch information
depili authored and gsigh committed Nov 30, 2022
1 parent 1ed73eb commit 136995b
Showing 1 changed file with 47 additions and 15 deletions.
62 changes: 47 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,35 @@ pkg_check_modules(PKGDEPS REQUIRED ${PKGDEPS})

set(CMAKE_AUTOMOC TRUE)

find_package(Qt5 5.3 COMPONENTS Core Gui LinguistTools Widgets Svg REQUIRED)

message(STATUS "Qt version: ${Qt5_VERSION}")
# Check for Qt5, and check for Qt6 if Qt5 is not found.
set(QT_COMPONENTS Core Gui LinguistTools Widgets Svg)
find_package(Qt5 5.3 QUIET COMPONENTS Core)
if(Qt5_FOUND)
find_package(Qt5 5.3 COMPONENTS ${QT_COMPONENTS} REQUIRED)
message(STATUS "Qt version: ${Qt5_VERSION}")
else()
find_package(Qt6 6.2 COMPONENTS ${QT_COMPONENTS} REQUIRED)
message(STATUS "Qt version: ${Qt6_VERSION}")
endif()

if(WIN32)
# MXE workaround: Use pkg-config to find Qt5 libs.
# MXE workaround: Use pkg-config to find Qt5 and Qt6 libs.
# https://github.com/mxe/mxe/issues/1642
# Not required (and doesn't work) on MSYS2.
if(NOT DEFINED ENV{MSYSTEM})
pkg_check_modules(QT5ALL REQUIRED Qt5Widgets>=5.3 Qt5Gui>=5.3 Qt5Svg>=5.3)
if(Qt5_FOUND)
pkg_check_modules(QT5ALL REQUIRED Qt5Widgets>=5.3 Qt5Gui>=5.3 Qt5Svg>=5.3)
else()
pkg_check_modules(QT6ALL REQUIRED Qt6Widgets>=6.2 Qt6Gui>=6.2 Qt6Svg>=6.2)
endif()
endif()
endif()

set(QT_LIBRARIES Qt5::Gui Qt5::Widgets Qt5::Svg)
if(Qt5_FOUND)
set(QT_LIBRARIES Qt5::Gui Qt5::Widgets Qt5::Svg)
else()
set(QT_LIBRARIES Qt6::Gui Qt6::Widgets Qt6::Svg)
endif()

set(BOOSTCOMPS filesystem serialization system)
if(ENABLE_TESTS)
Expand Down Expand Up @@ -495,7 +510,11 @@ if(ANDROID)
)
endif()

qt5_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
if(Qt5_FOUND)
qt5_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
else()
qt6_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
endif()

#===============================================================================
#= Translations
Expand All @@ -507,10 +526,17 @@ if (NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
configure_file("translations.qrc" "translations.qrc" COPYONLY)
endif ()

qt5_add_translation(QM_FILES ${TS_FILES})
qt5_create_translation(QM_FILES ${pulseview_SOURCES} ${TS_FILES})
if(Qt5_FOUND)
qt5_add_translation(QM_FILES ${TS_FILES})
qt5_create_translation(QM_FILES ${pulseview_SOURCES} ${TS_FILES})

qt5_add_resources(pulseview_RESOURCES_RCC ${CMAKE_BINARY_DIR}/translations.qrc)
qt5_add_resources(pulseview_RESOURCES_RCC ${CMAKE_BINARY_DIR}/translations.qrc)
else()
qt6_add_translation(QM_FILES ${TS_FILES})
qt6_create_translation(QM_FILES ${pulseview_SOURCES} ${TS_FILES})

qt6_add_resources(pulseview_RESOURCES_RCC ${CMAKE_BINARY_DIR}/translations.qrc)
endif()

#===============================================================================
#= Global Definitions
Expand Down Expand Up @@ -592,12 +618,18 @@ if(WIN32)
# We also need QWindowsIntegrationPlugin, Qt5PlatformSupport (only for
# Qt < 5.8.0), and all Qt libs and their dependencies.
add_definitions(-DQT_STATICPLUGIN)
list(APPEND PULSEVIEW_LINK_LIBS Qt5::QSvgPlugin)
list(APPEND PULSEVIEW_LINK_LIBS Qt5::QWindowsIntegrationPlugin)
if(Qt5Gui_VERSION VERSION_LESS 5.8.0)
list(APPEND PULSEVIEW_LINK_LIBS -lQt5PlatformSupport)
if(Qt5_FOUND)
list(APPEND PULSEVIEW_LINK_LIBS Qt5::QSvgPlugin)
list(APPEND PULSEVIEW_LINK_LIBS Qt5::QWindowsIntegrationPlugin)
if(Qt5Gui_VERSION VERSION_LESS 5.8.0)
list(APPEND PULSEVIEW_LINK_LIBS -lQt5PlatformSupport)
endif()
list(APPEND PULSEVIEW_LINK_LIBS ${QT5ALL_LDFLAGS})
else()
list(APPEND PULSEVIEW_LINK_LIBS Qt6::QSvgPlugin)
list(APPEND PULSEVIEW_LINK_LIBS Qt6::QWindowsIntegrationPlugin)
list(APPEND PULSEVIEW_LINK_LIBS ${QT6ALL_LDFLAGS})
endif()
list(APPEND PULSEVIEW_LINK_LIBS ${QT5ALL_LDFLAGS})
endif()

if(ENABLE_STACKTRACE)
Expand Down

0 comments on commit 136995b

Please sign in to comment.