Skip to content

Commit b1f98d8

Browse files
committed
Simplify and make explicit Qt5 vs. Qt6 choice
Guard USE_KF5 and USE_WEBKIT options behind USE_QT5. Cleanup superfluous APP_QT_VERSION cmake variable Drop automagic find_package(QT NAMES) mechanism qt-aliases.cmake: Drop QT_VERSION_MAJOR, simply bail out with >=Qt-5.15 Signed-off-by: Andreas Sturmlechner <[email protected]>
1 parent 95f2761 commit b1f98d8

File tree

2 files changed

+56
-95
lines changed

2 files changed

+56
-95
lines changed

CMakeLists.txt

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ project(uchmviewer HOMEPAGE_URL "https://github.com/eBookProjects/uChmViewer")
2626
include(cmake/get-version.cmake)
2727

2828
include(cmake/use-in.cmake)
29-
option(USE_KF5 "Use KDE Framework 5" OFF)
30-
option(USE_WEBKIT "Use Qt WebKit" OFF)
29+
option(USE_QT5 "Use Qt5" ON)
30+
if (USE_QT5)
31+
option(USE_KF5 "Use KDE Framework 5" OFF)
32+
option(USE_WEBKIT "Use Qt WebKit" OFF)
33+
endif ()
3134
option(USE_STATIC_CHMLIB "Use static link with chm library" OFF)
3235
option(USE_DEPLOY_RUNTIME "Copy runtime dependencies for deployment" OFF)
3336
option(USE_GETTEXT "Use GNU Gettext for translation" ON)
@@ -48,34 +51,24 @@ find_package(libzip REQUIRED)
4851
# Prepare to find Qt modules.
4952
set(APP_QT_MIN_VERSION 5.9)
5053
set(APP_QT_MODULES Core Network PrintSupport Widgets Xml)
51-
# Modules for WebKit or WebEngine.
52-
if (USE_WEBKIT)
53-
set(APP_QT_MIN_VERSION 5.0)
54-
list(APPEND APP_QT_MODULES WebKit WebKitWidgets)
55-
target_link_libraries(extra INTERFACE Qt::WebKit Qt::WebKitWidgets)
56-
target_compile_definitions(extra INTERFACE USE_WEBKIT)
54+
if (USE_QT5)
55+
# Modules for WebKit or WebEngine.
56+
if (USE_WEBKIT)
57+
set(APP_QT_MIN_VERSION 5.0)
58+
list(APPEND APP_QT_MODULES WebKit WebKitWidgets)
59+
target_link_libraries(extra INTERFACE Qt::WebKit Qt::WebKitWidgets)
60+
target_compile_definitions(extra INTERFACE USE_WEBKIT)
61+
else ()
62+
list(APPEND APP_QT_MODULES WebEngineWidgets)
63+
target_link_libraries(extra INTERFACE Qt::WebEngineWidgets)
64+
endif ()
65+
set(QT Qt5)
5766
else ()
58-
list(APPEND APP_QT_MODULES WebEngineWidgets)
59-
target_link_libraries(extra INTERFACE Qt::WebEngineWidgets)
60-
endif ()
61-
62-
set(APP_QT_VERSION ${APP_QT_MIN_VERSION} CACHE STRING "Preferred Qt version")
63-
64-
# What version of Qt are we working with?
65-
if ($CACHE{APP_QT_VERSION} VERSION_LESS 6)
66-
find_package(QT $CACHE{APP_QT_VERSION} NAMES Qt5)
67-
endif ()
68-
69-
if (NOT QT_FOUND)
70-
find_package(QT $CACHE{APP_QT_VERSION} NAMES Qt5 Qt6 REQUIRED)
71-
endif ()
72-
73-
74-
set(QT Qt${QT_VERSION_MAJOR})
75-
# Since Qt 6 QTextCodec moved in the Qt 5 Core Compat module.
76-
if (QT_VERSION_MAJOR GREATER_EQUAL 6)
77-
list(APPEND APP_QT_MODULES Core5Compat)
78-
target_link_libraries(extra INTERFACE ${QT}::Core5Compat)
67+
# Since Qt6 QTextCodec moved in the Qt5CoreCompat module. No WebKit in Qt6.
68+
list(APPEND APP_QT_MODULES Core5Compat WebEngineWidgets)
69+
target_link_libraries(extra INTERFACE Qt6::Core5Compat Qt::WebEngineWidgets)
70+
set(QT Qt6)
71+
set(APP_QT_MIN_VERSION 6.0)
7972
endif ()
8073

8174
if (USE_DBUS)
@@ -89,9 +82,9 @@ if (USE_MAC_APP)
8982
endif ()
9083

9184
# Now we know all the required Qt modules.
92-
find_package(${QT} REQUIRED ${APP_QT_MODULES})
85+
find_package(${QT} ${APP_QT_MIN_VERSION} REQUIRED ${APP_QT_MODULES})
9386

94-
if (USE_KF5)
87+
if (USE_QT5 AND USE_KF5)
9588
# Needed by find_package(KF5) below.
9689
find_package(ECM REQUIRED)
9790
list(APPEND CMAKE_MODULE_PATH ${ECM_MODULE_PATH})

cmake/qt-aliases.cmake

Lines changed: 32 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -37,91 +37,59 @@ cmake_minimum_required(VERSION 3.16)
3737
# Core macros #
3838
############################
3939

40-
# qt_wrap_cpp(outfiles)
41-
if (QT_VERSION_MAJOR VERSION_LESS 5.15)
42-
macro(qt_wrap_cpp)
43-
qt5_wrap_cpp(${ARGV})
44-
endmacro()
40+
if (NOT Qt5_FOUND OR Qt5_VERSION VERSION_GREATER_EQUAL 5.15)
41+
return()
4542
endif ()
4643

47-
# qt_add_resources(outfiles)
48-
if (QT_VERSION_MAJOR VERSION_LESS 5.15)
49-
macro(qt_add_resources)
50-
qt5_add_resources(${ARGV})
51-
endmacro()
52-
endif ()
44+
macro(qt_wrap_cpp)
45+
qt5_wrap_cpp(${ARGV})
46+
endmacro()
5347

54-
# qt_generate_moc()
55-
if (QT_VERSION_MAJOR VERSION_LESS 5.15)
56-
macro(qt_generate_moc)
57-
qt5_generate_moc(${ARGV})
58-
endmacro()
59-
endif ()
48+
macro(qt_add_resources)
49+
qt5_add_resources(${ARGV})
50+
endmacro()
6051

52+
macro(qt_generate_moc)
53+
qt5_generate_moc(${ARGV})
54+
endmacro()
6155

6256
############################
6357
# Widgets macros #
6458
############################
65-
66-
# qt_wrap_ui(outfiles)
67-
if (QT_VERSION_MAJOR VERSION_LESS 5.15)
68-
macro(qt_wrap_ui outfile)
69-
qt5_wrap_ui(${ARGV})
70-
endmacro()
71-
endif ()
72-
59+
macro(qt_wrap_ui outfile)
60+
qt5_wrap_ui(${ARGV})
61+
endmacro()
7362

7463
############################
7564
# DBUS macros #
7665
############################
66+
macro(qt_add_dbus_interface)
67+
qt5_add_dbus_interface(${ARGV})
68+
endmacro()
7769

78-
# qt_add_dbus_interface(outfiles)
79-
if (QT_VERSION_MAJOR VERSION_LESS 5.15)
80-
macro(qt_add_dbus_interface)
81-
qt5_add_dbus_interface(${ARGV})
82-
endmacro()
83-
endif ()
84-
85-
# qt_add_dbus_interfaces(outfiles)
86-
if (QT_VERSION_MAJOR VERSION_LESS 5.15)
87-
macro(qt_add_dbus_interfaces)
88-
qt5_add_dbus_interfaces(${ARGV})
89-
endmacro()
90-
endif()
91-
92-
# qt_add_dbus_adaptor(outfiles)
93-
if (QT_VERSION_MAJOR VERSION_LESS 5.15)
94-
macro(qt_add_dbus_adaptor)
95-
qt5_add_dbus_adaptor(${ARGV})
96-
endmacro()
97-
endif ()
70+
macro(qt_add_dbus_interfaces)
71+
qt5_add_dbus_interfaces(${ARGV})
72+
endmacro()
9873

99-
# qt_generate_dbus_interface()
100-
if (QT_VERSION_MAJOR VERSION_LESS 5.15)
101-
macro(qt_generate_dbus_interface)
102-
qt5_generate_dbus_interface(${ARGV})
103-
endmacro()
104-
endif ()
74+
macro(qt_add_dbus_adaptor)
75+
qt5_add_dbus_adaptor(${ARGV})
76+
endmacro()
10577

78+
macro(qt_generate_dbus_interface)
79+
qt5_generate_dbus_interface(${ARGV})
80+
endmacro()
10681

10782
############################
10883
# Linguist tools macros #
10984
############################
11085

111-
# qt_create_translation(qm_files)
112-
if (QT_VERSION_MAJOR VERSION_LESS 5.15)
113-
macro(qt_create_translation)
114-
qt5_create_translation(${ARGV})
115-
endmacro()
116-
endif ()
117-
118-
# qt_add_translation(qm_files)
119-
if (QT_VERSION_MAJOR VERSION_LESS 5.15)
120-
macro(qt_add_translation)
121-
qt5_add_translation(${ARGV})
122-
endmacro()
123-
endif ()
86+
macro(qt_create_translation)
87+
qt5_create_translation(${ARGV})
88+
endmacro()
12489

90+
macro(qt_add_translation)
91+
qt5_add_translation(${ARGV})
92+
endmacro()
12593

12694
############################
12795
# Module aliases #

0 commit comments

Comments
 (0)