From 0c122bb8ad6c73de4129cd8d65545e29ea2cb8a3 Mon Sep 17 00:00:00 2001
From: Camilla Berglund
Date: Wed, 2 Nov 2011 17:59:18 +0100
Subject: [PATCH] Added dynamic linking test.
---
readme.html | 1 +
tests/CMakeLists.txt | 71 ++++++++++++++++++++++++------------
tests/dynamic.c | 87 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 135 insertions(+), 24 deletions(-)
create mode 100644 tests/dynamic.c
diff --git a/readme.html b/readme.html
index 21f043a3..175e3b81 100644
--- a/readme.html
+++ b/readme.html
@@ -281,6 +281,7 @@ version of GLFW.
Added GLFW_INCLUDE_GL3 macro for telling the GLFW header to include gl3.h header instead of gl.h
Added windows simple multi-window test program
Added sharing simple OpenGL object sharing test program
+ Added dynamic simple dynamic linking test program
Added a parameter to glfwOpenWindow for specifying a context the new window's context will share objects with
Added initial window title parameter to glfwOpenWindow
Added glfwSetGamma, glfwSetGammaRamp and glfwGetGammaRamp functions and GLFWgammaramp type for monitor gamma ramp control
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index b85d79b4..81ba0dd6 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,35 +1,58 @@
-link_libraries(libglfwStatic ${GLFW_LIBRARIES} ${OPENGL_glu_LIBRARY})
+set(STATIC_DEPS libglfwStatic ${GLFW_LIBRARIES} ${OPENGL_glu_LIBRARY})
+set(SHARED_DEPS libglfwShared ${GLFW_LIBRARIES} ${OPENGL_glu_LIBRARY})
include_directories(${GLFW_SOURCE_DIR}/include
${GLFW_SOURCE_DIR}/support
${OPENGL_INCLUDE_DIR})
add_executable(defaults defaults.c)
-add_executable(events events.c)
-add_executable(fsaa fsaa.c getopt.c)
-add_executable(fsfocus fsfocus.c)
-add_executable(gamma gamma.c getopt.c)
-add_executable(glfwinfo glfwinfo.c getopt.c)
-add_executable(iconify iconify.c getopt.c)
-add_executable(joysticks joysticks.c)
-add_executable(listmodes listmodes.c)
-add_executable(peter peter.c)
-add_executable(reopen reopen.c)
+target_link_libraries(defaults ${STATIC_DEPS})
-if(APPLE)
- # Set fancy names for bundles
- add_executable(Accuracy MACOSX_BUNDLE accuracy.c)
- add_executable(Sharing MACOSX_BUNDLE sharing.c)
- add_executable(Tearing MACOSX_BUNDLE tearing.c)
- add_executable(Windows MACOSX_BUNDLE windows.c)
-else()
- # Set boring names for executables
- add_executable(accuracy WIN32 accuracy.c)
- add_executable(sharing WIN32 sharing.c)
- add_executable(tearing WIN32 tearing.c)
- add_executable(windows WIN32 windows.c)
-endif(APPLE)
+add_executable(dynamic dynamic.c)
+target_link_libraries(dynamic ${SHARED_DEPS})
+
+add_executable(events events.c)
+target_link_libraries(events ${STATIC_DEPS})
+
+add_executable(fsaa fsaa.c getopt.c)
+target_link_libraries(fsaa ${STATIC_DEPS})
+
+add_executable(fsfocus fsfocus.c)
+target_link_libraries(fsfocus ${STATIC_DEPS})
+
+add_executable(gamma gamma.c getopt.c)
+target_link_libraries(gamma ${STATIC_DEPS})
+
+add_executable(glfwinfo glfwinfo.c getopt.c)
+target_link_libraries(glfwinfo ${STATIC_DEPS})
+
+add_executable(iconify iconify.c getopt.c)
+target_link_libraries(iconify ${STATIC_DEPS})
+
+add_executable(joysticks joysticks.c)
+target_link_libraries(joysticks ${STATIC_DEPS})
+
+add_executable(listmodes listmodes.c)
+target_link_libraries(listmodes ${STATIC_DEPS})
+
+add_executable(peter peter.c)
+target_link_libraries(peter ${STATIC_DEPS})
+
+add_executable(reopen reopen.c)
+target_link_libraries(reopen ${STATIC_DEPS})
+
+add_executable(accuracy WIN32 MACOSX_BUNDLE accuracy.c)
+target_link_libraries(accuracy ${STATIC_DEPS})
+
+add_executable(sharing WIN32 MACOSX_BUNDLE sharing.c)
+target_link_libraries(sharing ${STATIC_DEPS})
+
+add_executable(tearing WIN32 MACOSX_BUNDLE tearing.c)
+target_link_libraries(tearing ${STATIC_DEPS})
+
+add_executable(windows WIN32 MACOSX_BUNDLE windows.c)
+target_link_libraries(windows ${STATIC_DEPS})
set(WINDOWS_BINARIES accuracy sharing tearing windows)
set(CONSOLE_BINARIES defaults events fsaa fsfocus gamma glfwinfo iconify
diff --git a/tests/dynamic.c b/tests/dynamic.c
new file mode 100644
index 00000000..0ad1c121
--- /dev/null
+++ b/tests/dynamic.c
@@ -0,0 +1,87 @@
+//========================================================================
+// Dynamic linking test
+// Copyright (c) Camilla Berglund
+//
+// This software is provided 'as-is', without any express or implied
+// warranty. In no event will the authors be held liable for any damages
+// arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it
+// freely, subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented; you must not
+// claim that you wrote the original software. If you use this software
+// in a product, an acknowledgment in the product documentation would
+// be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such, and must not
+// be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source
+// distribution.
+//
+//========================================================================
+//
+// This test came about as the result of bug #3060461
+//
+//========================================================================
+
+#define GLFW_DLL
+#include
+
+#include
+#include
+
+static void window_size_callback(GLFWwindow window, int width, int height)
+{
+ glViewport(0, 0, width, height);
+}
+
+int main(void)
+{
+ GLFWwindow window;
+ int major, minor, rev;
+ glfwGetVersion(&major, &minor, &rev);
+
+ if (major != GLFW_VERSION_MAJOR ||
+ minor != GLFW_VERSION_MINOR ||
+ rev != GLFW_VERSION_REVISION)
+ {
+ fprintf(stderr, "GLFW library version mismatch\n");
+ exit(EXIT_FAILURE);
+ }
+
+ printf("GLFW version: %i.%i.%i\n", major, minor, rev);
+ printf("GLFW version string: %s\n", glfwGetVersionString());
+
+ if (!glfwInit())
+ {
+ fprintf(stderr, "Failed to initialize GLFW\n");
+ exit(EXIT_FAILURE);
+ }
+
+ window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Dynamic Linking Test", NULL);
+ if (!window)
+ {
+ glfwTerminate();
+
+ fprintf(stderr, "Failed to open GLFW window\n");
+ exit(EXIT_FAILURE);
+ }
+
+ glfwSetWindowSizeCallback(window_size_callback);
+ glfwSwapInterval(1);
+
+ while (glfwIsWindow(window))
+ {
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ glfwSwapBuffers();
+ glfwPollEvents();
+ }
+
+ glfwTerminate();
+ exit(EXIT_SUCCESS);
+}
+