Build the Plugin Dependencies (macOS) #34
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build the Plugin Dependencies (macOS) | |
# This action is used to generate the plugin dependencies | |
# for macOS targets. A C++ plugin for QGIS needs to link the | |
# static QGIS libraries (e.g. qgis_core). Pre-built libraries | |
# are available in the QGIS installations, but they do not come | |
# with the accompanying header files. If you try to rebuild the | |
# libraries from scratch (e.g. by checking out the right commit | |
# and building QGIS), the C++ plugin will compile, but you won't | |
# be able to use it, due to the one-definition rule. QGIS | |
# will crash when trying to run with a C++ plugin on macOS. | |
# This GitHub action solves this issue by: | |
# 1) rebuilding the right QGIS version to get the header files. | |
# 2) downloading the QGIS installation binary to get the library | |
# files. | |
# 3) uploading the header + libraries as artifacts. | |
on: | |
workflow_dispatch: | |
inputs: | |
qgis-version: | |
description: "The QGIS version to build the dependencies." | |
default: '3_36_3' | |
lib-version: | |
description: "The QGIS version as a different string." | |
default: '3.36' | |
build-timestamp: | |
description: "The QGIS build timestamp (you can find it here: `https://download.qgis.org/downloads/macos/pr/`)." | |
default: '20240517_122510' | |
env: | |
QT_VERSION: 5.15.2 | |
QGIS_DEPS_VERSION: 0.9 | |
QGIS_DEPS_PATCH_VERSION: 0 | |
BUILD_DIR: build-QGIS | |
OUT_DIR: macos-final-libraries | |
LIB_PATH: output/lib | |
SRC_PATH: src | |
jobs: | |
build-macos-dependencies: | |
runs-on: macos-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
repository: qgis/QGIS | |
ref: final-${{ inputs.qgis-version }} | |
- name: Download the Official QGIS Release | |
# use a wildcard for the build date, as the build date is not known | |
run: | | |
wget -O qgis_installer.dmg https://download.qgis.org/downloads/macos/pr/qgis_pr_final-${{ inputs.qgis-version }}_${{ inputs.build-timestamp }}.dmg | |
# wget -O qgis_installer.dmg -r --no-parent -A 'qgis_pr_final-${{ inputs.qgis-version }}_*.dmg' https://download.qgis.org/downloads/macos/pr/ | |
- name: Mount Official QGIS | |
# To bypass EULA, we convert to cdr format. | |
run: | | |
hdiutil convert qgis_installer.dmg -format UDTO -o qgis_installer.cdr | |
hdiutil attach -quiet -nobrowse -noverify -noautoopen qgis_installer.cdr | |
echo QGIS installer image mounted. | |
- name: Copy pre-built libraries | |
run: | | |
mkdir -p ${{ env.OUT_DIR }}/${{ env.LIB_PATH }} | |
cp -v -R /Volumes/QGIS.app/QGIS.app/Contents/Frameworks/qgis_3d.framework ${{ env.OUT_DIR }}/${{ env.LIB_PATH }} | |
cp -R /Volumes/QGIS.app/QGIS.app/Contents/Frameworks/qgis_analysis.framework ${{ env.OUT_DIR }}/${{ env.LIB_PATH }} | |
cp -R /Volumes/QGIS.app/QGIS.app/Contents/Frameworks/qgis_core.framework ${{ env.OUT_DIR }}/${{ env.LIB_PATH }} | |
cp -R /Volumes/QGIS.app/QGIS.app/Contents/Frameworks/qgis_gui.framework ${{ env.OUT_DIR }}/${{ env.LIB_PATH }} | |
cp -R /Volumes/QGIS.app/QGIS.app/Contents/Frameworks/qgis_native.framework ${{ env.OUT_DIR }}/${{ env.LIB_PATH }} | |
cd ${{ env.OUT_DIR }}/${{ env.LIB_PATH }} | |
ls -la | |
- name: Unmount official QGIS | |
run: | | |
hdiutil detach /Volumes/QGIS.app/ | |
- name: Download Qt | |
run: | | |
wget https://qgis.org/downloads/macos/deps/qt-${QT_VERSION}.tar.gz | |
- name: Download qgis-deps | |
run: | | |
wget https://qgis.org/downloads/macos/deps/qgis-deps-${QGIS_DEPS_VERSION}.${QGIS_DEPS_PATCH_VERSION}.tar.gz | |
- name: Install Qt and deps | |
run: | | |
wget https://qgis.org/downloads/macos/deps/install_qgis_deps-${QGIS_DEPS_VERSION}.${QGIS_DEPS_PATCH_VERSION}.bash | |
chmod +x ./install_qgis_deps-${QGIS_DEPS_VERSION}.${QGIS_DEPS_PATCH_VERSION}.bash | |
echo ::group::Install deps | |
sudo ./install_qgis_deps-${QGIS_DEPS_VERSION}.${QGIS_DEPS_PATCH_VERSION}.bash | |
- name: Run cmake | |
run: | | |
mkdir -p ${{ env.BUILD_DIR }} | |
cd ${{ env.BUILD_DIR }} | |
PATH=/opt/QGIS/qgis-deps-${QGIS_DEPS_VERSION}/stage/bin:$PATH \ | |
cmake -DQGIS_MAC_DEPS_DIR=/opt/QGIS/qgis-deps-${QGIS_DEPS_VERSION}/stage \ | |
-DCMAKE_PREFIX_PATH=/opt/Qt/${QT_VERSION}/clang_64 \ | |
-DWITH_BINDINGS=TRUE \ | |
-DWITH_3D=TRUE \ | |
-DWITH_DRACO=FALSE \ | |
-DWITH_PDAL=TRUE \ | |
-DWITH_EPT=TRUE \ | |
-DCMAKE_OSX_ARCHITECTURES=x86_64 \ | |
.. | |
- name: Build QGIS | |
run: | | |
cd ${{ env.BUILD_DIR }} | |
make -j $(sysctl -n hw.ncpu) | |
- name: Copy the built headers to the already existing libraries | |
run: | | |
cp -v -R ${{ env.BUILD_DIR }}/output/lib/qgis_3d.framework/Versions/${{ inputs.lib-version }}/Headers ${{ env.OUT_DIR }}/${{ env.LIB_PATH }}/qgis_3d.framework | |
cp -v -R ${{ env.BUILD_DIR }}/output/lib/qgis_analysis.framework/Versions/${{ inputs.lib-version }}/Headers ${{ env.OUT_DIR }}/${{ env.LIB_PATH }}/qgis_analysis.framework | |
cp -v -R ${{ env.BUILD_DIR }}/output/lib/qgis_core.framework/Versions/${{ inputs.lib-version }}/Headers ${{ env.OUT_DIR }}/${{ env.LIB_PATH }}/qgis_core.framework | |
cp -v -R ${{ env.BUILD_DIR }}/output/lib/qgis_gui.framework/Versions/${{ inputs.lib-version }}/Headers ${{ env.OUT_DIR }}/${{ env.LIB_PATH }}/qgis_gui.framework | |
cp -v -R ${{ env.BUILD_DIR }}/output/lib/qgis_native.framework/Versions/${{ inputs.lib-version }}/Headers ${{ env.OUT_DIR }}/${{ env.LIB_PATH }}/qgis_native.framework | |
- name: Copy the generated header files in *.src to the library directory | |
run: | | |
mkdir -p ${{ env.OUT_DIR }}/${{ env.SRC_PATH }}/ui | |
cp -v -R ${{ env.BUILD_DIR }}/src/ui/*.h ${{ env.OUT_DIR }}/${{ env.SRC_PATH }}/ui | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: qgis-macos-libraries-${{ inputs.qgis-version }}_${{ inputs.build-timestamp }} | |
path: ${{ env.OUT_DIR }} |