cmake: Link resources statically, and init locally
authorManuel Nickschas <sputnick@quassel-irc.org>
Wed, 29 Aug 2018 16:15:47 +0000 (18:15 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sun, 18 Nov 2018 10:06:43 +0000 (11:06 +0100)
Link resource libraries statically in order to avoid problems with
symbol exporting. Move resource initialization from main() into the
respective libraries.

cmake/QuasselMacros.cmake
icons/CMakeLists.txt
src/client/CMakeLists.txt
src/client/client.cpp
src/common/CMakeLists.txt
src/common/quassel.cpp
src/core/core.cpp
src/main/CMakeLists.txt
src/main/main.cpp
src/uisupport/CMakeLists.txt
src/uisupport/graphicalui.cpp

index 3851d1b..19649da 100644 (file)
@@ -142,8 +142,9 @@ function(quassel_add_resource _name)
         WORKING_DIRECTORY ${basedir}
     )
 
         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)
 
     target_sources(${TARGET} PRIVATE ${qrc_srcpath})
     set_target_properties(${TARGET} PROPERTIES AUTOMOC OFF AUTOUIC OFF AUTORCC OFF)
 
index 4780efc..35eae34 100644 (file)
@@ -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.
 
     # 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)
 
     target_sources(${TARGET} PRIVATE hicolor_icons.qrc)
     set_target_properties(${TARGET} PROPERTIES AUTOMOC OFF AUTOUIC OFF)
 
index 6f4f669..1645538 100644 (file)
@@ -44,4 +44,8 @@ target_link_libraries(${TARGET}
         Quassel::Common
 )
 
         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)
 target_link_if_exists(${TARGET} PUBLIC Quassel::Resource::Data)
index b1e2f11..81a407b 100644 (file)
@@ -81,6 +81,10 @@ Client::Client(std::unique_ptr<AbstractUi> ui, QObject *parent)
     _coreConnection(new CoreConnection(this)),
     _connected(false)
 {
     _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()));
     //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()));
index f5bb920..2069a35 100644 (file)
@@ -68,6 +68,10 @@ target_link_libraries(${TARGET} PUBLIC
     ZLIB::ZLIB
 )
 
     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()
 if (HAVE_SYSLOG)
     target_compile_definitions(${TARGET} PRIVATE -DHAVE_SYSLOG)
 endif()
index ae39b03..f0f257c 100644 (file)
@@ -56,6 +56,9 @@ Quassel::Quassel()
     : Singleton<Quassel>{this}
     , _logger{new Logger{this}}
 {
     : Singleton<Quassel>{this}
     , _logger{new Logger{this}}
 {
+#ifdef EMBED_DATA
+    Q_INIT_RESOURCE(i18n);
+#endif
 }
 
 
 }
 
 
index e1ea083..339cbd3 100644 (file)
@@ -70,6 +70,8 @@ public:
 Core::Core()
     : Singleton<Core>{this}
 {
 Core::Core()
     : Singleton<Core>{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);
     // Parent all QObject-derived attributes, so when the Core instance gets moved into another
     // thread, they get moved with it
     _server.setParent(this);
index b8a4140..6ef3f78 100644 (file)
@@ -8,11 +8,6 @@ function(setup_executable _target _define)
     install(TARGETS ${_target} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
 endfunction()
 
     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()
 if (HAVE_UMASK)
     set_property(SOURCE main.cpp APPEND PROPERTY COMPILE_DEFINITIONS HAVE_UMASK)
 endif()
index 1cd6ba9..5ec89c5 100644 (file)
 
 int main(int argc, char **argv)
 {
 
 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);
     // Set umask so files are created with restricted permissions
 #ifdef HAVE_UMASK
     umask(S_IRWXG | S_IRWXO);
index 44fda17..5d0982c 100644 (file)
@@ -47,6 +47,10 @@ target_link_libraries(${TARGET}
         Quassel::Common
 )
 
         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
 if (WITH_KF5)
     target_link_libraries(${TARGET}
         PUBLIC
index ffd4e3d..6136ecf 100644 (file)
@@ -41,6 +41,13 @@ UiStyle *GraphicalUi::_uiStyle = 0;
 
 GraphicalUi::GraphicalUi(QObject *parent) : AbstractUi(parent), Singleton<GraphicalUi>(this)
 {
 
 GraphicalUi::GraphicalUi(QObject *parent) : AbstractUi(parent), Singleton<GraphicalUi>(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
 #ifdef Q_OS_WIN
     _dwTickCount = 0;
 #endif