Skip to content

Commit

Permalink
macos arm;
Browse files Browse the repository at this point in the history
优化代码;
  • Loading branch information
RealChuan committed Mar 29, 2024
1 parent 6de13ed commit 57ef0c8
Show file tree
Hide file tree
Showing 29 changed files with 546 additions and 429 deletions.
55 changes: 40 additions & 15 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,19 @@ jobs:
- macos-latest
- ubuntu-latest
qt_ver:
- 6.6.1
- 6.6.2
build_type:
- "RelWithDebInfo"
generators:
- "Ninja"
arch:
- x86_64
include:
- os: macos-latest
qt_ver: 6.6.2
build_type: "RelWithDebInfo"
generators: "Ninja"
arch: arm64

steps:
- name: Restore windows vcpkg
Expand All @@ -67,25 +75,34 @@ jobs:
ninja --version
cmake --version
vcpkg install breakpad --triplet x64-windows
- name: Install dependencies on macos
if: startsWith(matrix.os, 'macos')
- name: Install dependencies on ubuntu
if: startsWith(matrix.os, 'ubuntu')
shell: bash
run: |
sudo apt-get update
sudo apt-get install ninja-build build-essential libgl1-mesa-dev
ninja --version
cmake --version
gcc --version
vcpkg install breakpad --triplet x64-linux
- name: Install dependencies on macos-x86_64
if: startsWith(matrix.os, 'macos') && matrix.arch == 'x86_64'
shell: bash
run: |
brew install ninja pkg-config
ninja --version
cmake --version
clang --version
vcpkg install breakpad --triplet x64-osx
- name: Install dependencies on ubuntu
if: startsWith(matrix.os, 'ubuntu')
- name: Install dependencies on macos-arm64
if: startsWith(matrix.os, 'macos') && matrix.arch == 'arm64'
shell: bash
run: |
sudo apt-get update
sudo apt-get install ninja-build build-essential libgl1-mesa-dev
brew install ninja pkg-config
ninja --version
cmake --version
gcc --version
vcpkg install breakpad --triplet x64-linux
clang --version
vcpkg install breakpad --triplet arm64-osx
- name: Install Qt
uses: jurplel/install-qt-action@v3
Expand Down Expand Up @@ -124,8 +141,10 @@ jobs:
-S . \
-B ./build \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-DCMAKE_OSX_ARCHITECTURES="${{ matrix.arch }}" \
-G "${{ matrix.generators }}" \
-DCMAKE_INSTALL_PREFIX:PATH=instdir
- name: Build
shell: bash
run: |
Expand Down Expand Up @@ -197,12 +216,12 @@ jobs:
shell: bash
run: |
ls -al ./bin-64/${{ matrix.build_type }}
7z a -t7z -r -mx=9 -mmt Qt-App-${{ matrix.os }}-${{ matrix.build_type }}.7z ./bin-64/${{ matrix.build_type }}/*
7z a -t7z -r -mx=9 -mmt Qt-App-${{ matrix.os }}-${{matrix.arch}}-${{ matrix.build_type }}.7z ./bin-64/${{ matrix.build_type }}/*
- name: Upload packages
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.os }}-${{ matrix.build_type }}
path: Qt-App-${{ matrix.os }}-${{ matrix.build_type }}.7z
name: ${{ matrix.os }}-${{matrix.arch}}-${{ matrix.build_type }}
path: Qt-App-${{ matrix.os }}-${{matrix.arch}}-${{ matrix.build_type }}.7z

release:
name: Release
Expand All @@ -212,16 +231,22 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Download fonts
shell: bash
run: |
wget -c -nv "https://github.com/RealChuan/Qt-App/releases/download/0.0.1/fonts.7z"
- name: Download packages
uses: actions/download-artifact@v3

- name: Move packages
shell: bash
run: |
ls -al
mv ./windows-latest-RelWithDebInfo/Qt-App-*.7z .
mv ./macos-latest-RelWithDebInfo/Qt-App-*.7z .
mv ./ubuntu-latest-RelWithDebInfo/Qt-App-*.7z .
mv ./windows-latest-x86_64-RelWithDebInfo/Qt-App-*.7z .
mv ./ubuntu-latest-x86_64-RelWithDebInfo/Qt-App-*.7z .
mv ./macos-latest-x86_64-RelWithDebInfo/Qt-App-*.7z .
mv ./macos-latest-arm64-RelWithDebInfo/Qt-App-*.7z .
ls -al
- name: Create Release
Expand Down
35 changes: 25 additions & 10 deletions .github/workflows/qmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ jobs:
- macos-latest
- ubuntu-latest
qt_ver:
- 6.6.1
- 6.6.2
arch:
- x86_64
include:
- os: macos-latest
qt_ver: 6.6.2
arch: arm64

steps:
- name: Restore windows vcpkg
Expand All @@ -63,25 +69,34 @@ jobs:
ninja --version
cmake --version
vcpkg install breakpad --triplet x64-windows
- name: Install dependencies on macos
if: startsWith(matrix.os, 'macos')
- name: Install dependencies on ubuntu
if: startsWith(matrix.os, 'ubuntu')
shell: bash
run: |
sudo apt-get update
sudo apt-get install ninja-build build-essential libgl1-mesa-dev
ninja --version
cmake --version
gcc --version
vcpkg install breakpad --triplet x64-linux
- name: Install dependencies on macos-x86_64
if: startsWith(matrix.os, 'macos') && matrix.arch == 'x86_64'
shell: bash
run: |
brew install ninja pkg-config
ninja --version
cmake --version
clang --version
vcpkg install breakpad --triplet x64-osx
- name: Install dependencies on ubuntu
if: startsWith(matrix.os, 'ubuntu')
- name: Install dependencies on macos-arm64
if: startsWith(matrix.os, 'macos') && matrix.arch == 'arm64'
shell: bash
run: |
sudo apt-get update
sudo apt-get install ninja-build build-essential libgl1-mesa-dev
brew install ninja pkg-config
ninja --version
cmake --version
gcc --version
vcpkg install breakpad --triplet x64-linux
clang --version
vcpkg install breakpad --triplet arm64-osx
- name: Install Qt
uses: jurplel/install-qt-action@v3
Expand All @@ -106,5 +121,5 @@ jobs:
if: startsWith(matrix.os, 'macos') || startsWith(matrix.os, 'ubuntu')
shell: bash
run: |
qmake
qmake QMAKE_APPLE_DEVICE_ARCHS="${{ matrix.arch }}"
make -j4
3 changes: 2 additions & 1 deletion .github/workflows/toolchain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- macos-latest
- ubuntu-latest
qt_ver:
- 6.6.1
- 6.6.2

steps:
- name: Install Qt
Expand Down Expand Up @@ -49,6 +49,7 @@ jobs:
cmake --version
clang --version
vcpkg install breakpad --triplet x64-osx
vcpkg install breakpad --triplet arm64-osx
- name: Install dependencies on ubuntu
if: startsWith(matrix.os, 'ubuntu')
shell: bash
Expand Down
6 changes: 5 additions & 1 deletion 3rdparty/3rdparty.pri
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ win32{
}

macx{
vcpkg_path = /usr/local/share/vcpkg/installed/x64-osx
contains(QMAKE_APPLE_DEVICE_ARCHS, arm64) {
vcpkg_path = /usr/local/share/vcpkg/installed/arm64-osx
} else {
vcpkg_path = /usr/local/share/vcpkg/installed/x64-osx
}
}

unix:!macx{
Expand Down
2 changes: 1 addition & 1 deletion 3rdparty/breakpad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void createEnvironment()
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
auto systemEnviroment = QProcess::systemEnvironment();
QString str;
for (const QString &info : qAsConst(systemEnviroment)) {
for (const QString &info : std::as_const(systemEnviroment)) {
str += info;
str += '\n';
}
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(utils)

if(CMAKE_HOST_WIN32)
list(APPEND CMAKE_PREFIX_PATH "C:\\Qt\\6.6.1\\msvc2019_64")
list(APPEND CMAKE_PREFIX_PATH "C:\\Qt\\6.6.2\\msvc2019_64")
elseif(CMAKE_HOST_APPLE)

elseif(CMAKE_HOST_UNIX)
list(APPEND CMAKE_PREFIX_PATH "/opt/Qt/6.6.1/gcc_64")
list(APPEND CMAKE_PREFIX_PATH "/opt/Qt/6.6.2/gcc_64")
endif()

project(
Expand Down
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@

## Qt-App

基于插件是开发的桌面应用程序框架,可以用于快速开发桌面应用程序;
- 基于插件是开发的桌面应用程序框架,可以用于快速开发桌面应用程序;
[qt-creator/src/libs/extensionsystem at master · qt-creator/qt-creator (github.com)](https://github.com/qt-creator/qt-creator/tree/master/src/libs/extensionsystem)
- 配合[vcpkg](https://github.com/microsoft/vcpkg)进行使用;
- 同时支持[cmake](.github/workflows/cmake.yml)[qmake](.github/workflows/qmake.yml)编译;
- [支持Apple Silicon原生编译;](#问题和备注)
- 支持[actions](.github/workflows/cmake.yml)编译,打包、发布;

<div align="center"><img src="doc/Qt-App.jpg" width="90%" height="90%" /></div>

Expand Down Expand Up @@ -43,17 +47,21 @@
10. [utils](utils):工具函数封装;

## 问题和备注
1. MacOS,cmake生成的bundle,在.app/Contents/文件夹下没有生成`PkgInfo`文件;

- MacOS,cmake生成的bundle,在.app/Contents/文件夹下没有生成`PkgInfo`文件;
1. [app/CMakeLists](/apps/app/CMakeLists.txt),使用这个CMakeLists.txt可以在MacOS上生成bundle,也可以正常显示图标,但是没有PkgInfo文件;
2. cmake该怎么生成PkgInfo文件?
1. WireShark使用`set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/PkgInfo PROPERTIES MACOSX_PACKAGE_LOCATION .)`类似这种方式,拷贝到bundle中;
3. qmake默认会生成PkgInfo文件,只需要指定`TARGET=app`或者`CONFIG+=bundle`即可;
2. Unix 系统下,需要尽量使用静态库,避免动态库的依赖问题;
3. qmake默认会生成PkgInfo文件,只需要指定`TARGET=app`或者`CONFIG+=bundle`即可;

- Unix 系统下,需要尽量使用静态库,避免动态库的依赖问题;
1. 本项目有几个模块是动态库,因为是plugin,需要动态加载;
2. 然后需要对这几个动态库进行打包,然后在运行时加载,还需要对rpath`"-Wl,-rpath,\'\$$ORIGIN\':\'\$$ORIGIN/lib\':'\$$ORIGIN/../lib'")`,进行设置,否则会找不到动态库;
3. 或者使用install_name_tool(macos)、patchelf/chrpath(linux)修改动态库的依赖路径,非常麻烦;
4. 还要考虑到这些库都是可以共享的,所以不要重复打包;
5. 具体可以看[workflows](.github/workflows/cmake.yml)



- MacOS,[vcpkg](https://github.com/microsoft/vcpkg)编译第三方库问题;
1. 由于[vcpkg](https://github.com/microsoft/vcpkg)目前[只支持单独编译x64-osx和arm64-osx](https://github.com/microsoft/vcpkg/discussions/19454)
2. 在使用[cmake](.github/workflows/cmake.yml)时,需要指定`CMAKE_OSX_ARCHITECTURES=x86_64`或者`CMAKE_OSX_ARCHITECTURES=arm64`;
3. 在使用[qmake](.github/workflows/qmake.yml)时,需要指定`QMAKE_APPLE_DEVICE_ARCHS=x86_64`或者`QMAKE_APPLE_DEVICE_ARCHS=arm64`
4 changes: 2 additions & 2 deletions apps/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ else()
add_rpath(Qt-App)
endif()

set_target_properties(Qt-App PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE
TRUE)
set_target_properties(Qt-App PROPERTIES MACOSX_BUNDLE TRUE WIN32_EXECUTABLE
TRUE)

target_link_libraries(
Qt-App
Expand Down
4 changes: 2 additions & 2 deletions gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ set(PROJECT_SOURCES
messbox.h
multitextcursor.cpp
multitextcursor.h
toolbutton.cc
toolbutton.hpp
pushbutton.cc
pushbutton.hpp
treemodel.cpp
treemodel.h
waitwidget.cpp
Expand Down
Loading

0 comments on commit 57ef0c8

Please sign in to comment.