feat: mac os new build option BUILD_OSX_BUNDLE can be disabled to build a non app bundle

This commit is contained in:
sithlord48
2025-11-19 18:50:51 -05:00
committed by Chris Rizzitello
parent aa11dc94ba
commit 6eadba1ab2
6 changed files with 59 additions and 50 deletions

View File

@ -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)

View File

@ -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()

View File

@ -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 | |

View File

@ -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"

View File

@ -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 "$<SHELL_PATH:${CMAKE_SOURCE_DIR}/src/apps/res/entitlements-dev.plist>"
--sign "${APPLE_CODESIGN_DEV}"
"$<TARGET_BUNDLE_DIR:${target}>"
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 "$<SHELL_PATH:${CMAKE_SOURCE_DIR}/src/apps/res/entitlements-dev.plist>"
--sign "${APPLE_CODESIGN_DEV}"
"$<TARGET_BUNDLE_DIR:${target}>"
VERBATIM
)
endif()
else()
set_target_properties(${target} PROPERTIES MACOSX_BUNDLE FALSE)
endif()
else()
generate_app_man(${target} "${CMAKE_PROJECT_DESCRIPTION} \\(GUI\\)")

View File

@ -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 $<TARGET_BUNDLE_CONTENT_DIR:${CMAKE_PROJECT_PROPER_NAME}>/MacOS/translations)