Standalone bundle for OSX (w/ dependencies!)
authorPavel Puchkin <i@neoascetic.me>
Tue, 10 Mar 2015 17:29:13 +0000 (19:29 +0200)
committerLoic Blot <loic.blot@unix-experience.fr>
Tue, 17 Mar 2015 14:37:23 +0000 (15:37 +0100)
CMakeLists.txt
README.txt
misc/Info.plist
src/CMakeLists.txt
src/porting.cpp

index 3065710ab2fa89161b45d205e3a75622962cebcc..5d799f9cac065c4d00432c9c25c2d54cfb4f5e59 100644 (file)
@@ -41,7 +41,7 @@ else()
 endif()
 
 set(BUILD_CLIENT 1 CACHE BOOL "Build client")
-if(WIN32)
+if(WIN32 OR APPLE)
        set(BUILD_SERVER 0 CACHE BOOL "Build server")
 else()
        set(BUILD_SERVER 1 CACHE BOOL "Build server")
@@ -72,11 +72,13 @@ if(WIN32)
        set(EXAMPLE_CONF_DIR ".")
        set(LOCALEDIR "locale")
 elseif(APPLE)
-       set(SHAREDIR ".")
-       set(BINDIR ".")
-       set(DOCDIR "./doc/${PROJECT_NAME}")
+       set(BUNDLE_NAME ${PROJECT_NAME}.app)
+       set(BUNDLE_PATH "${BUNDLE_NAME}")
+       set(BINDIR ${BUNDLE_NAME}/Contents/MacOS)
+       set(SHAREDIR ${BUNDLE_NAME}/Contents/Resources)
+       set(DOCDIR "${SHAREDIR}/${PROJECT_NAME}")
        set(EXAMPLE_CONF_DIR ${DOCDIR})
-       set(LOCALEDIR "locale")
+       set(LOCALEDIR "${SHAREDIR}/locale")
 elseif(UNIX) # Linux, BSD etc
        if(RUN_IN_PLACE)
                set(SHAREDIR ".")
@@ -176,6 +178,11 @@ if(UNIX AND NOT APPLE)
        install(FILES "misc/minetest-icon.svg" DESTINATION "${ICONDIR}/hicolor/scalable/apps")
 endif()
 
+if(APPLE)
+       install(FILES "misc/minetest-icon.icns" DESTINATION "${SHAREDIR}")
+       install(FILES "misc/Info.plist" DESTINATION "${BUNDLE_PATH}/Contents")
+endif()
+
 #
 # Subdirectories
 # Be sure to add all relevant definitions above this
@@ -193,15 +200,6 @@ set(CPACK_PACKAGE_VENDOR "celeron55")
 set(CPACK_PACKAGE_CONTACT "Perttu Ahola <celeron55@gmail.com>")
 
 if(WIN32)
-       # For some reason these aren't copied otherwise
-       # NOTE: For some reason now it seems to work without these
-       #if(BUILD_CLIENT)
-       #       install(FILES bin/minetest.exe DESTINATION bin)
-       #endif()
-       #if(BUILD_SERVER)
-       #       install(FILES bin/minetestserver.exe DESTINATION bin)
-       #endif()
-
        if(CMAKE_SIZEOF_VOID_P EQUAL 8)
                set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win64")
        else(CMAKE_SIZEOF_VOID_P EQUAL 8)
@@ -209,16 +207,10 @@ if(WIN32)
        endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
 
        set(CPACK_GENERATOR ZIP)
-
-       # This might be needed for some installer
-       #set(CPACK_PACKAGE_EXECUTABLES bin/minetest.exe "Minetest" bin/minetestserver.exe "Minetest Server")
 elseif(APPLE)
+       set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
        set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-osx")
-       set(CPACK_PACKAGE_ICON ${CMAKE_CURRENT_SOURCE_DIR}/misc/minetest-icon.icns)
-       set(CPACK_BUNDLE_NAME ${PROJECT_NAME})
-       set(CPACK_BUNDLE_ICON ${CPACK_PACKAGE_ICON})
-       set(CPACK_BUNDLE_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/misc/Info.plist)
-       set(CPACK_GENERATOR "Bundle")
+       set(CPACK_GENERATOR ZIP)
 else()
        set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-linux")
        set(CPACK_GENERATOR TGZ)
index a3aa9e6b3fabf4debc837979551737c9899053a4..d9eb9fe4b9e1dee18af75a1a512c8c223915c1df 100644 (file)
@@ -1,4 +1,4 @@
-Minetest
+Minetest
 ========
 
 An InfiniMiner/Minecraft inspired game.
@@ -78,9 +78,9 @@ $share = /usr/share/minetest
 $user  = ~/.minetest
 
 OS X:
-$bin   = ?
-$share = ?
-$user  = ~/Library/Application Support/minetest
+$bin   = Contents/MacOS
+$share = Contents/Resources
+$user  = Contents/User OR ~/Library/Application Support/minetest
 
 World directory
 ----------------
index 848ccfa30816c03c519361527f898818ebfa3cba..1498ee474c0897d266f91065990b25d35a6fdb3d 100644 (file)
@@ -5,9 +5,9 @@
        <key>CFBundleDevelopmentRegion</key>
        <string>English</string>
        <key>CFBundleExecutable</key>
-       <string>../Resources/minetest</string>
+       <string>minetest</string>
        <key>CFBundleIconFile</key>
-       <string>minetest.icns</string>
+       <string>minetest-icon.icns</string>
        <key>CFBundleIdentifier</key>
        <string>net.minetest.minetest</string>
 </dict>
index d56ec18c0539ac43ef135d5673b6104e0598fb6c..2ce1086813ea7307b72e4e97150d90d1e2a890c4 100644 (file)
@@ -737,7 +737,20 @@ if(WIN32)
 endif()
 
 if(BUILD_CLIENT)
-       install(TARGETS ${PROJECT_NAME} DESTINATION ${BINDIR})
+       install(TARGETS ${PROJECT_NAME}
+               RUNTIME DESTINATION ${BINDIR}
+               LIBRARY DESTINATION ${BINDIR}
+               ARCHIVE DESTINATION ${BINDIR}
+               BUNDLE DESTINATION .
+       )
+
+       if(APPLE)
+               install(CODE "
+                       set(BU_CHMOD_BUNDLE_ITEMS ON)
+                       include(BundleUtilities)
+                       fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/${BUNDLE_PATH}\" \"\" \"\${CMAKE_INSTALL_PREFIX}/${BINDIR}\")
+               " COMPONENT Runtime)
+       endif()
 
        if(USE_GETTEXT)
                foreach(LOCALE ${GETTEXT_AVAILABLE_LOCALES})
index 64a51c7f50527505a4ec883eccf802da09d91909..71044636380cd679639b711f6a39e26b8093780a 100644 (file)
@@ -387,16 +387,16 @@ void initializePaths()
        */
        #elif defined(__APPLE__)
 
-       //https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/dyld.3.html
-       //TODO: Test this code
-       char buf[BUFSIZ];
-       uint32_t len = sizeof(buf);
-       FATAL_ERROR_IF(_NSGetExecutablePath(buf, &len) == -1, "");
-
-       pathRemoveFile(buf, '/');
-
-       path_share = std::string(buf) + "/..";
-       path_user = std::string(buf) + "/..";
+       CFBundleRef main_bundle = CFBundleGetMainBundle();
+       CFURLRef resources_url = CFBundleCopyResourcesDirectoryURL(main_bundle);
+       char path[PATH_MAX];
+       if (CFURLGetFileSystemRepresentation(resources_url, TRUE, (UInt8 *)path, PATH_MAX)) {
+               path_share = std::string(path);
+               path_user = std::string(path) + "/../User";
+       } else {
+               dstream << "WARNING: Could not determine bundle resource path" << std::endl;
+       }
+       CFRelease(resources_url);
 
        /*
                FreeBSD
@@ -523,24 +523,15 @@ void initializePaths()
        */
        #elif defined(__APPLE__)
 
-       // Code based on
-       // http://stackoverflow.com/questions/516200/relative-paths-not-working-in-xcode-c
        CFBundleRef main_bundle = CFBundleGetMainBundle();
        CFURLRef resources_url = CFBundleCopyResourcesDirectoryURL(main_bundle);
        char path[PATH_MAX];
-       if(CFURLGetFileSystemRepresentation(resources_url, TRUE, (UInt8 *)path, PATH_MAX))
-       {
-               dstream<<"Bundle resource path: "<<path<<std::endl;
-               //chdir(path);
-               path_share = std::string(path) + DIR_DELIM + STATIC_SHAREDIR;
-       }
-       else
-       {
-               // error!
-               dstream<<"WARNING: Could not determine bundle resource path"<<std::endl;
+       if (CFURLGetFileSystemRepresentation(resources_url, TRUE, (UInt8 *)path, PATH_MAX)) {
+               path_share = std::string(path);
+       } else {
+               dstream << "WARNING: Could not determine bundle resource path" << std::endl;
        }
        CFRelease(resources_url);
-
        path_user = std::string(getenv("HOME")) + "/Library/Application Support/" + PROJECT_NAME;
 
        #else // FreeBSD, and probably many other POSIX-like systems.