Skip to content

Commit

Permalink
CPack: Added support for creating DMG (and proper ZIP) files for OS/X…
Browse files Browse the repository at this point in the history
… via CPack.
  • Loading branch information
christianparpart committed Oct 30, 2020
1 parent 9acff54 commit 440c857
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 30 deletions.
35 changes: 26 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -255,17 +255,22 @@ jobs:
run: |
find build/ -print
echo "TODO: upload to artifact store"
- name: package
- name: "Create Package(s)"
run: |
set -e
cd build/src/contour/
zip -r ../../../contour-osx.zip contour.app
cd ../../..
mv -v "contour-osx.zip" "contour-${{ steps.set_env_var.outputs.version }}-${{ steps.set_env_var.outputs.RUN_ID }}-osx.zip"
- name: upload to artifact store
set -ex
cd build
sudo cpack
BASENAME="contour-${{ steps.set_env_var.outputs.version }}-${{ steps.set_env_var.outputs.RUN_ID }}-osx"
mv -vf "Contour-${{ steps.set_env_var.outputs.version }}-Darwin.zip" "../${BASENAME}.zip"
mv -vf "Contour-${{ steps.set_env_var.outputs.version }}-Darwin.dmg" "../${BASENAME}.dmg"
- name: upload to artifact store (ZIP)
uses: actions/upload-artifact@v2
with:
path: contour-${{ steps.set_env_var.outputs.version }}-${{ steps.set_env_var.outputs.RUN_ID }}-osx.zip
- name: upload to artifact store (DMG)
uses: actions/upload-artifact@v2
with:
path: contour-${{ steps.set_env_var.outputs.version }}-${{ steps.set_env_var.outputs.RUN_ID }}-osx.dmg

do_release:
name: Create Github release
Expand Down Expand Up @@ -395,8 +400,8 @@ jobs:
asset_content_type: application/zip

# -------------------------------------------------------------
- name: Upload OS/X package
id: upload-release-asset-osx
- name: Upload OS/X ZIP package
id: upload-release-asset-osx-zip
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -406,3 +411,15 @@ jobs:
asset_name: contour-${{ steps.set_env_var.outputs.version }}-${{ steps.set_env_var.outputs.RUN_ID }}-osx.zip
asset_content_type: application/zip

# -------------------------------------------------------------
- name: Upload OS/X DMG package
id: upload-release-asset-osx-dmg
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: contour-${{ steps.set_env_var.outputs.version }}-${{ steps.set_env_var.outputs.RUN_ID }}-osx.dmg
asset_name: contour-${{ steps.set_env_var.outputs.version }}-${{ steps.set_env_var.outputs.RUN_ID }}-osx.dmg
asset_content_type: application/x-apple-diskimage

98 changes: 98 additions & 0 deletions scripts/generate-iconset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#! /usr/bin/env python3
# Original script was copied from:
# https://github.com/retifrav/python-scripts/blob/master/generate-iconset/generate-iconset.py
#
# Usage: generate-iconset.py PATH_TO_HIGH_RES_PNG
# This will generate a PATH_TO_HIGH_RES.iconset/ folder as well as its companion .icns file next to it.

import os
import sys
import pathlib
import subprocess

if len(sys.argv) < 2:
print("No path to original / hi-res icon provided")
raise SystemExit

if len(sys.argv) > 2:
print("Too many arguments")
raise SystemExit

originalPicture = sys.argv[1]
if not (os.path.isfile(originalPicture)):
print(f"There is no such file: {sys.argv[1]}")
raise SystemExit

fname = pathlib.Path(originalPicture).stem
ext = pathlib.Path(originalPicture).suffix
destDir = pathlib.Path(originalPicture).parent

iconsetDir = os.path.join(destDir, f"{fname}.iconset")
if not (os.path.exists(iconsetDir)):
pathlib.Path(iconsetDir).mkdir(parents=False, exist_ok=True)

class IconParameters():
width = 0
scale = 1
def __init__(self,width,scale):
self.width = width
self.scale = scale
def getIconName(self):
if self.scale != 1:
return f"icon_{self.width}x{self.width}{ext}"
else:
return f"icon_{self.width//2}x{self.width//2}@2x{ext}"

# https://developer.apple.com/design/human-interface-guidelines/macos/icons-and-images/app-icon#app-icon-sizes
ListOfIconParameters = [
IconParameters(16, 1),
IconParameters(16, 2),
IconParameters(32, 1),
IconParameters(32, 2),
IconParameters(64, 1),
IconParameters(64, 2),
IconParameters(128, 1),
IconParameters(128, 2),
IconParameters(256, 1),
IconParameters(256, 2),
IconParameters(512, 1),
IconParameters(512, 2),
IconParameters(1024, 1),
IconParameters(1024, 2)
]

# generate iconset
for ip in ListOfIconParameters:
subprocess.call(
[
# option 1: sips
#"sips",
#"-z",
#str(ip.width),
#str(ip.width),
#originalPicture,
#"--out",

# option 2: ImageMagick
"magick",
"convert",
originalPicture,
"-resize",
str(ip.width),

os.path.join(iconsetDir, ip.getIconName())
]
)
#print(f"Generated {ip.getIconName()}")

# convert iconset to icns file
subprocess.call(
[
"iconutil",
"-c",
"icns",
iconsetDir,
"-o",
os.path.join(destDir, f"{fname}.icns")
]
)
109 changes: 88 additions & 21 deletions src/contour/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,50 +98,117 @@ if(CONTOUR_SANITIZE AND NOT MSVC)
target_link_libraries(contour ubsan)
endif()

install(TARGETS contour DESTINATION bin)

if(WIN32)
include(DeployQt)
windeployqt(contour)
install(
DIRECTORY "$<TARGET_FILE_DIR:contour>/"
DESTINATION "bin"
USE_SOURCE_PERMISSIONS
FILES_MATCHING
PATTERN "CMakeFiles" EXCLUDE
PATTERN "*_autogen" EXCLUDE
PATTERN "*.h" EXCLUDE
PATTERN "*.dll"
)
endif()

# ====================================================================================
# INSTALLER
# ====================================================================================

if(NOT(CPACK_GENERATOR))
if(APPLE)
set(CPACK_GENERATOR Bundle)
set(CPACK_GENERATOR DragNDrop ZIP)
elseif(WIN32)
set(CPACK_GENERATOR WIX ZIP)
endif()
endif()

set(CPACK_PACKAGE_NAME "Contour")
set(CPACK_PACKAGE_VENDOR "https://github.com/christianparpart/contour/")
set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/res/images/contour-logo.ico")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "`contour` is a modern terminal emulator, for everyday use.")
#TODO: set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE.txt")

set(CPACK_WIX_UPGRADE_GUID "0E736497-2B72-4117-95E9-54EC6DC2432A")
set(CPACK_WIX_PRODUCT_GUID "DC04A0C6-AAC4-4E1C-835E-8D4223FC5092")
#TODO? set(CPACK_WIX_PRODUCT_ICON "${CMAKE_CURRENT_SOURCE_DIR}/res/images/contour-logo.ico")
#TODO: set(CPACK_WIX_UI_DIALOG "${CMAKE_CURRENT_SOURCE_DIR}/res/images/contour-logo-256.png")
#TODO: set(CPACK_WIX_UI_BANNER "${CMAKE_CURRENT_SOURCE_DIR}/res/images/contour-logo-256.png")

set(CPACK_PACKAGE_EXECUTABLES contour "Contour Terminal Emulator")
set(CPACK_CREATE_DESKTOP_LINKS contour)

if(WIN32)
set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/res/images/contour-logo.ico")
set(CPACK_WIX_UPGRADE_GUID "0E736497-2B72-4117-95E9-54EC6DC2432A")
set(CPACK_WIX_PRODUCT_GUID "DC04A0C6-AAC4-4E1C-835E-8D4223FC5092")

include(DeployQt)
windeployqt(contour)
install(
DIRECTORY "$<TARGET_FILE_DIR:contour>/"
DESTINATION "bin"
USE_SOURCE_PERMISSIONS
FILES_MATCHING
PATTERN "CMakeFiles" EXCLUDE
PATTERN "*_autogen" EXCLUDE
PATTERN "*.h" EXCLUDE
PATTERN "*.dll"
)
elseif(APPLE)
set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/res/images/contour-logo.icns")

# See: https://stackoverflow.com/questions/35612687/cmake-macos-x-bundle-with-bundleutiliies-for-qt-application/48035834#48035834
set(APP_NAME contour)
set(App_Contents "${APP_NAME}.app/Contents")
set(INSTALL_RUNTIME_DIR "${App_Contents}/MacOS")
set(INSTALL_CMAKE_DIR "${App_Contents}/Resources")

# based on code from CMake's QtDialog/CMakeLists.txt
macro(install_qt5_plugin _qt_plugin_name _qt_plugins_var _prefix)
get_target_property(_qt_plugin_path "${_qt_plugin_name}" LOCATION)
if(EXISTS "${_qt_plugin_path}")
get_filename_component(_qt_plugin_file "${_qt_plugin_path}" NAME)
get_filename_component(_qt_plugin_type "${_qt_plugin_path}" PATH)
get_filename_component(_qt_plugin_type "${_qt_plugin_type}" NAME)
set(_qt_plugin_dest "${_prefix}/PlugIns/${_qt_plugin_type}")
install(FILES "${_qt_plugin_path}" DESTINATION "${_qt_plugin_dest}")
set(${_qt_plugins_var} "${${_qt_plugins_var}};\$ENV{DEST_DIR}\${CMAKE_INSTALL_PREFIX}/${_qt_plugin_dest}/${_qt_plugin_file}")
else()
message(FATAL_ERROR "QT plugin ${_qt_plugin_name} not found")
endif()
endmacro()

install_qt5_plugin("Qt5::QCocoaIntegrationPlugin" QT_PLUGINS ${App_Contents})

# ${_qt_plugin_dir} seems empty anyways, but the target bundle/dmg works.
# file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/qt.conf" "[Paths]\nPlugins = ${_qt_plugin_dir}\n")
# install(FILES "${CMAKE_CURRENT_BINARY_DIR}/qt.conf" DESTINATION "${INSTALL_CMAKE_DIR}")

# Install application icon
install(FILES "res/images/contour-logo.icns" DESTINATION "${INSTALL_CMAKE_DIR}" RENAME "contour.icns")

#add_custom_target(Docs SOURCES README.md LICENSE.txt)
#TODO: install(TARGETS Docs ...)

# Destination paths below are relative to ${CMAKE_INSTALL_PREFIX}
install(TARGETS ${APP_NAME}
BUNDLE DESTINATION . COMPONENT Runtime
RUNTIME DESTINATION "${INSTALL_RUNTIME_DIR}" COMPONENT Runtime
)

set(APPS "\${CMAKE_INSTALL_PREFIX}/${APP_NAME}.app") # Note Mac specific extension .app
set(DIRS ${CMAKE_BINARY_DIR}) # Directories to look for dependencies

# Path used for searching by FIND_XXX(), with appropriate suffixes added
if(CMAKE_PREFIX_PATH)
foreach(dir ${CMAKE_PREFIX_PATH})
list(APPEND DIRS "${dir}/bin" "${dir}/lib")
endforeach()
endif()

# Append Qt's lib folder which is two levels above Qt5Widgets_DIR
list(APPEND DIRS "${Qt5Widgets_DIR}/../..")

include(InstallRequiredSystemLibraries)

message(STATUS "APPS: ${APPS}")
message(STATUS "DIRS: ${DIRS}")
message(STATUS "QT_PLUGINS: ${QT_PLUGINS}")

install(CODE "
include(BundleUtilities)
fixup_bundle(\"${APPS}\" \"${QT_PLUGINS}\" \"${DIRS}\")
")
else()
# any other Unix
install(TARGETS contour DESTINATION bin)
endif()

include(CPack)
Binary file added src/contour/res/images/contour-logo.icns
Binary file not shown.
Binary file added src/contour/res/images/contour-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 440c857

Please sign in to comment.