shadowsocks-qt5
shadowsocks-qt5 copied to clipboard
Adding creating app bundle for cmake script on MacOS
Prior to 3.0.0, the qmake build script had the ability to create the app bundle, while the cmake script didn't included the clauses for doing the same - as of now it still simply creates an executable just like it on Linux.
Since 3.x has dropped the qmake script, I think it'd be nice to add that feature back and put it into cmake script. I already figured out how to do it and I have tested it on my machine. But I'm not a cmake expert, so I think I'd better just post the code here instead of creating a pull request.
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b75ea5d..70ddc66 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -28,7 +28,19 @@ if (WIN32)
list(APPEND SOURCE ss-qt5.rc)
endif()
-add_executable(${APP_NAME} ${SOURCE})
+if (APPLE)
+ set(MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME})
+ set(MACOSX_BUNDLE_GUI_IDENTIFIER "org.shadowsocks.shadowsocks-qt5")
+ set(MACOSX_BUNDLE_INFO_STRING "A cross-platform shadowsocks GUI client")
+ set(MACOSX_BUNDLE_ICON_FILE "shadowsocks-qt5.icns")
+ set(MACOSX_BUNDLE_LONG_VERSION_STRING ${PROJECT_VERSION})
+ set(MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION})
+ set(MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION})
+ add_executable(${APP_NAME} MACOSX_BUNDLE ${SOURCE}
+ "icons/shadowsocks-qt5.icns")
+else()
+ add_executable(${APP_NAME} ${SOURCE})
+endif()
target_link_libraries(${APP_NAME}
PUBLIC Qt5::Core
@@ -47,10 +59,24 @@ if (UNIX AND NOT APPLE)
target_link_libraries(${APP_NAME} PRIVATE Qt5::DBus)
endif()
-install(TARGETS ${APP_NAME}
+if (APPLE)
+ set_target_properties(
+ ${APP_NAME}
+ PROPERTIES
+ RESOURCE "icons/shadowsocks-qt5.icns"
+ )
+ add_custom_command(
+ TARGET ${APP_NAME}
+ POST_BUILD
+ COMMAND macdeployqt ${APP_NAME}.app
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/src
+ )
+else()
+ install(TARGETS ${APP_NAME}
RUNTIME DESTINATION bin)
+endif()
-if (UNIX)
+if (UNIX AND NOT APPLE)
install(FILES shadowsocks-qt5.desktop DESTINATION share/applications)
install(FILES icons/shadowsocks-qt5.png DESTINATION share/icons/hicolor/512x512/apps)
endif()
I'm not familiar with Mac OS. Is macdeployqt part of official Qt offer?
I think you can create a PR so others can also comment, thanks