Skip to content

Commit

Permalink
cmake: Migrate to Qt 6
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Sep 20, 2024
1 parent 5ba7353 commit aac8328
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 30 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 12 additions & 12 deletions cmake/module/FindQt5.cmake → cmake/module/FindQt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)

Expand All @@ -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()
58 changes: 43 additions & 15 deletions src/qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)

Expand Down Expand Up @@ -127,7 +141,7 @@ set_property(SOURCE macnotificationhandler.mm
)
target_link_libraries(bitcoinqt
PUBLIC
Qt5::Widgets
Qt6::Widgets
PRIVATE
core_interface
bitcoin_cli
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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 xml:space=\"preserve\"><\\/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
Expand Down
4 changes: 2 additions & 2 deletions src/qt/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 $<TARGET_PROPERTY:Qt5::QMinimalIntegrationPlugin,LOCATION_$<UPPER_CASE:$<CONFIG>>> $<TARGET_FILE_DIR:test_bitcoin-qt>/plugins/platforms
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_PROPERTY:Qt6::QMinimalIntegrationPlugin,LOCATION_$<UPPER_CASE:$<CONFIG>>> $<TARGET_FILE_DIR:test_bitcoin-qt>/plugins/platforms
VERBATIM
)
endif()
Expand Down

0 comments on commit aac8328

Please sign in to comment.