From 9d30f55f5304ad3d869fc043937d06eb47ef3c6a Mon Sep 17 00:00:00 2001 From: additional-pumpkin Date: Tue, 19 Sep 2023 18:10:09 +0300 Subject: [PATCH 1/3] Fixed broken build The file main.cpp includes mainwindow.h without USE_SOUND being defined. If USE_SOUND is defined when building mainwindow.cpp they'll get linked with different sized MainWindow classes. main.cpp will then allocate less than enough space for MainWindow causing it to segfault. --- CMakeLists.txt | 41 ++++++++++++++++++++++----- src/CMakeLists.txt | 27 ++++++++++-------- src/quazip/CMakeLists.txt | 3 +- src/quazip/qt6compat.h | 58 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 109 insertions(+), 20 deletions(-) create mode 100644 src/quazip/qt6compat.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c3830b94..bb13154e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,16 +4,15 @@ set(CMAKE_OSX_DEPLOYMENT_TARGET 10.13) project(chessx LANGUAGES CXX) -set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) -option(ENABLE_SOUNDS "Enable sounds (requires Qt5::Multimedia)" ON) -option(ENABLE_TTS "Enable text-to-speech (requires Qt5::TextToSpeech)" ON) +option(ENABLE_SOUNDS "Enable sounds (requires Qt6::Multimedia)" ON) +option(ENABLE_TTS "Enable text-to-speech (requires Qt6::TextToSpeech)" ON) option(ENABLE_SCID_SUPPORT "Enable support for Scid database format (*.si4)" ON) add_subdirectory(dep) - # common definitions to use with Qt add_library(qt_config INTERFACE) target_compile_definitions(qt_config INTERFACE @@ -23,7 +22,7 @@ target_compile_definitions(qt_config INTERFACE ) set(REQUIRED_QT_COMPONENTS - Core Xml DBus Network OpenGL Svg PrintSupport Gui Widgets + Core Xml DBus Network OpenGL Svg PrintSupport Gui Widgets Core5Compat ) if (ENABLE_SOUNDS) @@ -34,7 +33,7 @@ if (ENABLE_TTS) list(APPEND REQUIRED_QT_COMPONENTS TextToSpeech) endif() -find_package(Qt5 REQUIRED +find_package(Qt6 REQUIRED LinguistTools "${REQUIRED_QT_COMPONENTS}" Test @@ -61,7 +60,7 @@ set_source_files_properties(${TRANSLATIONS_SRC_FILES} OUTPUT_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/i18n" ) -qt5_add_translation(TRANSLATIONS_BIN_FILES ${TRANSLATIONS_SRC_FILES}) +qt6_add_translation(TRANSLATIONS_BIN_FILES ${TRANSLATIONS_SRC_FILES}) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) @@ -110,6 +109,7 @@ target_link_libraries(chessx PRIVATE board eco gui + Qt6::Multimedia ) if (CMAKE_HOST_APPLE) @@ -149,3 +149,30 @@ if (ENABLE_TESTING) add_subdirectory(tests/unittests) endif() +if (ENABLE_SOUNDS) + target_compile_definitions(chessx + PRIVATE + USE_SOUND + ) + target_link_libraries(chessx PRIVATE Qt6::Multimedia) + if (UNIX AND NOT APPLE) + # on Linux QtMultimedia links to pulseaudio + find_package(PulseAudio REQUIRED) + target_link_libraries(chessx + PRIVATE + ${PULSEAUDIO_LIBRARY} + ${PULSEAUDIO_MAINLOOP_LIBRARY} + ) + endif() +endif() + +if (ENABLE_TTS) + target_compile_definitions(chessx + PRIVATE + USE_SPEECH + ) + target_link_libraries(chessx PRIVATE Qt6::TextToSpeech) +endif() + + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 86b8a7d02..58f474500 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,7 +19,7 @@ target_link_libraries(bitboard PRIVATE qt_config PUBLIC - Qt5::Core + Qt6::Core ) if (cxx_std_11 IN_LIST CMAKE_CXX_COMPILE_FEATURES) @@ -79,7 +79,7 @@ target_link_libraries(eco PUBLIC board gui - Qt5::Core + Qt6::Core ) add_library(database-core STATIC @@ -235,17 +235,20 @@ target_include_directories(database database PRIVATE gui + ) target_link_libraries(database PRIVATE qt_config - Qt5::Widgets + Qt6::Widgets PUBLIC database-core - Qt5::Core - Qt5::Gui - Qt5::Network + Qt6::Core + Qt6::Gui + Qt6::Network + Qt6::Core5Compat + ) if (ENABLE_SCID_SUPPORT) @@ -461,12 +464,12 @@ target_link_libraries(gui qt_config eco quazip - Qt5::PrintSupport - Qt5::Svg + Qt6::PrintSupport + Qt6::Svg PUBLIC database - Qt5::Widgets - Qt5::Xml + Qt6::Widgets + Qt6::Xml ) if (ENABLE_SOUNDS) @@ -474,7 +477,7 @@ if (ENABLE_SOUNDS) PRIVATE USE_SOUND ) - target_link_libraries(gui PRIVATE Qt5::Multimedia) + target_link_libraries(gui PRIVATE Qt6::Multimedia) if (UNIX AND NOT APPLE) # on Linux QtMultimedia links to pulseaudio find_package(PulseAudio REQUIRED) @@ -491,6 +494,6 @@ if (ENABLE_TTS) PRIVATE USE_SPEECH ) - target_link_libraries(gui PRIVATE Qt5::TextToSpeech) + target_link_libraries(gui PRIVATE Qt6::TextToSpeech) endif() diff --git a/src/quazip/CMakeLists.txt b/src/quazip/CMakeLists.txt index 5f9b242e2..a21cab067 100644 --- a/src/quazip/CMakeLists.txt +++ b/src/quazip/CMakeLists.txt @@ -46,6 +46,7 @@ target_link_libraries(quazip qt_config PUBLIC ZLIB::ZLIB - Qt5::Core + Qt6::Core + Qt6::Core5Compat ) diff --git a/src/quazip/qt6compat.h b/src/quazip/qt6compat.h new file mode 100644 index 000000000..5c44f49da --- /dev/null +++ b/src/quazip/qt6compat.h @@ -0,0 +1,58 @@ +#ifndef QT6COMPAT_H +#define QT6COMPAT_H + +#include + +#ifdef USE_SOUND +#if QT_VERSION < 0x060000 +#include +#else +#include +class QSound : public QSoundEffect { +public: + QSound(const QString& url) : QSoundEffect() + { + setSource(QUrl(url)); + } + void play() + { + QSoundEffect::play(); + } + static void play(const QString& url) + { + static QSoundEffect effect; + effect.setSource(QUrl(url)); + effect.play(); + } +}; +#endif +#endif + +#if QT_VERSION < 0x060000 +#include +#define SET_CODEC_UTF8(s) \ + QTextCodec* textCodec = QTextCodec::codecForName("utf8"); \ + if(textCodec) s.setCodec(textCodec); +#define SET_CODEC_LATIN1(s) \ + QTextCodec* textCodec = QTextCodec::codecForName("ISO 8859-1"); \ + if(textCodec) s.setCodec(textCodec); +#else +#include +#define SET_CODEC_UTF8(s) s.setEncoding(QStringConverter::Utf8); +#define SET_CODEC_LATIN1(s) s.setEncoding(QStringConverter::Latin1); +#endif + +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) +#include +constexpr auto SkipEmptyParts = QString::SkipEmptyParts; +#else +using Qt::SkipEmptyParts; +#endif + +#if QT_VERSION < 0x060000 +#define EVENT_POSITION(event) (event)->pos() +#else +#define EVENT_POSITION(event) (event)->position().toPoint() +#endif + +#endif // QT6COMPAT_H From 6332b5ab44492c93f4a4f29b9093ce66ee7e5a27 Mon Sep 17 00:00:00 2001 From: themrrobert <10122432+themrrobert@users.noreply.github.com> Date: Tue, 19 Mar 2024 08:04:22 -0700 Subject: [PATCH 2/3] Additional build fixes --- chessx.pro | 5 ++--- src/database/polyglotdatabase.cpp | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/chessx.pro b/chessx.pro index a571311de..5f20e8e51 100644 --- a/chessx.pro +++ b/chessx.pro @@ -531,9 +531,8 @@ INCLUDEPATH += src/quazip INCLUDEPATH += $$[QT_INSTALL_PREFIX]/src/3rdparty/zlib win32 { - # DEFINES += ZLIB_WINAPI - # LIBS += -lz - INCLUDEPATH += $$[QT_INSTALL_HEADERS]/QtZlib + DEFINES += ZLIB_WINAPI + LIBS += -lz win32-g++:LIBS += -lz } diff --git a/src/database/polyglotdatabase.cpp b/src/database/polyglotdatabase.cpp index 0201ae0b8..0abceab55 100644 --- a/src/database/polyglotdatabase.cpp +++ b/src/database/polyglotdatabase.cpp @@ -22,7 +22,7 @@ using namespace chessx; #define MAX_COUNT 16384 -struct key_compare : std::__binary_function< const book_entry&, const book_entry&, bool > +struct key_compare { bool operator()( const book_entry& a, const book_entry& b ) const { From d47599075f56a61e7a068eba4f111a69d8f7d307 Mon Sep 17 00:00:00 2001 From: themrrobert <10122432+themrrobert@users.noreply.github.com> Date: Tue, 19 Mar 2024 08:20:14 -0700 Subject: [PATCH 3/3] Add some updates to INSTALL.md --- INSTALL.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 6217dae8c..c18d2ab2a 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -26,15 +26,13 @@ Windows. # 3. Requirements -To compile ChessX, you need zlib, qmake and **Qt5 version 5.14.1** or above. - -**known issue:** FICS does not work properly with Qt4 +To compile ChessX, you need zlib, qmake and **Qt6 version 6** or above. (Last built on 6.6.2) # 4. Compilation Compiling the source is simple. Execute: - qmake + qmake6 and then @@ -43,17 +41,21 @@ and then If the compilation is successful you should be able to run ChessX executable in **bin** (or **release**) subdirectory. It is called: **chessx** on Linux, **chessx.app** on Mac OS, and **chessx.exe** on Windows +On Windows you should then run the following to install the required dlls into the release directory: + + windeployqt release + ## 4.1 Compilation in Linux x64 systems On Linux x64, the following commands are required for successful compilation: Build the translations - lrelease-qt5 chessx.pro + lrelease chessx.pro -Run qmake, specifically qt5 version +Run qmake, specifically qt6 version - qmake-qt5 + qmake6 Compile with