Create macOS "bundle wrapper" scripts (#115)

These scripts must be installed side by side with the bundle with the
same name and run the executable inside the bundle when executed.
This commit is contained in:
Albrecht Schlosser 2020-07-23 02:07:43 +02:00
parent f357f4311c
commit 332003cd13
2 changed files with 64 additions and 11 deletions

View File

@ -57,9 +57,17 @@ macro (CREATE_EXAMPLE NAME SOURCES LIBRARIES)
set (TARGET_NAME ${NAME}) # CMake target name set (TARGET_NAME ${NAME}) # CMake target name
set (ICON_NAME) # macOS icon (max. one) set (ICON_NAME) # macOS icon (max. one)
set (PLIST) # macOS .plist file (max. one) set (PLIST) # macOS .plist file (max. one)
set (RESOURCE_PATH) # macOS resource path set (ICON_PATH) # macOS icon resource path
# rename target name "help" (reserved since CMake 2.8.12 and later) # create macOS bundle? 0 = no, 1 = yes
if (APPLE AND (NOT OPTION_APPLE_X11) AND (NOT OPTION_APPLE_SDL))
set (MAC_BUNDLE 1)
else ()
set (MAC_BUNDLE 0)
endif (APPLE AND (NOT OPTION_APPLE_X11) AND (NOT OPTION_APPLE_SDL))
# rename target name "help" (reserved since CMake 2.8.12)
# FIXME: not necessary in FLTK 1.4 but left for compatibility (06/2020) # FIXME: not necessary in FLTK 1.4 but left for compatibility (06/2020)
if (${TARGET_NAME} STREQUAL "help") if (${TARGET_NAME} STREQUAL "help")
@ -90,22 +98,42 @@ macro (CREATE_EXAMPLE NAME SOURCES LIBRARIES)
# set macOS (icon) resource path if applicable # set macOS (icon) resource path if applicable
if (APPLE AND (NOT OPTION_APPLE_X11) AND (NOT OPTION_APPLE_SDL) AND ICON_NAME) if (MAC_BUNDLE AND ICON_NAME)
set (RESOURCE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_NAME}.app/Contents/Resources/${ICON_NAME}") set (ICON_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_NAME}.app/Contents/Resources/${ICON_NAME}")
endif (APPLE AND (NOT OPTION_APPLE_X11) AND (NOT OPTION_APPLE_SDL) AND ICON_NAME) endif (MAC_BUNDLE AND ICON_NAME)
########################################################### ##############################################################################
# copy macOS "bundle wrapper" (shell script) to target (bin) directory
##############################################################################
# (1) file (COPY ...) to set execution permissions
# (2) file (RENAME ...) to move the file to its final place
##############################################################################
if (MAC_BUNDLE)
file (COPY
${CMAKE_CURRENT_SOURCE_DIR}/../CMake/macOS-bundle-wrapper.in
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
file (RENAME
${CMAKE_CURRENT_BINARY_DIR}/macOS-bundle-wrapper.in
${EXECUTABLE_OUTPUT_PATH}/${TARGET_NAME}
)
endif (MAC_BUNDLE)
##############################################################################
# add executable target and set properties (all platforms) # add executable target and set properties (all platforms)
########################################################### ##############################################################################
add_executable (${TARGET_NAME} WIN32 MACOSX_BUNDLE ${srcs} ${RESOURCE_PATH}) add_executable (${TARGET_NAME} WIN32 MACOSX_BUNDLE ${srcs} ${ICON_PATH})
set_target_properties (${TARGET_NAME} PROPERTIES OUTPUT_NAME ${NAME}) set_target_properties (${TARGET_NAME} PROPERTIES OUTPUT_NAME ${NAME})
target_link_libraries (${TARGET_NAME} ${LIBRARIES}) target_link_libraries (${TARGET_NAME} ${LIBRARIES})
if (RESOURCE_PATH) if (ICON_PATH)
set_target_properties (${TARGET_NAME} PROPERTIES MACOSX_BUNDLE_ICON_FILE ${ICON_NAME}) set_target_properties (${TARGET_NAME} PROPERTIES MACOSX_BUNDLE_ICON_FILE ${ICON_NAME})
set_target_properties (${TARGET_NAME} PROPERTIES RESOURCE ${RESOURCE_PATH}) set_target_properties (${TARGET_NAME} PROPERTIES RESOURCE ${ICON_PATH})
endif (RESOURCE_PATH) endif (ICON_PATH)
if (PLIST) if (PLIST)
set_target_properties (${TARGET_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/${PLIST}") set_target_properties (${TARGET_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/${PLIST}")

View File

@ -0,0 +1,25 @@
#!/bin/sh
#
# Run the executable of a macOS bundle for the Fast Light Tool Kit (FLTK).
#
# Copyright 1998-2020 by Bill Spitzak and others.
#
# This library is free software. Distribution and use rights are outlined in
# the file "COPYING" which should have been included with this file. If this
# file is missing or damaged, see the license at:
#
# https://www.fltk.org/COPYING.php
#
# Please see the following page on how to report bugs and issues:
#
# https://www.fltk.org/bugs.php
#
#
# Install this script side by side with the macOS bundle with the same name:
#
# - dir/prog.app macOS bundle (directory)
# - dir/prog this script: runs the executable 'prog' inside the bundle
#
prog="`basename \"$0\"`"
dir="`dirname \"$0\"`"
exec "$dir/$prog.app/Contents/MacOS/$prog" "$@"