Skip to content

Commit b167311

Browse files
authored
Merge pull request qgis#59177 from m-kuhn/macvcpkg
Mac Qt6 Builds
2 parents c314b4b + bc74595 commit b167311

File tree

10 files changed

+256
-9
lines changed

10 files changed

+256
-9
lines changed

.github/actions/setup-vcpkg/action.yml

+7-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@ runs:
1515
if: runner.os != 'Windows'
1616
shell: bash
1717
run: |
18-
. <(curl https://aka.ms/vcpkg-init.sh -L)
18+
export VCPKG_ROOT=$HOME/.vcpkg
19+
wget https://aka.ms/vcpkg-init.sh -O /tmp/vcpkg-init.sh
20+
. /tmp/vcpkg-init.sh
21+
echo "VCPKG_ROOT=$VCPKG_ROOT" >> $GITHUB_ENV
1922
echo "PATH=$VCPKG_ROOT;$PATH" >> $GITHUB_ENV
23+
# Integrate patch from https://github.com/microsoft/vcpkg/pull/41146
24+
wget https://raw.githubusercontent.com/microsoft/vcpkg/6271c9bfab7ff6dbf3444c3600a28e7c6b0ea462/scripts/cmake/z_vcpkg_fixup_rpath_macho.cmake -O /Users/runner/.vcpkg/scripts/cmake/z_vcpkg_fixup_rpath_macho.cmake
2025
2126
- name: Setup vcpkg
2227
if: runner.os == 'Windows'
@@ -25,4 +30,4 @@ runs:
2530
$env:VCPKG_ROOT = "C:/.vcpkg"
2631
iex (iwr -useb https://aka.ms/vcpkg-init.ps1)
2732
echo "VCPKG_ROOT=$env:VCPKG_ROOT" >> $env:GITHUB_ENV
28-
echo "PATH=$env:VCPKG_ROOT;$env:PATH" >> $env:GITHUB_ENV
33+
echo "PATH=$env:VCPKG_ROOT;$env:PATH" >> $env:GITHUB_ENV

.github/workflows/build-macos-qt6.yml

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
name: 🍎 Build - MacOS Qt6
3+
on:
4+
# push:
5+
# branches:
6+
# - main
7+
# pull_request:
8+
# release:
9+
# types: ['published']
10+
workflow_dispatch:
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
build:
18+
strategy:
19+
matrix:
20+
include:
21+
# - os: macos-13
22+
# triplet: x64-osx
23+
# deployment-target: "10.15"
24+
- os: macos-14
25+
triplet: arm64-osx-dynamic-release
26+
deployment-target: "11.0"
27+
name: build (macos)
28+
runs-on: ${{ matrix.os }}
29+
30+
steps:
31+
- name: 🐣 Checkout
32+
uses: actions/checkout@v4
33+
34+
- name: 🐩 Install CMake and Ninja
35+
uses: lukka/get-cmake@latest
36+
with:
37+
# Pin to specific version to avoid rebuilding too often
38+
# Also helps to avoid spurious build failures like https://github.com/qgis/QGIS/pull/47098
39+
cmakeVersion: 3.30.4
40+
41+
- name: 🎡 Setup vcpkg
42+
id: setup-vcpkg
43+
uses: ./.github/actions/setup-vcpkg
44+
45+
- name: 🔨 Prepare build env
46+
run: |
47+
brew install automake bison flex gnu-sed create-dmg autoconf-archive nasm libtool fdupes
48+
echo $(brew --prefix bison)/bin >> $GITHUB_PATH
49+
echo $(brew --prefix flex)/bin >> $GITHUB_PATH
50+
echo $(brew --prefix libtool)/bin >> $GITHUB_PATH
51+
52+
- uses: actions/setup-python@v5
53+
with:
54+
python-version: '3.11'
55+
56+
- name: 🍭 Setup XCode
57+
uses: maxim-lobanov/[email protected]
58+
with:
59+
xcode-version: latest-stable
60+
61+
- name: 🌱 Install dependencies and generate project files
62+
run: |
63+
echo "VCPKG_ROOT: ${VCPKG_ROOT}"
64+
65+
# Install first only with binarycaching, then deduplicate binaries and replace copies with symlinks.
66+
# Nuget doesn't understand the symlink concept
67+
cmake -S . \
68+
-G Ninja \
69+
-B build \
70+
-D WITH_VCPKG=ON \
71+
-D BUILD_WITH_QT6=ON \
72+
-D WITH_QTWEBKIT=OFF \
73+
-D WITH_BINDINGS=ON \
74+
-D QGIS_MACAPP_FRAMEWORK=OFF \
75+
-D VCPKG_TARGET_TRIPLET="${{ matrix.triplet }}" \
76+
-D VCPKG_HOST_TRIPLET="${{ matrix.triplet }}" \
77+
-D VCPKG_INSTALL_OPTIONS="--only-binarycaching" \
78+
-D NUGET_USERNAME=${{ github.actor }} \
79+
-D NUGET_TOKEN=${{ secrets.GITHUB_TOKEN }} || true
80+
81+
fdupes -r -1 build/vcpkg_installed/arm64-osx-dynamic/lib | grep libQt | while read line; do master=""; for file in ${line[*]}; do if [[ "x${master}" == "x" ]]; then master=$file; else rm "${file}"; ln -s $(basename "${master}") "${file}"; fi; done; done
82+
83+
cmake -D VCPKG_INSTALL_OPTIONS="" build
84+
85+
- name: 📑 Upload vcpkg build logs
86+
uses: actions/upload-artifact@v3
87+
if: failure()
88+
with:
89+
name: build-logs-${{ matrix.triplet }}
90+
path: |
91+
${{ env.VCPKG_ROOT }}/buildtrees/**/*.log
92+
93+
- name: 📦 Create SDK
94+
if: github.event_name == 'workflow_dispatch' || github.event_name == 'release'
95+
run: |
96+
./build/_deps/vcpkg-src/vcpkg export --zip --output-dir=./sdk --x-install-root=./build/vcpkg_installed --x-manifest-root=vcpkg
97+
98+
- name: 📤 Upload sdk
99+
if: github.event_name == 'workflow_dispatch' || github.event_name == 'release'
100+
uses: actions/upload-artifact@v4
101+
with:
102+
name: kadas-albireo2-sdk-${{ matrix.triplet }}
103+
path: |
104+
sdk/vcpkg-export-*.zip
105+
106+
- name: 🌋 Build
107+
run: |
108+
cmake --build build

CMakeLists.txt

+6-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ if(NOT SDK_PATH STREQUAL "")
3333
set(CMAKE_TOOLCHAIN_FILE "${SDK_PATH}/scripts/buildsystems/vcpkg.cmake")
3434
set(VCPKG_INSTALL_PREFIX "${SDK_PATH}/installed")
3535
if(APPLE AND NOT VCPKG_TARGET_TRIPLET)
36-
set(VCPKG_TARGET_TRIPLET "x64-osx-dynamic")
36+
message(FATAL_ERROR "VCPKG_TARGET_TRIPLET not set (set it to arm64-osx-dynamic-release or x64-osx-dynamic-release")
3737
endif()
3838
set(WITH_VCPKG ON)
3939
elseif(WITH_VCPKG)
@@ -45,7 +45,11 @@ else()
4545
endif()
4646

4747
if(WITH_VCPKG)
48-
list(APPEND CMAKE_PROGRAM_PATH "${VCPKG_INSTALL_PREFIX}/${VCPKG_TARGET_TRIPLET}/tools/python3/Scripts/")
48+
if(WIN32)
49+
list(APPEND CMAKE_PROGRAM_PATH "${VCPKG_INSTALL_PREFIX}/${VCPKG_TARGET_TRIPLET}/tools/python3/Scripts/")
50+
else()
51+
list(APPEND CMAKE_PROGRAM_PATH "${VCPKG_INSTALL_PREFIX}/${VCPKG_TARGET_TRIPLET}/bin")
52+
endif()
4953
set(PREFER_INTERNAL_LIBS FALSE)
5054
else()
5155
set(PREFER_INTERNAL_LIBS TRUE)

cmake/VcpkgToolchain.cmake

+13-4
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@ if(WITH_GUI)
1212
list(APPEND VCPKG_MANIFEST_FEATURES "gui")
1313
endif()
1414

15-
# Setup binary cache
16-
if(NOT "${NUGET_TOKEN}" STREQUAL "" AND WIN32)
17-
set(_VCPKG_EXECUTABLE "vcpkg.exe")
15+
# Binarycache can only be used on Windows or if mono is available.
16+
find_program(_VCPKG_MONO mono)
17+
if(NOT "${NUGET_TOKEN}" STREQUAL "" AND (_HOST_IS_WINDOWS OR EXISTS "${_VCPKG_MONO}"))
18+
if(_HOST_IS_WINDOWS)
19+
set(_VCPKG_EXECUTABLE "$ENV{VCPKG_ROOT}/vcpkg.exe")
20+
else()
21+
set(_VCPKG_EXECUTABLE "$ENV{VCPKG_ROOT}/vcpkg")
22+
endif()
1823

1924
execute_process(
2025
COMMAND ${_VCPKG_EXECUTABLE} fetch nuget
@@ -24,7 +29,11 @@ if(NOT "${NUGET_TOKEN}" STREQUAL "" AND WIN32)
2429
STRING(REGEX REPLACE "\n" ";" _FETCH_NUGET_OUTPUT "${_FETCH_NUGET_OUTPUT}")
2530
list(GET _FETCH_NUGET_OUTPUT -1 _NUGET_PATH)
2631

27-
set(_NUGET_EXE ${_NUGET_PATH})
32+
if(_HOST_IS_WINDOWS)
33+
set(_NUGET_EXE ${_NUGET_PATH})
34+
else()
35+
set(_NUGET_EXE ${_VCPKG_MONO} ${_NUGET_PATH})
36+
endif()
2837

2938
set(_CONFIG_PATH "${CMAKE_BINARY_DIR}/github-NuGet.Config")
3039

src/app/CMakeLists.txt

+7-1
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,13 @@ if (ANDROID)
512512
# require c++17
513513
target_compile_features(${QGIS_APP_NAME} PRIVATE cxx_std_17)
514514
else()
515-
add_executable(${QGIS_APP_NAME} MACOSX_BUNDLE WIN32 ${QGIS_APPMAIN_SRCS})
515+
if(APPLE)
516+
set (CREATE_MACOSX_BUNDLE TRUE CACHE BOOL "Create macosx bundle during build. Disable for development to avoid copying libraries and ease debugging.")
517+
if(CREATE_MACOSX_BUNDLE)
518+
set(MACOSX_BUNDLE "MACOSX_BUNDLE")
519+
endif()
520+
endif()
521+
add_executable(${QGIS_APP_NAME} ${MACOSX_BUNDLE} WIN32 ${QGIS_APPMAIN_SRCS})
516522

517523
if(MSVC AND BUILD_WITH_QT6)
518524
qt_disable_unicode_defines(${QGIS_APP_NAME})
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
diff --git a/setuptools/_distutils/command/build_ext.py b/setuptools/_distutils/command/build_ext.py
2+
index 06d949a..0dee0fe 100644
3+
--- a/setuptools/_distutils/command/build_ext.py
4+
+++ b/setuptools/_distutils/command/build_ext.py
5+
@@ -209,6 +209,14 @@ class build_ext(Command):
6+
elif isinstance(self.rpath, str):
7+
self.rpath = self.rpath.split(os.pathsep)
8+
9+
+ prefix = os.path.normpath(sys.prefix)
10+
+ vcpkg_prefix = os.path.dirname(os.path.dirname(prefix)) # Add debug compile?
11+
+
12+
+ if self.debug:
13+
+ self.library_dirs.append(os.path.join(vcpkg_prefix, 'debug', 'lib'))
14+
+ else:
15+
+ self.library_dirs.append(os.path.join(vcpkg_prefix, 'lib'))
16+
+
17+
# for extensions under windows use different directories
18+
# for Release and Debug builds.
19+
# also Python's library directory must be appended to library_dirs
20+
@@ -216,9 +224,9 @@ class build_ext(Command):
21+
# the 'libs' directory is for binary installs - we assume that
22+
# must be the *native* platform. But we don't really support
23+
# cross-compiling via a binary install anyway, so we let it go.
24+
- self.library_dirs.append(os.path.join(sys.exec_prefix, 'libs'))
25+
- if sys.base_exec_prefix != sys.prefix: # Issue 16116
26+
- self.library_dirs.append(os.path.join(sys.base_exec_prefix, 'libs'))
27+
+ # self.library_dirs.append(os.path.join(sys.exec_prefix, 'libs'))
28+
+ # if sys.base_exec_prefix != sys.prefix: # Issue 16116
29+
+ # self.library_dirs.append(os.path.join(sys.base_exec_prefix, 'libs'))
30+
if self.debug:
31+
self.build_temp = os.path.join(self.build_temp, "Debug")
32+
else:
33+
diff --git a/setuptools/_distutils/sysconfig.py b/setuptools/_distutils/sysconfig.py
34+
index 1a38e9f..2c8174d 100644
35+
--- a/setuptools/_distutils/sysconfig.py
36+
+++ b/setuptools/_distutils/sysconfig.py
37+
@@ -191,18 +191,21 @@ def _get_python_inc_from_config(plat_specific, spec_prefix):
38+
def _get_python_inc_posix_prefix(prefix):
39+
implementation = 'pypy' if IS_PYPY else 'python'
40+
python_dir = implementation + get_python_version() + build_flags
41+
- return os.path.join(prefix, "include", python_dir)
42+
+ vcpkg_prefix = os.path.dirname(os.path.dirname(prefix))
43+
+ return os.path.join(vcpkg_prefix, "include", python_dir)
44+
45+
46+
def _get_python_inc_nt(prefix, spec_prefix, plat_specific):
47+
+ vcpkg_prefix = os.path.dirname(os.path.dirname(prefix))
48+
+ python_dir = 'python' + get_python_version()
49+
if python_build:
50+
# Include both include dirs to ensure we can find pyconfig.h
51+
return (
52+
- os.path.join(prefix, "include")
53+
+ os.path.join(vcpkg_prefix, "include", python_dir)
54+
+ os.path.pathsep
55+
+ os.path.dirname(sysconfig.get_config_h_filename())
56+
)
57+
- return os.path.join(prefix, "include")
58+
+ return os.path.join(vcpkg_prefix, "include", python_dir)
59+
60+
61+
# allow this behavior to be monkey-patched. Ref pypa/distutils#2.
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
vcpkg_from_pythonhosted(
2+
OUT_SOURCE_PATH SOURCE_PATH
3+
PACKAGE_NAME setuptools
4+
VERSION ${VERSION}
5+
SHA512 d0a34f16dfa6bb9a6df39076cd43528cf854d343f6f801c448ea0ebab2a259aec3d03571e2a26709df6082ed2fcb6c43b86448be556fd559b6af41831b4f38e0
6+
PATCHES
7+
fix-prefix.patch
8+
)
9+
10+
vcpkg_python_build_and_install_wheel(SOURCE_PATH "${SOURCE_PATH}")
11+
12+
set(VCPKG_POLICY_EMPTY_INCLUDE_FOLDER enabled)
13+
14+
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")
15+
#execute_process(COMMAND ${PYTHON3} "${SOURCE_PATH}/setup.py" install "--prefix=${CURRENT_INSTALLED_DIR}/tools/python3" "--root=${CURRENT_PACKAGES_DIR}"
16+
# COMMAND_ERROR_IS_FATAL ANY
17+
# WORKING_DIRECTORY "${CURRENT_PACKAGES_DIR}/tools/python3"
18+
#)

vcpkg/ports/py-setuptools/vcpkg.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "py-setuptools",
3+
"version": "72.1.0",
4+
"description": "Official project repository for the Setuptools build system ",
5+
"homepage": "https://pypi.org/project/setuptools/",
6+
"license": "MIT",
7+
"dependencies": [
8+
"py-packaging",
9+
"py-wheel",
10+
"python3",
11+
{
12+
"name": "vcpkg-python-scripts",
13+
"host": true
14+
}
15+
]
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
set(VCPKG_TARGET_ARCHITECTURE arm64)
2+
set(VCPKG_CRT_LINKAGE dynamic)
3+
set(VCPKG_LIBRARY_LINKAGE dynamic)
4+
5+
set(VCPKG_CMAKE_SYSTEM_NAME Darwin)
6+
set(VCPKG_OSX_ARCHITECTURES arm64)
7+
set(VCPKG_BUILD_TYPE release)
8+
9+
set(VCPKG_FIXUP_MACHO_RPATH ON)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
set(VCPKG_TARGET_ARCHITECTURE x64)
2+
set(VCPKG_CRT_LINKAGE dynamic)
3+
set(VCPKG_LIBRARY_LINKAGE dynamic)
4+
5+
set(VCPKG_CMAKE_SYSTEM_NAME Darwin)
6+
set(VCPKG_OSX_ARCHITECTURES x86_64)
7+
set(VCPKG_BUILD_TYPE release)
8+
9+
set(VCPKG_FIXUP_MACHO_RPATH ON)
10+
set(VCPKG_OSX_DEPLOYMENT_TARGET 10.15)
11+

0 commit comments

Comments
 (0)