Created
June 12, 2013 22:31
-
-
Save i8degrees/5769710 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Filename: platform.cpp | |
* Comments: | |
* Defines functions that are to be used on specific platforms. | |
*/ | |
#ifdef __APPLE__ | |
#include "CoreFoundation/CoreFoundation.h" | |
#include <iostream> | |
#endif | |
// ---------------------------------------------------------------------------- | |
// This makes relative paths work in C++ in Xcode by changing directory to the | |
// Resources folder inside the .app bundle | |
#ifdef __APPLE__ | |
void macApp_setRelativePath() { | |
CFBundleRef mainBundle = CFBundleGetMainBundle(); | |
CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle); | |
char path[PATH_MAX]; | |
if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX)) | |
{ | |
// error! | |
} | |
CFRelease(resourcesURL); | |
chdir(path); | |
std::cout << "[Mac] Set path to " << path << std::endl; | |
} | |
#endif | |
// ---------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment