Skip to content

Commit

Permalink
Generate BundleInfo.plist for macos
Browse files Browse the repository at this point in the history
  • Loading branch information
mwestphal committed Mar 31, 2024
1 parent 122bd83 commit a44359d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 421 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ message(STATUS "VTK ${VTK_VERSION} found")
# Shared options between application and library
include(GNUInstallDirs)
cmake_dependent_option(F3D_WINDOWS_GUI "Build a non-console Win32 application" ON "WIN32" OFF)
cmake_dependent_option(F3D_MACOS_BUNDLE "Build a macOS bundle application" ON "APPLE" OFF)
cmake_dependent_option(F3D_MACOS_BUNDLE "Build a macOS bundle application" ON "UNIX" OFF)

# Force static library when creating a macOS bundle
cmake_dependent_option(BUILD_SHARED_LIBS "Build f3d with shared libraries" ON "NOT ANDROID" OFF)
Expand Down
2 changes: 1 addition & 1 deletion application/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ if(F3D_MACOS_BUNDLE)
set(MACOSX_BUNDLE_BUNDLE_VERSION ${F3D_VERSION})
set(MACOSX_BUNDLE_COPYRIGHT "Michael Migliore, Mathieu Westphal")

# Generate MacOS bundle
# Generate MacOS bundle using CMake variable generated by plugins
configure_file("${F3D_SOURCE_DIR}/resources/BundleInfo.plist.in"
"${CMAKE_CURRENT_BINARY_DIR}/BundleInfo.plist")
set_target_properties(f3d PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_BINARY_DIR}/BundleInfo.plist")
Expand Down
32 changes: 29 additions & 3 deletions cmake/f3dPlugin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ macro(f3d_plugin_declare_reader)
string(JSON F3D_READER_JSON
SET "${F3D_READER_JSON}" "description" "\"${F3D_READER_FORMAT_DESCRIPTION}\"")

set(F3D_MACOS_BUNDLE_EXTENSIONS ${F3D_READER_EXTENSIONS})
list(TRANSFORM F3D_READER_EXTENSIONS PREPEND "\"")
list(TRANSFORM F3D_READER_EXTENSIONS APPEND "\"")
list(JOIN F3D_READER_EXTENSIONS ", " F3D_READER_EXTENSIONS)
Expand Down Expand Up @@ -131,6 +132,27 @@ macro(f3d_plugin_declare_reader)
string(JSON F3D_PLUGIN_JSON
SET "${F3D_PLUGIN_JSON}" "readers" ${F3D_PLUGIN_CURRENT_READER_INDEX} "${F3D_READER_JSON}")

if(F3D_MACOS_BUNDLE)
list(JOIN F3D_MACOS_BUNDLE_EXTENSIONS "</string>
<string>" F3D_MACOS_BUNDLE_EXTENSIONS)

set(F3D_MACOS_BUNDLE_XML_PLUGIN
"${F3D_MACOS_BUNDLE_XML_PLUGIN}
<dict>
<key>CFBundleTypeName</key>
<string>${F3D_READER_FORMAT_DESCRIPTION}</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSIsAppleDefaultForType</key>
<true/>
<key>CFBundleTypeExtensions</key>
<array>
<string>${F3D_MACOS_BUNDLE_EXTENSIONS}</string>
</array>
</dict>
")
endif()

math(EXPR "F3D_PLUGIN_CURRENT_READER_INDEX" "${F3D_PLUGIN_CURRENT_READER_INDEX} +1")

configure_file("${_f3dPlugin_dir}/readerBoilerPlate.h.in"
Expand Down Expand Up @@ -185,8 +207,8 @@ macro(f3d_plugin_build)
set(F3D_PLUGIN_IS_STATIC ON)
set_property(GLOBAL APPEND PROPERTY F3D_STATIC_PLUGINS ${F3D_PLUGIN_NAME})
else()
set(F3D_PLUGIN_TYPE "MODULE")
set(F3D_PLUGIN_IS_STATIC OFF)
set(F3D_PLUGIN_TYPE "MODULE")
set(F3D_PLUGIN_IS_STATIC OFF)

get_target_property(target_type VTK::CommonCore TYPE)
if (target_type STREQUAL STATIC_LIBRARY)
Expand All @@ -206,7 +228,6 @@ macro(f3d_plugin_build)
list(APPEND f3d_plugin_link_options "${f3d_coverage_link_options}")
list(APPEND f3d_plugin_link_options "${f3d_sanitizer_link_options}")


vtk_module_find_modules(vtk_module_files "${CMAKE_CURRENT_SOURCE_DIR}")

if(NOT ${vtk_module_files} STREQUAL "")
Expand Down Expand Up @@ -370,4 +391,9 @@ macro(f3d_plugin_build)
install(FILES "${F3D_PLUGIN_JSON_FILE}"
DESTINATION "share/f3d/plugins"
COMPONENT plugin)

if(F3D_MACOS_BUNDLE)
set(F3D_MACOS_BUNDLE_XML "${F3D_MACOS_BUNDLE_XML}${F3D_MACOS_BUNDLE_XML_PLUGIN}" PARENT_SCOPE)
endif()

endmacro()
4 changes: 4 additions & 0 deletions plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ if (F3D_PLUGIN_BUILD_VDB)
message(FATAL_ERROR "VDB plugin requires VTK >= 9.2.20220714")
endif()
endif()

if(F3D_MACOS_BUNDLE)
set(F3D_MACOS_BUNDLE_XML ${F3D_MACOS_BUNDLE_XML} PARENT_SCOPE)
endif()
Loading

0 comments on commit a44359d

Please sign in to comment.