From aac8328791db84e8e487b2ac54a20e69bb60728a Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Fri, 20 Sep 2024 13:28:11 +0100 Subject: [PATCH] cmake: Migrate to Qt 6 --- CMakeLists.txt | 2 +- cmake/module/{FindQt5.cmake => FindQt.cmake} | 24 ++++---- src/qt/CMakeLists.txt | 58 +++++++++++++++----- src/qt/test/CMakeLists.txt | 4 +- 4 files changed, 58 insertions(+), 30 deletions(-) rename cmake/module/{FindQt5.cmake => FindQt.cmake} (80%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ae988ac904d6..bd004929f65eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -182,7 +182,7 @@ if(BUILD_GUI) if(BUILD_GUI_TESTS) list(APPEND qt_components Test) endif() - find_package(Qt5 5.11.3 MODULE REQUIRED + find_package(Qt 6.2 MODULE REQUIRED COMPONENTS ${qt_components} ) unset(qt_components) diff --git a/cmake/module/FindQt5.cmake b/cmake/module/FindQt.cmake similarity index 80% rename from cmake/module/FindQt5.cmake rename to cmake/module/FindQt.cmake index f39ee53d5b5c5..67803b185e35d 100644 --- a/cmake/module/FindQt5.cmake +++ b/cmake/module/FindQt.cmake @@ -3,10 +3,10 @@ # file COPYING or https://opensource.org/license/mit/. #[=======================================================================[ -FindQt5 -------- +FindQt +------ -Finds the Qt 5 headers and libraries. +Finds the Qt 6 headers and libraries. This is a wrapper around find_package() command that: - facilitates searching in various build environments @@ -19,7 +19,7 @@ if(CMAKE_HOST_APPLE) find_program(HOMEBREW_EXECUTABLE brew) if(HOMEBREW_EXECUTABLE) execute_process( - COMMAND ${HOMEBREW_EXECUTABLE} --prefix qt@5 + COMMAND ${HOMEBREW_EXECUTABLE} --prefix qt OUTPUT_VARIABLE _qt_homebrew_prefix ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE @@ -40,10 +40,10 @@ endif() # /usr/x86_64-w64-mingw32/lib/libm.a or /usr/arm-linux-gnueabihf/lib/libm.a. set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH) -find_package(Qt5 ${Qt5_FIND_VERSION} - COMPONENTS ${Qt5_FIND_COMPONENTS} +find_package(Qt6 ${Qt_FIND_VERSION} NO_MODULE QUIET + COMPONENTS ${Qt_FIND_COMPONENTS} HINTS ${_qt_homebrew_prefix} - PATH_SUFFIXES Qt5 # Required on OpenBSD systems. + PATH_SUFFIXES Qt6 # Required on OpenBSD systems. ) unset(_qt_homebrew_prefix) @@ -56,11 +56,11 @@ else() endif() include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Qt5 - REQUIRED_VARS Qt5_DIR - VERSION_VAR Qt5_VERSION +find_package_handle_standard_args(Qt + REQUIRED_VARS Qt6_DIR Qt6_FOUND + VERSION_VAR Qt6_VERSION ) -foreach(component IN LISTS Qt5_FIND_COMPONENTS ITEMS "") - mark_as_advanced(Qt5${component}_DIR) +foreach(component IN LISTS Qt_FIND_COMPONENTS ITEMS "") + mark_as_advanced(Qt6${component}_DIR) endforeach() diff --git a/src/qt/CMakeLists.txt b/src/qt/CMakeLists.txt index 297408a926baa..359847ac6efc6 100644 --- a/src/qt/CMakeLists.txt +++ b/src/qt/CMakeLists.txt @@ -11,21 +11,35 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") string(APPEND CMAKE_OBJCXX_COMPILE_OBJECT " ${APPEND_CPPFLAGS} ${APPEND_CXXFLAGS}") endif() -get_target_property(qt_lib_type Qt5::Core TYPE) +get_target_property(qt_lib_type Qt6::Core TYPE) function(import_plugins target) if(qt_lib_type STREQUAL "STATIC_LIBRARY") - set(plugins Qt5::QMinimalIntegrationPlugin) + set(plugins Qt6::QMinimalIntegrationPlugin) if(CMAKE_SYSTEM_NAME STREQUAL "Linux") - list(APPEND plugins Qt5::QXcbIntegrationPlugin) + list(APPEND plugins Qt6::QXcbIntegrationPlugin) elseif(WIN32) - list(APPEND plugins Qt5::QWindowsIntegrationPlugin Qt5::QWindowsVistaStylePlugin) + list(APPEND plugins Qt6::QWindowsIntegrationPlugin Qt6::QWindowsVistaStylePlugin) elseif(APPLE) - list(APPEND plugins Qt5::QCocoaIntegrationPlugin Qt5::QMacStylePlugin) + list(APPEND plugins Qt6::QCocoaIntegrationPlugin Qt6::QMacStylePlugin) endif() - qt5_import_plugins(${target} + qt6_import_plugins(${target} INCLUDE ${plugins} - EXCLUDE_BY_TYPE imageformats iconengines + EXCLUDE_BY_TYPE + accessiblebridge + platforms + platforms_darwin + xcbglintegrations + platformthemes + platforminputcontexts + generic + iconengines + imageformats + egldeviceintegrations + styles + networkaccess + networkinformation + tls ) endif() endfunction() @@ -44,7 +58,7 @@ set(CMAKE_AUTOUIC_SEARCH_PATHS forms) # to https://github.com/bitcoin-core/bitcoin-maintainer-tools/blob/main/update-translations.py file(GLOB ts_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} locale/*.ts) set_source_files_properties(${ts_files} PROPERTIES OUTPUT_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/locale) -qt5_add_translation(qm_files ${ts_files}) +qt6_add_translation(qm_files ${ts_files}) configure_file(bitcoin_locale.qrc bitcoin_locale.qrc USE_SOURCE_PERMISSIONS COPYONLY) @@ -127,7 +141,7 @@ set_property(SOURCE macnotificationhandler.mm ) target_link_libraries(bitcoinqt PUBLIC - Qt5::Widgets + Qt6::Widgets PRIVATE core_interface bitcoin_cli @@ -207,19 +221,33 @@ if(ENABLE_WALLET) target_link_libraries(bitcoinqt PRIVATE bitcoin_wallet - Qt5::Network + Qt6::Network ) endif() if(WITH_DBUS) - target_link_libraries(bitcoinqt PRIVATE Qt5::DBus) + target_link_libraries(bitcoinqt PRIVATE Qt6::DBus) endif() if(qt_lib_type STREQUAL "STATIC_LIBRARY") # We want to define static plugins to link ourselves, thus preventing # automatic linking against a "sane" set of default static plugins. - qt5_import_plugins(bitcoinqt - EXCLUDE_BY_TYPE bearer iconengines imageformats platforms styles + qt6_import_plugins(bitcoinqt + EXCLUDE_BY_TYPE + accessiblebridge + platforms + platforms_darwin + xcbglintegrations + platformthemes + platforminputcontexts + generic + iconengines + imageformats + egldeviceintegrations + styles + networkaccess + networkinformation + tls ) endif() @@ -321,8 +349,8 @@ else() file(GLOB ui_files ${CMAKE_CURRENT_SOURCE_DIR}/forms/*.ui) add_custom_target(translate COMMAND ${CMAKE_COMMAND} -E env XGETTEXT=${XGETTEXT_EXECUTABLE} COPYRIGHT_HOLDERS=${COPYRIGHT_HOLDERS} ${Python3_EXECUTABLE} ${PROJECT_SOURCE_DIR}/share/qt/extract_strings_qt.py ${translatable_sources} - COMMAND Qt5::lupdate -no-obsolete -I ${PROJECT_SOURCE_DIR}/src -locations relative ${CMAKE_CURRENT_SOURCE_DIR}/bitcoinstrings.cpp ${ui_files} ${qt_translatable_sources} -ts ${CMAKE_CURRENT_SOURCE_DIR}/locale/bitcoin_en.ts - COMMAND Qt5::lconvert -drop-translations -o ${CMAKE_CURRENT_SOURCE_DIR}/locale/bitcoin_en.xlf -i ${CMAKE_CURRENT_SOURCE_DIR}/locale/bitcoin_en.ts + COMMAND Qt6::lupdate -no-obsolete -I ${PROJECT_SOURCE_DIR}/src -locations relative ${CMAKE_CURRENT_SOURCE_DIR}/bitcoinstrings.cpp ${ui_files} ${qt_translatable_sources} -ts ${CMAKE_CURRENT_SOURCE_DIR}/locale/bitcoin_en.ts + COMMAND Qt6::lconvert -drop-translations -o ${CMAKE_CURRENT_SOURCE_DIR}/locale/bitcoin_en.xlf -i ${CMAKE_CURRENT_SOURCE_DIR}/locale/bitcoin_en.ts COMMAND ${SED_EXECUTABLE} -i.old -e "s|source-language=\"en\" target-language=\"en\"|source-language=\"en\"|" -e "/<\\/target>/d" ${CMAKE_CURRENT_SOURCE_DIR}/locale/bitcoin_en.xlf COMMAND ${CMAKE_COMMAND} -E rm ${CMAKE_CURRENT_SOURCE_DIR}/locale/bitcoin_en.xlf.old WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src diff --git a/src/qt/test/CMakeLists.txt b/src/qt/test/CMakeLists.txt index 582ed7146639d..46bc087bb0391 100644 --- a/src/qt/test/CMakeLists.txt +++ b/src/qt/test/CMakeLists.txt @@ -18,7 +18,7 @@ target_link_libraries(test_bitcoin-qt test_util bitcoin_node Boost::headers - Qt5::Test + Qt6::Test ) import_plugins(test_bitcoin-qt) @@ -35,7 +35,7 @@ endif() if(NOT QT_IS_STATIC) add_custom_command( TARGET test_bitcoin-qt POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different $>> $/plugins/platforms + COMMAND ${CMAKE_COMMAND} -E copy_if_different $>> $/plugins/platforms VERBATIM ) endif()