Skip to content

Commit 6ee6967

Browse files
committed
feat: Add support fot QT6 (optional)
1 parent 24cf55e commit 6ee6967

File tree

2 files changed

+46
-15
lines changed

2 files changed

+46
-15
lines changed

CMakeLists.txt

+28-5
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ if(WIN32)
8585
option(PORTABLE_WIN "Compile app for portability" OFF)
8686
endif(WIN32)
8787

88+
option(USE_QT6_BY_DEFAULT "Use Qt6 if available (if not available fallback to QT5)" OFF)
8889
option(UPDATE_TRANSLATIONS "Call lupdate to update translation files from source." OFF)
8990
option(TRANS_REMOVE_OBSOLETE "Add -noobsolete option to lupdate command to get rid of old text entries" OFF)
9091
option(ATTACH_FAKE_CLASSES "Fake classes can be used in application to tests functionalities" OFF)
@@ -523,15 +524,37 @@ endif(UNIX)
523524
set(QT_REQUIRED_VERSION 5.8)
524525
set(CMAKE_AUTOMOC TRUE) # required by moc preprocessor used in QT
525526

526-
find_package(QT NAMES Qt5 REQUIRED) # used to get version number in QT_VERSION_MAJOR and QT_VERSION
527-
message("Found QT: ${QT_VERSION}")
527+
if(USE_QT6_BY_DEFAULT)
528+
find_package(Qt6 COMPONENTS Core)
529+
if(NOT Qt6_FOUND)
530+
message("QT6 not found. Falling back to QT5.")
531+
endif()
532+
else()
533+
find_package(Qt5 COMPONENTS Core)
534+
if(NOT Qt5_FOUND)
535+
message("QT5 not found. Falling back to QT6.")
536+
endif()
537+
endif()
538+
539+
if (Qt6_FOUND OR NOT Qt5_FOUND)
540+
find_package(Qt6 ${QT_REQUIRED_VERSION}
541+
COMPONENTS Core Widgets Gui Network LinguistTools Concurrent
542+
REQUIRED)
543+
find_package(QT NAMES Qt6 REQUIRED) # used to get version number in QT_VERSION_MAJOR and QT_VERSION
528544

529-
find_package(Qt5 ${QT_REQUIRED_VERSION}
545+
QT_WRAP_UI(antimicrox_FORMS_HEADERS ${antimicrox_FORMS})
546+
QT_ADD_RESOURCES(antimicrox_RESOURCES_RCC ${antimicrox_RESOURCES})
547+
else()
548+
find_package(Qt5 ${QT_REQUIRED_VERSION}
530549
COMPONENTS Core Widgets Gui Network LinguistTools Concurrent
531550
REQUIRED)
551+
find_package(QT NAMES Qt5 REQUIRED) # used to get version number in QT_VERSION_MAJOR and QT_VERSION
552+
553+
QT5_WRAP_UI(antimicrox_FORMS_HEADERS ${antimicrox_FORMS})
554+
QT5_ADD_RESOURCES(antimicrox_RESOURCES_RCC ${antimicrox_RESOURCES})
555+
endif()
556+
message("Found QT: ${QT_VERSION}")
532557

533-
QT5_WRAP_UI(antimicrox_FORMS_HEADERS ${antimicrox_FORMS})
534-
QT5_ADD_RESOURCES(antimicrox_RESOURCES_RCC ${antimicrox_RESOURCES})
535558
add_subdirectory("share/antimicrox/translations")
536559
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
537560

share/antimicrox/translations/CMakeLists.txt

+18-10
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,27 @@ file(GLOB_RECURSE antimicrox_BASE_SOURCES ${PROJECT_SOURCE_DIR}/src/*.cpp)
66
file(GLOB_RECURSE antimicrox_BASE_FORMS ${PROJECT_SOURCE_DIR}/src/*.ui)
77

88

9-
if(UPDATE_TRANSLATIONS)
10-
message("Update translations - lupdate ON")
11-
if(TRANS_REMOVE_OBSOLETE)
12-
message("getting rid of old text entries: \"lupdate -noobsolete\" ON")
13-
QT5_CREATE_TRANSLATION(antimicrox_QMFILES ${antimicrox_BASE_SOURCES}
14-
${antimicrox_BASE_FORMS} ${antimicrox_TRANSLATIONS} OPTIONS -no-obsolete)
9+
if(QT_VERSION VERSION_GREATER_EQUAL 5.15)
10+
if(UPDATE_TRANSLATIONS)
11+
message("Update translations - lupdate ON")
12+
if(TRANS_REMOVE_OBSOLETE)
13+
message("getting rid of old text entries: \"lupdate -noobsolete\" ON")
14+
QT_CREATE_TRANSLATION(antimicrox_QMFILES ${antimicrox_BASE_SOURCES}
15+
${antimicrox_BASE_FORMS} ${antimicrox_TRANSLATIONS} OPTIONS -no-obsolete)
16+
else()
17+
QT_CREATE_TRANSLATION(antimicrox_QMFILES ${antimicrox_BASE_SOURCES}
18+
${antimicrox_BASE_FORMS} ${antimicrox_TRANSLATIONS})
19+
endif(TRANS_REMOVE_OBSOLETE)
1520
else()
16-
QT5_CREATE_TRANSLATION(antimicrox_QMFILES ${antimicrox_BASE_SOURCES}
17-
${antimicrox_BASE_FORMS} ${antimicrox_TRANSLATIONS})
18-
endif(TRANS_REMOVE_OBSOLETE)
21+
QT_ADD_TRANSLATION(antimicrox_QMFILES ${antimicrox_TRANSLATIONS})
22+
endif(UPDATE_TRANSLATIONS)
1923
else()
24+
# Since 5.15 QT commands are universal
2025
QT5_ADD_TRANSLATION(antimicrox_QMFILES ${antimicrox_TRANSLATIONS})
21-
endif(UPDATE_TRANSLATIONS)
26+
if(UPDATE_TRANSLATIONS)
27+
warning("Updating translations only for QT 5.15 or newer.")
28+
endif()
29+
endif()
2230

2331

2432
add_custom_target(updateqm DEPENDS ${antimicrox_QMFILES} COMMENT "Update translation files based on source and ui files")

0 commit comments

Comments
 (0)