Skip to content

Commit 0438409

Browse files
committed
feat: mac support arm64
1 parent 63c7c02 commit 0438409

File tree

5 files changed

+65
-10
lines changed

5 files changed

+65
-10
lines changed

.github/workflows/macos.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ jobs:
1717
strategy:
1818
matrix:
1919
qt-ver: [6.5.3]
20-
qt-arch-install: [clang_64]
21-
clang-arch: [x64]
20+
qt-arch-install: [arm64]
21+
build-arch: [x64, arm64]
2222
env:
2323
target-name: QtScrcpy
2424
qt-install-path: ${{ github.workspace }}/${{ matrix.qt-ver }}
@@ -47,7 +47,7 @@ jobs:
4747
ENV_QT_PATH: ${{ env.qt-install-path }}
4848
run: |
4949
python ci/generate-version.py
50-
ci/mac/build_for_mac.sh RelWithDebInfo
50+
ci/mac/build_for_mac.sh RelWithDebInfo ${{ matrix.build-arch }}
5151
# 获取ref最后一个/后的内容
5252
- name: Get the version
5353
shell: bash
@@ -59,9 +59,9 @@ jobs:
5959
id: package
6060
env:
6161
ENV_QT_PATH: ${{ env.qt-install-path }}
62-
publish_name: ${{ env.target-name }}-${{ env.plantform-des }}-${{ matrix.clang-arch }}-${{ steps.get-version.outputs.version }}
62+
publish_name: ${{ env.target-name }}-${{ env.plantform-des }}-${{ matrix.build-arch }}-${{ steps.get-version.outputs.version }}
6363
run: |
64-
ci/mac/publish_for_mac.sh ../build
64+
ci/mac/publish_for_mac.sh ../build ${{ matrix.build-arch }}
6565
ci/mac/package_for_mac.sh
6666
mv ci/build/QtScrcpy.app ci/build/${{ env.publish_name }}.app
6767
mv ci/build/QtScrcpy.dmg ci/build/${{ env.publish_name }}.dmg

QtScrcpy/CMakeLists.txt

+13
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ if(CMAKE_SIZEOF_VOID_P EQUAL 8)
2828
else()
2929
set(QC_CPU_ARCH x86)
3030
endif()
31+
32+
# MacOS
33+
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
34+
# mac default arch arm64
35+
if(NOT CMAKE_OSX_ARCHITECTURES)
36+
set(CMAKE_OSX_ARCHITECTURES arm64)
37+
endif()
38+
39+
if (CMAKE_OSX_ARCHITECTURES MATCHES "arm64")
40+
set(QC_CPU_ARCH arm64)
41+
endif()
42+
endif()
43+
3144
message(STATUS "[${PROJECT_NAME}] CPU_ARCH:${QC_CPU_ARCH}")
3245

3346
# CMake set

ci/mac/build_for_mac.sh

+24-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ echo ---------------------------------------------------------------
88
# 从环境变量获取必要参数
99
# 例如 /Users/barry/Qt5.12.5/5.12.5
1010
echo ENV_QT_PATH $ENV_QT_PATH
11-
qt_cmake_path=$ENV_QT_PATH/clang_64/lib/cmake/Qt5
1211

1312
# 获取绝对路径,保证其他目录执行此脚本依然正确
1413
{
@@ -22,6 +21,7 @@ cd $(dirname "$0")
2221

2322
# 启动参数声明
2423
build_mode=RelWithDebInfo
24+
cpu_arch=arm64
2525

2626
echo
2727
echo
@@ -36,8 +36,30 @@ if [[ $build_mode != "Release" && $build_mode != "Debug" && $build_mode != "MinS
3636
exit 1
3737
fi
3838

39+
echo
40+
echo
41+
echo ---------------------------------------------------------------
42+
echo check cpu arch[x64/arm64]
43+
echo ---------------------------------------------------------------
44+
45+
cpu_arch=$(echo $2)
46+
if [[ $cpu_arch != "x64" && $cpu_arch != "arm64" ]]; then
47+
echo "error: unkonow cpu mode -- $2"
48+
exit 1
49+
fi
50+
3951
# 提示
4052
echo current build mode: $build_mode
53+
echo current cpu mode: $cpu_arch
54+
55+
cmake_arch=x86_64
56+
if [ $cpu_arch == "x64" ]; then
57+
qt_cmake_path=$ENV_QT_PATH/clang_64/lib/cmake/Qt5
58+
cmake_arch=x86_64
59+
else
60+
qt_cmake_path=$ENV_QT_PATH/macos/lib/cmake/Qt6
61+
cmake_arch=arm64
62+
fi
4163

4264
echo
4365
echo
@@ -58,7 +80,7 @@ fi
5880
mkdir $build_path
5981
cd $build_path
6082

61-
cmake_params="-DCMAKE_PREFIX_PATH=$qt_cmake_path -DCMAKE_BUILD_TYPE=$build_mode -DCMAKE_OSX_ARCHITECTURES=x86_64"
83+
cmake_params="-DCMAKE_PREFIX_PATH=$qt_cmake_path -DCMAKE_BUILD_TYPE=$build_mode -DCMAKE_OSX_ARCHITECTURES=$cmake_arch"
6284
cmake $cmake_params ../..
6385
if [ $? -ne 0 ] ;then
6486
echo "cmake failed"

ci/mac/publish_for_mac.sh

+22-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ echo ---------------------------------------------------------------
77
# 从环境变量获取必要参数
88
# 例如 /Users/barry/Qt5.12.5/5.12.5
99
echo ENV_QT_PATH $ENV_QT_PATH
10-
qt_clang_path=$ENV_QT_PATH/clang_64
1110

1211
# 获取绝对路径,保证其他目录执行此脚本依然正确
1312
{
@@ -21,6 +20,27 @@ cd $(dirname "$0")
2120

2221
# 启动参数声明
2322
publish_dir=$1
23+
cpu_arch=$2
24+
25+
echo
26+
echo
27+
echo ---------------------------------------------------------------
28+
echo check cpu arch[x64/arm64]
29+
echo ---------------------------------------------------------------
30+
31+
if [[ $cpu_arch != "x64" && $cpu_arch != "arm64" ]]; then
32+
echo "error: unkonow cpu mode -- $2"
33+
exit 1
34+
fi
35+
36+
# 提示
37+
echo current cpu mode: $cpu_arch
38+
39+
if [ $cpu_arch == "x64" ]; then
40+
qt_clang_path=$ENV_QT_PATH/clang_64
41+
else
42+
qt_clang_path=$ENV_QT_PATH/macos
43+
fi
2444

2545
# 提示
2646
echo current publish dir: $publish_dir
@@ -30,7 +50,7 @@ keymap_path=$script_path/../../keymap
3050
# config_path=$script_path/../../config
3151

3252
publish_path=$script_path/$publish_dir
33-
release_path=$script_path/../../output/x64/RelWithDebInfo
53+
release_path=$script_path/../../output/$cpu_arch/RelWithDebInfo
3454

3555
export PATH=$qt_clang_path/bin:$PATH
3656

0 commit comments

Comments
 (0)