From 6333a5caaf92ee76f5a502c3b406c2f7868d913e Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 21 Jan 2013 16:21:59 +0100 Subject: [PATCH] Added CMake option for glfwInit chdir on OS X. --- CMakeLists.txt | 8 +++++++- src/cocoa_init.m | 6 ++++++ src/config.h.in | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 75044182..fb83af5e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,9 @@ option(GLFW_BUILD_EXAMPLES "Build the GLFW example programs" ON) option(GLFW_BUILD_TESTS "Build the GLFW test programs" ON) option(BUILD_SHARED_LIBS "Build shared libraries" OFF) -if (NOT APPLE) +if (APPLE) + option(GLFW_CD_RESOURCES "Make glfwInit chdir to Contents/Resources" ON) +else() option(GLFW_USE_EGL "Use EGL for context creation" OFF) endif() @@ -286,6 +288,10 @@ if (_GLFW_COCOA AND _GLFW_NSGL) option(GLFW_BUILD_UNIVERSAL "Build GLFW as a Universal Binary" OFF) + if (GLFW_CD_RESOURCES) + set(_GLFW_CD_RESOURCES 1) + endif() + # Universal build if (GLFW_BUILD_UNIVERSAL) message(STATUS "Building GLFW as Universal Binaries") diff --git a/src/cocoa_init.m b/src/cocoa_init.m index b2e78cd8..943ee702 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -34,6 +34,8 @@ // Change to our application bundle's resources directory, if present //======================================================================== +#if defined(_GLFW_CD_RESOURCES) + static void changeToResourcesDirectory(void) { char resourcesPath[MAXPATHLEN]; @@ -68,6 +70,8 @@ static void changeToResourcesDirectory(void) chdir(resourcesPath); } +#endif /* _GLFW_CD_RESOURCES */ + ////////////////////////////////////////////////////////////////////////// ////// GLFW platform API ////// @@ -90,7 +94,9 @@ int _glfwPlatformInit(void) return GL_FALSE; } +#if defined(_GLFW_CD_RESOURCES) changeToResourcesDirectory(); +#endif // Save the original gamma ramp _glfw.originalRampSize = CGDisplayGammaTableCapacity(CGMainDisplayID()); diff --git a/src/config.h.in b/src/config.h.in index 760ace43..b4f713d9 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -64,6 +64,9 @@ // Define this to 1 if glXGetProcAddressEXT is available #cmakedefine _GLFW_HAS_GLXGETPROCADDRESSEXT +// Define this to 1 if glfwInit should change the current directory +#cmakedefine _GLFW_CD_RESOURCES + // Define this to 1 if using OpenGL as the client library #cmakedefine _GLFW_USE_OPENGL // Define this to 1 if using OpenGL ES 1.1 as the client library