From ec2f42f01a95df0c524671ad7bf0ef1c55ecd63e Mon Sep 17 00:00:00 2001 From: Yaron Cohen-Tal Date: Thu, 27 Aug 2015 18:47:50 +0300 Subject: [PATCH] Add support for building static libs with CMake. Fix file permissions. Update documentation about building static libs and about using OpenGL ES / EGL. --- CMakeLists.txt | 17 ++++----- README.md | 81 +++++++++++++++++++++++++++++++++---------- compile | 0 config.guess | 0 config.sub | 0 depcomp | 0 install-sh | 0 missing | 0 src/CMakeLists.txt | 55 ++++++++++++++++++++--------- src/dispatch_common.h | 4 +-- test-driver | 0 11 files changed, 113 insertions(+), 44 deletions(-) mode change 100644 => 100755 compile mode change 100644 => 100755 config.guess mode change 100644 => 100755 config.sub mode change 100644 => 100755 depcomp mode change 100644 => 100755 install-sh mode change 100644 => 100755 missing mode change 100644 => 100755 test-driver diff --git a/CMakeLists.txt b/CMakeLists.txt index 302f166..9f2b43a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,12 +4,10 @@ if (NOT CMAKE_VERSION VERSION_LESS "3.1") cmake_policy (SET CMP0054 NEW) endif () project (Epoxy VERSION 1.3.1 LANGUAGES C) -set (EPOXY_ABI_VER 0) -if (ANDROID) - set (TARGET_NAME "epoxy_${EPOXY_ABI_VER}") -else () - set (TARGET_NAME "epoxy") -endif () +set (TARGET_NAME epoxy) +set (TARGET_VER 1.3.1_yaronct-4) +set (TARGET_ABI_VER 0) +set (TARGET_OUTPUT_NAME "${TARGET_NAME}") set (CMAKE_C_VISIBILITY_PRESET "hidden") @@ -25,9 +23,9 @@ if ((CMAKE_C_COMPILER_ID STREQUAL "GNU") OR (CMAKE_C_COMPILER_ID STREQUAL "Clang elseif (CMAKE_C_COMPILER_ID STREQUAL "MSVC") if (NOT CMAKE_C_FLAGS MATCHES "/W[0-4]") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4") - endif() + endif () endif () - + set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") find_package (X11) @@ -44,6 +42,9 @@ option (EPOXY_SUPPORT_EGL "Whether to build with EGL support" TRUE) cmake_dependent_option (EPOXY_SUPPORT_WGL "Whether to build with WGL support" ON WIN32 OFF) cmake_dependent_option (EPOXY_SUPPORT_GLX "Whether to build with GLX support" "${X11_FOUND}" "NOT (WIN32 OR ANDROID)" OFF) +option (EPOXY_BUILD_SHARED "Whether to build a shared library" TRUE) +option (EPOXY_BUILD_STATIC "Whether to build a static library" FALSE) + configure_file ("include/epoxy/config.h.in" "include/epoxy/config.h") add_subdirectory (src) diff --git a/README.md b/README.md index 8894cda..7632f3d 100644 --- a/README.md +++ b/README.md @@ -27,22 +27,34 @@ Features Building (CMake) ----------------- -CMake is now the recommended way to build epoxy. It should be as cample as: + +CMake is now the recommended way to build epoxy. It should be as simple as: cd cmake And then build the project, depending on the type of your toolset, e.g. for Unix -type "make", for MSVC open the solution in Visual studio and build the solution. +type "make", and for MSVC open the solution in Visual studio and build the +solution. -To rebuild the generated headers from the specs, add +* To rebuild the generated headers from the specs, add "-DEPOXY_REBUILD_FROM_SPECS=ON" to the "cmake" invocation. -Note that building with CMake currently doesn't support testing. +* To build also static libraries, add +"-DEPOXY_BUILD_STATIC=ON" to the "cmake" invocation. + +* To disable building shared libraries, add +"-DEPOXY_BUILD_SHARED=OFF" to the "cmake" invocation. + +Note that building with CMake currently doesn't support building or running +tests. Building (Autotools) --------------------- -On unix you can also use autotools to build: + +On Unix you can also use autotools to build. This type of build only supports +building shared libraries. However it also supports building and running tests. +To build with autotools, write: ./autogen.sh make @@ -51,14 +63,11 @@ On unix you can also use autotools to build: Dependencies for debian: -* automake * libegl1-mesa-dev * xutils-dev Dependencies for OS X (macports): -* automake -* autoconf * xorg-util-macros * pkgconfig @@ -67,17 +76,29 @@ The test suite has additional dependencies depending on the platform. Building (NMAKE) ----------------- -With MSVC you can also build directly with NMAKE: -1) Check src\Makefile.vc to ensure that PYTHONDIR is pointing to your Python installation, either a 32-bit or a 64-bit (x64) installation of Python 2 or 3 will do. +With MSVC you can also build directly with NMAKE. This type of build only +supports building shared libraries. However it also supports building +tests. + +1) Check src\Makefile.vc to ensure that PYTHONDIR is pointing to your Python + installation, either a 32-bit or a 64-bit (x64) installation of Python 2 or 3 + will do. 2) Copy "include\epoxy\config.h.guess" to "include\epoxy\config.h". -3) Open an MSVC Command prompt and run "nmake Makefile.vc CFG=release" or "nmake Makefile.vc CFG=debug" in src\ for a release or debug build. -4) Optionally, add src\ into your PATH and run the previous step in test\. Run the tests by running the built .exe's. -5) Assuming you want to install in %INSTALL_DIR%, copy common.h, config.h, khrplatform.h, eglplatform.h, gl.h, gl_generated.h, wgl.h, wgl_generated.h, egl.h and egl_generated.h from include\epoxy\ to %INSTALL_DIR%\include\epoxy\, copy src\epoxy.lib to %INSTALL_DIR%\lib\ and copy epoxy-vs12.dll and epoxy-vs12.pdb (if you've built a debug build) from src\ to %INSTALL_DIR%\bin\. Create directories as needed. +3) Open an MSVC Command prompt and run "nmake Makefile.vc CFG=release" or + "nmake Makefile.vc CFG=debug" in src\ for a release or debug build. +4) Optionally, add src\ into your PATH and run the previous step in test\. Run + the tests by running the built ".exe"-s. +5) Assuming you want to install in %INSTALL_DIR%, copy common.h, config.h, + khrplatform.h, eglplatform.h, gl.h, gl_generated.h, wgl.h, wgl_generated.h, + egl.h and egl_generated.h from include\epoxy\ to + %INSTALL_DIR%\include\epoxy\, copy src\epoxy.lib to %INSTALL_DIR%\lib\ and + copy epoxy-vs12.dll and epoxy-vs12.pdb (if you've built a debug build) from + src\ to %INSTALL_DIR%\bin\. Create directories as needed. 6) To clean the project, repeat steps 2 and 3, adding " clean" to the commands. -Switching your code to using epoxy ----------------------------------- +Switching your Code to Use Epoxy +--------------------------------- It should be as easy as replacing: @@ -111,7 +132,31 @@ available (```GL_ARB_texture_buffer_object```, for example). Note that this is not terribly fast, so keep it out of your hot paths, ok? -Why not use libGLEW? +Using OpenGL ES / EGL +---------------------- + +Building Epoxy with OpenGL ES / EGL support is now built-in. However, to +actually make use OpenGL ES and/or EGL on a computer, it's recommended (and in +some platforms necessary) to use an OpenGL ES / EGL emulator. I recommend using +[PowerVR SDK](http://community.imgtec.com/developers/powervr/graphics-sdk/), +which is available for Linux, OS X and Windows. Download it and run the +installer. In the installer, you don't have to check everything: Enough to check +"PowerVR Tools -> PVRVFrame" and "PowerVR SDK -> Native SDK". There's no need to +add anything from PowerVR SDK to the include directories to build or use Epoxy, +as it already includes all the necessary headers for using OpenGL ES / EGL. +There's also no need to link with anything from PowerVR SDK to build or use +Epoxy, as it loads the necessary libraries at run-time. However, when running +your app, if want to use EGL / OpenGL ES, you'll have to add the directory that +contains the right shared libraries ("GLES_CM", "GLESv2" and "EGL") to you +"PATH" environment variable. For instance, if you're on Windows, and used the +default locations when installing PowerVR SDK, then add +"C:\Imagination\PowerVR_Graphics\PowerVR_Tools\PVRVFrame\Library\Windows_x86_64" +to your "PATH" (for Windows 64 bit) or +"C:\Imagination\PowerVR_Graphics\PowerVR_Tools\PVRVFrame\Library\Windows_x86_32" +(for Windows 32 bit). For other platforms it would be something similar. Of +course, feel free to copy the shared libraries somewhere else. + +Why not use GLEW? -------------------- GLEW has several issues: @@ -138,8 +183,8 @@ meant replacing every single piece of GLEW, so we built piglit-dispatch from scratch. And since we wanted to reuse it in other GL-related projects, this is the result. -win32 issues ------------- +Windows issues +--------------- The automatic per-context symbol resolution for win32 requires that epoxy knows when ```wglMakeCurrent()``` is called, because diff --git a/compile b/compile old mode 100644 new mode 100755 diff --git a/config.guess b/config.guess old mode 100644 new mode 100755 diff --git a/config.sub b/config.sub old mode 100644 new mode 100755 diff --git a/depcomp b/depcomp old mode 100644 new mode 100755 diff --git a/install-sh b/install-sh old mode 100644 new mode 100755 diff --git a/missing b/missing old mode 100644 new mode 100755 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 34eb023..aac7ba9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -63,28 +63,51 @@ if (EPOXY_SUPPORT_WGL) "${CMAKE_CURRENT_BINARY_DIR}/../include/epoxy/wgl_generated.h") endif () -add_library ("${TARGET_NAME}" SHARED ${SOURCES} ${HEADERS}) +set (TARGET_OBJS_NAME "${TARGET_NAME}_objs") +add_library ("${TARGET_NAME}_objs" OBJECT ${SOURCES} ${HEADERS}) +set_target_properties ("${TARGET_NAME}_objs" PROPERTIES + POSITION_INDEPENDENT_CODE TRUE) +target_include_directories ("${TARGET_NAME}_objs" PUBLIC + "../include" + "${CMAKE_CURRENT_BINARY_DIR}/../include" + "${CMAKE_CURRENT_SOURCE_DIR}") if (CMAKE_C_COMPILER_ID STREQUAL "MSVC") - target_compile_definitions("${TARGET_NAME}" PUBLIC "inline=__inline") -endif() -set_target_properties("${TARGET_NAME}" PROPERTIES - DEFINE_SYMBOL EPOXY_EXPORTS) -if (NOT ANDROID) - set_target_properties("${TARGET_NAME}" PROPERTIES - VERSION "1.3.1_yaronct-2" - SOVERSION "${EPOXY_ABI_VER}") + target_compile_definitions ("${TARGET_NAME}_objs" PUBLIC "inline=__inline" EPOXY_EXPORTS) endif () - -target_include_directories ("${TARGET_NAME}" PUBLIC - "../include" - "${CMAKE_CURRENT_BINARY_DIR}/../include" - "${CMAKE_CURRENT_SOURCE_DIR}") +set (TARGETS_BUILT_NAMES "") +if (EPOXY_BUILD_SHARED) + list (APPEND TARGETS_BUILT_NAMES "${TARGET_NAME}_shared") + add_library ("${TARGET_NAME}_shared" SHARED $) + if (WIN32 OR ANDROID) + set_target_properties ("${TARGET_NAME}_shared" PROPERTIES + OUTPUT_NAME "${TARGET_OUTPUT_NAME}_${TARGET_ABI_VER}") + else () + set_target_properties ("${TARGET_NAME}_shared" PROPERTIES + OUTPUT_NAME "${TARGET_OUTPUT_NAME}") + endif () + if (NOT ANDROID) + set_target_properties("${TARGET_NAME}_shared" PROPERTIES + VERSION "${TARGET_VER}" + SOVERSION "${TARGET_ABI_VER}") + endif () +endif() +if (EPOXY_BUILD_STATIC) + list (APPEND TARGETS_BUILT_NAMES "${TARGET_NAME}_static") + add_library ("${TARGET_NAME}_static" STATIC $) + if (WIN32) + set_target_properties ("${TARGET_NAME}_static" PROPERTIES + OUTPUT_NAME "${TARGET_OUTPUT_NAME}_static_${TARGET_ABI_VER}") + else () + set_target_properties ("${TARGET_NAME}_static" PROPERTIES + OUTPUT_NAME "${TARGET_OUTPUT_NAME}_${TARGET_ABI_VER}") + endif () +endif() install (FILES ${HEADERS} DESTINATION "include/epoxy") -install (TARGETS "${TARGET_NAME}" +install (TARGETS ${TARGETS_BUILT_NAMES} RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) if (CMAKE_C_COMPILER_ID STREQUAL "MSVC") - INSTALL (FILES "${CMAKE_CURRENT_BINARY_DIR}/Debug/${TARGET_NAME}.pdb" + INSTALL (FILES "${CMAKE_CURRENT_BINARY_DIR}/Debug/${TARGET_OUTPUT_NAME}_${TARGET_ABI_VER}.pdb" DESTINATION lib CONFIGURATIONS Debug) endif () diff --git a/src/dispatch_common.h b/src/dispatch_common.h index 7ddbce1..262f34d 100644 --- a/src/dispatch_common.h +++ b/src/dispatch_common.h @@ -23,12 +23,12 @@ #include +#include "epoxy/gl.h" + #if EPOXY_SUPPORT_WGL #include "epoxy/wgl.h" #endif -#include "epoxy/gl.h" - #if EPOXY_SUPPORT_GLX #include "epoxy/glx.h" #endif diff --git a/test-driver b/test-driver old mode 100644 new mode 100755