From 6eadba1ab2d6cefd4d613acdfc97ba4e31fdd4b0 Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Wed, 19 Nov 2025 18:50:51 -0500 Subject: [PATCH] feat: mac os new build option BUILD_OSX_BUNDLE can be disabled to build a non app bundle --- CMakeLists.txt | 11 ++--- deploy/mac/deploy.cmake | 27 ++++++----- doc/dev/build.md | 1 + src/apps/deskflow-core/CMakeLists.txt | 2 +- src/apps/deskflow-gui/CMakeLists.txt | 64 ++++++++++++++------------- translations/CMakeLists.txt | 4 +- 6 files changed, 59 insertions(+), 50 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 70a7471c7..554952842 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -160,6 +160,8 @@ add_definitions(-DQT_NO_KEYWORDS) #Options for Linux platform support if(UNIX AND NOT APPLE) option(BUILD_X11_SUPPORT "Build with x11 support" ON) +elseif (APPLE) + option(BUILD_OSX_BUNDLE "Build mac os bundle" ON) endif() include(cmake/Libraries.cmake) @@ -172,13 +174,12 @@ if (WIN32) set(CMAKE_INSTALL_LIBDIR .) set(CMAKE_INSTALL_LICENSE_DIR .) set(CMAKE_INSTALL_I18N_DIR translations) -elseif(UNIX AND NOT APPLE) - set(CMAKE_INSTALL_LICENSE_DIR ${CMAKE_INSTALL_DATADIR}/licenses/${CMAKE_PROJECT_NAME}) - set(CMAKE_INSTALL_I18N_DIR ${CMAKE_INSTALL_DATADIR}/${CMAKE_PROJECT_NAME}/translations) -else() +elseif(BUILD_OSX_BUNDLE) set(CMAKE_INSTALL_BINDIR ${CMAKE_PROJECT_PROPER_NAME}.app/Contents/MacOS) set(CMAKE_INSTALL_LICENSE_DIR ${CMAKE_PROJECT_PROPER_NAME}.app/Contents/Resources) - set(CMAKE_INSTALL_I18N_DIR ${CMAKE_PROJECT_PROPER_NAME}.app/Contents/MacOS/translations) +else() + set(CMAKE_INSTALL_LICENSE_DIR ${CMAKE_INSTALL_DATADIR}/licenses/${CMAKE_PROJECT_NAME}) + set(CMAKE_INSTALL_I18N_DIR ${CMAKE_INSTALL_DATADIR}/${CMAKE_PROJECT_NAME}/translations) endif() add_subdirectory(doc) diff --git a/deploy/mac/deploy.cmake b/deploy/mac/deploy.cmake index cf8a0b3a7..496b37648 100644 --- a/deploy/mac/deploy.cmake +++ b/deploy/mac/deploy.cmake @@ -4,17 +4,20 @@ # HACK This is set when the files is included so its the real path # calling CMAKE_CURRENT_LIST_DIR after include would return the wrong scope var set(MY_DIR ${CMAKE_CURRENT_LIST_DIR}) - -install(CODE "execute_process(COMMAND - ${DEPLOYQT} - \"\${CMAKE_INSTALL_PREFIX}/${CMAKE_PROJECT_PROPER_NAME}.app\" - -timestamp -codesign=- -)") +set(OSX_BUNDLE ${BUILD_OSX_BUNDLE}) set(OS_STRING "macos-${BUILD_ARCHITECTURE}") -set(CPACK_PACKAGE_ICON "${MY_DIR}/dmg-volume.icns") -set(CPACK_DMG_BACKGROUND_IMAGE "${MY_DIR}/dmg-background.tiff") -set(CPACK_DMG_DS_STORE_SETUP_SCRIPT "${MY_DIR}/generate_ds_store.applescript") -set(CPACK_DMG_VOLUME_NAME "${CMAKE_PROJECT_PROPER_NAME}") -set(CPACK_DMG_SLA_USE_RESOURCE_FILE_LICENSE ON) -set(CPACK_GENERATOR "DragNDrop") + +if (OSX_BUNDLE) + install(CODE "execute_process(COMMAND + ${DEPLOYQT} + \"\${CMAKE_INSTALL_PREFIX}/${CMAKE_PROJECT_PROPER_NAME}.app\" + -timestamp -codesign=- + )") + set(CPACK_PACKAGE_ICON "${MY_DIR}/dmg-volume.icns") + set(CPACK_DMG_BACKGROUND_IMAGE "${MY_DIR}/dmg-background.tiff") + set(CPACK_DMG_DS_STORE_SETUP_SCRIPT "${MY_DIR}/generate_ds_store.applescript") + set(CPACK_DMG_VOLUME_NAME "${CMAKE_PROJECT_PROPER_NAME}") + set(CPACK_DMG_SLA_USE_RESOURCE_FILE_LICENSE ON) + set(CPACK_GENERATOR "DragNDrop") +endif() diff --git a/doc/dev/build.md b/doc/dev/build.md index 337979115..4e7a49220 100644 --- a/doc/dev/build.md +++ b/doc/dev/build.md @@ -27,6 +27,7 @@ CMake options: | BUILD_INSTALLER | Build installers/packages | ON | | | BUILD_TESTS | Build unit tests and legacy tests | ON | `gtest`| | BUILD_X11_SUPPORT | Build X11 backend (linux and bsd only) | ON | `x11 libs`| +| BUILD_OSX_BUNDLE | Build an app bundle (mac os only) | ON | | | ENABLE_COVERAGE | Enable test coverage | OFF | `gcov` | | SKIP_BUILD_TESTS | Skip running of tests at build time | OFF | | | VCPKG_QT | Build Qt w/ vcpkg (windows only) | OFF | | diff --git a/src/apps/deskflow-core/CMakeLists.txt b/src/apps/deskflow-core/CMakeLists.txt index d5e569ce0..f53c04c1a 100644 --- a/src/apps/deskflow-core/CMakeLists.txt +++ b/src/apps/deskflow-core/CMakeLists.txt @@ -44,7 +44,7 @@ install( RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) -if(APPLE) +if(BUILD_OSX_BUNDLE) set_target_properties(${target} PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE INSTALL_RPATH "@loader_path/../Libraries;@loader_path/../Frameworks" diff --git a/src/apps/deskflow-gui/CMakeLists.txt b/src/apps/deskflow-gui/CMakeLists.txt index c9a5cbcf4..0d94976bb 100644 --- a/src/apps/deskflow-gui/CMakeLists.txt +++ b/src/apps/deskflow-gui/CMakeLists.txt @@ -15,7 +15,7 @@ if(WIN32) set(EXE_ICON "IDI_ICON1 ICON DISCARDABLE \"${CMAKE_SOURCE_DIR}/src/apps/res/deskflow.ico\" ") configure_file(${CMAKE_SOURCE_DIR}/src/apps/res/windows.rc.in deskflow.rc) set(platform_extra deskflow.rc) -elseif(APPLE) +elseif(BUILD_OSX_BUNDLE) #setup our bundle plist file set(BUNDLE_EXECUTABLE_NAME "${target}") set(BUNDLE_BUNDLE_NAME "${target}") @@ -93,36 +93,40 @@ if(WIN32) ) elseif(APPLE) - set_target_properties(${target} PROPERTIES - INSTALL_RPATH "@loader_path/../Libraries;@loader_path/../Frameworks" - MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_BINARY_DIR}/deskflow.plist" - ) - - # Warning: Do not use for CI/production, as the `entitlements-dev.plist` file adds special - # entitlements that are only appropriate for local development. - # - # macOS made TCC stricter so that if you don't sign your local dev builds properly, macOS will - # nag you to remove and re-approve the app every time you make a change to the binary which is - # extremely annoying during development. - # - # If you were to use ad-hoc signing (i.e. not specify a certificate), TCC would still nag you - # because the binary identity is anchored not on the app ID, but on the CD hash (which changes - # based on the binary contents). - # - # To use, simply generate a personal certificate for free with Xcode and pass the ID to CMake. - # Full instructions are in the docs. - if (NOT "${APPLE_CODESIGN_DEV}" STREQUAL "") - message(STATUS "Apple codesign ID for development only: ${APPLE_CODESIGN_DEV}") - add_custom_command( - TARGET ${target} POST_BUILD - COMMAND /usr/bin/codesign - --force - --options runtime - --entitlements "$" - --sign "${APPLE_CODESIGN_DEV}" - "$" - VERBATIM + if (BUILD_OSX_BUNDLE) + set_target_properties(${target} PROPERTIES + INSTALL_RPATH "@loader_path/../Libraries;@loader_path/../Frameworks" + MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_BINARY_DIR}/deskflow.plist" ) + + # Warning: Do not use for CI/production, as the `entitlements-dev.plist` file adds special + # entitlements that are only appropriate for local development. + # + # macOS made TCC stricter so that if you don't sign your local dev builds properly, macOS will + # nag you to remove and re-approve the app every time you make a change to the binary which is + # extremely annoying during development. + # + # If you were to use ad-hoc signing (i.e. not specify a certificate), TCC would still nag you + # because the binary identity is anchored not on the app ID, but on the CD hash (which changes + # based on the binary contents). + # + # To use, simply generate a personal certificate for free with Xcode and pass the ID to CMake. + # Full instructions are in the docs. + if (NOT "${APPLE_CODESIGN_DEV}" STREQUAL "") + message(STATUS "Apple codesign ID for development only: ${APPLE_CODESIGN_DEV}") + add_custom_command( + TARGET ${target} POST_BUILD + COMMAND /usr/bin/codesign + --force + --options runtime + --entitlements "$" + --sign "${APPLE_CODESIGN_DEV}" + "$" + VERBATIM + ) + endif() + else() + set_target_properties(${target} PROPERTIES MACOSX_BUNDLE FALSE) endif() else() generate_app_man(${target} "${CMAKE_PROJECT_DESCRIPTION} \\(GUI\\)") diff --git a/translations/CMakeLists.txt b/translations/CMakeLists.txt index 51f9aae73..14fc316df 100644 --- a/translations/CMakeLists.txt +++ b/translations/CMakeLists.txt @@ -27,10 +27,10 @@ qt_create_translation(TRS ${CMAKE_SOURCE_DIR}/src ${${CMAKE_PROJECT_NAME}_TRS} O #ensure that the targets are built always add_custom_target(app_translations ALL DEPENDS ${TRS}) -if (NOT APPLE) +if (NOT BUILD_OSX_BUNDLE) # install our translations install(FILES ${TRS} DESTINATION ${CMAKE_INSTALL_I18N_DIR}) -elseif(APPLE) +else() #when making the bundle copy our translation into the bundle set(BUNDLE_TR_DIR $/MacOS/translations)