From 1cc13c73968b57054719aee21e39f5d30f82f8b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 16 Mar 2019 12:20:51 +0100 Subject: [PATCH] GL: provide separate MagnumOpenGLTesterTestLib for assert-less tests. These tests need to use MagnumGLTestLib, however the Application library they're using is linked agaist MagnumGL. This causes problems at least on Windows with GL::Context::current(), where the affected two tests (GLMeshGLTest and GLBufferImageGLTest) failed with current() having no context. --- src/Magnum/GL/CMakeLists.txt | 54 ++++++++++++++++++++++++++++--- src/Magnum/GL/Test/CMakeLists.txt | 4 +-- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/src/Magnum/GL/CMakeLists.txt b/src/Magnum/GL/CMakeLists.txt index 33d851ca5..05d85c715 100644 --- a/src/Magnum/GL/CMakeLists.txt +++ b/src/Magnum/GL/CMakeLists.txt @@ -249,15 +249,29 @@ if(WITH_OPENGLTESTER) set(MagnumOpenGLTester_SRCS OpenGLTester.cpp) set(MagnumOpenGLTester_HEADERS OpenGLTester.h) - add_library(MagnumOpenGLTester STATIC + # We need a separate library for tests that links exclusively to + # MagnumGLTestLib instead of MagnumGL otherwise there are problems on + # Windows with global state like GL::Context::current(). So build an object + # library and then include it in MagnumOpenGLTester and + # MagnumOpenGLTesterTestLib. See the MagnumOpenGLTesterTestLib target for + # further info. + add_library(MagnumOpenGLTesterObjects OBJECT ${MagnumOpenGLTester_SRCS} ${MagnumOpenGLTester_HEADERS}) - set_target_properties(MagnumOpenGLTester PROPERTIES - DEBUG_POSTFIX "-d" - FOLDER "Magnum/GL") # Assuming that PIC is not needed because the Tester lib is always linked # to the executable and not to any intermediate shared lib + set_target_properties(MagnumOpenGLTesterObjects PROPERTIES FOLDER "Magnum/GL") + target_include_directories(MagnumOpenGLTesterObjects PUBLIC + $ + $ + $) + add_library(MagnumOpenGLTester STATIC + $ + ${PROJECT_SOURCE_DIR}/src/dummy.cpp) # XCode workaround, see file comment for details + set_target_properties(MagnumOpenGLTester PROPERTIES + DEBUG_POSTFIX "-d" + FOLDER "Magnum/GL") # OPENGLTESTER_APPLICATION defined in the root CMakeLists, because it also # enables the application library dependencies target_link_libraries(MagnumOpenGLTester PUBLIC Magnum Corrade::TestSuite ${OPENGLTESTER_APPLICATION}) @@ -315,6 +329,38 @@ if(BUILD_TESTS) ARCHIVE DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) endif() + if(BUILD_GL_TESTS) + add_library(MagnumOpenGLTesterTestLib STATIC + $ + ${PROJECT_SOURCE_DIR}/src/dummy.cpp) # XCode workaround, see file comment for details + set_target_properties(MagnumOpenGLTesterTestLib PROPERTIES + DEBUG_POSTFIX "-d" + FOLDER "Magnum/GL") + target_link_libraries(MagnumOpenGLTesterTestLib PUBLIC Magnum Corrade::TestSuite) + # On Windows the ${OPENGLTESTER_APPLICATION} links to MagnumGL, which + # is causing asserts in GL::Context::current() due to two different + # instances of the global variable getting used. We circumvent that by + # using just the library file from ${OPENGLTESTER_APPLICATION} and + # linking to MagnumGLTestLib explicitly. It's not a problem on other + # platforms and I don't want to go through the trouble of correctly + # passing through all dependencies like X11, CGL etc., so I do it for + # Windows only and elsewhere I just link the same way as with + # MagnumOpenGLTester. + if(CORRADE_TARGET_WINDOWS) + if(MAGNUM_TARGET_GLES AND NOT MAGNUM_TARGET_DESKTOP_GLES) + # Otherwise it complains that EGL::EGL does not exist here + find_package(EGL) + endif() + target_link_libraries(MagnumOpenGLTesterTestLib PUBLIC + $ + MagnumGLTestLib) # this is different + target_include_directories(MagnumOpenGLTesterTestLib PUBLIC + $) + else() + target_link_libraries(MagnumOpenGLTesterTestLib PUBLIC Magnum Corrade::TestSuite MagnumGLTestLib ${OPENGLTESTER_APPLICATION}) + endif() + endif() + add_subdirectory(Test) endif() diff --git a/src/Magnum/GL/Test/CMakeLists.txt b/src/Magnum/GL/Test/CMakeLists.txt index 1c6704d84..b856f9728 100644 --- a/src/Magnum/GL/Test/CMakeLists.txt +++ b/src/Magnum/GL/Test/CMakeLists.txt @@ -109,7 +109,7 @@ if(BUILD_GL_TESTS) corrade_add_test(GLContextGLTest ContextGLTest.cpp LIBRARIES MagnumOpenGLTester) corrade_add_test(GLCubeMapTextureGLTest CubeMapTextureGLTest.cpp LIBRARIES MagnumOpenGLTester) corrade_add_test(GLFramebufferGLTest FramebufferGLTest.cpp LIBRARIES MagnumOpenGLTester) - corrade_add_test(GLMeshGLTest MeshGLTest.cpp LIBRARIES MagnumGLTestLib MagnumOpenGLTester) + corrade_add_test(GLMeshGLTest MeshGLTest.cpp LIBRARIES MagnumOpenGLTesterTestLib) corrade_add_test(GLRendererGLTest RendererGLTest.cpp LIBRARIES MagnumOpenGLTester) corrade_add_test(GLRenderbufferGLTest RenderbufferGLTest.cpp LIBRARIES MagnumOpenGLTester) corrade_add_test(GLTextureGLTest TextureGLTest.cpp LIBRARIES MagnumOpenGLTester) @@ -174,7 +174,7 @@ if(BUILD_GL_TESTS) endif() if(NOT MAGNUM_TARGET_GLES2) - corrade_add_test(GLBufferImageGLTest BufferImageGLTest.cpp LIBRARIES MagnumGLTestLib MagnumOpenGLTester) + corrade_add_test(GLBufferImageGLTest BufferImageGLTest.cpp LIBRARIES MagnumOpenGLTesterTestLib) corrade_add_test(GLPrimitiveQueryGLTest PrimitiveQueryGLTest.cpp LIBRARIES MagnumOpenGLTester) corrade_add_test(GLTextureArrayGLTest TextureArrayGLTest.cpp LIBRARIES MagnumOpenGLTester) corrade_add_test(GLTransformFeedbackGLTest TransformFeedbackGLTest.cpp LIBRARIES MagnumOpenGLTester)