Skip to content

Commit

Permalink
cmake: Add Qt 6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Aug 14, 2022
1 parent 8f3bc74 commit fe8a9cb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
19 changes: 14 additions & 5 deletions cmake/optional_qt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.

set(with_gui_values "auto" "Qt5" "no")
set(WITH_GUI "auto" CACHE STRING "Build GUI ([auto], Qt5, no)")
set(with_gui_values "auto" "Qt5" "Qt6" "no")
set(WITH_GUI "auto" CACHE STRING "Build GUI ([auto], Qt5, Qt6, no)")
if(NOT WITH_GUI IN_LIST with_gui_values)
message(FATAL_ERROR "WITH_GUI value is \"${WITH_GUI}\", but must be one of \"auto\", \"Qt5\" or \"no\".")
message(FATAL_ERROR "WITH_GUI value is \"${WITH_GUI}\", but must be one of \"auto\", \"Qt5\", \"Qt6\" or \"no\".")
endif()

if(CMAKE_SYSTEM_NAME STREQUAL Darwin AND NOT WITH_GUI STREQUAL no)
Expand All @@ -23,11 +23,19 @@ if(CMAKE_SYSTEM_NAME STREQUAL Darwin AND NOT WITH_GUI STREQUAL no)
endif()

if(WITH_GUI STREQUAL auto)
set(bitcoin_qt_versions Qt5)
set(bitcoin_qt_versions Qt6 Qt5)
else()
set(bitcoin_qt_versions ${WITH_GUI})
endif()

if(${CMAKE_VERSION} VERSION_LESS 3.16)
if(WITH_GUI STREQUAL Qt6)
message(FATAL_ERROR "CMake >= 3.16 is required to build the GUI with Qt 6.")
elseif(WITH_GUI STREQUAL auto)
set(bitcoin_qt_versions Qt5)
endif()
endif()

if(${CMAKE_VERSION} VERSION_LESS 3.12 AND CMAKE_CROSSCOMPILING)
if(WITH_GUI STREQUAL Qt5 OR bitcoin_qt_versions STREQUAL Qt5)
# Qt 5.15 uses `$<IN_LIST:>` in the `mkspecs/features/data/cmake/Qt5PluginTarget.cmake.in`.
Expand All @@ -44,14 +52,15 @@ if(NOT WITH_GUI STREQUAL no)
set(QT_NO_CREATE_VERSIONLESS_TARGETS ON)

if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
execute_process(COMMAND brew --prefix qt OUTPUT_VARIABLE qt_brew_prefix ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND brew --prefix qt@5 OUTPUT_VARIABLE qt5_brew_prefix ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()

if(WITH_GUI STREQUAL auto)
# The PATH_SUFFIXES option is required on OpenBSD systems.
find_package(QT NAMES ${bitcoin_qt_versions}
COMPONENTS Core
HINTS ${qt5_brew_prefix}
HINTS ${qt_brew_prefix} ${qt5_brew_prefix}
PATH_SUFFIXES Qt5
)
if(QT_FOUND)
Expand Down
9 changes: 7 additions & 2 deletions src/qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# See:
# - https://cmake.org/cmake/help/latest/manual/cmake-qt.7.html
# - https://doc.qt.io/qt-5/cmake-manual.html
# - https://doc.qt.io/qt-6/cmake-manual.html

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
Expand All @@ -16,14 +17,18 @@ set(qt_package ${WITH_GUI})
# The PATH_SUFFIXES option is required on OpenBSD systems.
find_package(${qt_package} 5.11.3 REQUIRED
COMPONENTS Widgets Network LinguistTools
HINTS ${qt5_brew_prefix}
HINTS ${qt_brew_prefix} ${qt5_brew_prefix}
PATH_SUFFIXES Qt5
)
message(STATUS "Found Qt, version ${${qt_package}_VERSION}")

file(GLOB ts_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} locale/*.ts)
set_source_files_properties(${ts_files} PROPERTIES OUTPUT_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/locale)
qt5_add_translation(qm_files ${ts_files})
if(${${qt_package}_VERSION_MAJOR} EQUAL 5)
qt5_add_translation(qm_files ${ts_files})
else()
qt6_add_translation(qm_files ${ts_files})
endif()

add_library(bitcoinqt STATIC EXCLUDE_FROM_ALL "")
target_sources(bitcoinqt
Expand Down

0 comments on commit fe8a9cb

Please sign in to comment.