From d4b64322860b0dfcc9e1340a3b3a0b0df3e2eb81 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Wed, 29 Aug 2018 18:15:47 +0200 Subject: [PATCH] cmake: Link resources statically, and init locally Link resource libraries statically in order to avoid problems with symbol exporting. Move resource initialization from main() into the respective libraries. --- cmake/QuasselMacros.cmake | 5 +++-- icons/CMakeLists.txt | 2 +- src/client/CMakeLists.txt | 4 ++++ src/client/client.cpp | 4 ++++ src/common/CMakeLists.txt | 4 ++++ src/common/quassel.cpp | 3 +++ src/core/core.cpp | 2 ++ src/main/CMakeLists.txt | 5 ----- src/main/main.cpp | 20 -------------------- src/uisupport/CMakeLists.txt | 4 ++++ src/uisupport/graphicalui.cpp | 7 +++++++ 11 files changed, 32 insertions(+), 28 deletions(-) diff --git a/cmake/QuasselMacros.cmake b/cmake/QuasselMacros.cmake index 3851d1bc..19649da8 100644 --- a/cmake/QuasselMacros.cmake +++ b/cmake/QuasselMacros.cmake @@ -142,8 +142,9 @@ function(quassel_add_resource _name) WORKING_DIRECTORY ${basedir} ) - # Generate library target that can be referenced elsewhere - quassel_add_module(Resource::${_name}) + # Generate library target that can be referenced elsewhere. Force static, because + # we can't easily export symbols from the generated sources. + quassel_add_module(Resource::${_name} STATIC) target_sources(${TARGET} PRIVATE ${qrc_srcpath}) set_target_properties(${TARGET} PROPERTIES AUTOMOC OFF AUTOUIC OFF AUTORCC OFF) diff --git a/icons/CMakeLists.txt b/icons/CMakeLists.txt index 4780efc1..35eae344 100644 --- a/icons/CMakeLists.txt +++ b/icons/CMakeLists.txt @@ -9,7 +9,7 @@ if (WANT_MONO OR WANT_QTCLIENT) # Always embed a hicolor fallback containing the most important (e.g. tray) icons. # The .qrc contains aliases, so it's best to keep this manually written rather than autogenerated. - quassel_add_module(Resource::HicolorIcons) + quassel_add_module(Resource::HicolorIcons STATIC) target_sources(${TARGET} PRIVATE hicolor_icons.qrc) set_target_properties(${TARGET} PROPERTIES AUTOMOC OFF AUTOUIC OFF) diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index 6f4f6690..16455385 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -44,4 +44,8 @@ target_link_libraries(${TARGET} Quassel::Common ) +if (EMBED_DATA) + set_property(SOURCE client.cpp APPEND PROPERTY COMPILE_DEFINITIONS EMBED_DATA) +endif() + target_link_if_exists(${TARGET} PUBLIC Quassel::Resource::Data) diff --git a/src/client/client.cpp b/src/client/client.cpp index b1e2f119..81a407b5 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -81,6 +81,10 @@ Client::Client(std::unique_ptr ui, QObject *parent) _coreConnection(new CoreConnection(this)), _connected(false) { +#ifdef EMBED_DATA + Q_INIT_RESOURCE(data); +#endif + //connect(mainUi(), SIGNAL(connectToCore(const QVariantMap &)), this, SLOT(connectToCore(const QVariantMap &))); connect(mainUi(), SIGNAL(disconnectFromCore()), this, SLOT(disconnectFromCore())); connect(this, SIGNAL(connected()), mainUi(), SLOT(connectedToCore())); diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index f5bb920d..2069a35b 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -68,6 +68,10 @@ target_link_libraries(${TARGET} PUBLIC ZLIB::ZLIB ) +if (EMBED_DATA) + set_property(SOURCE quassel.cpp APPEND PROPERTY COMPILE_DEFINITIONS EMBED_DATA) +endif() + if (HAVE_SYSLOG) target_compile_definitions(${TARGET} PRIVATE -DHAVE_SYSLOG) endif() diff --git a/src/common/quassel.cpp b/src/common/quassel.cpp index ae39b03b..f0f257c1 100644 --- a/src/common/quassel.cpp +++ b/src/common/quassel.cpp @@ -56,6 +56,9 @@ Quassel::Quassel() : Singleton{this} , _logger{new Logger{this}} { +#ifdef EMBED_DATA + Q_INIT_RESOURCE(i18n); +#endif } diff --git a/src/core/core.cpp b/src/core/core.cpp index e1ea0832..339cbd38 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -70,6 +70,8 @@ public: Core::Core() : Singleton{this} { + Q_INIT_RESOURCE(sql); + // Parent all QObject-derived attributes, so when the Core instance gets moved into another // thread, they get moved with it _server.setParent(this); diff --git a/src/main/CMakeLists.txt b/src/main/CMakeLists.txt index b8a41402..6ef3f783 100644 --- a/src/main/CMakeLists.txt +++ b/src/main/CMakeLists.txt @@ -8,11 +8,6 @@ function(setup_executable _target _define) install(TARGETS ${_target} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endfunction() -# We need to initialize the appropriate resources, so let's give our main.cpp some hints -if (EMBED_DATA) - set_property(SOURCE main.cpp APPEND PROPERTY COMPILE_DEFINITIONS EMBED_DATA) -endif() - if (HAVE_UMASK) set_property(SOURCE main.cpp APPEND PROPERTY COMPILE_DEFINITIONS HAVE_UMASK) endif() diff --git a/src/main/main.cpp b/src/main/main.cpp index 1cd6ba91..5ec89c55 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -57,26 +57,6 @@ int main(int argc, char **argv) { - // We need to explicitly initialize the required resources when linking statically -#ifndef BUILD_QTUI - Q_INIT_RESOURCE(sql); -#endif -#ifndef BUILD_CORE - Q_INIT_RESOURCE(pics); - Q_INIT_RESOURCE(hicolor_icons); -#endif - -#ifdef EMBED_DATA - Q_INIT_RESOURCE(i18n); -# ifndef BUILD_CORE - Q_INIT_RESOURCE(data); - Q_INIT_RESOURCE(icons); -# ifdef WITH_BUNDLED_ICONS - Q_INIT_RESOURCE(iconthemes); -# endif -# endif -#endif - // Set umask so files are created with restricted permissions #ifdef HAVE_UMASK umask(S_IRWXG | S_IRWXO); diff --git a/src/uisupport/CMakeLists.txt b/src/uisupport/CMakeLists.txt index 44fda179..5d0982c0 100644 --- a/src/uisupport/CMakeLists.txt +++ b/src/uisupport/CMakeLists.txt @@ -47,6 +47,10 @@ target_link_libraries(${TARGET} Quassel::Common ) +if (EMBED_DATA) + set_property(SOURCE graphicalui.cpp APPEND PROPERTY COMPILE_DEFINITIONS EMBED_DATA) +endif() + if (WITH_KF5) target_link_libraries(${TARGET} PUBLIC diff --git a/src/uisupport/graphicalui.cpp b/src/uisupport/graphicalui.cpp index ffd4e3df..6136ecf4 100644 --- a/src/uisupport/graphicalui.cpp +++ b/src/uisupport/graphicalui.cpp @@ -41,6 +41,13 @@ UiStyle *GraphicalUi::_uiStyle = 0; GraphicalUi::GraphicalUi(QObject *parent) : AbstractUi(parent), Singleton(this) { + Q_INIT_RESOURCE(pics); + Q_INIT_RESOURCE(hicolor_icons); +#ifdef EMBED_DATA + Q_INIT_RESOURCE(icons); + Q_INIT_RESOURCE(iconthemes); +#endif + #ifdef Q_OS_WIN _dwTickCount = 0; #endif -- 2.20.1