From 885a490cd2aeadbeb74dffd7810fdd84827d6d92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 1 Apr 2013 01:09:01 +0200 Subject: [PATCH 1/6] Updated FindCorrade.cmake from Corrade repository. --- modules/FindCorrade.cmake | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/FindCorrade.cmake b/modules/FindCorrade.cmake index 7dba9fc12..04b90ddd9 100644 --- a/modules/FindCorrade.cmake +++ b/modules/FindCorrade.cmake @@ -21,6 +21,7 @@ # Features of found Corrade library are exposed in these variables: # CORRADE_GCC46_COMPATIBILITY - Defined if compiled with compatibility # mode for GCC 4.6 +# CORRADE_BUILD_STATIC - Defined if compiled as static libraries # CORRADE_TARGET_NACL - Defined if compiled for Google Chrome # Native Client # CORRADE_TARGET_NACL_NEWLIB - Defined if compiled for Google Chrome @@ -155,6 +156,10 @@ string(FIND "${_corradeConfigure}" "#define CORRADE_GCC46_COMPATIBILITY" _GCC46_ if(NOT _GCC46_COMPATIBILITY EQUAL -1) set(CORRADE_GCC46_COMPATIBILITY 1) endif() +string(FIND "${_corradeConfigure}" "#define CORRADE_BUILD_STATIC" _BUILD_STATIC) +if(NOT _BUILD_STATIC EQUAL -1) + set(CORRADE_BUILD_STATIC 1) +endif() string(FIND "${_corradeConfigure}" "#define CORRADE_TARGET_NACL" _TARGET_NACL) if(NOT _TARGET_NACL EQUAL -1) set(CORRADE_TARGET_NACL 1) From 8c75f6e8c25106002729eabc5c733c3aa8d42d4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 1 Apr 2013 01:10:00 +0200 Subject: [PATCH 2/6] Expose MAGNUM_BUILD_STATIC in magnumConfigure.h. --- CMakeLists.txt | 4 ++++ doc/building.dox | 7 +++++-- doc/cmake.dox | 2 ++ modules/FindMagnum.cmake | 6 +++++- src/Magnum.h | 9 +++++++++ src/Platform/magnum-info.cpp | 6 ++++++ src/magnumConfigure.h.cmake | 1 + 7 files changed, 32 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index acef07eb3..9d6f55cd4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,6 +65,10 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/modules/") find_package(Corrade REQUIRED) +if(BUILD_STATIC) + set(MAGNUM_BUILD_STATIC 1) +endif() + # If targeting NaCl, set explicit OpenGL ES 2.0 support if(CORRADE_TARGET_NACL) set(TARGET_GLES 1) diff --git a/doc/building.dox b/doc/building.dox index 8eee27b50..621984b12 100644 --- a/doc/building.dox +++ b/doc/building.dox @@ -74,8 +74,11 @@ optional features. make make install -If you want to build with another compiler (e.g. Clang), pass -`-DCMAKE_CXX_COMPILER=clang++` to CMake. +The libraries are build as shared by default, pass `-DBUILD_STATIC=ON` to build +them as static. If you plan them to use with shared libraries later, enable +also position-independent code with `-DBUILD_STATIC_PIC=ON`. If you want to +build with another compiler (e.g. Clang), pass `-DCMAKE_CXX_COMPILER=clang++` +to CMake. @subsection building-optional Enabling or disabling features diff --git a/doc/cmake.dox b/doc/cmake.dox index 4cb3b1a86..ad07c3acd 100644 --- a/doc/cmake.dox +++ b/doc/cmake.dox @@ -95,6 +95,8 @@ convenience aliases `MAGNUM_APPLICATION_LIBRARIES` / Features of found %Magnum library are exposed in these CMake variables, they are also available as preprocessor variables if including Magnum.h: +- `MAGNUM_BUILD_STATIC` -- Defined if built as static libraries. Default are + shared libraries. - `MAGNUM_TARGET_GLES` -- Defined if compiled for OpenGL ES - `MAGNUM_TARGET_GLES2` -- Defined if compiled for OpenGL ES 2.0 - `MAGNUM_TARGET_GLES3` -- Defined if compiled for OpenGL ES 3.0 diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index 27ade163b..59367f8ff 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -45,6 +45,7 @@ # / MAGNUM_WINDOWLESSAPPLICATION_INCLUDE_DIRS to simplify porting. # # Features of found Magnum library are exposed in these variables: +# MAGNUM_BUILD_STATIC - Defined if compiled as static libraries # MAGNUM_TARGET_GLES - Defined if compiled for OpenGL ES # MAGNUM_TARGET_GLES2 - Defined if compiled for OpenGL ES 2.0 # MAGNUM_TARGET_GLES3 - Defined if compiled for OpenGL ES 3.0 @@ -111,7 +112,10 @@ find_path(MAGNUM_INCLUDE_DIR # Configuration file(READ ${MAGNUM_INCLUDE_DIR}/magnumConfigure.h _magnumConfigure) -# Built for specific target? +string(FIND "${_magnumConfigure}" "#define MAGNUM_BUILD_STATIC" _BUILD_STATIC) +if(NOT _BUILD_STATIC EQUAL -1) + set(MAGNUM_BUILD_STATIC 1) +endif() string(FIND "${_magnumConfigure}" "#define MAGNUM_TARGET_GLES" _TARGET_GLES) if(NOT _TARGET_GLES EQUAL -1) set(MAGNUM_TARGET_GLES 1) diff --git a/src/Magnum.h b/src/Magnum.h index 3540beea9..3be9bb7e0 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -69,6 +69,15 @@ using Corrade::Utility::Error; /** @todoc remove trailing underscores when Doxygen can handle `undef` */ +/** +@brief Static library build + +`MAGNUM_BUILD_STATIC` is defined if build as static libraries. Default are +shared libraries. +@see @ref building-corrade +*/ +#define MAGNUM_BUILD_STATIC_ + /** @brief OpenGL ES target diff --git a/src/Platform/magnum-info.cpp b/src/Platform/magnum-info.cpp index 9578c32dd..5dfa7bd7e 100644 --- a/src/Platform/magnum-info.cpp +++ b/src/Platform/magnum-info.cpp @@ -53,6 +53,12 @@ MagnumInfo::MagnumInfo(int& argc, char** argv): WindowlessGlxApplication(argc, a #ifdef CORRADE_GCC46_COMPATIBILITY d << "CORRADE_GCC46_COMPATIBILITY"; #endif + #ifdef CORRADE_BUILD_STATIC + d << "CORRADE_BUILD_STATIC"; + #endif + #ifdef MAGNUM_BUILD_STATIC + d << "MAGNUM_BUILD_STATIC"; + #endif #ifdef CORRADE_TARGET_NACL d << "CORRADE_TARGET_NACL"; #endif diff --git a/src/magnumConfigure.h.cmake b/src/magnumConfigure.h.cmake index db580c400..1cb5f49b5 100644 --- a/src/magnumConfigure.h.cmake +++ b/src/magnumConfigure.h.cmake @@ -22,6 +22,7 @@ DEALINGS IN THE SOFTWARE. */ +#cmakedefine MAGNUM_BUILD_STATIC #cmakedefine MAGNUM_TARGET_GLES #cmakedefine MAGNUM_TARGET_GLES2 #cmakedefine MAGNUM_TARGET_GLES3 From 0f27576855eb8b536239daf55c34f7a6ce5cf4bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 1 Apr 2013 01:10:44 +0200 Subject: [PATCH 3/6] FindMagnum.cmake: append MAGNUM_LIBRARIES also for static build. --- modules/FindMagnum.cmake | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index 59367f8ff..98626e802 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -142,11 +142,12 @@ if(NOT MAGNUM_TARGET_GLES) find_package(GLEW REQUIRED) endif() -# On Windows, *Application libraries need to have ${MAGNUM_LIBRARY} listed -# in dependencies also after *Application.lib static library name to avoid -# linker errors -if(WIN32) - set(_WINDOWCONTEXT_MAGNUM_LIBRARY_DEPENDENCY ${MAGNUM_LIBRARY}) +# On Windows and in static builds, *Application libraries need to have +# ${MAGNUM_LIBRARIES} listed in dependencies also after all other library names +# to avoid linker errors. Applicaiton libraries are often last thus it is +# +- sufficient to add it there only. +if(WIN32 OR MAGNUM_BUILD_STATIC) + set(_WINDOWCONTEXT_MAGNUM_LIBRARIES_DEPENDENCY ${MAGNUM_LIBRARIES}) endif() # Additional components @@ -167,7 +168,7 @@ foreach(component ${Magnum_FIND_COMPONENTS}) if(${component} STREQUAL GlutApplication) find_package(GLUT) if(GLUT_FOUND) - set(_MAGNUM_${_COMPONENT}_LIBRARIES ${GLUT_LIBRARIES} ${_WINDOWCONTEXT_MAGNUM_LIBRARY_DEPENDENCY}) + set(_MAGNUM_${_COMPONENT}_LIBRARIES ${GLUT_LIBRARIES} ${_WINDOWCONTEXT_MAGNUM_LIBRARIES_DEPENDENCY}) else() unset(MAGNUM_${_COMPONENT}_LIBRARY) endif() @@ -177,7 +178,7 @@ foreach(component ${Magnum_FIND_COMPONENTS}) if(${component} STREQUAL Sdl2Application) find_package(SDL2) if(SDL2_FOUND) - set(_MAGNUM_${_COMPONENT}_LIBRARIES ${SDL2_LIBRARY} ${_WINDOWCONTEXT_MAGNUM_LIBRARY_DEPENDENCY}) + set(_MAGNUM_${_COMPONENT}_LIBRARIES ${SDL2_LIBRARY} ${_WINDOWCONTEXT_MAGNUM_LIBRARIES_DEPENDENCY}) set(_MAGNUM_${_COMPONENT}_INCLUDE_DIRS ${SDL2_INCLUDE_DIR}) else() unset(MAGNUM_${_COMPONENT}_LIBRARY) @@ -190,7 +191,7 @@ foreach(component ${Magnum_FIND_COMPONENTS}) if(${component} STREQUAL GlxApplication) find_package(X11) if(X11_FOUND) - set(_MAGNUM_${_COMPONENT}_LIBRARIES ${X11_LIBRARIES} ${_WINDOWCONTEXT_MAGNUM_LIBRARY_DEPENDENCY}) + set(_MAGNUM_${_COMPONENT}_LIBRARIES ${X11_LIBRARIES} ${_WINDOWCONTEXT_MAGNUM_LIBRARIES_DEPENDENCY}) else() unset(MAGNUM_${_COMPONENT}_LIBRARY) endif() @@ -201,7 +202,7 @@ foreach(component ${Magnum_FIND_COMPONENTS}) find_package(EGL) find_package(X11) if(EGL_FOUND AND X11_FOUND) - set(_MAGNUM_${_COMPONENT}_LIBRARIES ${EGL_LIBRARY} ${X11_LIBRARIES} ${_WINDOWCONTEXT_MAGNUM_LIBRARY_DEPENDENCY}) + set(_MAGNUM_${_COMPONENT}_LIBRARIES ${EGL_LIBRARY} ${X11_LIBRARIES} ${_WINDOWCONTEXT_MAGNUM_LIBRARIES_DEPENDENCY}) else() unset(MAGNUM_${_COMPONENT}_LIBRARY) endif() @@ -211,7 +212,7 @@ foreach(component ${Magnum_FIND_COMPONENTS}) if(${component} STREQUAL WindowlessGlxApplication) find_package(X11) if(X11_FOUND) - set(_MAGNUM_${_COMPONENT}_LIBRARIES ${X11_LIBRARIES} ${_WINDOWCONTEXT_MAGNUM_LIBRARY_DEPENDENCY}) + set(_MAGNUM_${_COMPONENT}_LIBRARIES ${X11_LIBRARIES} ${_WINDOWCONTEXT_MAGNUM_LIBRARIES_DEPENDENCY}) else() unset(MAGNUM_${_COMPONENT}_LIBRARY) endif() From 6b753cfcb4dfe20810699a5aa1f7c4c789657402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 1 Apr 2013 01:11:29 +0200 Subject: [PATCH 4/6] FindMagnum.cmake: NaCl application has also dependencies. Although these are needed only with static build. --- modules/FindMagnum.cmake | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index 98626e802..3050a3ebc 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -185,7 +185,10 @@ foreach(component ${Magnum_FIND_COMPONENTS}) endif() endif() - # NaCl application has no additional dependencies + # NaCl application dependencies + if(${component} STREQUAL NaClApplication) + set(_MAGNUM_${_COMPONENT}_LIBRARIES ppapi_cpp ppapi ${_WINDOWCONTEXT_MAGNUM_LIBRARIES_DEPENDENCY}) + endif() # GLX application dependencies if(${component} STREQUAL GlxApplication) From 2f4bcd1455467795161fcc4cf13c3693fecae854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 1 Apr 2013 01:12:40 +0200 Subject: [PATCH 5/6] Added files for automatic resource importing from static libraries. Not documented yet, because I am ashamed of this way of doing things. With shared libraries the resources are imported automatically, with static ones the user must explicitly include these files in some non-static library or executable to have them imported. --- src/Shaders/CMakeLists.txt | 4 ++ src/Shaders/magnumShadersResourceImport.hpp | 37 +++++++++++++++++++ src/TextureTools/CMakeLists.txt | 4 ++ .../magnumTextureToolsResourceImport.hpp | 37 +++++++++++++++++++ 4 files changed, 82 insertions(+) create mode 100644 src/Shaders/magnumShadersResourceImport.hpp create mode 100644 src/TextureTools/magnumTextureToolsResourceImport.hpp diff --git a/src/Shaders/CMakeLists.txt b/src/Shaders/CMakeLists.txt index 6d2a92cf0..d5eff9498 100644 --- a/src/Shaders/CMakeLists.txt +++ b/src/Shaders/CMakeLists.txt @@ -49,6 +49,10 @@ set(MagnumShaders_HEADERS magnumShadersVisibility.h) +if(BUILD_STATIC) + set(MagnumShaders_HEADERS ${MagnumShaders_HEADERS} magnumShadersResourceImport.hpp) +endif() + add_library(MagnumShaders ${SHARED_OR_STATIC} ${MagnumShaders_SRCS}) if(BUILD_STATIC_PIC) # TODO: CMake 2.8.9 has this as POSITION_INDEPENDENT_CODE property diff --git a/src/Shaders/magnumShadersResourceImport.hpp b/src/Shaders/magnumShadersResourceImport.hpp new file mode 100644 index 000000000..624b956b1 --- /dev/null +++ b/src/Shaders/magnumShadersResourceImport.hpp @@ -0,0 +1,37 @@ +#ifndef Magnum_Shaders_magnumShadersResourceImport_hpp +#define Magnum_Shaders_magnumShadersResourceImport_hpp +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include "magnumConfigure.h" + +#ifdef MAGNUM_BUILD_STATIC +#include +static int magnumShadersResourceImport() { + RESOURCE_INITIALIZE(MagnumShaders_RCS) + return 0; +} AUTOMATIC_INITIALIZER(magnumShadersResourceImport) +#endif + +#endif diff --git a/src/TextureTools/CMakeLists.txt b/src/TextureTools/CMakeLists.txt index 01e7a6811..fdede4e15 100644 --- a/src/TextureTools/CMakeLists.txt +++ b/src/TextureTools/CMakeLists.txt @@ -37,6 +37,10 @@ set(MagnumTextureTools_HEADERS magnumTextureToolsVisibility.h) +if(BUILD_STATIC) + set(MagnumTextureTools_HEADERS ${MagnumTextureTools_HEADERS} magnumTextureToolsResourceImport.hpp) +endif() + add_library(MagnumTextureTools ${SHARED_OR_STATIC} ${MagnumTextureTools_SRCS}) if(BUILD_STATIC_PIC) # TODO: CMake 2.8.9 has this as POSITION_INDEPENDENT_CODE property diff --git a/src/TextureTools/magnumTextureToolsResourceImport.hpp b/src/TextureTools/magnumTextureToolsResourceImport.hpp new file mode 100644 index 000000000..d540e7536 --- /dev/null +++ b/src/TextureTools/magnumTextureToolsResourceImport.hpp @@ -0,0 +1,37 @@ +#ifndef Magnum_TextureTools_magnumTextureToolsResourceImport_hpp +#define Magnum_TextureTools_magnumTextureToolsResourceImport_hpp +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include "magnumConfigure.h" + +#ifdef MAGNUM_BUILD_STATIC +#include +static int magnumTextureToolsResourceImport() { + RESOURCE_INITIALIZE(MagnumTextureTools_RCS) + return 0; +} AUTOMATIC_INITIALIZER(magnumTextureToolsResourceImport) +#endif + +#endif From b555db02f902f4a49347120f50a26c3703090092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 1 Apr 2013 01:16:07 +0200 Subject: [PATCH 6/6] Updated toolchains submodule. --- toolchains | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toolchains b/toolchains index f84b61f69..4f69504e4 160000 --- a/toolchains +++ b/toolchains @@ -1 +1 @@ -Subproject commit f84b61f694295b70b5e3492161709b77342e597b +Subproject commit 4f69504e4df9b3a1a328ba344ff1857199046e9c