Skip to content

Commit

Permalink
macOS: Fix build dependencies
Browse files Browse the repository at this point in the history
Fixes #2450
  • Loading branch information
hluk committed Sep 4, 2023
1 parent 976aaa1 commit 3c4fe45
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 65 deletions.
40 changes: 19 additions & 21 deletions .github/workflows/build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ jobs:
include:
- os: ubuntu-20.04
buildname: Linux-GCC
build_type: Debug
compiler: g++
coverage: true
compiler_flags: >-
Expand All @@ -27,14 +26,12 @@ jobs:

- os: ubuntu-20.04
buildname: Linux-Clang
build_type: Debug
compiler: clang++
compiler_package: clang
with_qt6: false

- os: ubuntu-latest
buildname: Qt 6
build_type: Debug
compiler: g++
compiler_package: g++
with_qt6: true
Expand All @@ -46,6 +43,15 @@ jobs:
submodules: false
fetch-depth: 1

- name: Enable ccache
uses: hendrikmuhs/[email protected]
with:
key: ${{ github.job }}-${{ matrix.os }}

- name: Set up ccache
run: |
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
- name: Install dependencies
uses: nick-invision/retry@v2
env:
Expand All @@ -59,25 +65,17 @@ jobs:
'${{matrix.compiler_package}}'
- name: Build with CMake
uses: lukka/run-cmake@v3
uses: lukka/run-cmake@v10
with:
cmakeListsOrSettingsJson: CMakeListsTxtAdvanced
cmakeListsTxtPath: '${{github.workspace}}/CMakeLists.txt'
cmakeBuildType: Release
cmakeGenerator: Ninja
buildDirectory: '${{runner.workspace}}/build'
cmakeAppendedArgs: >-
-DWITH_TESTS=TRUE
-DPEDANTIC=TRUE
-DCMAKE_BUILD_TYPE='${{matrix.build_type}}'
-DCMAKE_INSTALL_PREFIX='${{runner.workspace}}/install'
-DCMAKE_CXX_FLAGS='${{matrix.compiler_flags}}'
-DCMAKE_C_FLAGS='${{matrix.compiler_flags}}'
-DCMAKE_CXX_COMPILER='${{matrix.compiler}}'
-DWITH_QT6='${{matrix.with_qt6}}'
- name: Install with CMake
run: cmake --install '${{runner.workspace}}/build'
configurePreset: Debug
buildPreset: Debug
configurePresetAdditionalArgs: >-
[
'-DCMAKE_CXX_COMPILER=${{matrix.compiler}}',
'-DCMAKE_CXX_FLAGS=${{matrix.compiler_flags}}',
'-DCMAKE_C_FLAGS=${{matrix.compiler_flags}}',
'-DWITH_QT6=${{matrix.with_qt6}}'
]
- name: Create gnupg directory for tests
run: mkdir -p ~/.gnupg
Expand Down
30 changes: 16 additions & 14 deletions .github/workflows/build-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ jobs:
include:
- os: macos-11
buildname: macOS 10.15
build_type: Release
compiler: clang_64
create_bundle: true

steps:
Expand All @@ -25,23 +23,27 @@ jobs:
submodules: false
fetch-depth: 1

- name: Enable ccache
uses: hendrikmuhs/[email protected]
with:
key: ${{ github.job }}-${{ matrix.os }}

- name: Set up ccache
run: |
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
- name: Install dependencies
env:
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1
HOMEBREW_NO_AUTO_UPDATE: 1
HOMEBREW_NO_INSTALL_CLEANUP: 1
run: '${{github.workspace}}/utils/github/install-macos.sh'

- name: Build with CMake
uses: lukka/run-cmake@v3
uses: lukka/run-cmake@v10
with:
cmakeListsOrSettingsJson: CMakeListsTxtAdvanced
cmakeListsTxtPath: '${{github.workspace}}/CMakeLists.txt'
cmakeBuildType: Release
cmakeGenerator: Ninja
buildDirectory: '${{runner.workspace}}/build'
cmakeAppendedArgs: >-
-DWITH_TESTS=TRUE
-DCMAKE_BUILD_TYPE='${{matrix.build_type}}'
-DCMAKE_PREFIX_PATH="/usr/local/opt/qt@5/lib/cmake"
-DCMAKE_OSX_DEPLOYMENT_TARGET='10.15'
-DCMAKE_CXX_FLAGS="-Wno-deprecated-declarations"
configurePreset: macOS
buildPreset: macOS

- name: Create gnupg directory for tests
run: mkdir -p ~/.gnupg
Expand Down
45 changes: 45 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"version": 3,
"configurePresets": [
{
"name": "Debug",
"generator": "Ninja",
"binaryDir": "${sourceParentDir}/build",
"installDir": "${sourceParentDir}/install",
"cacheVariables": {
"WITH_TESTS": "TRUE",
"PEDANTIC": "TRUE",
"CMAKE_C_COMPILER_LAUNCHER": "ccache",
"CMAKE_CXX_COMPILER_LAUNCHER": "ccache"
}
},
{
"name": "macOS",
"generator": "Ninja",
"binaryDir": "${sourceParentDir}/build",
"installDir": "${sourceParentDir}/build",
"cacheVariables": {
"WITH_TESTS": "TRUE",
"CMAKE_PREFIX_PATH": "/usr/local/opt/qt@5/lib/cmake",
"CMAKE_OSX_DEPLOYMENT_TARGET": "10.15",
"CMAKE_C_COMPILER_LAUNCHER": "ccache",
"CMAKE_CXX_COMPILER_LAUNCHER": "ccache",
"CMAKE_CXX_FLAGS": "-Wno-deprecated-declarations"
}
}
],
"buildPresets": [
{
"name": "Debug",
"configurePreset": "Debug",
"configuration": "Debug",
"targets": "install"
},
{
"name": "macOS",
"configurePreset": "macOS",
"configuration": "Release",
"targets": "install"
}
]
}
10 changes: 9 additions & 1 deletion docs/build-source-code.rst
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,15 @@ Build with the following commands:

cmake -DCMAKE_PREFIX_PATH="$(brew --prefix qt5)" .
cmake --build .
cpack
cmake --install .
macdeployqt CopyQ.app -dmg -verbose=2 -always-overwrite \
-executable=CopyQ.app/Contents/PlugIns/copyq/libitemfakevim.so \
-executable=CopyQ.app/Contents/PlugIns/copyq/libitemimage.so \
-executable=CopyQ.app/Contents/PlugIns/copyq/libitemnotes.so \
-executable=CopyQ.app/Contents/PlugIns/copyq/libitempinned.so \
-executable=CopyQ.app/Contents/PlugIns/copyq/libitemsync.so \
-executable=CopyQ.app/Contents/PlugIns/copyq/libitemtags.so \
-executable=CopyQ.app/Contents/PlugIns/copyq/libitemtext.so

This will produce a self-contained application bundle ``CopyQ.app``
which can then be copied or moved into ``/Applications``.
Expand Down
46 changes: 24 additions & 22 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -193,26 +193,28 @@ else()
COMPONENT Runtime
)

set(FIXUP_BUNDLE_APPS "\${CMAKE_INSTALL_PREFIX}/${COPYQ_EXECUTABLE_NAME}.app")

get_property(_copyq_installed_plugins GLOBAL PROPERTY COPYQ_INSTALLED_PLUGINS)

# Directories to look for dependencies
set(FIXUP_BUNDLE_DEP_DIRS "${CMAKE_BINARY_DIR};${QT_LIBRARY_DIRS};${${copyq_qt}Widgets_DIR}/../..")

message(STATUS "Fixup app: ${FIXUP_BUNDLE_APPS}")
message(STATUS "Fixup app plugins: ${_copyq_installed_plugins}")
message(STATUS "Fixup qt plugins: ${FIXUP_BUNDLE_QT_PLUGINS}")
message(STATUS "Fixup dirs: ${FIXUP_BUNDLE_DEP_DIRS}")
install(CODE "
include(BundleUtilities)
set(BU_CHMOD_BUNDLE_ITEMS ON)
fixup_bundle(\"${FIXUP_BUNDLE_APPS}\" \"${FIXUP_BUNDLE_QT_PLUGINS};${_copyq_installed_plugins}\" \"${FIXUP_BUNDLE_DEP_DIRS}\")
verify_app(\"${FIXUP_BUNDLE_APPS}\")
"
COMPONENT Runtime
)

set(CPACK_GENERATOR "DragNDrop")
include(CPack)
# FIXME: Disable cpack for now due to unresolvable libraries:
# https://github.com/Homebrew/homebrew-core/issues/140930
# set(FIXUP_BUNDLE_APPS "\${CMAKE_INSTALL_PREFIX}/${COPYQ_EXECUTABLE_NAME}.app")
#
# get_property(_copyq_installed_plugins GLOBAL PROPERTY COPYQ_INSTALLED_PLUGINS)
#
# # Directories to look for dependencies
# set(FIXUP_BUNDLE_DEP_DIRS "${CMAKE_BINARY_DIR};${QT_LIBRARY_DIRS};${QT_PLUGINS_DIR}/iconengines;${QT_PLUGINS_DIR}/imageformats;${QT_PLUGINS_DIR}/platforms;${QT_PLUGINS_DIR}/tls;${${copyq_qt}Widgets_DIR}/../..")
#
# message(STATUS "Fixup app: ${FIXUP_BUNDLE_APPS}")
# message(STATUS "Fixup app plugins: ${_copyq_installed_plugins}")
# message(STATUS "Fixup qt plugins: ${FIXUP_BUNDLE_QT_PLUGINS}")
# message(STATUS "Fixup dirs: ${FIXUP_BUNDLE_DEP_DIRS}")
# install(CODE "
# include(BundleUtilities)
# set(BU_CHMOD_BUNDLE_ITEMS ON)
# fixup_bundle(\"${FIXUP_BUNDLE_APPS}\" \"${FIXUP_BUNDLE_QT_PLUGINS};${_copyq_installed_plugins}\" \"${FIXUP_BUNDLE_DEP_DIRS}\")
# verify_app(\"${FIXUP_BUNDLE_APPS}\")
# "
# COMPONENT Runtime
# )
#
# set(CPACK_GENERATOR "DragNDrop")
# include(CPack)
endif()
19 changes: 13 additions & 6 deletions utils/github/bundle-macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@
# Creates macOS bundle.
set -xeuo pipefail

cpack
app_bundle_path="CopyQ.app"

app_bundle_path="$(echo _CPack_Packages/Darwin/DragNDrop/copyq-*/CopyQ.app)"
executable="${PWD}/${app_bundle_path}/Contents/MacOS/CopyQ"
plugins=("$app_bundle_path/Contents/PlugIns/copyq/"*.so)
qt_bin="$(brew --prefix qt@5)/bin"

rm -rf "$app_bundle_path/Contents/PlugIns/"{platforminputcontexts,printsupport,qmltooling}

"$qt_bin/macdeployqt" "$app_bundle_path" -dmg -verbose=2 -always-overwrite -no-plugins \
"${plugins[@]/#/-executable=}"

ls -Rl "$app_bundle_path"

# Test the app before deployment.
"$executable" --help
Expand All @@ -19,8 +27,8 @@ ls "$("$executable" info translations)/"
test "$("$executable" info has-global-shortcuts)" -eq "1"

# Uninstall local Qt to make sure we only use libraries from the bundle
remove=$(brew list --formula)
brew remove --force --ignore-dependencies $remove
brew remove --ignore-dependencies --force \
qt@5 copyq/kde/kf5-knotifications freetype

(
export PATH=""
Expand All @@ -35,7 +43,6 @@ brew remove --force --ignore-dependencies $remove

# Print dependencies to let us further make sure that we don't depend on local libraries
otool -L "$executable"
otool -L "$app_bundle_path/Contents/PlugIns/"*/*.dylib
otool -L "$app_bundle_path/Contents/PlugIns/copyq/"*
otool -L "$app_bundle_path/Contents/Frameworks/"Qt*.framework/Versions/5/Qt*

mv copyq-*.dmg CopyQ.dmg
2 changes: 2 additions & 0 deletions utils/github/install-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ else
fi

packages=(
ninja-build

# fixes some issues on X11
libxfixes-dev
libxtst-dev
Expand Down
2 changes: 1 addition & 1 deletion utils/github/install-macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ rm -rf \

brew tap copyq/kde utils/github/homebrew/

brew install qt5 copyq/kde/kf5-knotifications
brew install qt@5 copyq/kde/kf5-knotifications

0 comments on commit 3c4fe45

Please sign in to comment.