Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for macOS app bundles for GUI apps #2739

Merged
merged 16 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)

set(CMAKE_OSX_DEPLOYMENT_TARGET 10.15 CACHE STRING "")
project(mrtrix3 LANGUAGES CXX VERSION 3.0.4)

include(GNUInstallDirs)
Expand Down Expand Up @@ -59,6 +60,9 @@ include(LinkerSetup)
include(FindFFTW)
include(CompilerCache)
include(ECMEnableSanitizers)
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
include(MacOSBundle)
endif()

use_compiler_cache()

Expand Down
31 changes: 31 additions & 0 deletions cmake/MacOSBundle.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function(set_bundle_properties executable_name)
set(icon_files ${CMAKE_CURRENT_SOURCE_DIR}/../icons/macos/${executable_name}.icns)
if(${executable_name} STREQUAL "mrview")
list(APPEND icon_files ${CMAKE_CURRENT_SOURCE_DIR}/../icons/macos/mrview_doc.icns)
endif()

string(TIMESTAMP CURRENT_YEAR "%Y")
set(COPYRIGHT_YEAR "2008-${CURRENT_YEAR}" CACHE STRING "Copyright year")

target_sources(${executable_name} PRIVATE ${icon_files})
set_target_properties(${executable_name} PROPERTIES
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/../packaging/macos/bundle/${executable_name}.plist.in"
RESOURCE "${icon_files}"
INSTALL_RPATH "@executable_path/../../../../lib"
)
endfunction()

function(install_bundle_wrapper_scripts executable_name)
set(wrapper_script ${CMAKE_CURRENT_SOURCE_DIR}/../packaging/macos/bundle/wrapper_launcher.sh.in)
configure_file(${wrapper_script} ${PROJECT_BINARY_DIR}/bin/${executable_name}
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
@ONLY
)

install(FILES ${PROJECT_BINARY_DIR}/bin/${executable_name}
DESTINATION ${CMAKE_INSTALL_BINDIR}
RENAME "${executable_name}"
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)

endfunction()
13 changes: 11 additions & 2 deletions cmd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,18 @@ function(add_cmd CMD_SRC IS_GUI)
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin
)
if(MRTRIX_USE_PCH AND NOT ${IS_GUI})
target_precompile_headers(${CMD_NAME} REUSE_FROM pch_cmd)
target_precompile_headers(${CMD_NAME} REUSE_FROM pch_cmd)
endif()
install(TARGETS ${CMD_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

if (IS_GUI AND ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
set_bundle_properties(${CMD_NAME})
install_bundle_wrapper_scripts(${CMD_NAME})
endif ()

install(TARGETS ${CMD_NAME}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}
)
endfunction()


Expand Down
Binary file added icons/macos/mrview.icns
Binary file not shown.
Binary file added icons/macos/mrview_doc.icns
Binary file not shown.
Binary file added icons/macos/shview.icns
Binary file not shown.
156 changes: 156 additions & 0 deletions packaging/macos/bundle/mrview.plist.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleInfoDictionaryVersion</key> <string>6.0</string>
<key>CFBundleDevelopmentRegion</key> <string>en</string>
<key>CFBundleName</key> <string>MRView</string>
<key>CFBundleDisplayName</key> <string>MRView</string>
<key>CFBundleExecutable</key> <string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key> <string>${MACOSX_BUNDLE_EXECUTABLE_NAME}.icns</string>
<key>CFBundleIdentifier</key> <string>org.mrtrix.${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
<key>CFBundlePackageType</key> <string>APPL</string>
<key>CFBundleShortVersionString</key> <string>${PROJECT_VERSION}</string>
<key>CFBundleVersion</key> <string>${PROJECT_VERSION}</string>
<key>NSHumanReadableCopyright</key> <string>Copyright (c) ${COPYRIGHT_YEAR} the MRtrix3 contributors</string>
<key>LSMinimumSystemVersion</key> <string>${CMAKE_OSX_DEPLOYMENT_TARGET}</string>
<key>LSBackgroundOnly</key> <string>0</string>
<key>NSHighResolutionCapable</key> <true/>

<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleURLName</key>
<string>MRView file</string>
<key>CFBundleURLSchemes</key>
<array>
<string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
</array>
</dict>
</array>

<key>CFBundleDocumentTypes</key>
<array>

<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>gz</string>
</array>
<key>CFBundleTypeName</key>
<string>MRtrix of NIfTI image (compressed)</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleTypeIconFile</key>
<string>${MACOSX_BUNDLE_EXECUTABLE_NAME}_doc.icns</string>
</dict>

<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>mif</string>
</array>
<key>CFBundleTypeName</key>
<string>MRtrix image</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleTypeIconFile</key>
<string>${MACOSX_BUNDLE_EXECUTABLE_NAME}_doc.icns</string>
</dict>

<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>mih</string>
</array>
<key>CFBundleTypeName</key>
<string>MRtrix image header</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleTypeIconFile</key>
<string>${MACOSX_BUNDLE_EXECUTABLE_NAME}_doc.icns</string>
</dict>

<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>mif.gz</string>
</array>
<key>CFBundleTypeName</key>
<string>MRtrix image (compressed)</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleTypeIconFile</key>
<string>${MACOSX_BUNDLE_EXECUTABLE_NAME}_doc.icns</string>
</dict>

<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>nii</string>
</array>
<key>CFBundleTypeName</key>
<string>NIfTI image</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleTypeIconFile</key>
<string>${MACOSX_BUNDLE_EXECUTABLE_NAME}_doc.icns</string>
</dict>

<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>nii.gz</string>
</array>
<key>CFBundleTypeName</key>
<string>NIfTI image (compressed)</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleTypeIconFile</key>
<string>${MACOSX_BUNDLE_EXECUTABLE_NAME}_doc.icns</string>
</dict>

<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>mgh</string>
</array>
<key>CFBundleTypeName</key>
<string>MGH image</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleTypeIconFile</key>
<string>${MACOSX_BUNDLE_EXECUTABLE_NAME}_doc.icns</string>
</dict>

<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>mgz</string>
</array>
<key>CFBundleTypeName</key>
<string>MGH image (compressed)</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleTypeIconFile</key>
<string>${MACOSX_BUNDLE_EXECUTABLE_NAME}_doc.icns</string>
</dict>

<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>img</string>
</array>
<key>CFBundleTypeName</key>
<string>Analyze image</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleTypeIconFile</key>
<string>${MACOSX_BUNDLE_EXECUTABLE_NAME}_doc.icns</string>
</dict>

</array>
</dict>
</plist>
20 changes: 20 additions & 0 deletions packaging/macos/bundle/shview.plist.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleInfoDictionaryVersion</key> <string>6.0</string>
<key>CFBundleDevelopmentRegion</key> <string>en</string>
<key>CFBundleName</key> <string>SHView</string>
<key>CFBundleDisplayName</key> <string>SHView</string>
<key>CFBundleExecutable</key> <string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key> <string>${MACOSX_BUNDLE_EXECUTABLE_NAME}.icns</string>
<key>CFBundleIdentifier</key> <string>org.mrtrix.${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
<key>CFBundlePackageType</key> <string>APPL</string>
<key>CFBundleShortVersionString</key> <string>${PROJECT_VERSION}</string>
<key>CFBundleVersion</key> <string>${PROJECT_VERSION}</string>
<key>NSHumanReadableCopyright</key> <string>Copyright (c) ${COPYRIGHT_YEAR} the MRtrix3 contributors</string>
<key>LSMinimumSystemVersion</key> <string>${CMAKE_OSX_DEPLOYMENT_TARGET}</string>
<key>LSBackgroundOnly</key> <string>0</string>
<key>NSHighResolutionCapable</key> <true/>
</dict>
</plist>
12 changes: 12 additions & 0 deletions packaging/macos/bundle/wrapper_launcher.sh.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

# This script is a wrapper around the actual MacOSX bundle executable.

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
real_path=${DIR}/@executable_name@.app/Contents/MacOS/@executable_name@
if [ -x "${real_path}" ]; then
exec "${real_path}" "$@"
else
echo "Could not find executable at ${real_path}"
exit 1
fi
Loading