You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

215 lines
8.3 KiB

#
# This file is part of Magnum.
#
# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
# 2020, 2021, 2022 Vladimír Vondruš <mosra@centrum.cz>
#
# 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.
#
# IDE folder in VS, Xcode etc. CMake 3.12+, older versions have only the FOLDER
# property that would have to be set on each target separately.
set(CMAKE_FOLDER "Magnum/DebugTools")
set(MagnumDebugTools_SRCS
ColorMap.cpp)
set(MagnumDebugTools_GracefulAssert_SRCS
FrameProfiler.cpp)
set(MagnumDebugTools_HEADERS
ColorMap.h
DebugTools.h
FrameProfiler.h
visibility.h)
# Header files to display in project view of IDEs only
set(MagnumDebugTools_PRIVATE_HEADERS )
if(MAGNUM_BUILD_DEPRECATED)
list(APPEND MagnumDebugTools_SRCS Profiler.cpp)
list(APPEND MagnumDebugTools_HEADERS Profiler.h)
endif()
if(MAGNUM_TARGET_GL)
list(APPEND MagnumDebugTools_SRCS
ResourceManager.cpp
Screenshot.cpp
TextureImage.cpp)
list(APPEND MagnumDebugTools_HEADERS
ResourceManager.h
Screenshot.h
TextureImage.h)
if(MAGNUM_TARGET_GLES AND NOT MAGNUM_TARGET_GLES2)
corrade_add_resource(MagnumDebugTools_RESOURCES resources.conf)
list(APPEND MagnumDebugTools_SRCS ${MagnumDebugTools_RESOURCES})
if(MAGNUM_BUILD_STATIC)
# On the static build we're importing the resources manually, so no
# need to have the implicit initializers as well.
set_property(SOURCE ${MagnumDebugTools_RESOURCES} APPEND PROPERTY
COMPILE_DEFINITIONS
"CORRADE_AUTOMATIC_INITIALIZER=CORRADE_NOOP"
"CORRADE_AUTOMATIC_FINALIZER=CORRADE_NOOP")
endif()
endif()
if(NOT (MAGNUM_TARGET_WEBGL AND MAGNUM_TARGET_GLES2))
list(APPEND MagnumDebugTools_SRCS
BufferData.cpp)
list(APPEND MagnumDebugTools_HEADERS
BufferData.h)
endif()
if(MAGNUM_WITH_SCENEGRAPH)
list(APPEND MagnumDebugTools_SRCS
ForceRenderer.cpp
ObjectRenderer.cpp)
list(APPEND MagnumDebugTools_HEADERS
ForceRenderer.h
ObjectRenderer.h)
list(APPEND MagnumDebugTools_PRIVATE_HEADERS
Implementation/ForceRendererTransformation.h)
endif()
endif()
# Build the TestSuite-related functionality only if it is present
find_package(Corrade COMPONENTS TestSuite)
if(Corrade_TestSuite_FOUND AND MAGNUM_WITH_TRADE)
list(APPEND MagnumDebugTools_GracefulAssert_SRCS
CompareImage.cpp)
list(APPEND MagnumDebugTools_HEADERS
CompareImage.h)
endif()
# Objects shared between main and test library
add_library(MagnumDebugToolsObjects OBJECT
${MagnumDebugTools_SRCS}
${MagnumDebugTools_HEADERS}
${MagnumDebugTools_PRIVATE_HEADERS})
target_include_directories(MagnumDebugToolsObjects PUBLIC $<TARGET_PROPERTY:Magnum,INTERFACE_INCLUDE_DIRECTORIES>)
if(NOT MAGNUM_BUILD_STATIC)
target_compile_definitions(MagnumDebugToolsObjects PRIVATE "MagnumDebugToolsObjects_EXPORTS")
endif()
if(NOT MAGNUM_BUILD_STATIC OR MAGNUM_BUILD_STATIC_PIC)
set_target_properties(MagnumDebugToolsObjects PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()
if(MAGNUM_TARGET_GL)
target_include_directories(MagnumDebugToolsObjects PUBLIC $<TARGET_PROPERTY:MagnumGL,INTERFACE_INCLUDE_DIRECTORIES>)
endif()
# DebugTools library
add_library(MagnumDebugTools ${SHARED_OR_STATIC}
$<TARGET_OBJECTS:MagnumDebugToolsObjects>
${MagnumDebugTools_GracefulAssert_SRCS})
set_target_properties(MagnumDebugTools PROPERTIES DEBUG_POSTFIX "-d")
if(NOT MAGNUM_BUILD_STATIC)
set_target_properties(MagnumDebugTools PROPERTIES VERSION ${MAGNUM_LIBRARY_VERSION} SOVERSION ${MAGNUM_LIBRARY_SOVERSION})
elseif(MAGNUM_BUILD_STATIC_PIC)
set_target_properties(MagnumDebugTools PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()
target_link_libraries(MagnumDebugTools PUBLIC Magnum)
if(Corrade_TestSuite_FOUND AND MAGNUM_WITH_TRADE)
target_link_libraries(MagnumDebugTools PUBLIC
Corrade::TestSuite
MagnumTrade)
endif()
if(MAGNUM_TARGET_GL)
target_link_libraries(MagnumDebugTools PUBLIC MagnumGL)
if(MAGNUM_WITH_SCENEGRAPH)
target_link_libraries(MagnumDebugTools PUBLIC
MagnumMeshTools
MagnumPrimitives
MagnumSceneGraph
MagnumShaders)
endif()
endif()
install(TARGETS MagnumDebugTools
RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR}
LIBRARY DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}
ARCHIVE DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
install(FILES ${MagnumDebugTools_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/DebugTools)
if(MAGNUM_BUILD_TESTS)
# Library with graceful assert for testing
add_library(MagnumDebugToolsTestLib ${SHARED_OR_STATIC}
$<TARGET_OBJECTS:MagnumDebugToolsObjects>
${MagnumDebugTools_GracefulAssert_SRCS})
set_target_properties(MagnumDebugToolsTestLib PROPERTIES DEBUG_POSTFIX "-d")
target_compile_definitions(MagnumDebugToolsTestLib PRIVATE
"CORRADE_GRACEFUL_ASSERT" "MagnumDebugTools_EXPORTS")
if(MAGNUM_BUILD_STATIC_PIC)
set_target_properties(MagnumDebugToolsTestLib PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()
target_link_libraries(MagnumDebugToolsTestLib PUBLIC Magnum)
if(Corrade_TestSuite_FOUND AND MAGNUM_WITH_TRADE)
target_link_libraries(MagnumDebugToolsTestLib PUBLIC
Corrade::TestSuite
MagnumTrade)
endif()
if(MAGNUM_TARGET_GL)
target_link_libraries(MagnumDebugToolsTestLib PUBLIC MagnumGL)
if(MAGNUM_WITH_SCENEGRAPH)
target_link_libraries(MagnumDebugToolsTestLib PUBLIC
MagnumMeshTools
MagnumPrimitives
MagnumSceneGraph
MagnumShaders)
endif()
endif()
GL,DebugTools: "fix" global symbol duplication between test libraries. If a GL test library would link to MagnumOpenGLTesterTestLib (which has CORRADE_GRACEFUL_ASSERT enabled to be able to verify assertions) and then to MagnumDebugTools for DebugTools::bufferData(), it'd mean there's one GL::Context global from MagnumGLTestLib and one from MagnumGL. Then, depending on whatever random order the linker uses, different parts of the library would see a different global, ultimately leading to a dreaded GL::Context::current(): no current context assertion. Right now this only manifested on the macOS static CI build, but depending on a phase of the moon could happen for any platform in any circumstance. First attempt was to switch to linking to MagnumDebugToolsTestLib and then making MagnumDebugToolsTestLib depend on MagnumGLTestLib instead of MagnumGL, HOWEVER because DebugTools also depend on Primitives and Shaders and whatnot for some features, it just moved the conflict between MagnumGL and MagnumGLTestLib elsewhere -- and ASan started loudly complaining about GL::defaultFramebuffer being duplicated. So instead there's now a dedicated subset of DebugTools just for the GL test themselves, containing currently just DebugTools::bufferData(), as nothing else is needed ATM. It may grow further when needed, such as with textureImage(), or CompareImage, etc. But of course that wouldn't be enough -- MagnumOpenGLTesterTestLib actually still links to MagnumGL for Other Reasons, meaning we have to pass it last to prefer symbols from MagnumGLTestLib which have graceful asserts enabled. Hopefully this works well enough, otherwise I'd have to figure out yet another variant of the fix.
4 years ago
# A subset of DebugTools used by GL's own tests that link to
# MagnumGLTestLib (or MagnumOpenGLTesterTestLib), linking also to
# MagnumGLTestLibMagnumGL. We can't link those to MagnumDebugToolsTestLib
# because it depends on MagnumGL instead, which would lead to the
# GL::Context global to be duplicated, causing the dreaded
#
# GL::Context::current(): no current context
#
# assertion. We however also can't link MagnumDebugToolsTestLib to
# MagnumGLTestLib, because the other libraries it depends on (MeshTools,
# Shaders...) link to MagnumGL and so the same problem would just reappear
# elsewhere.
if(TARGET_GL AND BUILD_GL_TESTS AND NOT (MAGNUM_TARGET_WEBGL AND MAGNUM_TARGET_GLES2))
add_library(MagnumDebugToolsGLTestLibSubset ${SHARED_OR_STATIC}
# Add more files if needed
BufferData.cpp
BufferData.h)
set_target_properties(MagnumDebugToolsGLTestLibSubset PROPERTIES DEBUG_POSTFIX "-d")
target_compile_definitions(MagnumDebugToolsGLTestLibSubset PRIVATE
"CORRADE_GRACEFUL_ASSERT" "MagnumDebugTools_EXPORTS")
if(BUILD_STATIC_PIC)
set_target_properties(MagnumDebugToolsGLTestLibSubset PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()
target_link_libraries(MagnumDebugToolsGLTestLibSubset PUBLIC Magnum MagnumGLTestLib)
endif()
add_subdirectory(Test)
endif()
# Magnum DebugTools target alias for superprojects
add_library(Magnum::DebugTools ALIAS MagnumDebugTools)