]> sigrok.org Git - pulseview.git/blobdiff - CMakeLists.txt
Session: Fix issue #67 by improving error handling
[pulseview.git] / CMakeLists.txt
index 9fd2e9a3cd2d4af6df624d5e594ba2faae22303c..ec86073dcf956eb97fc03345f95e0b95abbcca70 100644 (file)
@@ -48,6 +48,7 @@ option(ENABLE_DECODE "Build with libsigrokdecode" TRUE)
 option(ENABLE_FLOW "Build with libsigrokflow" FALSE)
 option(ENABLE_TESTS "Enable unit tests" FALSE)
 option(STATIC_PKGDEPS_LIBS "Statically link to (pkg-config) libraries" FALSE)
+option(ENABLE_TS_UPDATE "Update .ts source files (Qt l10n)" FALSE)
 
 if(WIN32)
        # On Windows/MinGW we need to statically link to libraries.
@@ -82,30 +83,46 @@ include(memaccess)
 
 find_package(PkgConfig)
 
-check_cxx_compiler_flag("-std=c++17" HAVE_STD_CXX_17)
-check_cxx_compiler_flag("-std=c++14" HAVE_STD_CXX_14)
-check_cxx_compiler_flag("-std=c++11" HAVE_STD_CXX_11)
-if(HAVE_STD_CXX_17)
-       message(STATUS "Using C++17 for the application build")
-       set(CMAKE_CXX_STANDARD 17)
-       set(REQUIRED_STD_CXX_FLAGS "-std=c++17")
-elseif(HAVE_STD_CXX_14)
-       message(STATUS "Using C++14 for the application build")
-       set(CMAKE_CXX_STANDARD 14)
-       set(REQUIRED_STD_CXX_FLAGS "-std=c++14")
-elseif(HAVE_STD_CXX_11)
-       message(STATUS "Using C++11 for the application build")
-       set(CMAKE_CXX_STANDARD 11)
-       set(REQUIRED_STD_CXX_FLAGS "-std=c++11")
+if(CMAKE_VERSION VERSION_EQUAL "3.8.0" OR CMAKE_VERSION VERSION_GREATER "3.8.0")
+       check_cxx_compiler_flag("-std=c++17" HAVE_STD_CXX_17)
+       check_cxx_compiler_flag("-std=c++14" HAVE_STD_CXX_14)
+       check_cxx_compiler_flag("-std=c++11" HAVE_STD_CXX_11)
+       if(HAVE_STD_CXX_17)
+               message(STATUS "Using C++17 for the application build")
+               set(CMAKE_CXX_STANDARD 17)
+               set(REQUIRED_STD_CXX_FLAGS "-std=c++17")
+       elseif(HAVE_STD_CXX_14)
+               message(STATUS "Using C++14 for the application build")
+               set(CMAKE_CXX_STANDARD 14)
+               set(REQUIRED_STD_CXX_FLAGS "-std=c++14")
+       elseif(HAVE_STD_CXX_11)
+               message(STATUS "Using C++11 for the application build")
+               set(CMAKE_CXX_STANDARD 11)
+               set(REQUIRED_STD_CXX_FLAGS "-std=c++11")
+       else()
+               message(FATAL_ERROR "Need modern C++, at least language standard 11")
+       endif()
 else()
-       message(FATAL_ERROR "Need modern C++, at least language standard 11")
+       check_cxx_compiler_flag("-std=c++14" HAVE_STD_CXX_14)
+       check_cxx_compiler_flag("-std=c++11" HAVE_STD_CXX_11)
+       if(HAVE_STD_CXX_14)
+               message(STATUS "Using C++14 for the application build")
+               set(CMAKE_CXX_STANDARD 14)
+               set(REQUIRED_STD_CXX_FLAGS "-std=c++14")
+       elseif(HAVE_STD_CXX_11)
+               message(STATUS "Using C++11 for the application build")
+               set(CMAKE_CXX_STANDARD 11)
+               set(REQUIRED_STD_CXX_FLAGS "-std=c++11")
+       else()
+               message(FATAL_ERROR "Need modern C++, at least language standard 11")
+       endif()
 endif()
 
 list(APPEND PKGDEPS glib-2.0>=2.28.0)
 
 # Try to find the prefered glibmm-2.4. If not found then add glibmm-2.68
 # to the dependency list.
-pkg_check_modules(GLIBMM_2_4 glibmm-2.4>2.28.0)
+pkg_check_modules(GLIBMM_2_4 glibmm-2.4>=2.28.0)
 if(GLIBMM_2_4_FOUND)
        list(APPEND PKGDEPS glibmm-2.4>=2.28.0)
 else()
@@ -136,20 +153,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)
@@ -495,7 +527,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
@@ -507,10 +543,19 @@ 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})
-
-qt5_add_resources(pulseview_RESOURCES_RCC ${CMAKE_BINARY_DIR}/translations.qrc)
+if(Qt5_FOUND)
+       qt5_add_translation(QM_FILES ${TS_FILES})
+       qt5_add_resources(pulseview_RESOURCES_RCC ${CMAKE_BINARY_DIR}/translations.qrc)
+       if (ENABLE_TS_UPDATE)
+               qt5_create_translation(QM_FILES ${pulseview_SOURCES} ${TS_FILES})
+       endif ()
+else()
+       qt6_add_translation(QM_FILES ${TS_FILES})
+       qt6_add_resources(pulseview_RESOURCES_RCC ${CMAKE_BINARY_DIR}/translations.qrc)
+       if (ENABLE_TS_UPDATE)
+               qt6_create_translation(QM_FILES ${pulseview_SOURCES} ${TS_FILES})
+       endif ()
+endif()
 
 #===============================================================================
 #= Global Definitions
@@ -592,12 +637,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)