From ca5df44edb1963d4c634390d33229ec928e284dc Mon Sep 17 00:00:00 2001 From: Pavel Puchkin Date: Tue, 10 Mar 2015 19:29:13 +0200 Subject: Standalone bundle for OSX (w/ dependencies!) --- src/CMakeLists.txt | 15 ++++++++++++++- src/porting.cpp | 37 ++++++++++++++----------------------- 2 files changed, 28 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d56ec18c0..2ce108681 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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}) diff --git a/src/porting.cpp b/src/porting.cpp index 64a51c7f5..710446363 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -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: "<