Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a MacOS app bundle with cmake

This can be considered as a follow-up to CMake MacOS X bundle with BundleUtiliies for Qt application

I want to create a MACOS bundle on CI which can be used by users for an open source project.

What I have:

  • Main executable
  • Updater executable
  • icon file
  • helper script calling updater then main
  • data files in a folder (translations etc, some generated at build time)
  • plugin shared libs

What I've done so far:

  • add MACOSX_BUNDLE to the executable
  • add icon to its sources and to RESOURCE property
  • set MACOSX_BUNDLE_* properties
  • install everything in a cross-platform way (regular install(TARGETS calls and install(FILES for the resources)

But now I'm stuck on how to get those into the bundle w/o to much manual work.

From the linked question I got something like this:

set(APPS "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}.app")
set(LIBS )
set(DIRS "${CMAKE_BINARY_DIR}")
# Path used for searching by FIND_XXX(), with appropriate suffixes added
if(CMAKE_PREFIX_PATH)
        foreach(dir ${CMAKE_PREFIX_PATH})
                list(APPEND DIRS "${dir}/bin" "${dir}/lib")
        endforeach()
endif()
install(CODE "include(BundleUtilities)
  fixup_bundle(\"${APPS}\" \"${LIBS}\" \"${DIRS}\")")

But:

  • Why do I need to pass the *.app path manually? CMake does already know it, doesn't it?
  • LIBS should contain my plugins, shouldn't it? But what? Paths? Target names?
  • DIRS is also a mystery to me. No documentation even in CMake 3.12 (I'm still using 2.8.12 though :( )
  • How to add my generated and regular data files? Probably same or similar to the icon? But what about the generated ones?

Help, pointers to examples, full CMakeLists doing that etc. very welcome.

Note: I'm cross-compiling from linux on the CI and NOT using Qt so e.g. macdeployqt or so is out of question.

like image 541
Flamefire Avatar asked Nov 30 '18 15:11

Flamefire


1 Answers

Just got stuck on the same issue and google brought me here.

This worked for me:

set(CUR_TARGET myappname)
add_executable(${CUR_TARGET} MACOSX_BUNDLE ${MY_SRC})            
set_target_properties(${CUR_TARGET} PROPERTIES
    BUNDLE True
    MACOSX_BUNDLE_GUI_IDENTIFIER my.domain.style.identifier.${CUR_TARGET}
    MACOSX_BUNDLE_BUNDLE_NAME ${CUR_TARGET}
    MACOSX_BUNDLE_BUNDLE_VERSION "0.1"
    MACOSX_BUNDLE_SHORT_VERSION_STRING "0.1"
    MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/cmake/customtemplate.plist.in
)

The file customtemplate.plist.in is based on the cmake template from the cmake dir subfolder at your_cmake_install_dir/share/cmake/Modules/MacOSXBundleInfo.plist.in

like image 50
Luz Avatar answered Nov 09 '22 04:11

Luz