Skip to content

Commit

Permalink
qt: Support Qt6 for ARM64
Browse files Browse the repository at this point in the history
  • Loading branch information
calcitem committed Jun 9, 2024
1 parent e3a7b4b commit 07ff29a
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 33 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/qt-on-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ jobs:
uses: seanmiddleditch/gha-setup-vsdevenv@master

- name: Install Qt
uses: jurplel/install-qt-action@v3
uses: jurplel/install-qt-action@v4
with:
version: '5.15.2'
version: '6.7.1'
host: 'windows'
target: 'desktop'
arch: 'win64_msvc2019_64'
modules: 'qtbase qtmultimedia'
install-deps: 'true'
setup-python: 'true'
tools: 'tools_cmake'
Expand All @@ -43,7 +44,8 @@ jobs:
- name: Build Qt with CMake
run: |
cd src/ui/qt
cmake . -DCMAKE_PREFIX_PATH="D:\\a\\Sanmill\\Qt\\5.15.2\\msvc2019_64"
set "Qt6_DIR=D:\a\Sanmill\Qt\6.7.1\msvc2019_64\lib\cmake\Qt6"
cmake . -DCMAKE_PREFIX_PATH="D:\\a\\Sanmill\\Qt\\6.7.1\\msvc2019_64"
cmake --build . --target mill-pro --config Release
- name: Archive Qt
Expand Down
2 changes: 1 addition & 1 deletion README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ make build ARCH=x86-64-modern
如果您已经开始使用 Ubuntu 或任何基于 Ubuntu 的 Linux 发行版,则必须通过以 root 身份运行以下命令来安装 Qt:

```shell
sudo apt-get install qt5-default qtmultimedia5-dev qtcreator
sudo apt-get install qt6-base-dev qt6-multimedia-dev qtcreator
```

使用 Qt Creator 打开 `src/ui/qt/CMakeLists.txt` ,或者运行:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ When reporting an issue or a bug, please tell us which version and compiler you
If you have started using Ubuntu or any Ubuntu-based Linux distribution, you must install Qt by running the following command as root:

```shell
sudo apt-get install qt5-default qtmultimedia5-dev qtcreator
sudo apt-get install qt6-base-dev qt6-multimedia-dev qtcreator
```

Use Qt Creator to open `src/ui/qt/CMakeLists.txt` , or run
Expand Down
16 changes: 12 additions & 4 deletions src/bitboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,28 @@ constexpr Bitboard file_bb(Square s)

/// popcount() counts the number of non-zero bits in a bitboard

inline int popcount(Bitboard b) noexcept
inline int generic_popcount(Bitboard b) noexcept
{
#ifdef DO_NOT_USE_POPCNT

union {
Bitboard bb;
uint16_t u[2];
} v = {b};

return PopCnt16[v.u[0]] + PopCnt16[v.u[1]];
}

inline int popcount(Bitboard b) noexcept
{
#ifdef DO_NOT_USE_POPCNT

return generic_popcount(b);

#elif defined(_MSC_VER) || defined(__INTEL_COMPILER)

#if defined(_M_X64) || defined(_M_IX86)
return _mm_popcnt_u32(b);
#else
return generic_popcount(b);
#endif

#else // Assumed gcc or compatible compiler

Expand Down
7 changes: 5 additions & 2 deletions src/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,13 @@ void prefetch(void *addr)
__asm__("");
#endif

#if defined(__INTEL_COMPILER) || defined(_MSC_VER)
#if defined(__INTEL_COMPILER) || \
(defined(_MSC_VER) && !defined(_M_ARM) && !defined(_M_ARM64))
_mm_prefetch(static_cast<char *>(addr), _MM_HINT_T0);
#else
#elif defined(__GNUC__) || defined(__clang__)
__builtin_prefetch(addr);
#else
(void)addr;
#endif
}

Expand Down
14 changes: 14 additions & 0 deletions src/perfect/perfect_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,21 @@
#define STRCPY(destination, destination_size, source) \
strcpy_s(destination, destination_size, source)

#if defined(_M_ARM) || defined(_M_ARM64)
// TODO: See generic_popcount()
inline int popcnt_software(uint32_t x) noexcept
{
int count = 0;
while (x) {
count += x & 1;
x >>= 1;
}
return count;
}
#define POPCNT(x) popcnt_software(x)
#else
#define POPCNT(x) __popcnt(x)
#endif

#else // _WIN32

Expand Down
8 changes: 6 additions & 2 deletions src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,15 @@
#define IS_64BIT
#endif

#if defined(USE_POPCNT) && (defined(__INTEL_COMPILER) || defined(_MSC_VER))
#if defined(USE_POPCNT) && \
(defined(__INTEL_COMPILER) || \
(defined(_MSC_VER) && !defined(_M_ARM) && !defined(_M_ARM64)))
#include <nmmintrin.h> // Intel and Microsoft header for _mm_popcnt_u64()
#endif

#if !defined(NO_PREFETCH) && (defined(__INTEL_COMPILER) || defined(_MSC_VER))
#if !defined(NO_PREFETCH) && \
(defined(__INTEL_COMPILER) || \
(defined(_MSC_VER) && !defined(_M_ARM) && !defined(_M_ARM64)))
#include <xmmintrin.h> // Intel and Microsoft header for _mm_prefetch()
#endif

Expand Down
3 changes: 2 additions & 1 deletion src/ui/qt/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
**/install_manifest.txt
JSON/

# Ignore all files generated by Qt Creator
# Ignore all files generated by Qt
.qt
.cache
*.prev
qtcsettings.cmake
Expand Down
15 changes: 12 additions & 3 deletions src/ui/qt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
cmake_minimum_required(VERSION 3.10)
project(mill-pro)

# Set C++ standard
set(CMAKE_CXX_STANDARD 17)

find_package(Qt5 REQUIRED COMPONENTS Core Gui Multimedia Widgets)
find_package(Qt6 REQUIRED COMPONENTS Core Gui Multimedia Widgets)

# Include directories
include_directories(${CMAKE_SOURCE_DIR} ../../../include ../.. ../../test)
include_directories(../../perfect)

qt5_add_resources(RESOURCES_RCC ${RESOURCES})
# Add resource files
qt_add_resources(RESOURCES_RCC ${RESOURCES})

# Source grouping
file(GLOB SOURCES_CORE ../../*.cpp ../../*.h ../../../include/*.h)
source_group("Source Files\\Core" FILES ${SOURCES_CORE})

Expand All @@ -25,8 +29,12 @@ source_group("Source Files\\Perfect" FILES ${SOURCES_PERFECT})
file(GLOB FORMS *.ui)
file(GLOB RESOURCE_FILES *.rc *.qrc)

# Compiler flags
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /W4")
if(CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64")
# Add ARM64-specific flags or settings
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -fdiagnostics-color=auto -Wno-deprecated -Wno-unused-parameter")
else()
Expand All @@ -46,12 +54,13 @@ set(all_sources

list(APPEND all_sources ${SOURCES_PERFECT})

# Link libraries and set properties for automatic Qt handling
add_executable(${PROJECT_NAME} ${all_sources})

if(MSVC)
target_link_libraries(${PROJECT_NAME} shlwapi)
endif()
target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Gui Qt5::Multimedia Qt5::Widgets)
target_link_libraries(${PROJECT_NAME} Qt6::Core Qt6::Gui Qt6::Multimedia Qt6::Widgets)

set_target_properties(${PROJECT_NAME} PROPERTIES AUTOMOC ON AUTOUIC ON AUTORCC ON)

4 changes: 2 additions & 2 deletions src/ui/qt/boarditem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void BoardItem::drawBoard(QPainter *painter)
{
#ifndef QT_MOBILE_APP_UI
QColor shadowColor(128, 42, 42);
shadowColor.setAlphaF(0.3);
shadowColor.setAlphaF(0.3f);
painter->fillRect(boundingRect(), QBrush(shadowColor));
#endif /* ! QT_MOBILE_APP_UI */

Expand Down Expand Up @@ -260,7 +260,7 @@ void BoardItem::drawPolarCoordinates(QPainter *painter)
painter->setFont(font);

for (int r = 0; r < RANK_NB; r++) {
QString text('1' + r);
QString text(QChar('1' + r));
painter->drawText(points[(FILE_NB - 1) * RANK_NB + r], text);
}
}
Expand Down
45 changes: 40 additions & 5 deletions src/ui/qt/build.bat
Original file line number Diff line number Diff line change
@@ -1,11 +1,46 @@
@echo off
setlocal

:: Clean repository
git clean -fdx

cmake .
:: Detect system architecture and set Qt6_DIR accordingly
if exist "%ProgramFiles%\Arm" (
set "Qt6_DIR=C:\Qt\6.7.1\msvc2019_arm64\lib\cmake\Qt6"
) else (
set "Qt6_DIR=C:\Qt\6.7.1\msvc2019_64\lib\cmake\Qt6"
)

:: Detect Visual Studio version
set "vsver="
for /f "tokens=*" %%i in ('dir "C:\Program Files\Microsoft Visual Studio\" /b /ad-h') do (
if "%%i"=="2019" (
set "vsver=Visual Studio 16 2019"
) else if "%%i"=="2022" (
set "vsver=Visual Studio 17 2022"
)
)

if not defined vsver (
echo "No suitable Visual Studio version found."
exit /b 1
)

:: Set system architecture based on previous detection
if exist "%ProgramFiles%\Arm" (
set "arch=ARM64"
) else (
set "arch=X64"
)

:: Generate project files
cmake -G "%vsver%" -A %arch% .

cmake --build . --target mill-pro
windeployqt "Debug\mill-pro.exe"
:: Build and deploy Debug version
cmake --build . --target mill-pro --config Debug
C:\Qt\Tools\QtDesignStudio\qt6_design_studio_reduced_version\bin\windeployqt "Debug\mill-pro.exe"

:: Build and deploy Release version
cmake --build . --target mill-pro --config Release
windeployqt "Release\mill-pro.exe"
C:\Qt\Tools\QtDesignStudio\qt6_design_studio_reduced_version\bin\windeployqt "Release\mill-pro.exe"

# cov-build --dir cov-int cmake --build . --target mill-pro
46 changes: 39 additions & 7 deletions src/ui/qt/build.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,46 @@
#!/bin/bash
set -e

# Clean repository
git clean -fdx

cmake .
# Detect Qt installation and set Qt6_DIR
Qt6_BIN=$(dirname "$(which qmake 2>/dev/null)")
Qt6_DIR="${Qt6_BIN%/bin}"

if [[ -z "$Qt6_DIR" ]]; then
echo "Qt6 installation not found."
exit 1
fi

# Detect system architecture
ARCH=$(uname -m)
if [[ "$ARCH" == "arm64" || "$ARCH" == "aarch64" ]]; then
ARCH="ARM64"
else
ARCH="x86_64"
fi

cmake --build . --target mill-pro
#windeployqt "Debug/mill-pro"
# Detect compiler version
if command -v gcc > /devontinue; then
GCC_VER=$(gcc -dumpversion)
echo "GCC version $GCC_VER detected."
elif command -v clang > /dev/null; then
CLANG_VER=$(clang --version | grep version | awk '{print $3}')
echo "Clang version $CLANG_VER detected."
else
echo "No suitable compiler found."
exit 1
fi

cmake --build . --target mill-pro --config Release
#windeployqt "Release/mill-pro"
# Generate project files for Debug
cmake -G "Unix Makefiles" -DCMAKE_PREFIX_PATH="$Qt6_DIR" -DCMAKE_BUILD_TYPE=Debug $EXTRA_CMAKE_FLAGS -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=Debug .

# cmake .. -G "Xcode" -DCMAKE_PREFIX_PATH=~/Qt5.12.12/5.12.12/clang_64 -DCMAKE_OSX_ARCHITECTURES=x86_64
# Build and deploy Debug version
cmake --build . --target mill-pro --config Debug -j

# cov-build --dir cov-int cmake --build . --target mill-pro
# Generate project files for Release
cmake -G "Unix Makefiles" -DCMAKE_PREFIX_PATH="$Qt6_DIR" -DCMAKE_BUILD_TYPE=Release $EXTRA_CMAKE_FLAGS -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=Release .

# Build and deploy Release version
cmake --build . --target mill-pro --config Release -j
2 changes: 1 addition & 1 deletion src/ui/qt/pieceitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ PieceItem::PieceItem(QGraphicsItem *parent)
#endif /* QT_MOBILE_APP_UI */

removeLineColor = QColor(227, 23, 13);
removeLineColor.setAlphaF(0.9);
removeLineColor.setAlphaF(0.9f);
}

PieceItem::~PieceItem() = default;
Expand Down
4 changes: 3 additions & 1 deletion src/ui/qt/winmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ int main(int argc, char *argv[])

QApplication a(argc, argv);
QTranslator translator;
translator.load("mill-pro-qt_zh_CN");
if (!translator.load("mill-pro-qt_zh_CN")) {
qWarning() << "Failed to load translation file.";
}
a.installTranslator(&translator);
MillGameWindow w;
w.show();
Expand Down

0 comments on commit 07ff29a

Please sign in to comment.