cmake build system: visiblity support for clang
[supercollider.git] / common / SC_StandAloneInfo_Darwin.cpp
blob65dafdbcfc147b7324b6d78eba0095bfce692d71
1 #if defined(__APPLE__) || defined(SC_IPHONE)
3 #include <sys/param.h>
4 #include <stdexcept>
5 #include <cstring> // for strncpy
7 #include <CoreFoundation/CFString.h>
8 #include <CoreFoundation/CFBundle.h>
9 //#include <CoreServices/CoreServices.h>
11 #include "SC_StandAloneInfo_Darwin.h"
13 bool SC_StandAloneInfo::sIsStandAlone;
14 bool SC_StandAloneInfo::haveCheckedBundleStatus;
15 char SC_StandAloneInfo::dirPath[PATH_MAX];
17 void SC_StandAloneInfo::SC_StandAloneInfoInit() {
18 CFStringEncoding encoding = kCFStringEncodingASCII;
20 if ( !haveCheckedBundleStatus )
22 haveCheckedBundleStatus = true;
23 CFStringRef stringToFind = CFSTR("SCClassLibrary");
24 CFURLRef enablerURL = CFBundleCopyResourceURL (
25 CFBundleGetMainBundle(),
26 stringToFind,
27 NULL,
28 NULL
30 if ( enablerURL )
32 CFStringRef string2ToFind = CFSTR(".app/");
33 CFRange findResult = CFStringFind(CFURLGetString(enablerURL), string2ToFind, kCFCompareCaseInsensitive);
34 if(findResult.length != 0)
36 // You'd think we could get an absolute path to the Resources directory. But
37 // we can't, we can only get a relative path, or an absolute path to a
38 // specific resource. Since we don't know the application name, we get the
39 // latter, and then hack off the resource name.
41 sIsStandAlone = true;
42 CFStringRef rawPath = CFURLCopyFileSystemPath(enablerURL, kCFURLPOSIXPathStyle);
44 CFRange discardRange = CFStringFind (
45 CFURLCopyFileSystemPath(enablerURL, kCFURLPOSIXPathStyle),
46 stringToFind,
50 CFRange validRange;
51 validRange.location = 0;
52 validRange.length = discardRange.location - 1;
54 CFStringRef dirPathCFString = CFStringCreateWithSubstring (
55 kCFAllocatorDefault,
56 rawPath,
57 validRange
60 CFStringGetCString (
61 dirPathCFString,
62 dirPath,
63 PATH_MAX,
64 encoding
66 }else
68 getcwd(dirPath, PATH_MAX);
71 else
73 getcwd(dirPath, PATH_MAX);
78 bool SC_StandAloneInfo::IsStandAlone() {
79 if ( !haveCheckedBundleStatus )
81 SC_StandAloneInfoInit();
83 return sIsStandAlone;
86 void SC_StandAloneInfo::GetResourceDir(char* pathBuf, int length)
88 if ( !haveCheckedBundleStatus )
90 SC_StandAloneInfoInit();
92 strncpy(pathBuf, dirPath, length);
96 #endif