From 95ee188c7b86b4448acbcfb01a42ac139cee6388 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Fri, 3 Sep 2021 20:18:05 +0400 Subject: [PATCH 01/20] Get rid of GTK integration --- CMakeLists.txt | 4 +--- external/qt/CMakeLists.txt | 20 ++++++------------- .../qt_static_plugins/qt_static_plugins.cpp | 2 -- options.cmake | 7 ------- variables.cmake | 1 - 5 files changed, 7 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6bf1930..dcb0992 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,9 +10,7 @@ if (LINUX AND Qt5WaylandClient_FOUND) add_subdirectory(linux_wayland_helper) endif() -if (LINUX - AND NOT DESKTOP_APP_USE_PACKAGED - AND NOT DESKTOP_APP_DISABLE_GTK_INTEGRATION) +if (LINUX AND NOT DESKTOP_APP_USE_PACKAGED) add_subdirectory(linux_gtk_helper) endif() if (DESKTOP_APP_USE_ALLOCATION_TRACER) diff --git a/external/qt/CMakeLists.txt b/external/qt/CMakeLists.txt index 8391f65..711dc71 100644 --- a/external/qt/CMakeLists.txt +++ b/external/qt/CMakeLists.txt @@ -212,17 +212,11 @@ else() plugins/wayland-decoration-client/${qt_lib_prefix}bradient ) endif() - set(qt_libs_gtk_plugins) - if (NOT DESKTOP_APP_DISABLE_GTK_INTEGRATION) - set(qt_libs_gtk_plugins - plugins/platformthemes/${qt_lib_prefix}qgtk3 - ) - endif() set(qt_libs plugins/platforminputcontexts/${qt_lib_prefix}composeplatforminputcontextplugin ${qt_libs_dbus_plugins} ${qt_libs_waylandclient_plugins} - ${qt_libs_gtk_plugins} + plugins/platformthemes/${qt_lib_prefix}qgtk3 plugins/platforms/${qt_lib_prefix}qxcb plugins/xcbglintegrations/${qt_lib_prefix}qxcb-egl-integration plugins/xcbglintegrations/${qt_lib_prefix}qxcb-glx-integration @@ -290,13 +284,11 @@ else() $ ) endif() - if (NOT DESKTOP_APP_DISABLE_GTK_INTEGRATION) - target_link_libraries(external_qt - INTERFACE - desktop-app::linux_gtk_helper - $ - ) - endif() + target_link_libraries(external_qt + INTERFACE + desktop-app::linux_gtk_helper + $ + ) target_link_libraries(external_qt INTERFACE fontconfig diff --git a/external/qt/qt_static_plugins/qt_static_plugins.cpp b/external/qt/qt_static_plugins/qt_static_plugins.cpp index 71b4bad..341cc99 100644 --- a/external/qt/qt_static_plugins/qt_static_plugins.cpp +++ b/external/qt/qt_static_plugins/qt_static_plugins.cpp @@ -39,9 +39,7 @@ Q_IMPORT_PLUGIN(QWaylandEglClientBufferPlugin) Q_IMPORT_PLUGIN(QWaylandWlShellIntegrationPlugin) Q_IMPORT_PLUGIN(QWaylandBradientDecorationPlugin) #endif // !DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION -#ifndef DESKTOP_APP_DISABLE_GTK_INTEGRATION Q_IMPORT_PLUGIN(QGtk3ThemePlugin) -#endif // !DESKTOP_APP_DISABLE_GTK_INTEGRATION #endif // Q_OS_WIN | Q_OS_MAC | Q_OS_UNIX #endif // !DESKTOP_APP_USE_PACKAGED diff --git a/options.cmake b/options.cmake index 10d8c89..91d8897 100644 --- a/options.cmake +++ b/options.cmake @@ -42,13 +42,6 @@ if (DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION) ) endif() -if (DESKTOP_APP_DISABLE_GTK_INTEGRATION) - target_compile_definitions(common_options - INTERFACE - DESKTOP_APP_DISABLE_GTK_INTEGRATION - ) -endif() - if (DESKTOP_APP_USE_PACKAGED) target_compile_definitions(common_options INTERFACE diff --git a/variables.cmake b/variables.cmake index 554ef40..5ff5748 100644 --- a/variables.cmake +++ b/variables.cmake @@ -21,7 +21,6 @@ option(DESKTOP_APP_LOTTIE_USE_CACHE "Use caching in lottie animations." ON) option(DESKTOP_APP_DISABLE_DBUS_INTEGRATION "Disable all code for D-Bus integration (Linux only)." OFF) option(DESKTOP_APP_DISABLE_X11_INTEGRATION "Disable all code for X11 integration (Linux only)." OFF) option(DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION "Disable all code for Wayland integration (Linux only)." OFF) -option(DESKTOP_APP_DISABLE_GTK_INTEGRATION "Disable all code for GTK integration (Linux only)." OFF) option(DESKTOP_APP_USE_ALLOCATION_TRACER "Use simple allocation tracer (Linux only)." OFF) option(DESKTOP_APP_USE_PACKAGED "Find libraries using CMake instead of exact paths." ${no_special_target}) option(DESKTOP_APP_USE_PACKAGED_LAZY "Bundle recommended Qt plugins for self-contained packages. (Linux only)" OFF) From 98c52815e90f049af4e97209a2283584bfecc913 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Tue, 7 Sep 2021 22:34:23 +0400 Subject: [PATCH 02/20] Add a check for DESKTOP_APP_DISABLE_AUTOUPDATE in external_auto_updates Like that done for external_crash_reports --- external/auto_updates/CMakeLists.txt | 26 ++++++++++++++------------ external/ffmpeg/CMakeLists.txt | 1 + 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/external/auto_updates/CMakeLists.txt b/external/auto_updates/CMakeLists.txt index d762119..981e8df 100644 --- a/external/auto_updates/CMakeLists.txt +++ b/external/auto_updates/CMakeLists.txt @@ -7,16 +7,18 @@ add_library(external_auto_updates INTERFACE IMPORTED GLOBAL) add_library(desktop-app::external_auto_updates ALIAS external_auto_updates) -if (WIN32 AND NOT DESKTOP_APP_USE_PACKAGED) - add_subdirectory(lzma) - target_link_libraries(external_auto_updates - INTERFACE - desktop-app::external_lzma - ) -else() - add_subdirectory(xz) - target_link_libraries(external_auto_updates - INTERFACE - desktop-app::external_xz - ) +if (NOT DESKTOP_APP_DISABLE_AUTOUPDATE) + if (WIN32 AND NOT DESKTOP_APP_USE_PACKAGED) + add_subdirectory(lzma) + target_link_libraries(external_auto_updates + INTERFACE + desktop-app::external_lzma + ) + else() + add_subdirectory(xz) + target_link_libraries(external_auto_updates + INTERFACE + desktop-app::external_xz + ) + endif() endif() diff --git a/external/ffmpeg/CMakeLists.txt b/external/ffmpeg/CMakeLists.txt index 4479736..720e3d7 100644 --- a/external/ffmpeg/CMakeLists.txt +++ b/external/ffmpeg/CMakeLists.txt @@ -64,6 +64,7 @@ else() if (LINUX) target_link_static_libraries(external_ffmpeg INTERFACE + lzma va-x11 va-drm va From f343a1634cbdefb476e9020687db30a356ffe8f2 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 23 Jul 2021 18:54:17 +0300 Subject: [PATCH 03/20] Use macOS libs from Libraries/local. --- external/auto_updates/xz/CMakeLists.txt | 4 ++-- external/iconv/CMakeLists.txt | 2 +- external/jpeg/CMakeLists.txt | 2 +- external/openal/CMakeLists.txt | 8 ++++---- external/openssl/CMakeLists.txt | 8 ++------ external/openssl/openssl_common/CMakeLists.txt | 2 +- external/opus/CMakeLists.txt | 4 ++-- external/qt/package.cmake | 2 ++ external/zlib/CMakeLists.txt | 2 +- options_mac.cmake | 2 +- variables.cmake | 4 +--- 11 files changed, 18 insertions(+), 22 deletions(-) diff --git a/external/auto_updates/xz/CMakeLists.txt b/external/auto_updates/xz/CMakeLists.txt index 438dd15..8631a5d 100644 --- a/external/auto_updates/xz/CMakeLists.txt +++ b/external/auto_updates/xz/CMakeLists.txt @@ -13,11 +13,11 @@ if (DESKTOP_APP_USE_PACKAGED) elseif (APPLE) target_include_directories(external_xz SYSTEM INTERFACE - /usr/local/macos/include + ${libs_loc}/local/include ) target_link_libraries(external_xz INTERFACE - /usr/local/macos/lib/liblzma.a + ${libs_loc}/local/lib/liblzma.a ) else() target_link_static_libraries(external_xz diff --git a/external/iconv/CMakeLists.txt b/external/iconv/CMakeLists.txt index 36245b1..94434bf 100644 --- a/external/iconv/CMakeLists.txt +++ b/external/iconv/CMakeLists.txt @@ -13,6 +13,6 @@ if (APPLE AND DESKTOP_APP_USE_PACKAGED) elseif (APPLE) target_link_libraries(external_iconv INTERFACE - /usr/local/macos/lib/libiconv.a + ${libs_loc}/local/lib/libiconv.a ) endif() diff --git a/external/jpeg/CMakeLists.txt b/external/jpeg/CMakeLists.txt index 9cb5ff8..5ed56cf 100644 --- a/external/jpeg/CMakeLists.txt +++ b/external/jpeg/CMakeLists.txt @@ -14,7 +14,7 @@ elseif (WIN32) target_include_directories(external_jpeg SYSTEM INTERFACE ${libs_loc}/mozjpeg) target_link_libraries(external_jpeg INTERFACE ${libs_loc}/mozjpeg/$,Debug,Release>/jpeg-static.lib) elseif (APPLE) - target_link_libraries(external_jpeg INTERFACE /usr/local/macos/lib/libjpeg.a) + target_link_libraries(external_jpeg INTERFACE ${libs_loc}/local/lib/libjpeg.a) else() target_link_static_libraries(external_jpeg INTERFACE jpeg) endif() diff --git a/external/openal/CMakeLists.txt b/external/openal/CMakeLists.txt index 483d905..f97013a 100644 --- a/external/openal/CMakeLists.txt +++ b/external/openal/CMakeLists.txt @@ -27,15 +27,15 @@ elseif (WIN32) INTERFACE ${libs_loc}/openal-soft/build/$,Debug,RelWithDebInfo>/OpenAL32.lib ) -elseif(APPLE) +elseif (APPLE) target_include_directories(external_openal SYSTEM INTERFACE - /usr/local/macos/include - /usr/local/macos/include/AL + ${libs_loc}/local/include + ${libs_loc}/local/include/AL ) target_link_libraries(external_openal INTERFACE - /usr/local/macos/lib/libopenal.a + ${libs_loc}/local/lib/libopenal.a ) else() target_include_directories(external_openal SYSTEM diff --git a/external/openssl/CMakeLists.txt b/external/openssl/CMakeLists.txt index d66b5d8..0e0b9d9 100644 --- a/external/openssl/CMakeLists.txt +++ b/external/openssl/CMakeLists.txt @@ -9,15 +9,11 @@ add_library(desktop-app::external_openssl ALIAS external_openssl) if (WIN32) set(openssl_lib_ext lib) - if (build_win64) - set(openssl_lib_loc ${libs_loc}/openssl_1_1_1/out64) - else() - set(openssl_lib_loc ${libs_loc}/openssl_1_1_1/out32) - endif() + set(openssl_lib_loc ${libs_loc}/openssl/out) else() set(openssl_lib_ext a) if (APPLE) - set(openssl_lib_loc ${libs_loc}/openssl_1_1_1) + set(openssl_lib_loc ${libs_loc}/openssl) else() set(openssl_lib_loc /usr/local/desktop-app/openssl-1.1.1/lib) endif() diff --git a/external/openssl/openssl_common/CMakeLists.txt b/external/openssl/openssl_common/CMakeLists.txt index 3343366..3caa6fb 100644 --- a/external/openssl/openssl_common/CMakeLists.txt +++ b/external/openssl/openssl_common/CMakeLists.txt @@ -16,7 +16,7 @@ if (NOT DESKTOP_APP_USE_PACKAGED) else() target_include_directories(external_openssl_common SYSTEM INTERFACE - ${libs_loc}/openssl_1_1_1/include + ${libs_loc}/openssl/include ) endif() diff --git a/external/opus/CMakeLists.txt b/external/opus/CMakeLists.txt index 4ad35f0..5fd2606 100644 --- a/external/opus/CMakeLists.txt +++ b/external/opus/CMakeLists.txt @@ -34,10 +34,10 @@ else() elseif (APPLE) target_include_directories(external_opus SYSTEM INTERFACE - /usr/local/macos/include/opus + ${libs_loc}/local/include/opus ) set_target_properties(external_opus PROPERTIES - IMPORTED_LOCATION /usr/local/macos/lib/libopus.a + IMPORTED_LOCATION ${libs_loc}/local/lib/libopus.a ) else() target_include_directories(external_opus SYSTEM diff --git a/external/qt/package.cmake b/external/qt/package.cmake index adbc8ed..3169cbe 100644 --- a/external/qt/package.cmake +++ b/external/qt/package.cmake @@ -9,6 +9,8 @@ if (NOT DESKTOP_APP_USE_PACKAGED) if (WIN32) set(qt_loc ${libs_loc}/Qt-${qt_version}) + elseif (APPLE) + set(qt_loc ${libs_loc}/local/Qt-${qt_version}) else() set(qt_loc /usr/local/desktop-app/Qt-${qt_version}) endif() diff --git a/external/zlib/CMakeLists.txt b/external/zlib/CMakeLists.txt index d5b1660..b1bf692 100644 --- a/external/zlib/CMakeLists.txt +++ b/external/zlib/CMakeLists.txt @@ -21,7 +21,7 @@ elseif (WIN32) set(zlib_lib_loc ${libs_loc}/zlib/contrib/vstudio/vc14/${zlib_config_folder}/ZlibStat$,Debug,ReleaseWithoutAsm>) target_link_libraries(external_zlib INTERFACE ${zlib_lib_loc}/zlibstat.lib) elseif (APPLE) - target_link_libraries(external_zlib INTERFACE /usr/local/macos/lib/libz.a) + target_link_libraries(external_zlib INTERFACE ${libs_loc}/local/lib/libz.a) else() target_link_libraries(external_zlib INTERFACE z) endif() diff --git a/options_mac.cmake b/options_mac.cmake index 7f2944e..d4b0543 100644 --- a/options_mac.cmake +++ b/options_mac.cmake @@ -14,7 +14,7 @@ endif() if (NOT DESKTOP_APP_USE_PACKAGED) target_include_directories(common_options SYSTEM INTERFACE - /usr/local/macos/include + ${libs_loc}/local/include ) endif() diff --git a/variables.cmake b/variables.cmake index 5ff5748..08b5bd9 100644 --- a/variables.cmake +++ b/variables.cmake @@ -84,8 +84,6 @@ endif() if (build_win64) get_filename_component(libs_loc "../Libraries/win64" REALPATH) -elseif (NOT APPLE) - get_filename_component(libs_loc "../Libraries" REALPATH) else() - get_filename_component(libs_loc "../Libraries/macos" REALPATH) + get_filename_component(libs_loc "../Libraries" REALPATH) endif() From e97617c7c5e5e00a06b9b7fb2fa735e3a23e2673 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 8 Sep 2021 13:47:06 +0300 Subject: [PATCH 04/20] Remove unused libs for built-in webrtc audio backends. --- external/webrtc/CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/external/webrtc/CMakeLists.txt b/external/webrtc/CMakeLists.txt index 464b7f6..3a0d9ff 100644 --- a/external/webrtc/CMakeLists.txt +++ b/external/webrtc/CMakeLists.txt @@ -93,10 +93,6 @@ else() target_link_libraries(external_webrtc INTERFACE Secur32.lib # Required for rtc_base/http_common.cc - dmoguids.lib # Required for the built-in WASAPI AEC, see modules/audio_device/BUILD.gn - wmcodecdspuuid.lib - amstrmid.lib - msdmo.lib ) elseif (APPLE) target_link_libraries(external_webrtc From 1ad8c72d783f1763d57aa307616a1fb9d0a9f601 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Thu, 9 Sep 2021 01:14:19 +0400 Subject: [PATCH 05/20] Add missed CMAKE_DL_LIBS --- external/jemalloc/CMakeLists.txt | 2 +- linux_gtk_helper/CMakeLists.txt | 1 + linux_wayland_helper/CMakeLists.txt | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/external/jemalloc/CMakeLists.txt b/external/jemalloc/CMakeLists.txt index 377cf1d..ce696f9 100644 --- a/external/jemalloc/CMakeLists.txt +++ b/external/jemalloc/CMakeLists.txt @@ -42,7 +42,7 @@ if (NOT JEMALLOC_FOUND) target_link_libraries(external_jemalloc_bundled INTERFACE - dl + ${CMAKE_DL_LIBS} pthread ) diff --git a/linux_gtk_helper/CMakeLists.txt b/linux_gtk_helper/CMakeLists.txt index 69973e8..9ffc982 100644 --- a/linux_gtk_helper/CMakeLists.txt +++ b/linux_gtk_helper/CMakeLists.txt @@ -17,6 +17,7 @@ target_compile_definitions(linux_gtk_helper PRIVATE G_LOG_DOMAIN="GtkHelper") target_link_libraries(linux_gtk_helper PUBLIC desktop-app::external_glib + ${CMAKE_DL_LIBS} ) find_package(PkgConfig REQUIRED) diff --git a/linux_wayland_helper/CMakeLists.txt b/linux_wayland_helper/CMakeLists.txt index cccc93d..f0a80ed 100644 --- a/linux_wayland_helper/CMakeLists.txt +++ b/linux_wayland_helper/CMakeLists.txt @@ -18,4 +18,5 @@ target_link_libraries(linux_wayland_helper PUBLIC desktop-app::external_glib desktop-app::external_gsl + ${CMAKE_DL_LIBS} ) From 750861b4ab7433c3cb3706c4392eec743cba74a2 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Thu, 9 Sep 2021 01:14:43 +0400 Subject: [PATCH 06/20] Link drm & zlib statically like before, make GL optional --- external/ffmpeg/CMakeLists.txt | 2 +- external/qt/CMakeLists.txt | 7 ++----- external/zlib/CMakeLists.txt | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/external/ffmpeg/CMakeLists.txt b/external/ffmpeg/CMakeLists.txt index 720e3d7..70d46d5 100644 --- a/external/ffmpeg/CMakeLists.txt +++ b/external/ffmpeg/CMakeLists.txt @@ -72,11 +72,11 @@ else() Xv Xext Xfixes + drm ) target_link_libraries(external_ffmpeg INTERFACE X11 - drm pthread ) endif() diff --git a/external/qt/CMakeLists.txt b/external/qt/CMakeLists.txt index 711dc71..4778988 100644 --- a/external/qt/CMakeLists.txt +++ b/external/qt/CMakeLists.txt @@ -259,6 +259,7 @@ else() target_link_static_libraries(external_qt INTERFACE proxy + epoxy xkbcommon xkbcommon-x11 xcb-glx @@ -276,6 +277,7 @@ else() xcb-util xcb-render-util xcb-keysyms + z ) if (Qt5WaylandClient_FOUND) target_link_libraries(external_qt @@ -288,13 +290,8 @@ else() INTERFACE desktop-app::linux_gtk_helper $ - ) - target_link_libraries(external_qt - INTERFACE fontconfig freetype - EGL - GL xcb X11 X11-xcb diff --git a/external/zlib/CMakeLists.txt b/external/zlib/CMakeLists.txt index b1bf692..15d3b41 100644 --- a/external/zlib/CMakeLists.txt +++ b/external/zlib/CMakeLists.txt @@ -23,5 +23,5 @@ elseif (WIN32) elseif (APPLE) target_link_libraries(external_zlib INTERFACE ${libs_loc}/local/lib/libz.a) else() - target_link_libraries(external_zlib INTERFACE z) + target_link_static_libraries(external_zlib INTERFACE z) endif() From fb97c14bf72d7b94c7d184a47a799c7437a1b948 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 10 Sep 2021 22:20:38 +0300 Subject: [PATCH 07/20] Removed -Wno-range-loop-analysis clang option for macOS. --- options_mac.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/options_mac.cmake b/options_mac.cmake index d4b0543..ae73cc2 100644 --- a/options_mac.cmake +++ b/options_mac.cmake @@ -35,7 +35,6 @@ INTERFACE -Wno-sign-compare -Wno-unknown-attributes -Wno-pragma-system-header-outside-header - -Wno-range-loop-analysis ) if (DESKTOP_APP_SPECIAL_TARGET) From c390b046f0fedfc50f1787dffdb0fb5237b841ac Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Fri, 10 Sep 2021 22:27:46 +0400 Subject: [PATCH 08/20] Don't use glib in gtk/wayland helpers --- linux_gtk_helper/CMakeLists.txt | 3 --- linux_gtk_helper/linux_gtk_helper.cpp | 7 +++---- linux_wayland_helper/CMakeLists.txt | 3 --- linux_wayland_helper/linux_wayland_helper.cpp | 6 +++--- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/linux_gtk_helper/CMakeLists.txt b/linux_gtk_helper/CMakeLists.txt index 9ffc982..753111e 100644 --- a/linux_gtk_helper/CMakeLists.txt +++ b/linux_gtk_helper/CMakeLists.txt @@ -12,11 +12,8 @@ PRIVATE linux_gtk_helper.cpp ) -target_compile_definitions(linux_gtk_helper PRIVATE G_LOG_DOMAIN="GtkHelper") - target_link_libraries(linux_gtk_helper PUBLIC - desktop-app::external_glib ${CMAKE_DL_LIBS} ) diff --git a/linux_gtk_helper/linux_gtk_helper.cpp b/linux_gtk_helper/linux_gtk_helper.cpp index 4cb4ea1..3217d95 100644 --- a/linux_gtk_helper/linux_gtk_helper.cpp +++ b/linux_gtk_helper/linux_gtk_helper.cpp @@ -5,11 +5,10 @@ // https://github.com/desktop-app/legal/blob/master/LEGAL // #include -#include -#include #include #include #include +#include #define LOAD_SYMBOL(handle, func) LoadSymbol(handle, #func, func) @@ -218,7 +217,7 @@ bool LoadLibrary(Handle &handle, const char *name) { if (handle) { return true; } - g_warning("Could not load library '%s': %s", name, dlerror()); + std::cerr << dlerror() << std::endl; return false; } @@ -228,7 +227,7 @@ inline bool LoadSymbol(const Handle &handle, const char *name, Function &func) { ? reinterpret_cast(dlsym(handle.get(), name)) : nullptr; if (const auto error = dlerror()) { - g_warning("Failed to load function '%s': %s", name, error); + std::cerr << error << std::endl; } return (func != nullptr); } diff --git a/linux_wayland_helper/CMakeLists.txt b/linux_wayland_helper/CMakeLists.txt index f0a80ed..7f7d8d3 100644 --- a/linux_wayland_helper/CMakeLists.txt +++ b/linux_wayland_helper/CMakeLists.txt @@ -12,11 +12,8 @@ PRIVATE linux_wayland_helper.cpp ) -target_compile_definitions(linux_wayland_helper PRIVATE G_LOG_DOMAIN="WaylandHelper") - target_link_libraries(linux_wayland_helper PUBLIC - desktop-app::external_glib desktop-app::external_gsl ${CMAKE_DL_LIBS} ) diff --git a/linux_wayland_helper/linux_wayland_helper.cpp b/linux_wayland_helper/linux_wayland_helper.cpp index 5d75469..67c9f0c 100644 --- a/linux_wayland_helper/linux_wayland_helper.cpp +++ b/linux_wayland_helper/linux_wayland_helper.cpp @@ -7,9 +7,9 @@ #include #include #include -#include #include #include +#include #define LOAD_SYMBOL(handle, func) LoadSymbol(handle, #func, func) @@ -184,7 +184,7 @@ bool LoadLibrary(Handle &handle, const char *name) { if (handle) { return true; } - g_warning("Could not load library '%s': %s", name, dlerror()); + std::cerr << dlerror() << std::endl; return false; } @@ -194,7 +194,7 @@ inline bool LoadSymbol(const Handle &handle, const char *name, Function &func) { ? reinterpret_cast(dlsym(handle.get(), name)) : nullptr; if (const auto error = dlerror()) { - g_warning("Failed to load function '%s': %s", name, error); + std::cerr << error << std::endl; } return (func != nullptr); } From aa5afd0a41520404016b94b30e879d9986f7102a Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Fri, 10 Sep 2021 22:28:29 +0400 Subject: [PATCH 09/20] Add glib helper to make it optional for Qt --- CMakeLists.txt | 3 + external/qt/CMakeLists.txt | 3 +- linux_glib_helper/CMakeLists.txt | 28 ++ linux_glib_helper/linux_glib_helper.cpp | 405 ++++++++++++++++++++++++ 4 files changed, 438 insertions(+), 1 deletion(-) create mode 100644 linux_glib_helper/CMakeLists.txt create mode 100644 linux_glib_helper/linux_glib_helper.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index dcb0992..cf0834a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,9 @@ if (LINUX AND Qt5WaylandClient_FOUND) add_subdirectory(linux_wayland_helper) endif() +if (LINUX AND NOT DESKTOP_APP_USE_PACKAGED) + add_subdirectory(linux_glib_helper) +endif() if (LINUX AND NOT DESKTOP_APP_USE_PACKAGED) add_subdirectory(linux_gtk_helper) endif() diff --git a/external/qt/CMakeLists.txt b/external/qt/CMakeLists.txt index 4778988..93d475b 100644 --- a/external/qt/CMakeLists.txt +++ b/external/qt/CMakeLists.txt @@ -290,12 +290,13 @@ else() INTERFACE desktop-app::linux_gtk_helper $ + desktop-app::linux_glib_helper + $ fontconfig freetype xcb X11 X11-xcb - glib-2.0 ${CMAKE_DL_LIBS} pthread ) diff --git a/linux_glib_helper/CMakeLists.txt b/linux_glib_helper/CMakeLists.txt new file mode 100644 index 0000000..f3a4d13 --- /dev/null +++ b/linux_glib_helper/CMakeLists.txt @@ -0,0 +1,28 @@ +# This file is part of Desktop App Toolkit, +# a set of libraries for developing nice desktop applications. +# +# For license and copyright information please follow this link: +# https://github.com/desktop-app/legal/blob/master/LEGAL + +add_library(linux_glib_helper STATIC) +add_library(desktop-app::linux_glib_helper ALIAS linux_glib_helper) + +nice_target_sources(linux_glib_helper ${CMAKE_CURRENT_SOURCE_DIR} +PRIVATE + linux_glib_helper.cpp +) + +target_link_libraries(linux_glib_helper +PUBLIC + ${CMAKE_DL_LIBS} +) + +find_package(PkgConfig REQUIRED) +pkg_check_modules(GLIB2 REQUIRED glib-2.0) +pkg_check_modules(GOBJECT REQUIRED gobject-2.0) + +target_include_directories(linux_glib_helper SYSTEM +PRIVATE + ${GLIB2_INCLUDE_DIRS} + ${GOBJECT_INCLUDE_DIRS} +) diff --git a/linux_glib_helper/linux_glib_helper.cpp b/linux_glib_helper/linux_glib_helper.cpp new file mode 100644 index 0000000..a6d0474 --- /dev/null +++ b/linux_glib_helper/linux_glib_helper.cpp @@ -0,0 +1,405 @@ +// This file is part of Desktop App Toolkit, +// a set of libraries for developing nice desktop applications. +// +// For license and copyright information please follow this link: +// https://github.com/desktop-app/legal/blob/master/LEGAL +// +#include +#include +#include +#include +#include + +#define LOAD_SYMBOL(handle, func) LoadSymbol(handle, #func, func) + +namespace GlibHelper { +namespace { + +void (*g_free)(gpointer mem); +void (*g_log_default_handler)( + const gchar* log_domain, + GLogLevelFlags log_level, + const gchar* message, + gpointer unused_data); +guint (*g_log_set_handler)( + const gchar* log_domain, + GLogLevelFlags log_levels, + GLogFunc log_func, + gpointer user_data); +GMainContext* (*g_main_context_default)(void); +gboolean (*g_main_context_iteration)(GMainContext* context, gboolean may_block); +GMainContext* (*g_main_context_new)(void); +gboolean (*g_main_context_pending)(GMainContext* context); +void (*g_main_context_pop_thread_default)(GMainContext* context); +void (*g_main_context_push_thread_default)(GMainContext* context); +GMainContext* (*g_main_context_ref)(GMainContext* context); +void (*g_main_context_unref)(GMainContext* context); +void (*g_main_context_wakeup)(GMainContext* context); +void (*g_return_if_fail_warning)( + const char* log_domain, + const char* pretty_function, + const char* expression); +void (*g_slist_free)(GSList* list); +void (*g_source_add_poll)(GSource* source, GPollFD* fd); +guint (*g_source_attach)(GSource* source, GMainContext* context); +void (*g_source_destroy)(GSource* source); +GSource* (*g_source_new)(GSourceFuncs* source_funcs, guint struct_size); +void (*g_source_remove_poll)(GSource* source, GPollFD* fd); +void (*g_source_set_can_recurse)(GSource* source, gboolean can_recurse); +void (*g_source_unref)(GSource* source); +int (*g_strcmp0)(const char* str1, const char* str2); + +GParamSpec* (*g_object_class_find_property)( + GObjectClass* oclass, + const gchar* property_name); +void (*g_object_get_valist)( + GObject* object, + const gchar* first_property_name, + va_list var_args); +GObject* (*g_object_new_with_properties)( + GType object_type, + guint n_properties, + const char** names, + const GValue* values); +GObject* (*g_object_new_valist)( + GType object_type, + const gchar* first_property_name, + va_list var_args); +void (*g_object_set_valist)( + GObject* object, + const gchar* first_property_name, + va_list var_args); +void (*g_object_unref)(gpointer object); +gulong (*g_signal_connect_data)( + gpointer instance, + const gchar* detailed_signal, + GCallback c_handler, + gpointer data, + GClosureNotify destroy_data, + GConnectFlags connect_flags); +GTypeInstance* (*g_type_check_instance_cast)( + GTypeInstance* instance, + GType iface_type); +gboolean (*g_type_check_instance_is_a)( + GTypeInstance* instance, + GType iface_type); +gboolean (*g_type_check_instance_is_fundamentally_a)( + GTypeInstance* instance, + GType fundamental_type); +void (*g_type_ensure)(GType type); + +struct HandleDeleter { + void operator()(void *handle) { + dlclose(handle); + } +}; + +using Handle = std::unique_ptr; + +bool LoadLibrary(Handle &handle, const char *name) { + handle = Handle(dlopen(name, RTLD_LAZY | RTLD_NODELETE)); + if (handle) { + return true; + } + std::cerr << dlerror() << std::endl; + return false; +} + +template +inline bool LoadSymbol(const Handle &handle, const char *name, Function &func) { + func = handle + ? reinterpret_cast(dlsym(handle.get(), name)) + : nullptr; + if (const auto error = dlerror()) { + std::cerr << error << std::endl; + } + return (func != nullptr); +} + +bool Resolve() { + static const auto loaded = [&] { + auto lib = Handle(); + return LoadLibrary(lib, "libglib-2.0.so.0") + && LOAD_SYMBOL(lib, g_free) + && LOAD_SYMBOL(lib, g_log_default_handler) + && LOAD_SYMBOL(lib, g_log_set_handler) + && LOAD_SYMBOL(lib, g_main_context_default) + && LOAD_SYMBOL(lib, g_main_context_iteration) + && LOAD_SYMBOL(lib, g_main_context_new) + && LOAD_SYMBOL(lib, g_main_context_pending) + && LOAD_SYMBOL(lib, g_main_context_pop_thread_default) + && LOAD_SYMBOL(lib, g_main_context_push_thread_default) + && LOAD_SYMBOL(lib, g_main_context_ref) + && LOAD_SYMBOL(lib, g_main_context_unref) + && LOAD_SYMBOL(lib, g_main_context_wakeup) + && LOAD_SYMBOL(lib, g_return_if_fail_warning) + && LOAD_SYMBOL(lib, g_slist_free) + && LOAD_SYMBOL(lib, g_source_add_poll) + && LOAD_SYMBOL(lib, g_source_attach) + && LOAD_SYMBOL(lib, g_source_destroy) + && LOAD_SYMBOL(lib, g_source_new) + && LOAD_SYMBOL(lib, g_source_remove_poll) + && LOAD_SYMBOL(lib, g_source_set_can_recurse) + && LOAD_SYMBOL(lib, g_source_unref) + && LOAD_SYMBOL(lib, g_strcmp0) + && LoadLibrary(lib, "libgobject-2.0.so.0") + && LOAD_SYMBOL(lib, g_object_class_find_property) + && LOAD_SYMBOL(lib, g_object_get_valist) + && LOAD_SYMBOL(lib, g_object_new_valist) + && LOAD_SYMBOL(lib, g_object_new_with_properties) + && LOAD_SYMBOL(lib, g_object_set_valist) + && LOAD_SYMBOL(lib, g_object_unref) + && LOAD_SYMBOL(lib, g_signal_connect_data) + && LOAD_SYMBOL(lib, g_type_check_instance_cast) + && LOAD_SYMBOL(lib, g_type_check_instance_is_a) + && LOAD_SYMBOL(lib, g_type_check_instance_is_fundamentally_a) + && LOAD_SYMBOL(lib, g_type_ensure); + }(); + return loaded; +} + +} // namespace +} // namespace GlibHelper + +void g_free(gpointer mem) { + GlibHelper::Resolve(); + GlibHelper::g_free(mem); +} + +void g_log_default_handler( + const gchar* log_domain, + GLogLevelFlags log_level, + const gchar* message, + gpointer unused_data) { + GlibHelper::Resolve(); + GlibHelper::g_log_default_handler( + log_domain, + log_level, + message, + unused_data); +} + +guint g_log_set_handler( + const gchar* log_domain, + GLogLevelFlags log_levels, + GLogFunc log_func, + gpointer user_data) { + GlibHelper::Resolve(); + return GlibHelper::g_log_set_handler( + log_domain, + log_levels, + log_func, + user_data); +} + +GMainContext* g_main_context_default(void) { + GlibHelper::Resolve(); + return GlibHelper::g_main_context_default(); +} + +gboolean g_main_context_iteration(GMainContext* context, gboolean may_block) { + GlibHelper::Resolve(); + return GlibHelper::g_main_context_iteration(context, may_block); +} + +GMainContext* g_main_context_new(void) { + GlibHelper::Resolve(); + return GlibHelper::g_main_context_new(); +} + +gboolean g_main_context_pending(GMainContext* context) { + GlibHelper::Resolve(); + return GlibHelper::g_main_context_pending(context); +} + +void g_main_context_pop_thread_default(GMainContext* context) { + GlibHelper::Resolve(); + GlibHelper::g_main_context_pop_thread_default(context); +} + +void g_main_context_push_thread_default(GMainContext* context) { + GlibHelper::Resolve(); + GlibHelper::g_main_context_push_thread_default(context); +} + +GMainContext* g_main_context_ref(GMainContext* context) { + GlibHelper::Resolve(); + return GlibHelper::g_main_context_ref(context); +} + +void g_main_context_unref(GMainContext* context) { + GlibHelper::Resolve(); + GlibHelper::g_main_context_unref(context); +} + +void g_main_context_wakeup(GMainContext* context) { + GlibHelper::Resolve(); + GlibHelper::g_main_context_wakeup(context); +} + +void g_return_if_fail_warning( + const char* log_domain, + const char* pretty_function, + const char* expression) { + GlibHelper::Resolve(); + GlibHelper::g_return_if_fail_warning( + log_domain, + pretty_function, + expression); +} + +void g_slist_free(GSList* list) { + GlibHelper::Resolve(); + GlibHelper::g_slist_free(list); +} + +void g_source_add_poll(GSource* source, GPollFD* fd) { + GlibHelper::Resolve(); + GlibHelper::g_source_add_poll(source, fd); +} + +guint g_source_attach(GSource* source, GMainContext* context) { + GlibHelper::Resolve(); + return GlibHelper::g_source_attach(source, context); +} + +void g_source_destroy(GSource* source) { + GlibHelper::Resolve(); + GlibHelper::g_source_destroy(source); +} + +GSource* g_source_new(GSourceFuncs* source_funcs, guint struct_size) { + GlibHelper::Resolve(); + return GlibHelper::g_source_new(source_funcs, struct_size); +} + +void g_source_remove_poll(GSource* source, GPollFD* fd) { + GlibHelper::Resolve(); + GlibHelper::g_source_remove_poll(source, fd); +} + +void g_source_set_can_recurse(GSource* source, gboolean can_recurse) { + GlibHelper::Resolve(); + GlibHelper::g_source_set_can_recurse(source, can_recurse); +} + +void g_source_unref(GSource* source) { + GlibHelper::Resolve(); + GlibHelper::g_source_unref(source); +} + +int g_strcmp0(const char* str1, const char* str2) { + GlibHelper::Resolve(); + return GlibHelper::g_strcmp0(str1, str2); +} + +GParamSpec* g_object_class_find_property( + GObjectClass* oclass, + const gchar* property_name) { + GlibHelper::Resolve(); + return GlibHelper::g_object_class_find_property( + oclass, + property_name); +} + +void g_object_get( + gpointer _object, + const gchar *first_property_name, + ...) { + GlibHelper::Resolve(); + + GObject *object = (GObject*) _object; + va_list var_args; + + g_return_if_fail(G_IS_OBJECT(object)); + + va_start(var_args, first_property_name); + GlibHelper::g_object_get_valist(object, first_property_name, var_args); + va_end(var_args); +} + +gpointer g_object_new( + GType object_type, + const gchar *first_property_name, + ...) { + GlibHelper::Resolve(); + + GObject *object; + va_list var_args; + + /* short circuit for calls supplying no properties */ + if (!first_property_name) + return GlibHelper::g_object_new_with_properties(object_type, 0, NULL, NULL); + + va_start(var_args, first_property_name); + object = GlibHelper::g_object_new_valist(object_type, first_property_name, var_args); + va_end(var_args); + + return object; +} + +void g_object_set( + gpointer _object, + const gchar *first_property_name, + ...) { + GlibHelper::Resolve(); + + GObject *object = (GObject*) _object; + va_list var_args; + + g_return_if_fail(G_IS_OBJECT(object)); + + va_start(var_args, first_property_name); + GlibHelper::g_object_set_valist(object, first_property_name, var_args); + va_end(var_args); +} + +void g_object_unref(gpointer object) { + GlibHelper::Resolve(); + GlibHelper::g_object_unref(object); +} + +gulong g_signal_connect_data( + gpointer instance, + const gchar* detailed_signal, + GCallback c_handler, + gpointer data, + GClosureNotify destroy_data, + GConnectFlags connect_flags) { + GlibHelper::Resolve(); + return GlibHelper::g_signal_connect_data( + instance, + detailed_signal, + c_handler, + data, + destroy_data, + connect_flags); +} + +GTypeInstance* g_type_check_instance_cast( + GTypeInstance* instance, + GType iface_type) { + GlibHelper::Resolve(); + return GlibHelper::g_type_check_instance_cast(instance, iface_type); +} + +gboolean g_type_check_instance_is_a( + GTypeInstance* instance, + GType iface_type) { + GlibHelper::Resolve(); + return GlibHelper::g_type_check_instance_is_a(instance, iface_type); +} + +gboolean g_type_check_instance_is_fundamentally_a( + GTypeInstance* instance, + GType fundamental_type) { + GlibHelper::Resolve(); + return GlibHelper::g_type_check_instance_is_fundamentally_a( + instance, + fundamental_type); +} + +void g_type_ensure(GType type) { + GlibHelper::Resolve(); + GlibHelper::g_type_ensure(type); +} From 49ca0abd71bb267505c4bbf39eb5a5fb97761e02 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Fri, 10 Sep 2021 22:28:57 +0400 Subject: [PATCH 10/20] Use -Wl,--as-needed --- options_linux.cmake | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/options_linux.cmake b/options_linux.cmake index f3569bd..04a4008 100644 --- a/options_linux.cmake +++ b/options_linux.cmake @@ -17,6 +17,11 @@ INTERFACE -Wno-sign-compare ) +target_link_options(common_options +INTERFACE + -Wl,--as-needed +) + if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") target_compile_options(common_options INTERFACE From f8e4318937d38525c978e4dd337300b9bd1587a9 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Fri, 10 Sep 2021 22:55:54 +0400 Subject: [PATCH 11/20] nimf doesn't need glib to be linked --- external/nimf_qt5/CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/external/nimf_qt5/CMakeLists.txt b/external/nimf_qt5/CMakeLists.txt index 57f52a6..2f2e55b 100644 --- a/external/nimf_qt5/CMakeLists.txt +++ b/external/nimf_qt5/CMakeLists.txt @@ -23,10 +23,14 @@ else() im-nimf-qt5.cpp ) + find_package(PkgConfig REQUIRED) + pkg_check_modules(GIO REQUIRED gio-2.0) + target_include_directories(external_nimf_qt5 PRIVATE ${nimf_qt5_src} ${libnimf_src} + ${GIO_INCLUDE_DIRS} ) target_compile_definitions(external_nimf_qt5 @@ -41,7 +45,6 @@ else() target_link_libraries(external_nimf_qt5 PRIVATE desktop-app::external_qt - desktop-app::external_glib ${CMAKE_DL_LIBS} ) endif() From 6001968f8524c73312b18b9b715a36ce7082840d Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Sat, 11 Sep 2021 01:57:25 +0400 Subject: [PATCH 12/20] Use glib in desktop-app libs only with dbus --- external/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 118178c..183368e 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -25,7 +25,7 @@ if (LINUX AND NOT DESKTOP_APP_DISABLE_DBUS_INTEGRATION) endif() endif() add_checked_subdirectory(ffmpeg) -if (LINUX) +if (LINUX AND NOT DESKTOP_APP_DISABLE_DBUS_INTEGRATION) add_checked_subdirectory(glib) add_checked_subdirectory(glibmm) endif() From d3e1827ff0dbd8dbea944ddbb7bc9350dabb24af Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Sat, 11 Sep 2021 06:19:50 +0400 Subject: [PATCH 13/20] Don't link hime-im-client, use it with dlopen instead --- external/CMakeLists.txt | 2 +- .../hime_qt/hime_im_client/CMakeLists.txt | 75 +------ .../hime_im_client/hime_im_client_helper.cpp | 208 ++++++++++++++++++ external/qt/qt_static_plugins/CMakeLists.txt | 8 +- .../qt_static_plugins/qt_static_plugins.cpp | 4 +- 5 files changed, 228 insertions(+), 69 deletions(-) create mode 100644 external/hime_qt/hime_im_client/hime_im_client_helper.cpp diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 183368e..58ba80a 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -30,7 +30,7 @@ if (LINUX AND NOT DESKTOP_APP_DISABLE_DBUS_INTEGRATION) add_checked_subdirectory(glibmm) endif() add_checked_subdirectory(gsl) -if (LINUX AND NOT DESKTOP_APP_DISABLE_DBUS_INTEGRATION) +if (LINUX AND NOT DESKTOP_APP_DISABLE_X11_INTEGRATION) add_checked_subdirectory(hime_qt) endif() if (add_hunspell_library) diff --git a/external/hime_qt/hime_im_client/CMakeLists.txt b/external/hime_qt/hime_im_client/CMakeLists.txt index 3fd077f..5392daa 100644 --- a/external/hime_qt/hime_im_client/CMakeLists.txt +++ b/external/hime_qt/hime_im_client/CMakeLists.txt @@ -13,85 +13,28 @@ else() init_target(external_hime_im_client "(external)") set(hime_loc ${third_party_loc}/hime) - set(hime_src ${hime_loc}/src) - set(hime_im_client_src ${hime_src}/im-client) + set(hime_im_client_src ${hime_loc}/src/im-client) - nice_target_sources(external_hime_im_client ${hime_im_client_src} + nice_target_sources(external_hime_im_client ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE - hime-im-client-attr.h - hime-im-client.c - hime-im-client.h - hime-protocol.h - hime-send.c + hime_im_client_helper.cpp ) - nice_target_sources(external_hime_im_client ${hime_src} - PRIVATE - hime-conf.c - util.c - im-addr.c - hime-crypt.c - ) - - find_package(PkgConfig REQUIRED) - pkg_check_modules(GTK REQUIRED gtk+-3.0) - target_include_directories(external_hime_im_client PUBLIC ${hime_im_client_src} - PRIVATE - ${hime_src} - ${hime_src}/IMdkit/include - ${GTK_INCLUDE_DIRS} ) - target_compile_definitions(external_hime_im_client + find_package(PkgConfig REQUIRED) + pkg_check_modules(X11 REQUIRED x11) + + target_include_directories(external_hime_im_client SYSTEM PRIVATE - HIME_BIN_DIR="/usr/bin" - HIME_TABLE_DIR="/usr/share/hime/table" - UNIX=1 - FREEBSD=0 - CLIENT_LIB=1 - GTK_DISABLE_DEPRECATED + ${X11_INCLUDE_DIRS} ) - if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - add_library(external_hime_im_client_options INTERFACE) - - target_compile_options(external_hime_im_client_options - INTERFACE - -Wno-sometimes-uninitialized - ) - - target_link_libraries(external_hime_im_client - PRIVATE - external_hime_im_client_options - ) - endif() - target_link_libraries(external_hime_im_client PRIVATE - desktop-app::external_glib + ${CMAKE_DL_LIBS} ) - - if (DESKTOP_APP_USE_PACKAGED) - pkg_check_modules(X11 REQUIRED IMPORTED_TARGET x11) - - target_link_libraries(external_hime_im_client - PRIVATE - PkgConfig::X11 - ) - else() - pkg_check_modules(X11 REQUIRED x11) - - target_include_directories(external_hime_im_client SYSTEM - PRIVATE - ${X11_INCLUDE_DIRS} - ) - - target_link_libraries(external_hime_im_client - PRIVATE - X11 - ) - endif() endif() diff --git a/external/hime_qt/hime_im_client/hime_im_client_helper.cpp b/external/hime_qt/hime_im_client/hime_im_client_helper.cpp new file mode 100644 index 0000000..7ad8ed6 --- /dev/null +++ b/external/hime_qt/hime_im_client/hime_im_client_helper.cpp @@ -0,0 +1,208 @@ +// This file is part of Desktop App Toolkit, +// a set of libraries for developing nice desktop applications. +// +// For license and copyright information please follow this link: +// https://github.com/desktop-app/legal/blob/master/LEGAL +// +#include +#include +#include +#include +#include + +#define LOAD_SYMBOL(handle, func) LoadSymbol(handle, #func, func) + +namespace HimeHelper { +namespace { + +void (*hime_im_client_close)(HIME_client_handle *handle); +void (*hime_im_client_focus_in)(HIME_client_handle *handle); +void (*hime_im_client_focus_out)(HIME_client_handle *handle); +void (*hime_im_client_focus_out2)(HIME_client_handle *handle, char **rstr); +int (*hime_im_client_forward_key_press)( + HIME_client_handle *handle, + const KeySym key, + const uint32_t state, + char **rstr); +int (*hime_im_client_forward_key_release)( + HIME_client_handle *handle, + const KeySym key, + const uint32_t state, + char **rstr); +int (*hime_im_client_get_preedit)( + HIME_client_handle *handle, + char **str, + HIME_PREEDIT_ATTR att[], + int *cursor, + int *sub_comp_len); +HIME_client_handle *(*hime_im_client_open)(Display *display); +void (*hime_im_client_reset)(HIME_client_handle *handle); +void (*hime_im_client_set_cursor_location)( + HIME_client_handle *handle, + const int x, + const int y); +void (*hime_im_client_set_flags)( + HIME_client_handle *handle, + const int flags, + int *ret_flags); +void (*hime_im_client_set_client_window)( + HIME_client_handle *handle, + const Window win); +void (*hime_im_client_set_window)(HIME_client_handle *handle, Window win); + +struct HandleDeleter { + void operator()(void *handle) { + dlclose(handle); + } +}; + +using Handle = std::unique_ptr; + +bool LoadLibrary(Handle &handle, const char *name) { + handle = Handle(dlopen(name, RTLD_LAZY | RTLD_NODELETE)); + if (handle) { + return true; + } + std::cerr << dlerror() << std::endl; + return false; +} + +template +inline bool LoadSymbol(const Handle &handle, const char *name, Function &func) { + func = handle + ? reinterpret_cast(dlsym(handle.get(), name)) + : nullptr; + if (const auto error = dlerror()) { + std::cerr << error << std::endl; + } + return (func != nullptr); +} + +bool Resolve() { + static const auto loaded = [&] { + auto lib = Handle(); + return LoadLibrary(lib, "libhime-im-client.so.1") + && LOAD_SYMBOL(lib, hime_im_client_close) + && LOAD_SYMBOL(lib, hime_im_client_focus_in) + && LOAD_SYMBOL(lib, hime_im_client_focus_out) + && LOAD_SYMBOL(lib, hime_im_client_focus_out2) + && LOAD_SYMBOL(lib, hime_im_client_forward_key_press) + && LOAD_SYMBOL(lib, hime_im_client_forward_key_release) + && LOAD_SYMBOL(lib, hime_im_client_get_preedit) + && LOAD_SYMBOL(lib, hime_im_client_open) + && LOAD_SYMBOL(lib, hime_im_client_reset) + && LOAD_SYMBOL(lib, hime_im_client_set_cursor_location) + && LOAD_SYMBOL(lib, hime_im_client_set_flags) + && (LOAD_SYMBOL(lib, hime_im_client_set_client_window) + || LOAD_SYMBOL(lib, hime_im_client_set_window)); + }(); + return loaded; +} + +} // namespace +} // namespace HimeHelper + +void hime_im_client_close(HIME_client_handle *handle) { + HimeHelper::Resolve(); + HimeHelper::hime_im_client_close(handle); +} + +void hime_im_client_focus_in(HIME_client_handle *handle) { + HimeHelper::Resolve(); + HimeHelper::hime_im_client_focus_in(handle); +} + +void hime_im_client_focus_out(HIME_client_handle *handle) { + HimeHelper::Resolve(); + HimeHelper::hime_im_client_focus_out(handle); +} + +void hime_im_client_focus_out2(HIME_client_handle *handle, char **rstr) { + HimeHelper::Resolve(); + HimeHelper::hime_im_client_focus_out2(handle, rstr); +} + +int hime_im_client_forward_key_press( + HIME_client_handle *handle, + const KeySym key, + const uint32_t state, + char **rstr) { + HimeHelper::Resolve(); + return HimeHelper::hime_im_client_forward_key_press( + handle, + key, + state, + rstr); +} + +int hime_im_client_forward_key_release( + HIME_client_handle *handle, + const KeySym key, + const uint32_t state, + char **rstr) { + HimeHelper::Resolve(); + return HimeHelper::hime_im_client_forward_key_release( + handle, + key, + state, + rstr); +} + +int hime_im_client_get_preedit( + HIME_client_handle *handle, + char **str, + HIME_PREEDIT_ATTR att[], + int *cursor, + int *sub_comp_len) { + HimeHelper::Resolve(); + return HimeHelper::hime_im_client_get_preedit( + handle, + str, + att, + cursor, + sub_comp_len); +} + +HIME_client_handle *hime_im_client_open(Display *display) { + HimeHelper::Resolve(); + return HimeHelper::hime_im_client_open(display); +} + +void hime_im_client_reset(HIME_client_handle *handle) { + HimeHelper::Resolve(); + HimeHelper::hime_im_client_reset(handle); +} + +void hime_im_client_set_cursor_location( + HIME_client_handle *handle, + const int x, + const int y) { + HimeHelper::Resolve(); + HimeHelper::hime_im_client_set_cursor_location( + handle, + x, + y); +} + +void hime_im_client_set_flags( + HIME_client_handle *handle, + const int flags, + int *ret_flags) { + HimeHelper::Resolve(); + HimeHelper::hime_im_client_set_flags( + handle, + flags, + ret_flags); +} + +void hime_im_client_set_client_window( + HIME_client_handle *handle, + const Window win) { + HimeHelper::Resolve(); + HimeHelper::hime_im_client_set_client_window(handle, win); +} + +void hime_im_client_set_window(HIME_client_handle *handle, Window win) { + HimeHelper::Resolve(); + HimeHelper::hime_im_client_set_window(handle, win); +} diff --git a/external/qt/qt_static_plugins/CMakeLists.txt b/external/qt/qt_static_plugins/CMakeLists.txt index 8764174..4cbb27b 100644 --- a/external/qt/qt_static_plugins/CMakeLists.txt +++ b/external/qt/qt_static_plugins/CMakeLists.txt @@ -28,7 +28,6 @@ if (LINUX) target_link_libraries(external_qt_static_plugins PUBLIC desktop-app::external_fcitx_qt5 - desktop-app::external_hime_qt ) if (NOT DESKTOP_APP_DISABLE_X11_INTEGRATION) @@ -38,4 +37,11 @@ if (LINUX) ) endif() endif() + + if (NOT DESKTOP_APP_DISABLE_X11_INTEGRATION) + target_link_libraries(external_qt_static_plugins + PUBLIC + desktop-app::external_hime_qt + ) + endif() endif() diff --git a/external/qt/qt_static_plugins/qt_static_plugins.cpp b/external/qt/qt_static_plugins/qt_static_plugins.cpp index 341cc99..4ed1a8f 100644 --- a/external/qt/qt_static_plugins/qt_static_plugins.cpp +++ b/external/qt/qt_static_plugins/qt_static_plugins.cpp @@ -51,7 +51,9 @@ Q_IMPORT_PLUGIN(QFcitxPlatformInputContextPlugin) #ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION Q_IMPORT_PLUGIN(QFcitx5PlatformInputContextPlugin) #endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION -Q_IMPORT_PLUGIN(QHimePlatformInputContextPlugin) #endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION +#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION +Q_IMPORT_PLUGIN(QHimePlatformInputContextPlugin) +#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION #endif // !DESKTOP_APP_USE_PACKAGED || DESKTOP_APP_USE_PACKAGED_LAZY #endif // Q_OS_UNIX && !Q_OS_MAC From 03fad319f5911419e736c26f9458598a4d1e55f8 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Sun, 12 Sep 2021 00:58:47 +0400 Subject: [PATCH 14/20] Use clang to build jemalloc (it crashes with gcc) --- external/jemalloc/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/jemalloc/CMakeLists.txt b/external/jemalloc/CMakeLists.txt index ce696f9..642ee2c 100644 --- a/external/jemalloc/CMakeLists.txt +++ b/external/jemalloc/CMakeLists.txt @@ -23,7 +23,7 @@ if (NOT JEMALLOC_FOUND) include(ExternalProject) ExternalProject_Add(jemalloc SOURCE_DIR ${jemalloc_loc} - CONFIGURE_COMMAND cd "${jemalloc_loc}" && ./autogen.sh + CONFIGURE_COMMAND cd "${jemalloc_loc}" && CC=clang CXX=clang++ ./autogen.sh INSTALL_COMMAND : BUILD_IN_SOURCE 1 BUILD_BYPRODUCTS ${jemalloc_loc}/lib/libjemalloc.a From 7ca99a4d080cd63fb266e7d396ac7834c37755c0 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Sun, 12 Sep 2021 01:46:54 +0400 Subject: [PATCH 15/20] Adjust --as-needed for allocation tracer and jemalloc --- external/jemalloc/CMakeLists.txt | 8 +++++++- options_linux.cmake | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/external/jemalloc/CMakeLists.txt b/external/jemalloc/CMakeLists.txt index 642ee2c..b9394a8 100644 --- a/external/jemalloc/CMakeLists.txt +++ b/external/jemalloc/CMakeLists.txt @@ -12,7 +12,13 @@ if (DESKTOP_APP_USE_PACKAGED) pkg_check_modules(JEMALLOC IMPORTED_TARGET jemalloc) if (JEMALLOC_FOUND) - target_link_libraries(external_jemalloc INTERFACE PkgConfig::JEMALLOC) + target_link_libraries(external_jemalloc + INTERFACE + -Wl,--no-as-needed + PkgConfig::JEMALLOC + ${JEMALLOC_LINK_LIBRARIES} + -Wl,--as-needed + ) endif() endif() diff --git a/options_linux.cmake b/options_linux.cmake index 04a4008..48d2211 100644 --- a/options_linux.cmake +++ b/options_linux.cmake @@ -64,7 +64,7 @@ if (DESKTOP_APP_USE_ALLOCATION_TRACER) -Wl,-wrap,aligned_alloc -Wl,-wrap,posix_memalign -Wl,-wrap,free - -Wl,--no-as-needed,-lrt + -Wl,--no-as-needed,-lrt,--as-needed ) target_link_libraries(common_options INTERFACE From 2827dd851edfca602cbb98cae6b3dbd123c4aa39 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 12 Sep 2021 01:39:17 +0300 Subject: [PATCH 16/20] Force -fPIE flags in jemalloc build. --- external/jemalloc/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/jemalloc/CMakeLists.txt b/external/jemalloc/CMakeLists.txt index b9394a8..c720bd6 100644 --- a/external/jemalloc/CMakeLists.txt +++ b/external/jemalloc/CMakeLists.txt @@ -29,7 +29,7 @@ if (NOT JEMALLOC_FOUND) include(ExternalProject) ExternalProject_Add(jemalloc SOURCE_DIR ${jemalloc_loc} - CONFIGURE_COMMAND cd "${jemalloc_loc}" && CC=clang CXX=clang++ ./autogen.sh + CONFIGURE_COMMAND cd "${jemalloc_loc}" && CC=clang CXX=clang++ EXTRA_CFLAGS=-fPIE EXTRA_CXXFLAGS=-fPIE ./autogen.sh INSTALL_COMMAND : BUILD_IN_SOURCE 1 BUILD_BYPRODUCTS ${jemalloc_loc}/lib/libjemalloc.a From c94b46f2fd99341a8217fe74b250bd0d0827b060 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Sun, 12 Sep 2021 03:26:43 +0400 Subject: [PATCH 17/20] Add missed webrtc shared dependencies --- external/webrtc/CMakeLists.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/external/webrtc/CMakeLists.txt b/external/webrtc/CMakeLists.txt index 3a0d9ff..7e4deb0 100644 --- a/external/webrtc/CMakeLists.txt +++ b/external/webrtc/CMakeLists.txt @@ -111,5 +111,12 @@ else() Xrender Xtst ) + target_link_libraries(external_webrtc + INTERFACE + X11 + gio-2.0 + gobject-2.0 + glib-2.0 + ) endif() endif() From a4257299f6af3d1e59304aa716251ed9139a40dd Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Wed, 15 Sep 2021 12:40:09 +0400 Subject: [PATCH 18/20] Link libgcc statically in pair with libstdc++ --- options_linux.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/options_linux.cmake b/options_linux.cmake index 48d2211..eef76c8 100644 --- a/options_linux.cmake +++ b/options_linux.cmake @@ -78,6 +78,7 @@ if (NOT DESKTOP_APP_USE_PACKAGED) target_link_options(common_options INTERFACE -static-libstdc++ + -static-libgcc ) elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") target_link_static_libraries(common_options From 3c8e9a0c759a136ac8c5999b7e5c2c0c43319887 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Wed, 15 Sep 2021 22:45:50 +0400 Subject: [PATCH 19/20] Don't link anything for jemalloc on FreeBSD --- external/jemalloc/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/external/jemalloc/CMakeLists.txt b/external/jemalloc/CMakeLists.txt index c720bd6..0c0f0be 100644 --- a/external/jemalloc/CMakeLists.txt +++ b/external/jemalloc/CMakeLists.txt @@ -7,6 +7,10 @@ add_library(external_jemalloc INTERFACE IMPORTED GLOBAL) add_library(desktop-app::external_jemalloc ALIAS external_jemalloc) +if (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") + return() +endif() + if (DESKTOP_APP_USE_PACKAGED) find_package(PkgConfig REQUIRED) pkg_check_modules(JEMALLOC IMPORTED_TARGET jemalloc) From dbc1e4fb358faeda2abec4f32336eab1d7552922 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Sun, 19 Sep 2021 09:29:52 +0400 Subject: [PATCH 20/20] Use whole-program optimization to eliminate linking of unused symbols --- options_linux.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/options_linux.cmake b/options_linux.cmake index eef76c8..2797c7b 100644 --- a/options_linux.cmake +++ b/options_linux.cmake @@ -95,6 +95,7 @@ if (NOT DESKTOP_APP_USE_PACKAGED) INTERFACE -pthread -rdynamic + -fwhole-program ) endif()