diff --git a/doc/building.dox b/doc/building.dox index 2173ab1de..56c24d996 100644 --- a/doc/building.dox +++ b/doc/building.dox @@ -134,6 +134,12 @@ plan to use them with shared libraries later, enable also position-independent code with `BUILD_STATIC_PIC`. If you want to build with another compiler (e.g. Clang), pass `-DCMAKE_CXX_COMPILER=clang++` to CMake. +Libraries built in `Debug` configuration (e.g. with `CMAKE_BUILD_TYPE` set to +`Debug`) have `-d` suffix to make it possible to have both debug and release +libraries installed alongside each other. Headers and other files are the same +for both. The library distinction is handled automatically when using %Magnum +in depending projects, see @ref cmake for more information. + %Magnum by default does not install `FindMagnum.cmake`, as you should bundle the module with your code instead of depending on it being in system location. You can install it by enabling `WITH_FIND_MODULE`. diff --git a/doc/cmake.dox b/doc/cmake.dox index d106817c5..81ea3723d 100644 --- a/doc/cmake.dox +++ b/doc/cmake.dox @@ -132,6 +132,11 @@ convenience aliases `MAGNUM_APPLICATION_LIBRARIES` / `MAGNUM_WINDOWLESSAPPLICATION_LIBRARIES` and `MAGNUM_APPLICATION_INCLUDE_DIRS` / `MAGNUM_WINDOWLESSAPPLICATION_INCLUDE_DIRS` to simplify porting. +The package is found if either debug or release version of each requested +library is found. If both debug and release libraries are found, proper version +is chosen based on actual build configuration of the project (i.e. `Debug` +build is linked to debug libraries, `Release` build to release libraries). + Features of found %Magnum library are exposed in these CMake variables, they are also available as preprocessor variables if including Magnum.h: diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index f4c822644..89bb4ed94 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -59,6 +59,12 @@ # MAGNUM_WINDOWLESSAPPLICATION_LIBRARIES and MAGNUM_APPLICATION_INCLUDE_DIRS # / MAGNUM_WINDOWLESSAPPLICATION_INCLUDE_DIRS to simplify porting. # +# The package is found if either debug or release version of each requested +# library is found. If both debug and release libraries are found, proper +# version is chosen based on actual build configuration of the project (i.e. +# Debug build is linked to debug libraries, Release build to release +# libraries). +# # Features of found Magnum library are exposed in these variables: # MAGNUM_BUILD_DEPRECATED - Defined if compiled with deprecated APIs # included @@ -75,13 +81,14 @@ # plugins (i.e. instead of `MagnumPlugins/` prefix). # # Additionally these variables are defined for internal usage: -# MAGNUM_INCLUDE_DIR - Root include dir (w/o -# dependencies) -# MAGNUM_LIBRARY - Magnum library (w/o -# dependencies) -# MAGNUM_*_LIBRARY - Component libraries (w/o -# dependencies) -# MAGNUM_LIBRARY_INSTALL_DIR - Library installation directory +# MAGNUM_INCLUDE_DIR - Root include dir (w/o dependencies) +# MAGNUM_LIBRARY - Magnum library (w/o dependencies) +# MAGNUM_LIBRARY_DEBUG - Debug version of Magnum library, if found +# MAGNUM_LIBRARY_RELEASE - Release version of Magnum library, if found +# MAGNUM_*_LIBRARY - Component libraries (w/o dependencies) +# MAGNUM_*_LIBRARY_DEBUG - Debug version of given library, if found +# MAGNUM_*_LIBRARY_RELEASE - Release version of given library, if found +# MAGNUM_LIBRARY_INSTALL_DIR - Library installation directory # MAGNUM_PLUGINS_INSTALL_DIR - Plugin installation directory # MAGNUM_PLUGINS_FONT_INSTALL_DIR - Font plugin installation # directory @@ -93,11 +100,10 @@ # directory # MAGNUM_PLUGINS_AUDIOIMPORTER_INSTALL_DIR - Audio omporter plugin # installation directory -# MAGNUM_CMAKE_FIND_MODULE_INSTALL_DIR - Installation dir for CMake -# Find* modules -# MAGNUM_INCLUDE_INSTALL_DIR - Header installation directory -# MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR - Plugin header installation -# directory +# MAGNUM_CMAKE_FIND_MODULE_INSTALL_DIR - Installation dir for CMake Find* +# modules +# MAGNUM_INCLUDE_INSTALL_DIR - Header installation directory +# MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR - Plugin header installation directory # # @@ -128,8 +134,23 @@ # Dependencies find_package(Corrade REQUIRED) -# Magnum library -find_library(MAGNUM_LIBRARY Magnum) +# Base Magnum library +find_library(MAGNUM_LIBRARY_DEBUG Magnum-d) +find_library(MAGNUM_LIBRARY_RELEASE Magnum) + +# Set the MAGNUM_LIBRARY variable based on what was found +if(MAGNUM_LIBRARY_DEBUG AND MAGNUM_LIBRARY_RELEASE) + set(MAGNUM_LIBRARY + debug ${MAGNUM_LIBRARY_DEBUG} + optimized ${MAGNUM_LIBRARY_RELEASE}) + get_filename_component(_MAGNUM_LIBRARY_PATH ${MAGNUM_LIBRARY_DEBUG} PATH) +elseif(MAGNUM_LIBRARY_DEBUG) + set(MAGNUM_LIBRARY ${MAGNUM_LIBRARY_DEBUG}) + get_filename_component(_MAGNUM_LIBRARY_PATH ${MAGNUM_LIBRARY_DEBUG} PATH) +elseif(MAGNUM_LIBRARY_RELEASE) + set(MAGNUM_LIBRARY ${MAGNUM_LIBRARY_RELEASE}) + get_filename_component(_MAGNUM_LIBRARY_PATH ${MAGNUM_LIBRARY_RELEASE} PATH) +endif() # Root include dir find_path(MAGNUM_INCLUDE_DIR @@ -247,7 +268,20 @@ foreach(component ${Magnum_FIND_COMPONENTS}) set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX Magnum/${component}) set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES ${component}.h) - find_library(MAGNUM_${_COMPONENT}_LIBRARY Magnum${component}) + # Try to find both debug and release version + find_library(MAGNUM_${_COMPONENT}_LIBRARY_DEBUG Magnum${component}-d) + find_library(MAGNUM_${_COMPONENT}_LIBRARY_RELEASE Magnum${component}) + + # Set the _LIBRARY variable based on what was found + if(MAGNUM_${_COMPONENT}_LIBRARY_DEBUG AND MAGNUM_${_COMPONENT}_LIBRARY_RELEASE) + set(MAGNUM_${_COMPONENT}_LIBRARY + debug ${MAGNUM_${_COMPONENT}_LIBRARY_DEBUG} + optimized ${MAGNUM_${_COMPONENT}_LIBRARY_RELEASE}) + elseif(MAGNUM_${_COMPONENT}_LIBRARY_DEBUG) + set(MAGNUM_${_COMPONENT}_LIBRARY ${MAGNUM_${_COMPONENT}_LIBRARY_DEBUG}) + elseif(MAGNUM_${_COMPONENT}_LIBRARY_RELEASE) + set(MAGNUM_${_COMPONENT}_LIBRARY ${MAGNUM_${_COMPONENT}_LIBRARY_RELEASE}) + endif() endif() # Applications @@ -353,7 +387,11 @@ foreach(component ${Magnum_FIND_COMPONENTS}) set(Magnum_${component}_FOUND TRUE) # Don't expose variables w/o dependencies to end users - mark_as_advanced(FORCE MAGNUM_${_COMPONENT}_LIBRARY _MAGNUM_${_COMPONENT}_INCLUDE_DIR) + mark_as_advanced(FORCE + MAGNUM_${_COMPONENT}_LIBRARY_DEBUG + MAGNUM_${_COMPONENT}_LIBRARY_RELEASE + MAGNUM_${_COMPONENT}_LIBRARY + _MAGNUM_${_COMPONENT}_INCLUDE_DIR) # Global aliases for Windowless*Application and *Application components. # If already set, unset them to avoid ambiguity. @@ -397,6 +435,8 @@ set(MAGNUM_CMAKE_FIND_MODULE_INSTALL_DIR ${CMAKE_ROOT}/Modules) set(MAGNUM_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include/Magnum) set(MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include/MagnumPlugins) mark_as_advanced(FORCE + MAGNUM_LIBRARY_DEBUG + MAGNUM_LIBRARY_RELEASE MAGNUM_LIBRARY MAGNUM_INCLUDE_DIR MAGNUM_LIBRARY_INSTALL_DIR @@ -420,7 +460,6 @@ if(MAGNUM_BUILD_DEPRECATED) endif() # Get base plugin directory from main library location -get_filename_component(_MAGNUM_LIBRARY_PATH ${MAGNUM_LIBRARY} PATH) set(MAGNUM_PLUGINS_DIR ${_MAGNUM_LIBRARY_PATH}/magnum CACHE PATH "Base directory where to look for Magnum plugins") diff --git a/src/Magnum/Audio/CMakeLists.txt b/src/Magnum/Audio/CMakeLists.txt index f4f13603e..f5b35054d 100644 --- a/src/Magnum/Audio/CMakeLists.txt +++ b/src/Magnum/Audio/CMakeLists.txt @@ -46,6 +46,7 @@ set(MagnumAudio_HEADERS visibility.h) add_library(MagnumAudio ${SHARED_OR_STATIC} ${MagnumAudio_SOURCES}) +set_target_properties(MagnumAudio PROPERTIES DEBUG_POSTFIX "-d") target_link_libraries(MagnumAudio ${CORRADE_PLUGINMANAGER_LIBRARIES} ${OPENAL_LIBRARY}) install(TARGETS MagnumAudio diff --git a/src/Magnum/CMakeLists.txt b/src/Magnum/CMakeLists.txt index 72503b047..5ff0d2030 100644 --- a/src/Magnum/CMakeLists.txt +++ b/src/Magnum/CMakeLists.txt @@ -160,6 +160,7 @@ add_library(MagnumMathObjects OBJECT ${MagnumMath_SRCS}) add_library(Magnum ${SHARED_OR_STATIC} ${Magnum_SRCS} $) +set_target_properties(Magnum PROPERTIES DEBUG_POSTFIX "-d") # TODO: fix when CMake sets target_EXPORTS for OBJECT targets as well if(NOT BUILD_STATIC OR BUILD_STATIC_PIC) @@ -235,7 +236,9 @@ if(BUILD_TESTS) # Libraries with graceful assert for testing add_library(MagnumMathTestLib ${SHARED_OR_STATIC} $) - set_target_properties(MagnumMathTestLib PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) + set_target_properties(MagnumMathTestLib PROPERTIES + COMPILE_FLAGS "-DCORRADE_GRACEFUL_ASSERT" + DEBUG_POSTFIX "-d") target_link_libraries(MagnumMathTestLib ${CORRADE_UTILITY_LIBRARY}) # On Windows we need to install first and then run the tests to avoid "DLL diff --git a/src/Magnum/DebugTools/CMakeLists.txt b/src/Magnum/DebugTools/CMakeLists.txt index 619c34fb1..4455b248e 100644 --- a/src/Magnum/DebugTools/CMakeLists.txt +++ b/src/Magnum/DebugTools/CMakeLists.txt @@ -51,6 +51,7 @@ set(MagnumDebugTools_HEADERS visibility.h) add_library(MagnumDebugTools ${SHARED_OR_STATIC} ${MagnumDebugTools_SRCS}) +set_target_properties(MagnumDebugTools PROPERTIES DEBUG_POSTFIX "-d") if(BUILD_STATIC_PIC) # TODO: CMake 2.8.9 has this as POSITION_INDEPENDENT_CODE property set_target_properties(MagnumDebugTools PROPERTIES COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}") diff --git a/src/Magnum/MeshTools/CMakeLists.txt b/src/Magnum/MeshTools/CMakeLists.txt index fb2b324ca..67f9a9a82 100644 --- a/src/Magnum/MeshTools/CMakeLists.txt +++ b/src/Magnum/MeshTools/CMakeLists.txt @@ -66,6 +66,7 @@ endif() add_library(MagnumMeshTools ${SHARED_OR_STATIC} $ ${MagnumMeshTools_GracefulAssert_SRCS}) +set_target_properties(MagnumMeshTools PROPERTIES DEBUG_POSTFIX "-d") if(BUILD_STATIC_PIC) # TODO: CMake 2.8.9 has this as POSITION_INDEPENDENT_CODE property set_target_properties(MagnumMeshTools PROPERTIES COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}") @@ -83,7 +84,9 @@ if(BUILD_TESTS) add_library(MagnumMeshToolsTestLib ${SHARED_OR_STATIC} $ ${MagnumMeshTools_GracefulAssert_SRCS}) - set_target_properties(MagnumMeshToolsTestLib PROPERTIES COMPILE_FLAGS "-DCORRADE_GRACEFUL_ASSERT -DMagnumMeshTools_EXPORTS") + set_target_properties(MagnumMeshToolsTestLib PROPERTIES + COMPILE_FLAGS "-DCORRADE_GRACEFUL_ASSERT -DMagnumMeshTools_EXPORTS" + DEBUG_POSTFIX "-d") target_link_libraries(MagnumMeshToolsTestLib Magnum) # On Windows we need to install first and then run the tests to avoid "DLL diff --git a/src/Magnum/Platform/CMakeLists.txt b/src/Magnum/Platform/CMakeLists.txt index 320cafdc1..e3a70508e 100644 --- a/src/Magnum/Platform/CMakeLists.txt +++ b/src/Magnum/Platform/CMakeLists.txt @@ -44,6 +44,7 @@ if(WITH_ANDROIDAPPLICATION) AndroidApplication.cpp Implementation/Egl.cpp ${ANDROID_NATIVE_APP_GLUE_SRC}) + set_target_properties(MagnumAndroidApplication PROPERTIES DEBUG_POSTFIX "-d") install(FILES AndroidApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(TARGETS MagnumAndroidApplication RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} @@ -56,6 +57,7 @@ if(WITH_GLUTAPPLICATION) find_package(GLUT) if(GLUT_FOUND) add_library(MagnumGlutApplication STATIC GlutApplication.cpp) + set_target_properties(MagnumGlutApplication PROPERTIES DEBUG_POSTFIX "-d") install(FILES GlutApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(TARGETS MagnumGlutApplication RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} @@ -72,6 +74,7 @@ if(WITH_SDL2APPLICATION) if(SDL2_FOUND) include_directories(${SDL2_INCLUDE_DIR}) add_library(MagnumSdl2Application STATIC Sdl2Application.cpp) + set_target_properties(MagnumSdl2Application PROPERTIES DEBUG_POSTFIX "-d") install(FILES Sdl2Application.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(TARGETS MagnumSdl2Application RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} @@ -89,6 +92,7 @@ if(WITH_NACLAPPLICATION) endif() add_library(MagnumNaClApplication STATIC NaClApplication.cpp) + set_target_properties(MagnumNaClApplication PROPERTIES DEBUG_POSTFIX "-d") install(FILES NaClApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(TARGETS MagnumNaClApplication RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} @@ -103,6 +107,7 @@ if(WITH_WINDOWLESSNACLAPPLICATION) endif() add_library(MagnumWindowlessNaClApplication STATIC WindowlessNaClApplication.cpp) + set_target_properties(MagnumWindowlessNaClApplication PROPERTIES DEBUG_POSTFIX "-d") install(FILES WindowlessNaClApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(TARGETS MagnumWindowlessNaClApplication RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} @@ -128,6 +133,7 @@ if(WITH_GLXAPPLICATION) $ $ GlxApplication.cpp) + set_target_properties(MagnumGlxApplication PROPERTIES DEBUG_POSTFIX "-d") install(FILES GlxApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(TARGETS MagnumGlxApplication RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} @@ -143,6 +149,7 @@ if(WITH_XEGLAPPLICATION) $ $ XEglApplication.cpp) + set_target_properties(MagnumXEglApplication PROPERTIES DEBUG_POSTFIX "-d") install(FILES XEglApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(TARGETS MagnumXEglApplication RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} @@ -161,7 +168,9 @@ endif() if(WITH_WINDOWLESSGLXAPPLICATION) add_library(MagnumWindowlessGlxApplication STATIC WindowlessGlxApplication.cpp) # X11 macros are a mess, disable warnings for C-style casts - set_target_properties(MagnumWindowlessGlxApplication PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast") + set_target_properties(MagnumWindowlessGlxApplication PROPERTIES + COMPILE_FLAGS "-Wno-old-style-cast" + DEBUG_POSTFIX "-d") install(FILES WindowlessGlxApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(TARGETS MagnumWindowlessGlxApplication RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} diff --git a/src/Magnum/Primitives/CMakeLists.txt b/src/Magnum/Primitives/CMakeLists.txt index b791282eb..6f2119939 100644 --- a/src/Magnum/Primitives/CMakeLists.txt +++ b/src/Magnum/Primitives/CMakeLists.txt @@ -53,6 +53,7 @@ set(MagnumPrimitives_HEADERS visibility.h) add_library(MagnumPrimitives ${SHARED_OR_STATIC} ${MagnumPrimitives_SRCS}) +set_target_properties(MagnumPrimitives PROPERTIES DEBUG_POSTFIX "-d") if(BUILD_STATIC_PIC) # TODO: CMake 2.8.9 has this as POSITION_INDEPENDENT_CODE property set_target_properties(MagnumPrimitives PROPERTIES COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}") diff --git a/src/Magnum/SceneGraph/CMakeLists.txt b/src/Magnum/SceneGraph/CMakeLists.txt index 4eaf4e304..4b4c42b4b 100644 --- a/src/Magnum/SceneGraph/CMakeLists.txt +++ b/src/Magnum/SceneGraph/CMakeLists.txt @@ -83,6 +83,7 @@ endif() add_library(MagnumSceneGraph ${SHARED_OR_STATIC} $ ${MagnumSceneGraph_GracefulAssert_SRCS}) +set_target_properties(MagnumSceneGraph PROPERTIES DEBUG_POSTFIX "-d") target_link_libraries(MagnumSceneGraph Magnum) install(TARGETS MagnumSceneGraph @@ -96,7 +97,9 @@ if(BUILD_TESTS) add_library(MagnumSceneGraphTestLib ${SHARED_OR_STATIC} $ ${MagnumSceneGraph_GracefulAssert_SRCS}) - set_target_properties(MagnumSceneGraphTestLib PROPERTIES COMPILE_FLAGS "-DCORRADE_GRACEFUL_ASSERT -DMagnumSceneGraph_EXPORTS") + set_target_properties(MagnumSceneGraphTestLib PROPERTIES + COMPILE_FLAGS "-DCORRADE_GRACEFUL_ASSERT -DMagnumSceneGraph_EXPORTS" + DEBUG_POSTFIX "-d") target_link_libraries(MagnumSceneGraphTestLib MagnumMathTestLib) # On Windows we need to install first and then run the tests to avoid "DLL diff --git a/src/Magnum/Shaders/CMakeLists.txt b/src/Magnum/Shaders/CMakeLists.txt index 8b2e16a16..6ffa51558 100644 --- a/src/Magnum/Shaders/CMakeLists.txt +++ b/src/Magnum/Shaders/CMakeLists.txt @@ -60,6 +60,7 @@ if(BUILD_STATIC) endif() add_library(MagnumShaders ${SHARED_OR_STATIC} ${MagnumShaders_SRCS}) +set_target_properties(MagnumShaders PROPERTIES DEBUG_POSTFIX "-d") if(BUILD_STATIC_PIC) # TODO: CMake 2.8.9 has this as POSITION_INDEPENDENT_CODE property set_target_properties(MagnumShaders PROPERTIES COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}") diff --git a/src/Magnum/Shapes/CMakeLists.txt b/src/Magnum/Shapes/CMakeLists.txt index 812b209f8..4c8669773 100644 --- a/src/Magnum/Shapes/CMakeLists.txt +++ b/src/Magnum/Shapes/CMakeLists.txt @@ -62,6 +62,7 @@ set(MagnumShapes_HEADERS visibility.h) add_library(MagnumShapes ${SHARED_OR_STATIC} ${MagnumShapes_SRCS}) +set_target_properties(MagnumShapes PROPERTIES DEBUG_POSTFIX "-d") if(BUILD_STATIC_PIC) # TODO: CMake 2.8.9 has this as POSITION_INDEPENDENT_CODE property set_target_properties(MagnumShapes PROPERTIES COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}") diff --git a/src/Magnum/Text/CMakeLists.txt b/src/Magnum/Text/CMakeLists.txt index 7206c9002..c742bd3f8 100644 --- a/src/Magnum/Text/CMakeLists.txt +++ b/src/Magnum/Text/CMakeLists.txt @@ -46,6 +46,7 @@ if(MAGNUM_BUILD_DEPRECATED) endif() add_library(MagnumText ${SHARED_OR_STATIC} ${MagnumText_SRCS}) +set_target_properties(MagnumText PROPERTIES DEBUG_POSTFIX "-d") if(BUILD_STATIC_PIC) # TODO: CMake 2.8.9 has this as POSITION_INDEPENDENT_CODE property set_target_properties(MagnumText PROPERTIES COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}") diff --git a/src/Magnum/TextureTools/CMakeLists.txt b/src/Magnum/TextureTools/CMakeLists.txt index aa8f6b4e5..19e06bb5c 100644 --- a/src/Magnum/TextureTools/CMakeLists.txt +++ b/src/Magnum/TextureTools/CMakeLists.txt @@ -41,6 +41,7 @@ if(BUILD_STATIC) endif() add_library(MagnumTextureTools ${SHARED_OR_STATIC} ${MagnumTextureTools_SRCS}) +set_target_properties(MagnumTextureTools PROPERTIES DEBUG_POSTFIX "-d") if(BUILD_STATIC_PIC) # TODO: CMake 2.8.9 has this as POSITION_INDEPENDENT_CODE property set_target_properties(MagnumTextureTools PROPERTIES COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}")