Browse Source

MacOS dmg package build (cmake only, no CI yet)

Yurii Puchkov 4 years ago
parent
commit
bad270cce4

+ 61 - 0
.github/workflows/MacOS-pack.yml

@@ -0,0 +1,61 @@
+name: Packaging(MacOS)
+
+on:
+  push:
+    branches:
+      - master
+      - feature/RND-680-macos-.dmg-package-build
+    paths-ignore:
+      - 'README.md'
+      - 'LICENSE'
+
+  pull_request:
+    paths-ignore:
+      - 'README.md'
+      - 'LICENSE'
+
+env:
+  PRODUCT: flameshot
+
+jobs:
+  catalina:
+    name: macOS Catalina 10.15
+    runs-on: macos-10.15
+
+    steps:
+      - name: Checkout Source code
+        uses: actions/checkout@v1
+
+      - name: Install Qt
+        run: brew install qt cmake
+
+      - name: Configure
+        run: |
+          mkdir build
+          cd build
+          rm -rf ./src/flameshot.dmg ./src/flameshot.app/
+          cmake .. -DQt5_DIR=$(brew --prefix qt5)/lib/cmake/Qt5
+
+      - name: Compile
+        run: |
+          cd build
+          make
+
+      - name: Build dmg image
+        run: |
+          cd build
+          /usr/local/opt/qt5/bin/macdeployqt src/flameshot.app -dmg
+
+      - name: Upload dmg image
+        shell: bash
+        run: |
+          python3 -m pip install -U -q requests
+          echo "================MacOS dmg image download link================"
+          echo $(python3 $GITHUB_WORKSPACE/scripts/upload_services/transferwee.py upload $GITHUB_WORKSPACE/build/src/flameshot.dmg)
+          echo "=====no operation for you can see link in the log console====="
+
+      - name: Artifact Upload
+        uses: actions/upload-artifact@v2
+        with:
+          name: MacOS-artifact
+          path: ${{ github.workspace }}/build/src/flameshot.dmg

+ 8 - 0
CMakeLists.txt

@@ -2,6 +2,10 @@ cmake_minimum_required(VERSION 3.13)
 # cmake_policy(SET CMP0076 OLD)
 
 # This can be read from ${PROJECT_NAME} after project() is called
+if(APPLE)
+  set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum OS X deployment version")
+endif()
+
 project(
   flameshot
   VERSION 0.8.5.4
@@ -18,6 +22,10 @@ if(WIN32)
     add_definitions(-DFLAMESHOT_VERSION_BUGFIX=${CMAKE_PROJECT_VERSION_PATCH})
     add_definitions(-DFLAMESHOT_VERSION_BUILD=1)
     add_definitions(-DFLAMESHOT_VERSION_STRING="${PROJECT_VERSION}")
+elseif(APPLE)
+  set(Qt5_DIR "$(brew --prefix qt5)/lib/cmake/Qt5/" CACHE PATH "directory where Qt5Config.cmake exists.")
+  set(CMAKE_MACOSX_BUNDLE ON)
+  set(CMAKE_MACOSX_RPATH ON)
 endif()
 set(RUN_IN_PLACE ${DEFAULT_RUN_IN_PLACE} CACHE BOOL
 	"Run directly in source directory structure")

+ 40 - 0
cmake/modules/MacOSXBundleInfo.plist.in

@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>CFBundleDevelopmentRegion</key>
+ 	<string>English</string>
+	<key>CFBundleExecutable</key>
+	<string>flameshot</string>
+	<key>CFBundleGetInfoString</key>
+	<string></string>
+	<key>CFBundleIconFile</key>
+	<string>flameshot</string>
+	<key>CFBundleIdentifier</key>
+	<string>https://flameshot.org/</string>
+	<key>CFBundleInfoDictionaryVersion</key>
+	<string>6.0</string>
+	<key>CFBundleLongVersionString</key>
+	<string></string>
+	<key>CFBundleName</key>
+	<string></string>
+	<key>CFBundlePackageType</key>
+	<string>APPL</string>
+	<key>CFBundleShortVersionString</key>
+	<string></string>
+	<key>CFBundleSignature</key>
+	<string>????</string>
+	<key>CFBundleVersion</key>
+	<string>0.8.5</string>
+	<key>CSResourcesFileMapped</key>
+	<true/>
+	<key>NSHumanReadableCopyright</key>
+	<string></string>
+	<key>LSMinimumSystemVersion</key>
+	<string>10.15</string>
+	<key>NSPrincipalClass</key>
+	<string>NSApplication</string>
+	<key>NSHighResolutionCapable</key>
+	<string>True</string>
+</dict>
+</plist>

BIN
data/img/app/org.flameshot.Flameshot-1024.png


+ 60 - 5
src/CMakeLists.txt

@@ -14,7 +14,43 @@ set(CMAKE_AUTOMOC ON)
 set(CMAKE_AUTORCC ON)
 set(CMAKE_AUTOUIC ON)
 
-add_executable(flameshot)
+# set application icon
+if (APPLE)
+    # generate iconset
+    execute_process(
+            COMMAND bash "-c" "mkdir -p flameshot.iconset"
+    )
+    execute_process(
+            COMMAND bash "-c" "sips -z 16 16     ../data/img/app/flameshot.png --out flameshot.iconset/icon_16x16.png"
+            COMMAND bash "-c" "sips -z 32 32     ../data/img/app/flameshot.png --out flameshot.iconset/icon_16x16@2x.png"
+            COMMAND bash "-c" "sips -z 32 32     ../data/img/app/flameshot.png --out flameshot.iconset/icon_32x32.png"
+            COMMAND bash "-c" "sips -z 64 64     ../data/img/app/flameshot.png --out flameshot.iconset/icon_32x32@2x.png"
+            COMMAND bash "-c" "sips -z 64 64     ../data/img/app/flameshot.png --out flameshot.iconset/icon_64x64x.png"
+            COMMAND bash "-c" "sips -z 128 128   ../data/img/app/flameshot.png --out flameshot.iconset/icon_64x64@2.png"
+            COMMAND bash "-c" "sips -z 128 128   ../data/img/app/flameshot.png --out flameshot.iconset/icon_128x128.png"
+            COMMAND bash "-c" "sips -z 256 256   ../data/img/app/org.flameshot.Flameshot-1024.png --out flameshot.iconset/icon_128x128@2x.png"
+            COMMAND bash "-c" "sips -z 256 256   ../data/img/app/org.flameshot.Flameshot-1024.png --out flameshot.iconset/icon_256x256.png"
+            COMMAND bash "-c" "sips -z 512 512   ../data/img/app/org.flameshot.Flameshot-1024.png --out flameshot.iconset/icon_256x256@2x.png"
+            COMMAND bash "-c" "sips -z 512 512   ../data/img/app/org.flameshot.Flameshot-1024.png --out flameshot.iconset/icon_512x512.png"
+            COMMAND bash "-c" "sips -z 1024 1024 ../data/img/app/org.flameshot.Flameshot-1024.png --out flameshot.iconset/icon_512x512@2x.png"
+            COMMAND bash "-c" "iconutil -c icns flameshot.iconset"
+    )
+
+    execute_process(
+            COMMAND bash "-c" "rm -R flameshot.iconset"
+    )
+
+    # Set application icon
+    set(MACOSX_BUNDLE_ICON_FILE flameshot.icns)
+
+    # And this part tells CMake where to find and install the file itself
+    set(APP_ICON_MACOSX ${CMAKE_BINARY_DIR}/flameshot.icns)
+    set_source_files_properties(${APP_ICON_MACOSX} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
+
+    add_executable(flameshot MACOSX_BUNDLE main.cpp ${APP_ICON_MACOSX})
+else()
+    add_executable(flameshot)
+endif()
 
 add_executable(Flameshot::flameshot ALIAS flameshot)
 
@@ -22,6 +58,7 @@ if(WIN32)
   set_property(TARGET flameshot PROPERTY WIN32_EXECUTABLE true)
 endif()
 
+
 add_subdirectory(cli)
 add_subdirectory(config)
 add_subdirectory(core)
@@ -154,10 +191,10 @@ include(GNUInstallDirs)
 set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/Flameshot)
 
 # Install binary
-install(
-  TARGETS flameshot
-  EXPORT flameshot-targets
-  RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
+install(TARGETS flameshot
+        EXPORT flameshot-targets
+        BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}
+        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
 
 # Install desktop files, completion and dbus files
 configure_file(${CMAKE_SOURCE_DIR}/data/desktopEntry/package/org.flameshot.Flameshot.desktop
@@ -245,3 +282,21 @@ if(WIN32)
     message("Unable to find executable QTDIR/bin/windeployqt.")
   endif()
 endif()
+
+# macdeployqt
+if (APPLE)
+    set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
+    execute_process(COMMAND brew --prefix qt5 OUTPUT_VARIABLE QTDIR)
+    string(REGEX REPLACE "\n$" "" QTDIR "${QTDIR}")
+    set(MAC_DEPLOY_QT ${QTDIR}/bin/macdeployqt)
+    if (EXISTS ${MAC_DEPLOY_QT})
+        set_source_files_properties(resources/icon.icns PROPERTIES
+                MACOSX_PACKAGE_LOCATION Resources)
+
+        set_target_properties(${target} PROPERTIES
+                MACOSX_BUNDLE TRUE
+                )
+    else ()
+        message("Unable to find executable ${MAC_DEPLOY_QT}.")
+    endif ()
+endif ()