diff --git a/Meta/Lagom/CMakeLists.txt b/Meta/Lagom/CMakeLists.txt index bfd402c31f..c901519180 100644 --- a/Meta/Lagom/CMakeLists.txt +++ b/Meta/Lagom/CMakeLists.txt @@ -534,6 +534,10 @@ if (BUILD_LAGOM) add_serenity_subdirectory(Ladybird) endif() + if (APPLE) + add_serenity_subdirectory(Meta/Lagom/Contrib/MacPDF) + endif() + add_executable(icc ../../Userland/Utilities/icc.cpp) target_link_libraries(icc LibCore LibGfx LibMain) diff --git a/Meta/Lagom/Contrib/MacPDF/CMakeLists.txt b/Meta/Lagom/Contrib/MacPDF/CMakeLists.txt new file mode 100644 index 0000000000..1934f3ddcd --- /dev/null +++ b/Meta/Lagom/Contrib/MacPDF/CMakeLists.txt @@ -0,0 +1,55 @@ +# This has the effect of making LC_RPATH absolute. +# Since the binary is in Build/lagom/bin/MacPDF.app/Contents/MacOS/MacPDF, +# the default "@executable_path/../lib" doesn't work to get from the binary +# to Build/lagom/lib. +# FIXME: Pass "-Wl,-rpath,@executable_path/../../../../lib" instead for a relative path? +# Long-term, probably want to copy the dylibs into the bundle instead. +set(CMAKE_SKIP_BUILD_RPATH FALSE) +set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) + +set(RESOURCES + LagomPDFDocument.xib + MainMenu.xib +) + +add_executable(MacPDF MACOSX_BUNDLE + main.mm + AppDelegate.mm + LagomPDFDocument.mm + LagomPDFView.mm +) +target_compile_options(MacPDF PRIVATE + -fobjc-arc +) +target_link_libraries(MacPDF PRIVATE LibCore LibGfx LibPDF) +target_link_libraries(MacPDF PRIVATE + "-framework Cocoa" + "-framework UniformTypeIdentifiers" +) + +set_target_properties(MacPDF PROPERTIES + MACOSX_BUNDLE TRUE + + # FIXME: Apparently the Info.plist is only copied when the binary relinks, + # not if only the Info.plist contents changes and you rebuild? + MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist" +) + +# Normally you'd set `RESOURCE "${RESOURCES}"` on the MacPDF target properties +# and add `"${RESOURCES}" to the sources in add_executable() +# and CMake would add build steps to compile the xib files to nib files and +# add them to the bundle. +# But with CMake's ninja generator that seems to not work, so do it manually. +# See also https://github.com/dolphin-emu/dolphin/blob/2e39c79984490e/Source/Core/MacUpdater/CMakeLists.txt#L49-L56 +find_program(IBTOOL ibtool HINTS "/usr/bin" "${OSX_DEVELOPER_ROOT}/usr/bin") +foreach(xib ${RESOURCES}) + string(REGEX REPLACE "[.]xib$" ".nib" nib "${xib}") + + # FIXME: This is gross! It makes the link at least as slow as compiling all xib files. + # Better to have a separate command for the compiles and to only do the copying in the postbuild. + add_custom_command(TARGET MacPDF POST_BUILD + COMMAND ${IBTOOL} --errors --warnings --notices --output-format human-readable-text + --compile "$/Contents/Resources/${nib}" + "${CMAKE_CURRENT_SOURCE_DIR}/${xib}" + COMMENT "Compiling ${CMAKE_CURRENT_SOURCE_DIR}/${xib}.xib") +endforeach() diff --git a/Meta/Lagom/Contrib/MacPDF/Info.plist b/Meta/Lagom/Contrib/MacPDF/Info.plist index a6a9233d6c..65d5b3c2ca 100644 --- a/Meta/Lagom/Contrib/MacPDF/Info.plist +++ b/Meta/Lagom/Contrib/MacPDF/Info.plist @@ -19,6 +19,20 @@ LagomPDFDocument + CFBundleExecutable + MacPDF + CFBundleIdentifier + org.serenityos.MacPDF + CFBundleName + MacPDF + CFBundlePackageType + APPL + LSMinimumSystemVersion + 13.3 + NSMainNibFile + MainMenu + NSPrincipalClass + NSApplication NSSupportsAutomaticTermination NSSupportsSuddenTermination