Skip to content

Commit

Permalink
Add MacOSBundle.cmake module
Browse files Browse the repository at this point in the history
  • Loading branch information
daljit46 committed Jun 3, 2024
1 parent 1a015dd commit 1eafc83
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ include(LinkerSetup)
include(FindFFTW)
include(CompilerCache)
include(ECMEnableSanitizers)
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
include(MacOSBundle)
endif()

use_compiler_cache()

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

target_sources(${executable_name} PRIVATE ${mrtrix_icon_macos})
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 ${mrtrix_icon_macos}
INSTALL_RPATH "@executable_path/../../../../lib"
)
endfunction()
21 changes: 5 additions & 16 deletions cmd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,18 @@ function(add_cmd CMD_SRC IS_GUI)
$<IF:$<BOOL:${IS_GUI}>,mrtrix::gui,mrtrix::headless>
mrtrix::exec-version-lib
)
if (IS_GUI AND (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin"))
set(mrtrix_icon_macos "${CMAKE_SOURCE_DIR}/icons/macos/${CMD_NAME}.icns")
set_source_files_properties(${mrtrix_icon_macos} PROPERTIES
MACOSX_PACKAGE_LOCATION "Resources"
)
target_sources(${CMD_NAME} PRIVATE ${mrtrix_icon_macos})
if (${CMD_NAME} STREQUAL mrview)
set(mrtrix_icon_macos "${CMAKE_SOURCE_DIR}/icons/macos/${CMD_NAME}_doc.icns")
set_source_files_properties(${mrtrix_icon_macos} PROPERTIES
MACOSX_PACKAGE_LOCATION "Resources"
)
target_sources(${CMD_NAME} PRIVATE ${mrtrix_icon_macos})
endif ()
endif ()
set_target_properties(${CMD_NAME} PROPERTIES
MACOSX_BUNDLE ${IS_GUI}
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/cmake/bundle/${CMD_NAME}.plist.in
LINK_DEPENDS_NO_SHARED true
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin
)
if(MRTRIX_USE_PCH AND NOT ${IS_GUI})
target_precompile_headers(${CMD_NAME} REUSE_FROM pch_cmd)
endif()

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

install(TARGETS ${CMD_NAME}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}
Expand Down

0 comments on commit 1eafc83

Please sign in to comment.