diff --git a/CMakeLists.txt b/CMakeLists.txt index 5bc282c11..a998f733f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,5 @@ -cmake_minimum_required(VERSION 2.6) +# CMake 2.8.8 required for OBJECT library target +cmake_minimum_required(VERSION 2.8.8) project(Magnum) option(BUILD_TESTS "Build unit tests (requires Qt4)." OFF) diff --git a/README.md b/README.md index 028d58445..e8e51707a 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Minimal dependencies * C++ compiler with good C++11 support. Currently the only compilers which support everything needed are **GCC** >= 4.6 and **Clang** >= 3.1 (from SVN). - * **CMake** >= 2.6 + * **CMake** >= 2.8.8 (needed for `OBJECT` library target) * **OpenGL headers**, on Linux most probably shipped with Mesa * **GLEW** - OpenGL extension wrangler * **Corrade** - Plugin management and utility library. You can get it at diff --git a/doc/Building.dox b/doc/Building.dox index 9a90e1f29..e43906db0 100644 --- a/doc/Building.dox +++ b/doc/Building.dox @@ -12,7 +12,7 @@ Minimal set of tools and libraries required for building is: - C++ compiler with good C++11 support. Currently the only compilers which support everything needed are **GCC** >= 4.6 and **Clang** >= 3.1 (from SVN). -- **CMake** >= 2.6 +- **CMake** >= 2.8.8 (needed for `OBJECT` library target) - **OpenGL** headers, on Linux most probably shipped with Mesa - **GLEW** - OpenGL extension wrangler - **Corrade** - Plugin management and utility library. You can get it at diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 587bd8a3d..be26f0de8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,14 +2,15 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -std=c++0x -fvisibility= include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CORRADE_INCLUDE_DIR}) -add_subdirectory(Math) -add_subdirectory(MeshTools) -add_subdirectory(Physics) -add_subdirectory(Primitives) -add_subdirectory(Shaders) +# On 64bit Linux with GCC flag -fPIC is needed for building some static libraries +if(CMAKE_SIZEOF_VOID_P EQUAL 8 AND CMAKE_COMPILER_IS_GNUCC AND CMAKE_SYSTEM_NAME STREQUAL "Linux") + set(USE_FPIC ON) +else() + set(USE_FPIC OFF) +endif() +# Files shared between main library and unit test library set(Magnum_SRCS - Object.cpp AbstractImage.cpp AbstractTexture.cpp AbstractShaderProgram.cpp @@ -27,21 +28,48 @@ set(Magnum_SRCS Trade/AbstractImporter.cpp Trade/MeshData.cpp +) +add_library(MagnumObjects OBJECT ${Magnum_SRCS}) +# Files shared between main library and math unit test library +set(MagnumMath_SRCS Math/Math.cpp ) +add_library(MagnumMathObjects OBJECT ${MagnumMath_SRCS}) -add_library(Magnum SHARED ${Magnum_SRCS}) +if(USE_FPIC) + set_target_properties(MagnumObjects PROPERTIES COMPILE_FLAGS -fPIC) + set_target_properties(MagnumMathObjects PROPERTIES COMPILE_FLAGS -fPIC) +endif() -target_link_libraries(Magnum ${CORRADE_UTILITY_LIBRARY} ${CORRADE_PLUGINMANAGER_LIBRARY} ${OPENGL_gl_LIBRARY} ${GLEW_LIBRARY}) +# Files compiled with different flags for main library and unit test library +set(Magnum_GracefulAssert_SRCS + Object.cpp +) +# Main library +add_library(Magnum SHARED + $ + $ + ${Magnum_GracefulAssert_SRCS} +) +target_link_libraries(Magnum ${CORRADE_UTILITY_LIBRARY} ${CORRADE_PLUGINMANAGER_LIBRARY} ${OPENGL_gl_LIBRARY} ${GLEW_LIBRARY}) install(TARGETS Magnum DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) +add_subdirectory(Math) +add_subdirectory(MeshTools) +add_subdirectory(Physics) +add_subdirectory(Primitives) +add_subdirectory(Shaders) + if(BUILD_TESTS) enable_testing() # Library with graceful assert for testing - add_library(MagnumTestLib SHARED ${Magnum_SRCS}) + add_library(MagnumTestLib SHARED + $ + ${Magnum_GracefulAssert_SRCS} + ) set_target_properties(MagnumTestLib PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) target_link_libraries(MagnumTestLib ${CORRADE_UTILITY_LIBRARY} ${CORRADE_PLUGINMANAGER_LIBRARY} ${OPENGL_gl_LIBRARY} ${GLEW_LIBRARY}) diff --git a/src/Math/CMakeLists.txt b/src/Math/CMakeLists.txt index 58350ed6e..efb6838e2 100644 --- a/src/Math/CMakeLists.txt +++ b/src/Math/CMakeLists.txt @@ -3,12 +3,6 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}) add_subdirectory(Geometry) if(BUILD_TESTS) - - # Add Math library for testing purposes - add_library(MagnumMath STATIC - Math.cpp - ) - enable_testing() add_subdirectory(Test) endif() diff --git a/src/Math/Geometry/CMakeLists.txt b/src/Math/Geometry/CMakeLists.txt index 7242acb5b..6879e1b55 100644 --- a/src/Math/Geometry/CMakeLists.txt +++ b/src/Math/Geometry/CMakeLists.txt @@ -4,4 +4,3 @@ if(BUILD_TESTS) enable_testing() add_subdirectory(Test) endif() - diff --git a/src/Math/Test/CMakeLists.txt b/src/Math/Test/CMakeLists.txt index 05f843a62..e51e74fde 100644 --- a/src/Math/Test/CMakeLists.txt +++ b/src/Math/Test/CMakeLists.txt @@ -9,4 +9,6 @@ corrade_add_test(MathMatrixTest MatrixTest.h MatrixTest.cpp ${CORRADE_UTILITY_LI corrade_add_test(MathMatrix3Test Matrix3Test.h Matrix3Test.cpp ${CORRADE_UTILITY_LIBRARY}) corrade_add_test(MathMatrix4Test Matrix4Test.h Matrix4Test.cpp ${CORRADE_UTILITY_LIBRARY}) -corrade_add_test(MathTest MathTest.h MathTest.cpp MagnumMath) +set(MathTest_MOC MathTest.h) +set(MathTest_SRCS MathTest.cpp $) +corrade_add_multifile_test(MathTest MathTest_MOC MathTest_SRCS) diff --git a/src/MeshTools/CMakeLists.txt b/src/MeshTools/CMakeLists.txt index a8e99d968..3433698cb 100644 --- a/src/MeshTools/CMakeLists.txt +++ b/src/MeshTools/CMakeLists.txt @@ -1,11 +1,23 @@ +# Files shared between main library and unit test library set(MagnumMeshTools_SRCS - FlipNormals.cpp - GenerateFlatNormals.cpp Tipsify.cpp ) +add_library(MagnumMeshToolsObjects OBJECT ${MagnumMeshTools_SRCS}) +if(USE_FPIC) + set_target_properties(MagnumMeshToolsObjects PROPERTIES COMPILE_FLAGS -fPIC) +endif() -add_library(MagnumMeshTools SHARED ${MagnumMeshTools_SRCS}) +# Files compiled with different flags for main library and unit test library +set(MagnumMeshTools_GracefulAssert_SRCS + FlipNormals.cpp + GenerateFlatNormals.cpp +) +# Main library +add_library(MagnumMeshTools SHARED + $ + ${MagnumMeshTools_GracefulAssert_SRCS} +) target_link_libraries(MagnumMeshTools Magnum) install(TARGETS MagnumMeshTools DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) @@ -14,7 +26,10 @@ if(BUILD_TESTS) enable_testing() # Library with graceful assert for testing - add_library(MagnumMeshToolsTestLib SHARED ${MagnumMeshTools_SRCS}) + add_library(MagnumMeshToolsTestLib SHARED + $ + ${MagnumMeshTools_GracefulAssert_SRCS} + ) set_target_properties(MagnumMeshToolsTestLib PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) target_link_libraries(MagnumMeshToolsTestLib ${MAGNUM_LIBRARY})