Added standard option to switch between static and dynamic library, dropped dynamic test.

This commit is contained in:
Camilla Berglund 2012-03-25 13:53:53 +02:00
parent f21f196036
commit 7b46a184cb
6 changed files with 43 additions and 151 deletions

View File

@ -11,6 +11,7 @@ set(GLFW_VERSION_FULL "${GLFW_VERSION}.${GLFW_VERSION_PATCH}${GLFW_VERSION_EXTRA
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)
find_package(OpenGL REQUIRED)
@ -33,6 +34,10 @@ if (WIN32)
# Set up library and include paths
list(APPEND GLFW_INCLUDE_DIR ${OPENGL_INCLUDE_DIR})
list(APPEND GLFW_LIBRARIES ${OPENGL_gl_LIBRARY})
if (BUILD_SHARED_LIBS)
list(APPEND GLFW_LIBRARIES winmm)
endif()
endif()
#--------------------------------------------------------------------

View File

@ -1,7 +1,11 @@
# This line is used to link with static libraries
# Note that the library list should be updated to be obtained from
# the main CMakeLists.txt
link_libraries(libglfwStatic ${GLFW_LIBRARIES} ${OPENGL_glu_LIBRARY})
link_libraries(glfw ${OPENGL_glu_LIBRARY})
if (BUILD_SHARED_LIBS)
add_definitions(-DGLFW_DLL)
else()
link_libraries(${GLFW_LIBRARIES})
endif()
include_directories(${GLFW_SOURCE_DIR}/include
${GLFW_SOURCE_DIR}/support

View File

@ -279,7 +279,6 @@ version of GLFW.</p>
<li>Added <code>GLFW_INCLUDE_GL3</code> macro for telling the GLFW header to include <code>gl3.h</code> header instead of <code>gl.h</code></li>
<li>Added <code>windows</code> simple multi-window test program</li>
<li>Added <code>sharing</code> simple OpenGL object sharing test program</li>
<li>Added <code>dynamic</code> simple dynamic linking test program</li>
<li>Added <code>modes</code> video mode enumeration and setting test program</li>
<li>Added a parameter to <code>glfwOpenWindow</code> for specifying a context the new window's context will share objects with</li>
<li>Added initial window title parameter to <code>glfwOpenWindow</code></li>

View File

@ -39,17 +39,13 @@ else()
message(FATAL_ERROR "No supported platform was selected")
endif()
add_library(libglfwStatic STATIC ${libglfw_SOURCES})
add_library(libglfwShared SHARED ${libglfw_SOURCES})
target_link_libraries(libglfwShared ${GLFW_LIBRARIES})
set_target_properties(libglfwStatic libglfwShared PROPERTIES
CLEAN_DIRECT_OUTPUT 1
OUTPUT_NAME glfw)
add_library(glfw ${libglfw_SOURCES})
if (BUILD_SHARED_LIBS)
if (WIN32)
target_link_libraries(libglfwShared winmm)
# The GLFW DLL needs a special compile-time macro and import library name
set_target_properties(libglfwShared PROPERTIES
set_target_properties(glfw PROPERTIES
COMPILE_DEFINITIONS "GLFW_BUILD_DLL;_GLFW_NO_DLOAD_GDI32;_GLFW_NO_DLOAD_WINMM"
PREFIX ""
IMPORT_PREFIX ""
@ -58,12 +54,17 @@ endif()
if (APPLE)
# Append -fno-common to the compile flags to work around a bug in the Apple GCC
get_target_property(CFLAGS libglfwShared COMPILE_FLAGS)
get_target_property(CFLAGS glfw COMPILE_FLAGS)
if (NOT CFLAGS)
set(CFLAGS "")
endif()
set_target_properties(libglfwShared PROPERTIES COMPILE_FLAGS "${CFLAGS} -fno-common")
set_target_properties(glfw PROPERTIES COMPILE_FLAGS "${CFLAGS} -fno-common")
endif()
install(TARGETS libglfwStatic libglfwShared DESTINATION lib)
target_link_libraries(glfw ${GLFW_LIBRARIES})
target_link_libraries(glfw LINK_INTERFACE_LIBRARIES)
endif()
install(TARGETS glfw DESTINATION lib)

View File

@ -1,68 +1,42 @@
set(STATIC_DEPS libglfwStatic ${GLFW_LIBRARIES} ${OPENGL_glu_LIBRARY})
set(SHARED_DEPS libglfwShared ${GLFW_LIBRARIES} ${OPENGL_glu_LIBRARY})
link_libraries(glfw ${OPENGL_glu_LIBRARY})
if (BUILD_SHARED_LIBS)
add_definitions(-DGLFW_DLL)
else()
link_libraries(${GLFW_LIBRARIES})
endif()
include_directories(${GLFW_SOURCE_DIR}/include
${GLFW_SOURCE_DIR}/support
${OPENGL_INCLUDE_DIR})
add_executable(defaults defaults.c)
target_link_libraries(defaults ${STATIC_DEPS})
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(modes modes.c getopt.c)
target_link_libraries(modes ${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})
set_target_properties(accuracy PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Accuracy")
add_executable(sharing WIN32 MACOSX_BUNDLE sharing.c)
target_link_libraries(sharing ${STATIC_DEPS})
set_target_properties(sharing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Sharing")
add_executable(tearing WIN32 MACOSX_BUNDLE tearing.c)
target_link_libraries(tearing ${STATIC_DEPS})
set_target_properties(tearing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Tearing")
add_executable(title WIN32 MACOSX_BUNDLE title.c)
target_link_libraries(title ${STATIC_DEPS})
set_target_properties(title PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Title")
add_executable(windows WIN32 MACOSX_BUNDLE windows.c)
target_link_libraries(windows ${STATIC_DEPS})
set_target_properties(windows PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Windows")
set(WINDOWS_BINARIES accuracy sharing tearing title windows)

View File

@ -1,91 +0,0 @@
//========================================================================
// Dynamic linking test
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
//
// 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 <GL/glfw3.h>
#include <stdio.h>
#include <stdlib.h>
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);
printf("GLFW header version: %i.%i.%i\n",
GLFW_VERSION_MAJOR,
GLFW_VERSION_MINOR,
GLFW_VERSION_REVISION);
printf("GLFW library version: %i.%i.%i\n", major, minor, rev);
printf("GLFW library version string: %s\n", glfwGetVersionString());
if (major != GLFW_VERSION_MAJOR ||
minor != GLFW_VERSION_MINOR ||
rev != GLFW_VERSION_REVISION)
{
fprintf(stderr, "GLFW library version mismatch\n");
exit(EXIT_FAILURE);
}
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);
}