From cdd0147edb6b177681dca01a2363d33d4086aab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 23 Oct 2019 22:49:25 +0200 Subject: [PATCH] Disable automatic resource initializers when building static. That's done manually, and when such a static lib is linked to a DLL, the suddenly appearing global constructors are unexpected. --- src/Magnum/DebugTools/CMakeLists.txt | 8 ++++++++ src/Magnum/Shaders/CMakeLists.txt | 7 +++++++ src/Magnum/TextureTools/CMakeLists.txt | 8 ++++++++ 3 files changed, 23 insertions(+) diff --git a/src/Magnum/DebugTools/CMakeLists.txt b/src/Magnum/DebugTools/CMakeLists.txt index 36b164546..60a5ef979 100644 --- a/src/Magnum/DebugTools/CMakeLists.txt +++ b/src/Magnum/DebugTools/CMakeLists.txt @@ -51,6 +51,14 @@ if(TARGET_GL) if(MAGNUM_TARGET_GLES AND NOT MAGNUM_TARGET_GLES2) corrade_add_resource(MagnumDebugTools_RESOURCES resources.conf) list(APPEND MagnumDebugTools_SRCS ${MagnumDebugTools_RESOURCES}) + if(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) diff --git a/src/Magnum/Shaders/CMakeLists.txt b/src/Magnum/Shaders/CMakeLists.txt index 8096bcf64..7f4ce43b4 100644 --- a/src/Magnum/Shaders/CMakeLists.txt +++ b/src/Magnum/Shaders/CMakeLists.txt @@ -63,6 +63,13 @@ set(MagnumShaders_PRIVATE_HEADERS Implementation/CreateCompatibilityShader.h) add_library(MagnumShadersObjects OBJECT ${MagnumShaders_SRCS} ${MagnumShaders_HEADERS}) +if(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 ${MagnumShaders_RCS} APPEND PROPERTY COMPILE_DEFINITIONS + "CORRADE_AUTOMATIC_INITIALIZER=CORRADE_NOOP" + "CORRADE_AUTOMATIC_FINALIZER=CORRADE_NOOP") +endif() target_include_directories(MagnumShadersObjects PUBLIC $ $) diff --git a/src/Magnum/TextureTools/CMakeLists.txt b/src/Magnum/TextureTools/CMakeLists.txt index e4390fda5..a139824d9 100644 --- a/src/Magnum/TextureTools/CMakeLists.txt +++ b/src/Magnum/TextureTools/CMakeLists.txt @@ -34,6 +34,14 @@ set(MagnumTextureTools_HEADERS if(TARGET_GL) corrade_add_resource(MagnumTextureTools_RCS resources.conf) set_target_properties(MagnumTextureTools_RCS-dependencies PROPERTIES FOLDER "Magnum/TextureTools") + if(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 ${MagnumTextureTools_RCS} APPEND PROPERTY + COMPILE_DEFINITIONS + "CORRADE_AUTOMATIC_INITIALIZER=CORRADE_NOOP" + "CORRADE_AUTOMATIC_FINALIZER=CORRADE_NOOP") + endif() list(APPEND MagnumTextureTools_SRCS DistanceField.cpp