Skip to content

Instantly share code, notes, and snippets.

@i8degrees
Created June 12, 2013 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save i8degrees/5769710 to your computer and use it in GitHub Desktop.
Save i8degrees/5769710 to your computer and use it in GitHub Desktop.
/*
* 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