From d1a7e08aa044c2ace3c6b17ddf83cf971b31c46a Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 28 Apr 2021 22:46:12 +0400 Subject: [PATCH 01/29] Don't link wayland-client statically. --- external/kwayland/CMakeLists.txt | 11 ++++++----- external/qt/CMakeLists.txt | 9 +++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/external/kwayland/CMakeLists.txt b/external/kwayland/CMakeLists.txt index beb28f9..2030048 100644 --- a/external/kwayland/CMakeLists.txt +++ b/external/kwayland/CMakeLists.txt @@ -25,14 +25,15 @@ else() /usr/local/include/KF5/KWayland/Client ) - target_link_static_libraries(external_kwayland - INTERFACE - wayland-client - ffi - ) + # target_link_static_libraries(external_kwayland + # INTERFACE + # wayland-client # We load system libwayland-*.so dynamically now. + # ffi + # ) target_link_libraries(external_kwayland INTERFACE + $ # For wayland-* stubs. ${qt_loc}/lib/libQt5Concurrent.a desktop-app::external_qt ) diff --git a/external/qt/CMakeLists.txt b/external/qt/CMakeLists.txt index 40b25b0..2881abb 100644 --- a/external/qt/CMakeLists.txt +++ b/external/qt/CMakeLists.txt @@ -347,9 +347,9 @@ else() endif() target_link_static_libraries(external_qt INTERFACE - wayland-egl - wayland-cursor - wayland-client + # wayland-egl # We load system libwayland-*.so dynamically now. + # wayland-cursor + # wayland-client xkbcommon xkbcommon-x11 xcb-glx @@ -367,7 +367,7 @@ else() xcb-util xcb-render-util xcb-keysyms - ffi + # ffi ) if (DESKTOP_APP_USE_GLIBC_WRAPS) target_link_libraries(external_qt @@ -378,6 +378,7 @@ else() endif() target_link_libraries(external_qt INTERFACE + $ # For wayland-* stubs. fontconfig freetype EGL From cd19d4af120b8bfd8c695836d37c1a0579ee4ef6 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 15 Apr 2021 16:49:01 +0400 Subject: [PATCH 02/29] Add external rnnoise library. --- external/CMakeLists.txt | 1 + external/rnnoise/CMakeLists.txt | 52 +++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 external/rnnoise/CMakeLists.txt diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index fb76b5d..bce6cf7 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -55,6 +55,7 @@ endif() add_checked_subdirectory(qr_code_generator) add_checked_subdirectory(ranges) add_checked_subdirectory(rlottie) +add_checked_subdirectory(rnnoise) if (APPLE) add_checked_subdirectory(sp_media_key_tap) endif() diff --git a/external/rnnoise/CMakeLists.txt b/external/rnnoise/CMakeLists.txt new file mode 100644 index 0000000..70f09bb --- /dev/null +++ b/external/rnnoise/CMakeLists.txt @@ -0,0 +1,52 @@ +# 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 + +if (DESKTOP_APP_USE_PACKAGED) + add_library(external_rnnoise INTERFACE IMPORTED GLOBAL) + add_library(desktop-app::external_rnnoise ALIAS external_rnnoise) + + find_package(PkgConfig REQUIRED) + pkg_check_modules(RNNOISE IMPORTED_TARGET rnnoise) + + target_link_libraries(external_rnnoise INTERFACE PkgConfig::RNNOISE) +else() + add_library(external_rnnoise STATIC IMPORTED GLOBAL) + add_library(desktop-app::external_rnnoise ALIAS external_rnnoise) + + if (WIN32) + target_include_directories(external_rnnoise + INTERFACE + ${libs_loc}/rnnoise/include + ) + if (build_win64) + set(opus_config_folder x64) + else() + set(opus_config_folder Win32) + endif() + set(opus_lib_loc ${libs_loc}/rnnoise/out) + set_target_properties(external_rnnoise PROPERTIES + IMPORTED_LOCATION "${opus_lib_loc}/Release/rnnoise.lib" + IMPORTED_LOCATION_DEBUG "${opus_lib_loc}/Debug/rnnoise.lib" + ) + elseif (APPLE) + target_include_directories(external_rnnoise + INTERFACE + /usr/local/macos/include/rnnoise + ) + set_target_properties(external_rnnoise PROPERTIES + IMPORTED_LOCATION /usr/local/macos/lib/librnnoise.a + ) + else() + target_include_directories(external_rnnoise + INTERFACE + /usr/local/include/rnnoise + ) + find_library(RNNOISE_LIBRARY librnnoise.a) + set_target_properties(external_rnnoise PROPERTIES + IMPORTED_LOCATION "${RNNOISE_LIBRARY}" + ) + endif() +endif() From 57540cc1db9ee107dc82d9e9952d3b059b1da49c Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 19 Apr 2021 13:40:40 +0400 Subject: [PATCH 03/29] Link rnnoise from Libraries on macOS. --- external/rnnoise/CMakeLists.txt | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/external/rnnoise/CMakeLists.txt b/external/rnnoise/CMakeLists.txt index 70f09bb..f36d467 100644 --- a/external/rnnoise/CMakeLists.txt +++ b/external/rnnoise/CMakeLists.txt @@ -16,28 +16,24 @@ else() add_library(external_rnnoise STATIC IMPORTED GLOBAL) add_library(desktop-app::external_rnnoise ALIAS external_rnnoise) + set(rnnoise_lib_loc ${libs_loc}/rnnoise/out) if (WIN32) target_include_directories(external_rnnoise INTERFACE ${libs_loc}/rnnoise/include ) - if (build_win64) - set(opus_config_folder x64) - else() - set(opus_config_folder Win32) - endif() - set(opus_lib_loc ${libs_loc}/rnnoise/out) set_target_properties(external_rnnoise PROPERTIES - IMPORTED_LOCATION "${opus_lib_loc}/Release/rnnoise.lib" - IMPORTED_LOCATION_DEBUG "${opus_lib_loc}/Debug/rnnoise.lib" + IMPORTED_LOCATION "${rnnoise_lib_loc}/Release/rnnoise.lib" + IMPORTED_LOCATION_DEBUG "${rnnoise_lib_loc}/Debug/rnnoise.lib" ) elseif (APPLE) target_include_directories(external_rnnoise INTERFACE - /usr/local/macos/include/rnnoise + ${libs_loc}/rnnoise/include ) set_target_properties(external_rnnoise PROPERTIES - IMPORTED_LOCATION /usr/local/macos/lib/librnnoise.a + IMPORTED_LOCATION "${rnnoise_lib_loc}/Release/librnnoise.a" + IMPORTED_LOCATION_DEBUG "${rnnoise_lib_loc}/Debug/librnnoise.a" ) else() target_include_directories(external_rnnoise From 32273e3fb1a88a32ee8d2a6769317154b8b5953a Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 27 Apr 2021 19:34:56 +0400 Subject: [PATCH 04/29] Fix build with rnnoise on Linux. --- external/rnnoise/CMakeLists.txt | 2 +- external/webrtc/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/external/rnnoise/CMakeLists.txt b/external/rnnoise/CMakeLists.txt index f36d467..601c98b 100644 --- a/external/rnnoise/CMakeLists.txt +++ b/external/rnnoise/CMakeLists.txt @@ -38,7 +38,7 @@ else() else() target_include_directories(external_rnnoise INTERFACE - /usr/local/include/rnnoise + /usr/local/include ) find_library(RNNOISE_LIBRARY librnnoise.a) set_target_properties(external_rnnoise PROPERTIES diff --git a/external/webrtc/CMakeLists.txt b/external/webrtc/CMakeLists.txt index 477fc6f..7809d79 100644 --- a/external/webrtc/CMakeLists.txt +++ b/external/webrtc/CMakeLists.txt @@ -60,6 +60,7 @@ else() INTERFACE ${webrtc_loc} ${webrtc_loc}/third_party/abseil-cpp + ${webrtc_loc}/third_party/libyuv/include ) set(webrtc_libs @@ -71,7 +72,6 @@ else() ${webrtc_loc}/sdk/objc ${webrtc_loc}/sdk/objc/base ${webrtc_loc}/sdk/objc/components/video_codec - ${webrtc_loc}/third_party/libyuv/include ) endif() foreach (lib ${webrtc_libs}) From c606fca6a6c29c672b1e8abe3b25195253c67982 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 22 Apr 2021 17:29:26 +0400 Subject: [PATCH 05/29] Fix configure on x64 Native Tools Command Prompt. --- variables.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/variables.cmake b/variables.cmake index 7e683a7..22d410a 100644 --- a/variables.cmake +++ b/variables.cmake @@ -75,6 +75,8 @@ if (WIN32) set(build_win64 1) set(build_winstore 1) set(build_winstore64 1) + elseif (CMAKE_SIZEOF_VOID_P EQUAL 8) + set(build_win64 1) endif() elseif (APPLE) if (DESKTOP_APP_SPECIAL_TARGET STREQUAL "osx") From 4e7ec4e0e1ce2d30e0a4dbff6b801862d763cdec Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Thu, 29 Apr 2021 18:51:10 +0400 Subject: [PATCH 06/29] Move wayland helper from lib_base here --- CMakeLists.txt | 5 + external/kwayland/CMakeLists.txt | 9 +- external/qt/CMakeLists.txt | 12 +- linux_wayland_helper/CMakeLists.txt | 21 + linux_wayland_helper/linux_wayland_helper.cpp | 619 ++++++++++++++++++ 5 files changed, 654 insertions(+), 12 deletions(-) create mode 100644 linux_wayland_helper/CMakeLists.txt create mode 100644 linux_wayland_helper/linux_wayland_helper.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 037b2eb..cc13d1b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,3 +8,8 @@ add_subdirectory(external) if (DESKTOP_APP_USE_GLIBC_WRAPS) add_subdirectory(linux_glibc_wraps) endif() +if (LINUX + AND NOT DESKTOP_APP_USE_PACKAGED + AND NOT DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION) + add_subdirectory(linux_wayland_helper) +endif() diff --git a/external/kwayland/CMakeLists.txt b/external/kwayland/CMakeLists.txt index 2030048..60988aa 100644 --- a/external/kwayland/CMakeLists.txt +++ b/external/kwayland/CMakeLists.txt @@ -25,15 +25,10 @@ else() /usr/local/include/KF5/KWayland/Client ) - # target_link_static_libraries(external_kwayland - # INTERFACE - # wayland-client # We load system libwayland-*.so dynamically now. - # ffi - # ) - target_link_libraries(external_kwayland INTERFACE - $ # For wayland-* stubs. + desktop-app::linux_wayland_helper + $ ${qt_loc}/lib/libQt5Concurrent.a desktop-app::external_qt ) diff --git a/external/qt/CMakeLists.txt b/external/qt/CMakeLists.txt index 2881abb..f69e42d 100644 --- a/external/qt/CMakeLists.txt +++ b/external/qt/CMakeLists.txt @@ -347,9 +347,6 @@ else() endif() target_link_static_libraries(external_qt INTERFACE - # wayland-egl # We load system libwayland-*.so dynamically now. - # wayland-cursor - # wayland-client xkbcommon xkbcommon-x11 xcb-glx @@ -367,7 +364,6 @@ else() xcb-util xcb-render-util xcb-keysyms - # ffi ) if (DESKTOP_APP_USE_GLIBC_WRAPS) target_link_libraries(external_qt @@ -376,9 +372,15 @@ else() $ ) endif() + if (Qt5WaylandClient_FOUND) + target_link_libraries(external_qt + INTERFACE + desktop-app::linux_wayland_helper + $ + ) + endif() target_link_libraries(external_qt INTERFACE - $ # For wayland-* stubs. fontconfig freetype EGL diff --git a/linux_wayland_helper/CMakeLists.txt b/linux_wayland_helper/CMakeLists.txt new file mode 100644 index 0000000..cccc93d --- /dev/null +++ b/linux_wayland_helper/CMakeLists.txt @@ -0,0 +1,21 @@ +# 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_wayland_helper STATIC) +add_library(desktop-app::linux_wayland_helper ALIAS linux_wayland_helper) + +nice_target_sources(linux_wayland_helper ${CMAKE_CURRENT_SOURCE_DIR} +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 +) diff --git a/linux_wayland_helper/linux_wayland_helper.cpp b/linux_wayland_helper/linux_wayland_helper.cpp new file mode 100644 index 0000000..5f01a4b --- /dev/null +++ b/linux_wayland_helper/linux_wayland_helper.cpp @@ -0,0 +1,619 @@ +// 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 +#include + +#define LOAD_SYMBOL(handle, func) LoadSymbol(handle, #func, func) + +namespace Wayland { +namespace { + +constexpr auto WL_CLOSURE_MAX_ARGS = 20; + +struct wl_egl_window *(*wl_egl_window_create)( + struct wl_surface *surface, + int width, + int height); +void (*wl_egl_window_destroy)(struct wl_egl_window *egl_window); +void (*wl_egl_window_resize)( + struct wl_egl_window *egl_window, + int width, + int height, + int dx, + int dy); +void (*wl_egl_window_get_attached_size)( + struct wl_egl_window *egl_window, + int *width, + int *height); + +struct wl_buffer *(*wl_cursor_image_get_buffer)( + struct wl_cursor_image *image); +struct wl_cursor_theme *(*wl_cursor_theme_load)( + const char *name, + int size, + struct wl_shm *shm); +void (*wl_cursor_theme_destroy)(struct wl_cursor_theme *theme); +struct wl_cursor *(*wl_cursor_theme_get_cursor)( + struct wl_cursor_theme *theme, + const char *name); + +int (*wl_cursor_frame_and_duration)( + struct wl_cursor *cursor, + uint32_t time, + uint32_t *duration); + +void (*wl_proxy_destroy)(struct wl_proxy *proxy); +uint32_t (*wl_proxy_get_version)(struct wl_proxy *proxy); +void (*wl_array_init)(struct wl_array *array); +void (*wl_array_release)(struct wl_array *array); +void *(*wl_array_add)(struct wl_array *array, size_t size); +int (*wl_proxy_add_listener)( + struct wl_proxy *proxy, + void (**implementation)(void), + void *data); +void (*wl_proxy_set_user_data)(struct wl_proxy *proxy, void *user_data); +void *(*wl_proxy_get_user_data)(struct wl_proxy *proxy); +int (*wl_display_get_fd)(struct wl_display *display); +int (*wl_display_get_error)(struct wl_display *display); +int (*wl_display_dispatch)(struct wl_display *display); +struct wl_event_queue *(*wl_display_create_queue)(struct wl_display *display); +int (*wl_display_dispatch_queue_pending)( + struct wl_display *display, + struct wl_event_queue *queue); +int (*wl_display_prepare_read_queue)( + struct wl_display *display, + struct wl_event_queue *queue); +int (*wl_display_flush)(struct wl_display *display); +void (*wl_display_cancel_read)(struct wl_display *display); +int (*wl_display_read_events)(struct wl_display *display); +void (*wl_event_queue_destroy)(struct wl_event_queue *queue); +int (*wl_display_prepare_read)(struct wl_display *display); +int (*wl_display_dispatch_pending)(struct wl_display *display); +struct wl_display *(*wl_display_connect)(const char *name); +struct wl_display *(*wl_display_connect_to_fd)(int fd); +void (*wl_display_disconnect)(struct wl_display *display); +void *(*wl_proxy_create_wrapper)(void *proxy); +void (*wl_proxy_wrapper_destroy)(void *proxy_wrapper); +void (*wl_proxy_set_queue)(struct wl_proxy *proxy, struct wl_event_queue *queue); +int (*wl_display_roundtrip)(struct wl_display *display); +struct wl_proxy *(*wl_proxy_marshal_array_constructor)( + struct wl_proxy *proxy, + uint32_t opcode, + union wl_argument *args, + const struct wl_interface *interface); +struct wl_proxy *(*wl_proxy_marshal_array_constructor_versioned)( + struct wl_proxy *proxy, + uint32_t opcode, + union wl_argument *args, + const struct wl_interface *interface, + uint32_t version); +uint32_t (*wl_proxy_get_id)(struct wl_proxy *proxy); +const void *(*wl_proxy_get_listener)(struct wl_proxy *proxy); + +struct argument_details { + char type; + int nullable; +}; + +const char *get_next_argument( + const char *signature, + struct argument_details *details) { + details->nullable = 0; + for(; *signature; ++signature) { + switch(*signature) { + case 'i': + case 'u': + case 'f': + case 's': + case 'o': + case 'n': + case 'a': + case 'h': + details->type = *signature; + return signature + 1; + case '?': + details->nullable = 1; + } + } + details->type = '\0'; + return signature; +} + +void wl_argument_from_va_list( + const char *signature, + union wl_argument *args, + int count, + va_list ap) { + int i; + const char *sig_iter; + struct argument_details arg; + + sig_iter = signature; + for (i = 0; i < count; i++) { + sig_iter = get_next_argument(sig_iter, &arg); + + switch(arg.type) { + case 'i': + args[i].i = va_arg(ap, int32_t); + break; + case 'u': + args[i].u = va_arg(ap, uint32_t); + break; + case 'f': + args[i].f = va_arg(ap, wl_fixed_t); + break; + case 's': + args[i].s = va_arg(ap, const char *); + break; + case 'o': + args[i].o = va_arg(ap, struct wl_object *); + break; + case 'n': + args[i].o = va_arg(ap, struct wl_object *); + break; + case 'a': + args[i].a = va_arg(ap, struct wl_array *); + break; + case 'h': + args[i].h = va_arg(ap, int32_t); + break; + case '\0': + return; + } + } +} + +bool LoadLibrary(void **handle, const char *name) { + *handle = dlopen(name, RTLD_LAZY | RTLD_NODELETE); + if (!*handle) { + g_warning("Could not load '%s': %s", name, dlerror()); + } + return (*handle != nullptr); +} + +template +inline bool LoadSymbol(void *handle, const char *name, Function &func) { + func = reinterpret_cast(dlsym(handle, name)); + if (const auto error = dlerror()) { + g_warning("Failed to load '%1' function: %2", name, error); + } + return (func != nullptr); +} + +bool Resolve() { + static const auto loaded = [&] { + void *egl, *cursor, *client = nullptr; + gsl::finally([&] { + if (egl) { + dlclose(egl); + } + if (cursor) { + dlclose(cursor); + } + if (client) { + dlclose(client); + } + }); + return LoadLibrary(&egl, "libwayland-egl.so.1") + && LOAD_SYMBOL(egl, wl_egl_window_create) + && LOAD_SYMBOL(egl, wl_egl_window_destroy) + && LOAD_SYMBOL(egl, wl_egl_window_resize) + && LOAD_SYMBOL(egl, wl_egl_window_get_attached_size) + && LoadLibrary(&cursor, "libwayland-cursor.so.0") + && LOAD_SYMBOL(cursor, wl_cursor_image_get_buffer) + && LOAD_SYMBOL(cursor, wl_cursor_theme_load) + && LOAD_SYMBOL(cursor, wl_cursor_theme_destroy) + && LOAD_SYMBOL(cursor, wl_cursor_theme_get_cursor) + && LOAD_SYMBOL(cursor, wl_cursor_frame_and_duration) + && LoadLibrary(&client, "libwayland-client.so.0") + && LOAD_SYMBOL(client, wl_proxy_destroy) + && LOAD_SYMBOL(client, wl_proxy_get_version) + && LOAD_SYMBOL(client, wl_array_init) + && LOAD_SYMBOL(client, wl_array_release) + && LOAD_SYMBOL(client, wl_array_add) + && LOAD_SYMBOL(client, wl_proxy_add_listener) + && LOAD_SYMBOL(client, wl_proxy_set_user_data) + && LOAD_SYMBOL(client, wl_proxy_get_user_data) + && LOAD_SYMBOL(client, wl_display_get_fd) + && LOAD_SYMBOL(client, wl_display_get_error) + && LOAD_SYMBOL(client, wl_display_dispatch) + && LOAD_SYMBOL(client, wl_display_create_queue) + && LOAD_SYMBOL(client, wl_display_dispatch_queue_pending) + && LOAD_SYMBOL(client, wl_display_prepare_read_queue) + && LOAD_SYMBOL(client, wl_display_flush) + && LOAD_SYMBOL(client, wl_display_cancel_read) + && LOAD_SYMBOL(client, wl_display_read_events) + && LOAD_SYMBOL(client, wl_event_queue_destroy) + && LOAD_SYMBOL(client, wl_display_prepare_read) + && LOAD_SYMBOL(client, wl_display_dispatch_pending) + && LOAD_SYMBOL(client, wl_display_connect) + && LOAD_SYMBOL(client, wl_display_connect_to_fd) + && LOAD_SYMBOL(client, wl_display_disconnect) + && LOAD_SYMBOL(client, wl_proxy_create_wrapper) + && LOAD_SYMBOL(client, wl_proxy_wrapper_destroy) + && LOAD_SYMBOL(client, wl_proxy_set_queue) + && LOAD_SYMBOL(client, wl_display_roundtrip) + && LOAD_SYMBOL(client, wl_proxy_marshal_array_constructor) + && LOAD_SYMBOL(client, wl_proxy_marshal_array_constructor_versioned) + && LOAD_SYMBOL(client, wl_proxy_get_id) + && LOAD_SYMBOL(client, wl_proxy_get_listener); + }(); + return loaded; +} + +} // namespace +} // namespace Wayland + +namespace W = Wayland; + +extern "C" { + +struct wl_egl_window *wl_egl_window_create( + struct wl_surface *surface, + int width, + int height) { + Expects(W::wl_egl_window_create != nullptr); + + return W::wl_egl_window_create(surface, width, height); +} + +void wl_egl_window_destroy(struct wl_egl_window *egl_window) { + Expects(W::wl_egl_window_destroy != nullptr); + + W::wl_egl_window_destroy(egl_window); +} + +void wl_egl_window_resize( + struct wl_egl_window *egl_window, + int width, + int height, + int dx, + int dy) { + Expects(W::wl_egl_window_resize != nullptr); + + W::wl_egl_window_resize(egl_window, width, height, dx, dy); +} + +void wl_egl_window_get_attached_size( + struct wl_egl_window *egl_window, + int *width, + int *height) { + Expects(W::wl_egl_window_get_attached_size != nullptr); + + W::wl_egl_window_get_attached_size(egl_window, width, height); +} + +struct wl_buffer *wl_cursor_image_get_buffer(struct wl_cursor_image *image) { + Expects(W::wl_cursor_image_get_buffer != nullptr); + + return W::wl_cursor_image_get_buffer(image); +} + +struct wl_cursor_theme *wl_cursor_theme_load( + const char *name, + int size, + struct wl_shm *shm) { + Expects(W::wl_cursor_theme_load != nullptr); + + return W::wl_cursor_theme_load(name, size, shm); +} + +void wl_cursor_theme_destroy(struct wl_cursor_theme *theme) { + Expects(W::wl_cursor_theme_destroy != nullptr); + + W::wl_cursor_theme_destroy(theme); +} + +struct wl_cursor *wl_cursor_theme_get_cursor( + struct wl_cursor_theme *theme, + const char *name) { + Expects(W::wl_cursor_theme_get_cursor != nullptr); + + return W::wl_cursor_theme_get_cursor(theme, name); +} + +int wl_cursor_frame_and_duration( + struct wl_cursor *cursor, + uint32_t time, + uint32_t *duration) { + Expects(W::wl_cursor_frame_and_duration != nullptr); + + return W::wl_cursor_frame_and_duration(cursor, time, duration); +} + +void wl_proxy_destroy(struct wl_proxy *proxy) { + Expects(W::wl_proxy_destroy != nullptr); + + W::wl_proxy_destroy(proxy); +} + +uint32_t wl_proxy_get_version(struct wl_proxy *proxy) { + Expects(W::wl_proxy_get_version != nullptr); + + return W::wl_proxy_get_version(proxy); +} + +void wl_array_init(struct wl_array *array) { + Expects(W::wl_array_init != nullptr); + + W::wl_array_init(array); +} + +void wl_array_release(struct wl_array *array) { + Expects(W::wl_array_release != nullptr); + + W::wl_array_release(array); +} + +void *wl_array_add(struct wl_array *array, size_t size) { + Expects(W::wl_array_add != nullptr); + + return W::wl_array_add(array, size); +} + +int wl_proxy_add_listener( + struct wl_proxy *proxy, + void (**implementation)(void), + void *data) { + Expects(W::wl_proxy_add_listener != nullptr); + + return W::wl_proxy_add_listener(proxy, implementation, data); +} + +void wl_proxy_set_user_data(struct wl_proxy *proxy, void *user_data) { + Expects(W::wl_proxy_set_user_data != nullptr); + + W::wl_proxy_set_user_data(proxy, user_data); +} + +void *wl_proxy_get_user_data(struct wl_proxy *proxy) { + Expects(W::wl_proxy_get_user_data != nullptr); + + return W::wl_proxy_get_user_data(proxy); +} + +int wl_display_get_fd(struct wl_display *display) { + Expects(W::wl_display_get_fd != nullptr); + + return W::wl_display_get_fd(display); +} + +int wl_display_get_error(struct wl_display *display) { + Expects(W::wl_display_get_error != nullptr); + + return W::wl_display_get_error(display); +} + +int wl_display_dispatch(struct wl_display *display) { + Expects(W::wl_display_dispatch != nullptr); + + return W::wl_display_dispatch(display); +} + +struct wl_event_queue *wl_display_create_queue(struct wl_display *display) { + Expects(W::wl_display_create_queue != nullptr); + + return W::wl_display_create_queue(display); +} + +int wl_display_dispatch_queue_pending( + struct wl_display *display, + struct wl_event_queue *queue) { + Expects(W::wl_display_dispatch_queue_pending != nullptr); + + return W::wl_display_dispatch_queue_pending(display, queue); +} + +int wl_display_prepare_read_queue( + struct wl_display *display, + struct wl_event_queue *queue) { + Expects(W::wl_display_prepare_read_queue != nullptr); + + return W::wl_display_prepare_read_queue(display, queue); +} + +int wl_display_flush(struct wl_display *display) { + Expects(W::wl_display_flush != nullptr); + + return W::wl_display_flush(display); +} + +void wl_display_cancel_read(struct wl_display *display) { + Expects(W::wl_display_cancel_read != nullptr); + + W::wl_display_cancel_read(display); +} + +int wl_display_read_events(struct wl_display *display) { + Expects(W::wl_display_read_events != nullptr); + + return W::wl_display_read_events(display); +} + +void wl_event_queue_destroy(struct wl_event_queue *queue) { + Expects(W::wl_event_queue_destroy != nullptr); + + W::wl_event_queue_destroy(queue); +} + +int wl_display_prepare_read(struct wl_display *display) { + Expects(W::wl_display_prepare_read != nullptr); + + return W::wl_display_prepare_read(display); +} + +int wl_display_dispatch_pending(struct wl_display *display) { + Expects(W::wl_display_dispatch_pending != nullptr); + + return W::wl_display_dispatch_pending(display); +} + +struct wl_display *wl_display_connect(const char *name) { + if (!W::Resolve()) { + errno = ENOENT; + return nullptr; + } + return W::wl_display_connect(name); +} + +struct wl_display *wl_display_connect_to_fd(int fd) { + if (!W::Resolve()) { + errno = ENOENT; + return nullptr; + } + return W::wl_display_connect_to_fd(fd); +} + +void wl_display_disconnect(struct wl_display *display) { + Expects(W::wl_display_disconnect != nullptr); + + W::wl_display_disconnect(display); +} + +void *wl_proxy_create_wrapper(void *proxy) { + Expects(W::wl_proxy_create_wrapper != nullptr); + + return W::wl_proxy_create_wrapper(proxy); +} + +void wl_proxy_wrapper_destroy(void *proxy_wrapper) { + Expects(W::wl_proxy_wrapper_destroy != nullptr); + + W::wl_proxy_wrapper_destroy(proxy_wrapper); +} + +void wl_proxy_set_queue( + struct wl_proxy *proxy, + struct wl_event_queue *queue) { + Expects(W::wl_proxy_set_queue != nullptr); + + W::wl_proxy_set_queue(proxy, queue); +} + +int wl_display_roundtrip(struct wl_display *display) { + Expects(W::wl_display_roundtrip != nullptr); + + return W::wl_display_roundtrip(display); +} + +struct wl_proxy *wl_proxy_marshal_array_constructor( + struct wl_proxy *proxy, + uint32_t opcode, + union wl_argument *args, + const struct wl_interface *interface) { + Expects(W::wl_proxy_marshal_array_constructor != nullptr); + + return W::wl_proxy_marshal_array_constructor( + proxy, + opcode, + args, + interface); +} + +struct wl_proxy *wl_proxy_marshal_array_constructor_versioned( + struct wl_proxy *proxy, + uint32_t opcode, + union wl_argument *args, + const struct wl_interface *interface, + uint32_t version) { + Expects(W::wl_proxy_marshal_array_constructor_versioned != nullptr); + + return W::wl_proxy_marshal_array_constructor_versioned( + proxy, + opcode, + args, + interface, + version); +} + +uint32_t wl_proxy_get_id(struct wl_proxy *proxy) { + Expects(W::wl_proxy_get_id != nullptr); + + return W::wl_proxy_get_id(proxy); +} + +const void *wl_proxy_get_listener(struct wl_proxy *proxy) { + Expects(W::wl_proxy_get_listener != nullptr); + + return W::wl_proxy_get_listener(proxy); +} + +void wl_proxy_marshal(struct wl_proxy *proxy, uint32_t opcode, ...) { + union wl_argument args[W::WL_CLOSURE_MAX_ARGS]; + va_list ap; + + va_start(ap, opcode); + + // wl_proxy { wl_object { wl_interface *, ... }, ... } + struct wl_object *object = (struct wl_object*)proxy; + struct wl_interface *interface = *((struct wl_interface**)object); + W::wl_argument_from_va_list( + interface->methods[opcode].signature, + args, + W::WL_CLOSURE_MAX_ARGS, + ap); + + va_end(ap); + + wl_proxy_marshal_array_constructor(proxy, opcode, args, nullptr); +} + +struct wl_proxy *wl_proxy_marshal_constructor( + struct wl_proxy *proxy, + uint32_t opcode, + const struct wl_interface *interface, + ...) { + union wl_argument args[W::WL_CLOSURE_MAX_ARGS]; + va_list ap; + + va_start(ap, interface); + + // wl_proxy { wl_object { wl_interface *, ... }, ... } + struct wl_object *object = (struct wl_object*)proxy; + struct wl_interface *i = *((struct wl_interface**)object); + W::wl_argument_from_va_list( + i->methods[opcode].signature, + args, + W::WL_CLOSURE_MAX_ARGS, + ap); + + va_end(ap); + + return wl_proxy_marshal_array_constructor(proxy, opcode, args, interface); +} + +struct wl_proxy *wl_proxy_marshal_constructor_versioned( + struct wl_proxy *proxy, + uint32_t opcode, + const struct wl_interface *interface, + uint32_t version, + ...) { + union wl_argument args[W::WL_CLOSURE_MAX_ARGS]; + va_list ap; + + va_start(ap, version); + + // wl_proxy { wl_object { wl_interface *, ... }, ... } + struct wl_object *object = (struct wl_object*)proxy; + struct wl_interface *i = *((struct wl_interface**)object); + W::wl_argument_from_va_list( + i->methods[opcode].signature, + args, + W::WL_CLOSURE_MAX_ARGS, + ap); + + va_end(ap); + + return wl_proxy_marshal_array_constructor_versioned(proxy, opcode, + args, interface, + version); +} +} // extern "C" From 6d1b48811e9f3c74072aa1cb9e0ea07d17985fe1 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Thu, 29 Apr 2021 21:30:27 +0400 Subject: [PATCH 07/29] Fix build without Wayland of static binary --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cc13d1b..d3790ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,6 @@ if (DESKTOP_APP_USE_GLIBC_WRAPS) endif() if (LINUX AND NOT DESKTOP_APP_USE_PACKAGED - AND NOT DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION) + AND Qt5WaylandClient_FOUND) add_subdirectory(linux_wayland_helper) endif() From 1720a174c4d96bc1512837adcae257c6637438e5 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Mon, 3 May 2021 11:10:31 +0400 Subject: [PATCH 08/29] Link Qt with libproxy --- external/qt/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/external/qt/CMakeLists.txt b/external/qt/CMakeLists.txt index f69e42d..b4e7d9f 100644 --- a/external/qt/CMakeLists.txt +++ b/external/qt/CMakeLists.txt @@ -347,6 +347,7 @@ else() endif() target_link_static_libraries(external_qt INTERFACE + proxy xkbcommon xkbcommon-x11 xcb-glx From c8341354e1b8dcf7b5e424717932048a0c6bc8e2 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 10 May 2021 10:53:30 +0400 Subject: [PATCH 09/29] Link webrtc with more Xlib libraries. --- external/CMakeLists.txt | 1 - .../hime_qt/hime_im_client/CMakeLists.txt | 2 +- external/webrtc/CMakeLists.txt | 30 ++++++++++---- external/webview/CMakeLists.txt | 39 ------------------- 4 files changed, 23 insertions(+), 49 deletions(-) delete mode 100644 external/webview/CMakeLists.txt diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index bce6cf7..3521f29 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -65,7 +65,6 @@ endif() add_checked_subdirectory(ton) add_checked_subdirectory(variant) add_checked_subdirectory(webrtc) -add_checked_subdirectory(webview) if (LINUX AND NOT DESKTOP_APP_DISABLE_X11_INTEGRATION) add_checked_subdirectory(xcb) endif() diff --git a/external/hime_qt/hime_im_client/CMakeLists.txt b/external/hime_qt/hime_im_client/CMakeLists.txt index c90c717..cb4a55b 100644 --- a/external/hime_qt/hime_im_client/CMakeLists.txt +++ b/external/hime_qt/hime_im_client/CMakeLists.txt @@ -34,7 +34,7 @@ else() ) find_package(PkgConfig REQUIRED) - pkg_search_module(GTK REQUIRED gtk+-2.0 gtk+-3.0) + pkg_search_module(GTK REQUIRED gtk+-3.0) target_include_directories(external_hime_im_client PUBLIC diff --git a/external/webrtc/CMakeLists.txt b/external/webrtc/CMakeLists.txt index 7809d79..b11fd21 100644 --- a/external/webrtc/CMakeLists.txt +++ b/external/webrtc/CMakeLists.txt @@ -21,6 +21,7 @@ else() RTC_ENABLE_VP9 HAVE_SCTP WEBRTC_USE_H264 + WEBRTC_USE_BUILTIN_ISAC_FLOAT WEBRTC_LIBRARY_IMPL WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS=1 ABSL_ALLOCATOR_NOTHROW=1 @@ -47,6 +48,7 @@ else() target_compile_definitions(external_webrtc INTERFACE WEBRTC_LINUX + WEBRTC_USE_X11 ) endif() @@ -78,6 +80,14 @@ else() list(APPEND webrtc_libs_list "${webrtc_build_loc}/${lib}${webrtc_lib_suffix}") endforeach() + target_link_libraries(external_webrtc + INTERFACE + ${webrtc_libs_list} + desktop-app::external_openssl + desktop-app::external_jpeg + desktop-app::external_opus + ) + if (WIN32) target_link_libraries(external_webrtc INTERFACE @@ -92,13 +102,17 @@ else() INTERFACE -ObjC ) + else() + # Required for desktop_capture + target_link_static_libraries(external_webrtc + INTERFACE + Xcomposite + Xdamage + Xext + Xfixes + Xrandr + Xrender + Xtst + ) endif() - - target_link_libraries(external_webrtc - INTERFACE - ${webrtc_libs_list} - desktop-app::external_openssl - desktop-app::external_jpeg - desktop-app::external_opus - ) endif() diff --git a/external/webview/CMakeLists.txt b/external/webview/CMakeLists.txt deleted file mode 100644 index d0990b8..0000000 --- a/external/webview/CMakeLists.txt +++ /dev/null @@ -1,39 +0,0 @@ -# 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(external_webview INTERFACE IMPORTED GLOBAL) -add_library(desktop-app::external_webview ALIAS external_webview) - -add_library(external_webview_bundled INTERFACE) - -set(webview_loc ${third_party_loc}/webview) - -if (WIN32) - target_include_directories(external_webview_bundled - INTERFACE - ${webview_loc}/script/microsoft.web.webview2.1.0.664.37/build/native/include - ) - - if (build_win64) - set(webview_arch x64) - else() - set(webview_arch x86) - endif() - target_link_libraries(external_webview_bundled - INTERFACE - ${webview_loc}/script/microsoft.web.webview2.1.0.664.37/build/native/${webview_arch}/WebView2LoaderStatic.lib - ) -endif() - -target_include_directories(external_webview_bundled -INTERFACE - ${webview_loc} -) - -target_link_libraries(external_webview -INTERFACE - external_webview_bundled -) From 9a8fc7b7cbf2394c03b0350532e366682d3c0494 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 10 May 2021 14:38:07 +0400 Subject: [PATCH 10/29] Fix libwayland loader. --- linux_wayland_helper/linux_wayland_helper.cpp | 59 +++++++++++++++---- 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/linux_wayland_helper/linux_wayland_helper.cpp b/linux_wayland_helper/linux_wayland_helper.cpp index 5f01a4b..2a9e6bc 100644 --- a/linux_wayland_helper/linux_wayland_helper.cpp +++ b/linux_wayland_helper/linux_wayland_helper.cpp @@ -11,6 +11,8 @@ #include #include +#include + #define LOAD_SYMBOL(handle, func) LoadSymbol(handle, #func, func) namespace Wayland { @@ -171,27 +173,58 @@ void wl_argument_from_va_list( } } -bool LoadLibrary(void **handle, const char *name) { - *handle = dlopen(name, RTLD_LAZY | RTLD_NODELETE); - if (!*handle) { - g_warning("Could not load '%s': %s", name, dlerror()); +using Handle = void*; + +bool LoadLibrary(Handle &handle, const char *name) { + handle = dlopen(name, RTLD_LAZY | RTLD_NODELETE); + if (handle) { + std::cout << "Loaded library '" << name << "'." << std::endl; + return true; } - return (*handle != nullptr); + const auto error = dlerror(); + g_warning("Could not load library '%s': %s", name, error); + std::cerr + << "Could not load library '" + << name + << "', error: '" + << error + << "'." + << std::endl; + return false; } template -inline bool LoadSymbol(void *handle, const char *name, Function &func) { - func = reinterpret_cast(dlsym(handle, name)); +inline bool LoadSymbol(Handle handle, const char *name, Function &func) { + func = handle + ? reinterpret_cast(dlsym(handle, name)) + : nullptr; if (const auto error = dlerror()) { - g_warning("Failed to load '%1' function: %2", name, error); + g_warning("Failed to load function '%s': %s", name, error); + std::cerr + << "Could not load function '" + << name + << "', error: '" + << error + << "'." + << std::endl; + } else if (handle && !func) { + std::cerr + << "Could not load function '" + << name + << "', error unknown." + << std::endl; + } else if (func) { + std::cout << "Loaded function '" << name << "'." << std::endl; } return (func != nullptr); } bool Resolve() { static const auto loaded = [&] { - void *egl, *cursor, *client = nullptr; - gsl::finally([&] { + auto egl = Handle(); + auto cursor = Handle(); + auto client = Handle(); + const auto guard = gsl::finally([&] { if (egl) { dlclose(egl); } @@ -202,18 +235,18 @@ bool Resolve() { dlclose(client); } }); - return LoadLibrary(&egl, "libwayland-egl.so.1") + return LoadLibrary(egl, "libwayland-egl.so.1") && LOAD_SYMBOL(egl, wl_egl_window_create) && LOAD_SYMBOL(egl, wl_egl_window_destroy) && LOAD_SYMBOL(egl, wl_egl_window_resize) && LOAD_SYMBOL(egl, wl_egl_window_get_attached_size) - && LoadLibrary(&cursor, "libwayland-cursor.so.0") + && LoadLibrary(cursor, "libwayland-cursor.so.0") && LOAD_SYMBOL(cursor, wl_cursor_image_get_buffer) && LOAD_SYMBOL(cursor, wl_cursor_theme_load) && LOAD_SYMBOL(cursor, wl_cursor_theme_destroy) && LOAD_SYMBOL(cursor, wl_cursor_theme_get_cursor) && LOAD_SYMBOL(cursor, wl_cursor_frame_and_duration) - && LoadLibrary(&client, "libwayland-client.so.0") + && LoadLibrary(client, "libwayland-client.so.0") && LOAD_SYMBOL(client, wl_proxy_destroy) && LOAD_SYMBOL(client, wl_proxy_get_version) && LOAD_SYMBOL(client, wl_array_init) From 4ea94848d8cb7b7033562b546d0ae7490b1de213 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 10 May 2021 14:38:22 +0400 Subject: [PATCH 11/29] Define 'WEBRTC_USE_PIPEWIRE'. --- external/webrtc/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/external/webrtc/CMakeLists.txt b/external/webrtc/CMakeLists.txt index b11fd21..96c08e7 100644 --- a/external/webrtc/CMakeLists.txt +++ b/external/webrtc/CMakeLists.txt @@ -49,6 +49,7 @@ else() INTERFACE WEBRTC_LINUX WEBRTC_USE_X11 + WEBRTC_USE_PIPEWIRE ) endif() From 538b39ec9d26d15978f84702eb112a97c06f15c8 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 10 May 2021 15:54:27 +0400 Subject: [PATCH 12/29] Remove libwayland loading debug info. --- linux_wayland_helper/linux_wayland_helper.cpp | 26 +------------------ 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/linux_wayland_helper/linux_wayland_helper.cpp b/linux_wayland_helper/linux_wayland_helper.cpp index 2a9e6bc..c3de899 100644 --- a/linux_wayland_helper/linux_wayland_helper.cpp +++ b/linux_wayland_helper/linux_wayland_helper.cpp @@ -178,18 +178,9 @@ using Handle = void*; bool LoadLibrary(Handle &handle, const char *name) { handle = dlopen(name, RTLD_LAZY | RTLD_NODELETE); if (handle) { - std::cout << "Loaded library '" << name << "'." << std::endl; return true; } - const auto error = dlerror(); - g_warning("Could not load library '%s': %s", name, error); - std::cerr - << "Could not load library '" - << name - << "', error: '" - << error - << "'." - << std::endl; + g_warning("Could not load library '%s': %s", name, dlerror()); return false; } @@ -200,21 +191,6 @@ inline bool LoadSymbol(Handle handle, const char *name, Function &func) { : nullptr; if (const auto error = dlerror()) { g_warning("Failed to load function '%s': %s", name, error); - std::cerr - << "Could not load function '" - << name - << "', error: '" - << error - << "'." - << std::endl; - } else if (handle && !func) { - std::cerr - << "Could not load function '" - << name - << "', error unknown." - << std::endl; - } else if (func) { - std::cout << "Loaded function '" << name << "'." << std::endl; } return (func != nullptr); } From 42d3840cdee046ad1e1fd980c37a2d099bc98e4f Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 14 May 2021 15:09:28 +0400 Subject: [PATCH 13/29] Add simple allocation tracer on Linux. --- CMakeLists.txt | 3 + external/qt/CMakeLists.txt | 24 ++ linux_allocation_tracer/CMakeLists.txt | 26 +++ .../linux_allocation_trace_reader.cpp | 216 ++++++++++++++++++ .../linux_allocation_tracer.cpp | 172 ++++++++++++++ .../linux_allocation_tracer.h | 20 ++ variables.cmake | 1 + 7 files changed, 462 insertions(+) create mode 100644 linux_allocation_tracer/CMakeLists.txt create mode 100644 linux_allocation_tracer/linux_allocation_trace_reader.cpp create mode 100644 linux_allocation_tracer/linux_allocation_tracer.cpp create mode 100644 linux_allocation_tracer/linux_allocation_tracer.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d3790ae..15c7247 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,3 +13,6 @@ if (LINUX AND Qt5WaylandClient_FOUND) add_subdirectory(linux_wayland_helper) endif() +if (DESKTOP_APP_USE_ALLOCATION_TRACER) + add_subdirectory(linux_allocation_tracer) +endif() diff --git a/external/qt/CMakeLists.txt b/external/qt/CMakeLists.txt index b4e7d9f..81ad5eb 100644 --- a/external/qt/CMakeLists.txt +++ b/external/qt/CMakeLists.txt @@ -325,6 +325,23 @@ else() -pthread -rdynamic ) + if (DESKTOP_APP_USE_ALLOCATION_TRACER) + target_link_options(external_qt + INTERFACE + # -Wl,-wrap,__malloc + -Wl,-wrap,__libc_malloc + -Wl,-wrap,malloc + -Wl,-wrap,valloc + -Wl,-wrap,pvalloc + -Wl,-wrap,calloc + -Wl,-wrap,realloc + -Wl,-wrap,memalign + -Wl,-wrap,aligned_alloc + -Wl,-wrap,posix_memalign + -Wl,-wrap,free + -Wl,--no-as-needed,-lrt + ) + endif() if (DESKTOP_APP_USE_GLIBC_WRAPS) target_link_options(external_qt INTERFACE @@ -366,6 +383,13 @@ else() xcb-render-util xcb-keysyms ) + if (DESKTOP_APP_USE_ALLOCATION_TRACER) + target_link_libraries(external_qt + INTERFACE + desktop-app::linux_allocation_tracer + $ + ) + endif() if (DESKTOP_APP_USE_GLIBC_WRAPS) target_link_libraries(external_qt INTERFACE diff --git a/linux_allocation_tracer/CMakeLists.txt b/linux_allocation_tracer/CMakeLists.txt new file mode 100644 index 0000000..ea8c3cc --- /dev/null +++ b/linux_allocation_tracer/CMakeLists.txt @@ -0,0 +1,26 @@ +# 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_allocation_tracer STATIC) +add_library(desktop-app::linux_allocation_tracer ALIAS linux_allocation_tracer) + +nice_target_sources(linux_allocation_tracer ${CMAKE_CURRENT_SOURCE_DIR} +PRIVATE + linux_allocation_tracer.cpp + linux_allocation_tracer.h +) + +add_executable(allocation_trace_reader WIN32) +init_target(allocation_trace_reader) + +target_sources(allocation_trace_reader +PRIVATE + linux_allocation_trace_reader.cpp +) + +target_link_options(allocation_trace_reader PRIVATE -static-libstdc++) + +set_target_properties(allocation_trace_reader PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) diff --git a/linux_allocation_tracer/linux_allocation_trace_reader.cpp b/linux_allocation_tracer/linux_allocation_trace_reader.cpp new file mode 100644 index 0000000..a1cf487 --- /dev/null +++ b/linux_allocation_tracer/linux_allocation_trace_reader.cpp @@ -0,0 +1,216 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include +#include +#include +#include +#include +#include +#include + +constexpr auto kBufferSize = 1024 * 1024; +char Buffer[kBufferSize]; + +struct Fields { + std::uint32_t time = 0; + std::size_t mallocs = 0; + std::size_t reallocs = 0; + std::size_t frees = 0; + std::size_t unknownReallocs = 0; + std::size_t unknownFrees = 0; +}; +Fields State; +std::unordered_map Map; +std::vector Snapshots; + +void WriteTime(std::uint32_t time) { + std::time_t t = std::time_t(time); + const auto parsed = std::localtime(&t); + std::cout + << std::setw(2) << std::setfill('0') << parsed->tm_hour + << ":" + << std::setw(2) << std::setfill('0') << parsed->tm_min + << ":" + << std::setw(2) << std::setfill('0') << parsed->tm_sec; +} + +void PrintState() { + if (!State.time) { + return; + } + WriteTime(State.time); + auto full = std::uint64_t(0); + for (const auto &[address, amount] : Map) { + full += amount; + } + + class NumPunct final : public std::numpunct { + protected: + char do_thousands_sep() const override { return '\''; } + std::string do_grouping() const override { return "\03"; } + }; + + const auto &locale = std::cout.getloc(); + std::cout.imbue(std::locale(std::locale::classic(), new NumPunct())); + std::cout + << ": " + << std::setw(13) << std::setfill(' ') << full + << " (unknown: " + << State.unknownFrees + << ")" + << std::endl; + std::cout.imbue(locale); +} + +void Add(std::uint64_t address, std::uint64_t size) { + const auto i = Map.find(address); + if (i != end(Map)) { + std::cout + << "WARNING: Repeated entry for " + << address + << " (size: " + << size + << ")." + << std::endl; + return; + } + Map.emplace(address, size); +} + +void ParseMalloc(const char *buffer) { + const auto size = *reinterpret_cast(buffer); + const auto address = *reinterpret_cast(buffer + 8); + Add(address, size); + ++State.mallocs; +} + +void ParseRealloc(const char *buffer) { + const auto old = *reinterpret_cast(buffer); + const auto size = *reinterpret_cast(buffer + 8); + const auto address = *reinterpret_cast(buffer + 16); + const auto i = Map.find(old); + if (i == end(Map)) { + ++State.unknownReallocs; + Add(address, size); + } else if (old != address) { + Map.erase(i); + Add(address, size); + ++State.reallocs; + } else { + i->second = size; + ++State.reallocs; + } +} + +void ParseFree(const char *buffer) { + const auto address = *reinterpret_cast(buffer); + const auto i = Map.find(address); + if (i == end(Map)) { + ++State.unknownFrees; + } else { + Map.erase(i); + ++State.frees; + } +} + +long Parse(const char *buffer, const char *end) { + auto result = 0; + while (end > buffer) { + const auto command = buffer[0]; + auto entry = 0; + switch (command) { + case 1: entry = 5 + 2 * sizeof(std::uint64_t); break; + case 2: entry = 5 + 3 * sizeof(std::uint64_t); break; + case 3: entry = 5 + sizeof(std::uint64_t); break; + default: + std::cout + << "WARNING: Garbage in trace file, command: " + << int(command) + << "." + << std::endl; + return -1; + } + if (end - buffer < entry) { + break; + } + const auto time = *reinterpret_cast(++buffer); + buffer += 4; + if (time > State.time) { + PrintState(); + State.time = time; + } else if (time < State.time) { + std::cout + << "WARNING: Time " + << time + << " after " + << State.time + << "." + << std::endl; + } + switch (command) { + case 1: ParseMalloc(buffer); break; + case 2: ParseRealloc(buffer); break; + case 3: ParseFree(buffer); break; + } + buffer += entry - 5; + result += entry; + } + return result; +} + +int main(int argc, char *argv[]) { + if (argc != 2) { + std::cout + << "Usage 'allocation_trace_reader [trace_file_path]'." + << std::endl; + return -1; + } + const auto file = fopen(argv[1], "rb"); + if (!file) { + std::cout + << "ERROR: Could not open '" + << argv[1] + << "'." + << std::endl; + return -1; + } + char *data = Buffer; + while (true) { + const auto read = fread(data, 1, Buffer + kBufferSize - data, file); + if (read == 0) { + if (data != Buffer) { + std::cout + << "WARNING: Trace file end is corrupt, could not parse: " + << std::size_t(data - Buffer) + << std::endl; + } + break; + } + data += read; + const auto parsed = Parse(Buffer, data); + if (parsed < 0) { + break; + } + data -= parsed; + if (data - Buffer > 0) { + std::memmove(Buffer, Buffer + parsed, data - Buffer); + } + } + PrintState(); + std::cout << "Mallocs: " << State.mallocs << "." << std::endl; + std::cout << "Reallocs: " << State.reallocs << "." << std::endl; + std::cout << "Frees: " << State.frees << "." << std::endl; + if (State.unknownReallocs) { + std::cout + << "Unknown realloc() calls: " + << State.unknownReallocs + << "." + << std::endl; + } + return 0; +} diff --git a/linux_allocation_tracer/linux_allocation_tracer.cpp b/linux_allocation_tracer/linux_allocation_tracer.cpp new file mode 100644 index 0000000..03cfa7b --- /dev/null +++ b/linux_allocation_tracer/linux_allocation_tracer.cpp @@ -0,0 +1,172 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "linux_allocation_tracer.h" + +#include +#include +#include +#include +#include +#include +#include + +namespace { + +std::atomic MallocLogger; +std::atomic VallocLogger; +std::atomic PVallocLogger; +std::atomic CallocLogger; +std::atomic ReallocLogger; +std::atomic MemAlignLogger; +std::atomic AlignedAllocLogger; +std::atomic PosixMemAlignLogger; +std::atomic FreeLogger; + +} // namespace + +extern "C" { + +//void *__real___malloc(size_t size); +void *__real___libc_malloc(size_t size); + +void *__real_malloc(size_t size); +void *__real_valloc(size_t size); +void *__real_pvalloc(size_t size); +void *__real_calloc(size_t num, size_t size); +void *__real_realloc(void *ptr, size_t size); +void *__real_memalign(size_t alignment, size_t size); +void *__real_aligned_alloc(size_t alignment, size_t size); +int __real_posix_memalign(void **memptr, size_t alignment, size_t size); +void __real_free(void *ptr); + +// void *__wrap___malloc(size_t size) { +// const auto result = __real___malloc(size); +// if (const auto logger = MallocLogger.load()) { +// logger(size, result); +// } +// return result; +// } + +void *__wrap___libc_malloc(size_t size) { + const auto result = __real___libc_malloc(size); + if (const auto logger = MallocLogger.load()) { + logger(size, result); + } + return result; +} + +void *__wrap_malloc(size_t size) { + const auto result = __real_malloc(size); + if (const auto logger = MallocLogger.load()) { + logger(size, result); + } + return result; +} + +void *__wrap_valloc(size_t size) { + const auto result = __real_valloc(size); + if (const auto logger = VallocLogger.load()) { + logger(size, result); + } + return result; +} + +void *__wrap_pvalloc(size_t size) { + const auto result = __real_pvalloc(size); + if (const auto logger = PVallocLogger.load()) { + logger(size, result); + } + return result; +} + +void *__wrap_calloc(size_t num, size_t size) { + const auto result = __real_calloc(num, size); + if (const auto logger = CallocLogger.load()) { + logger(num, size, result); + } + return result; +} + +void *__wrap_realloc(void *ptr, size_t size) { + const auto result = __real_realloc(ptr, size); + if (const auto logger = ReallocLogger.load()) { + logger(ptr, size, result); + } + return result; +} + +void *__wrap_memalign(size_t alignment, size_t size) { + const auto result = __real_memalign(alignment, size); + if (const auto logger = MemAlignLogger.load()) { + logger(alignment, size, result); + } + return result; +} + +void *__wrap_aligned_alloc(size_t alignment, size_t size) { + const auto result = __real_aligned_alloc(alignment, size); + if (const auto logger = AlignedAllocLogger.load()) { + logger(alignment, size, result); + } + return result; +} + +int __wrap_posix_memalign(void **memptr, size_t alignment, size_t size) { + const auto result = __real_posix_memalign(memptr, alignment, size); + if (!result) { + if (const auto logger = PosixMemAlignLogger.load()) { + logger(alignment, size, *memptr); + } + } + return result; +} + +void __wrap_free(void *ptr) { + if (const auto logger = FreeLogger.load()) { + logger(ptr); + } + __real_free(ptr); +} + +} // extern "C" + +void SetMallocLogger(void (*logger)(size_t, void *)) { + MallocLogger = logger; +} + +void SetVallocLogger(void (*logger)(size_t, void *)) { + VallocLogger = logger; +} + +void SetPVallocLogger(void (*logger)(size_t, void *)) { + PVallocLogger = logger; +} + +void SetCallocLogger(void (*logger)(size_t, size_t, void *)) { + CallocLogger = logger; +} + +void SetReallocLogger(void (*logger)(void *, size_t, void *)) { + ReallocLogger = logger; +} + +void SetMemAlignLogger(void (*logger)(size_t, size_t, void *)) { + MemAlignLogger = logger; +} + +void SetAlignedAllocLogger(void (*logger)(size_t, size_t, void *)) { + AlignedAllocLogger = logger; +} + +void SetPosixMemAlignLogger(void (*logger)(size_t, size_t, void *)) { + PosixMemAlignLogger = logger; +} + +void SetFreeLogger(void (*logger)(void *)) { + FreeLogger = logger; +} diff --git a/linux_allocation_tracer/linux_allocation_tracer.h b/linux_allocation_tracer/linux_allocation_tracer.h new file mode 100644 index 0000000..f9e362f --- /dev/null +++ b/linux_allocation_tracer/linux_allocation_tracer.h @@ -0,0 +1,20 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +#include + +void SetMallocLogger(void (*logger)(size_t, void *)); +void SetVallocLogger(void (*logger)(size_t, void *)); +void SetPVallocLogger(void (*logger)(size_t, void *)); +void SetCallocLogger(void (*logger)(size_t, size_t, void *)); +void SetReallocLogger(void (*logger)(void *, size_t, void *)); +void SetMemAlignLogger(void (*logger)(size_t, size_t, void *)); +void SetAlignedAllocLogger(void (*logger)(size_t, size_t, void *)); +void SetPosixMemAlignLogger(void (*logger)(size_t, size_t, void *)); +void SetFreeLogger(void (*logger)(void *)); diff --git a/variables.cmake b/variables.cmake index 22d410a..7a6eeb9 100644 --- a/variables.cmake +++ b/variables.cmake @@ -33,6 +33,7 @@ option(DESKTOP_APP_DISABLE_X11_INTEGRATION "Disable all code for X11 integration 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_GLIBC_WRAPS "Use wraps for new GLIBC features." 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) option(DESKTOP_APP_USE_PACKAGED_LAZY_PLATFORMTHEMES "Bundle recommended Qt platform themes for self-contained packages. (Linux only)" ${DESKTOP_APP_USE_PACKAGED_LAZY}) From 5318ac7c54dbf33b17ccc4bd3281bb8b8db25e02 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Sun, 16 May 2021 11:33:25 +0400 Subject: [PATCH 14/29] Add external_mallocng module --- external/CMakeLists.txt | 3 +++ external/mallocng/CMakeLists.txt | 38 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 external/mallocng/CMakeLists.txt diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 3521f29..53a57d8 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -41,6 +41,9 @@ if (LINUX AND NOT DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION) add_checked_subdirectory(kwayland) endif() add_checked_subdirectory(lz4) +if (LINUX) + add_checked_subdirectory(mallocng) +endif() add_checked_subdirectory(minizip) if (LINUX) add_checked_subdirectory(nimf_qt5) diff --git a/external/mallocng/CMakeLists.txt b/external/mallocng/CMakeLists.txt new file mode 100644 index 0000000..34b97ed --- /dev/null +++ b/external/mallocng/CMakeLists.txt @@ -0,0 +1,38 @@ +# 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(external_mallocng STATIC) +add_library(desktop-app::external_mallocng ALIAS external_mallocng) +init_target(external_mallocng "(external)") + +set(mallocng_loc ${third_party_loc}/mallocng) + +nice_target_sources(external_mallocng ${mallocng_loc} +PRIVATE + malloc.c + calloc.c + free.c + realloc.c + aligned_alloc.c + posix_memalign.c + memalign.c + malloc_usable_size.c + meta.h + glue.h +) + +target_include_directories(external_mallocng +PRIVATE + ${mallocng_loc} +) + +target_compile_options(external_mallocng +PUBLIC + -fno-builtin-malloc + -fno-builtin-calloc + -fno-builtin-realloc + -fno-builtin-free +) From 294a18baf8896609aeb78b0d9b92a8011b0fa2e5 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 17 May 2021 13:07:18 +0400 Subject: [PATCH 15/29] Fix hime-im-client build with GTK3 headers. --- external/hime_qt/hime_im_client/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/external/hime_qt/hime_im_client/CMakeLists.txt b/external/hime_qt/hime_im_client/CMakeLists.txt index cb4a55b..63773b0 100644 --- a/external/hime_qt/hime_im_client/CMakeLists.txt +++ b/external/hime_qt/hime_im_client/CMakeLists.txt @@ -34,7 +34,7 @@ else() ) find_package(PkgConfig REQUIRED) - pkg_search_module(GTK REQUIRED gtk+-3.0) + pkg_check_modules(GTK REQUIRED gtk+-3.0) target_include_directories(external_hime_im_client PUBLIC @@ -52,6 +52,7 @@ else() UNIX=1 FREEBSD=0 CLIENT_LIB=1 + GTK_DISABLE_DEPRECATED ) target_link_libraries(external_hime_im_client From de65519132126db2c2166cdf5af5f12e61652419 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 17 May 2021 13:12:04 +0400 Subject: [PATCH 16/29] Fix build of mallocng. --- external/mallocng/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/external/mallocng/CMakeLists.txt b/external/mallocng/CMakeLists.txt index 34b97ed..cfe42a8 100644 --- a/external/mallocng/CMakeLists.txt +++ b/external/mallocng/CMakeLists.txt @@ -24,6 +24,11 @@ PRIVATE glue.h ) +target_compile_options(external_mallocng +PRIVATE + -Wno-unused-value +) + target_include_directories(external_mallocng PRIVATE ${mallocng_loc} From 45be9e321517f15378982bd0353f80ab884679eb Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 19 May 2021 10:22:35 +0400 Subject: [PATCH 17/29] Link external_mallocng with --whole-archive. --- external/mallocng/CMakeLists.txt | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/external/mallocng/CMakeLists.txt b/external/mallocng/CMakeLists.txt index cfe42a8..50b841c 100644 --- a/external/mallocng/CMakeLists.txt +++ b/external/mallocng/CMakeLists.txt @@ -4,13 +4,15 @@ # For license and copyright information please follow this link: # https://github.com/desktop-app/legal/blob/master/LEGAL -add_library(external_mallocng STATIC) +add_library(external_mallocng INTERFACE IMPORTED GLOBAL) add_library(desktop-app::external_mallocng ALIAS external_mallocng) -init_target(external_mallocng "(external)") + +add_library(external_mallocng_bundled STATIC) +init_target(external_mallocng_bundled "(external)") set(mallocng_loc ${third_party_loc}/mallocng) -nice_target_sources(external_mallocng ${mallocng_loc} +nice_target_sources(external_mallocng_bundled ${mallocng_loc} PRIVATE malloc.c calloc.c @@ -24,18 +26,25 @@ PRIVATE glue.h ) -target_compile_options(external_mallocng +target_compile_options(external_mallocng_bundled PRIVATE -Wno-unused-value ) -target_include_directories(external_mallocng +target_include_directories(external_mallocng_bundled PRIVATE ${mallocng_loc} ) +target_link_libraries(external_mallocng +INTERFACE + -Wl,--whole-archive + external_mallocng_bundled + -Wl,--no-whole-archive +) + target_compile_options(external_mallocng -PUBLIC +INTERFACE -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc From bcc0ac15f497513455aa144ffe4e658f7aca0e73 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 19 May 2021 13:18:46 +0400 Subject: [PATCH 18/29] Add valloc/pvalloc to external_mallocng. --- external/mallocng/CMakeLists.txt | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/external/mallocng/CMakeLists.txt b/external/mallocng/CMakeLists.txt index 50b841c..c3d2422 100644 --- a/external/mallocng/CMakeLists.txt +++ b/external/mallocng/CMakeLists.txt @@ -24,6 +24,8 @@ PRIVATE malloc_usable_size.c meta.h glue.h + valloc.c + pvalloc.c ) target_compile_options(external_mallocng_bundled @@ -42,11 +44,3 @@ INTERFACE external_mallocng_bundled -Wl,--no-whole-archive ) - -target_compile_options(external_mallocng -INTERFACE - -fno-builtin-malloc - -fno-builtin-calloc - -fno-builtin-realloc - -fno-builtin-free -) From 6c5ac4cae99dfb7063d948dedce2ba85a4d0dabc Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Tue, 1 Jun 2021 12:04:27 +0400 Subject: [PATCH 19/29] Add forgotten REQUIRED to rnnoise --- external/rnnoise/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/rnnoise/CMakeLists.txt b/external/rnnoise/CMakeLists.txt index 601c98b..3bba816 100644 --- a/external/rnnoise/CMakeLists.txt +++ b/external/rnnoise/CMakeLists.txt @@ -9,7 +9,7 @@ if (DESKTOP_APP_USE_PACKAGED) add_library(desktop-app::external_rnnoise ALIAS external_rnnoise) find_package(PkgConfig REQUIRED) - pkg_check_modules(RNNOISE IMPORTED_TARGET rnnoise) + pkg_check_modules(RNNOISE REQUIRED IMPORTED_TARGET rnnoise) target_link_libraries(external_rnnoise INTERFACE PkgConfig::RNNOISE) else() From e8fba0e1b8bb512a3eb9323e4f90c78cd1f7d3d0 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Tue, 1 Jun 2021 12:05:02 +0400 Subject: [PATCH 20/29] Fix build with RelWithDebInfo target in non-packaged mode --- external/webrtc/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/webrtc/CMakeLists.txt b/external/webrtc/CMakeLists.txt index 96c08e7..675e4e5 100644 --- a/external/webrtc/CMakeLists.txt +++ b/external/webrtc/CMakeLists.txt @@ -12,7 +12,7 @@ if (DESKTOP_APP_USE_PACKAGED) target_link_libraries(external_webrtc INTERFACE tg_owt::tg_owt) else() set(webrtc_loc ${libs_loc}/tg_owt/src) - set(webrtc_build_loc ${libs_loc}/tg_owt/out/$) + set(webrtc_build_loc ${libs_loc}/tg_owt/out/$,Debug,Release>) target_compile_definitions(external_webrtc INTERFACE From 4caa8674681fb50a2244b58eb701508017c360d6 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Thu, 10 Jun 2021 22:20:37 +0400 Subject: [PATCH 21/29] Use custom xdg-shell fork --- external/qt/CMakeLists.txt | 1 - external/qt/qt_static_plugins/qt_static_plugins.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/external/qt/CMakeLists.txt b/external/qt/CMakeLists.txt index 81ad5eb..dea3ac2 100644 --- a/external/qt/CMakeLists.txt +++ b/external/qt/CMakeLists.txt @@ -269,7 +269,6 @@ else() set(qt_libs_waylandclient_plugins plugins/wayland-decoration-client/${qt_lib_prefix}bradient plugins/wayland-shell-integration/${qt_lib_prefix}wl-shell - plugins/wayland-shell-integration/${qt_lib_prefix}xdg-shell plugins/wayland-graphics-integration-client/${qt_lib_prefix}qt-plugin-wayland-egl plugins/platforms/${qt_lib_prefix}qwayland-egl plugins/platforms/${qt_lib_prefix}qwayland-generic diff --git a/external/qt/qt_static_plugins/qt_static_plugins.cpp b/external/qt/qt_static_plugins/qt_static_plugins.cpp index dce89ca..34501ae 100644 --- a/external/qt/qt_static_plugins/qt_static_plugins.cpp +++ b/external/qt/qt_static_plugins/qt_static_plugins.cpp @@ -36,7 +36,6 @@ Q_IMPORT_PLUGIN(QXdgDesktopPortalThemePlugin) #ifndef DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION Q_IMPORT_PLUGIN(QWaylandEglClientBufferPlugin) Q_IMPORT_PLUGIN(QWaylandWlShellIntegrationPlugin) -Q_IMPORT_PLUGIN(QWaylandXdgShellIntegrationPlugin) Q_IMPORT_PLUGIN(QWaylandBradientDecorationPlugin) Q_IMPORT_PLUGIN(QWaylandIntegrationPlugin) Q_IMPORT_PLUGIN(QWaylandEglPlatformIntegrationPlugin) From 03efe01ff978b84745414e046e4766225ffffb7f Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 9 Jun 2021 11:46:24 +0300 Subject: [PATCH 22/29] Added MediaPlayer framework on macOS for NowPlaying support. --- options_mac.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/options_mac.cmake b/options_mac.cmake index ba1b16f..55fa5e3 100644 --- a/options_mac.cmake +++ b/options_mac.cmake @@ -77,6 +77,7 @@ INTERFACE WebKit IOKit GSS + MediaPlayer ) if (NOT build_osx) From 97b9c3f6d899b8a24137b9e6c076f5752d13a037 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 9 Jun 2021 11:45:34 +0300 Subject: [PATCH 23/29] Removed SPMediaKeyTap solution for macOS media keys. --- external/CMakeLists.txt | 3 --- external/sp_media_key_tap/CMakeLists.txt | 26 ------------------------ 2 files changed, 29 deletions(-) delete mode 100644 external/sp_media_key_tap/CMakeLists.txt diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 53a57d8..00b6b01 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -59,9 +59,6 @@ add_checked_subdirectory(qr_code_generator) add_checked_subdirectory(ranges) add_checked_subdirectory(rlottie) add_checked_subdirectory(rnnoise) -if (APPLE) - add_checked_subdirectory(sp_media_key_tap) -endif() if (LINUX AND NOT DESKTOP_APP_DISABLE_DBUS_INTEGRATION) add_checked_subdirectory(statusnotifieritem) endif() diff --git a/external/sp_media_key_tap/CMakeLists.txt b/external/sp_media_key_tap/CMakeLists.txt deleted file mode 100644 index ccbc02a..0000000 --- a/external/sp_media_key_tap/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -# 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 - -if (EXISTS ${third_party_loc}/SPMediaKeyTap) - add_library(external_sp_media_key_tap STATIC) - add_library(desktop-app::external_sp_media_key_tap ALIAS external_sp_media_key_tap) - init_target(external_sp_media_key_tap "(external)") - - set(sp_media_key_tap_loc ${third_party_loc}/SPMediaKeyTap) - - target_sources(external_sp_media_key_tap - PRIVATE - ${sp_media_key_tap_loc}/SPMediaKeyTap.m - ${sp_media_key_tap_loc}/SPMediaKeyTap.h - ${sp_media_key_tap_loc}/SPInvocationGrabbing/NSObject+SPInvocationGrabbing.m - ${sp_media_key_tap_loc}/SPInvocationGrabbing/NSObject+SPInvocationGrabbing.h - ) - - target_include_directories(external_sp_media_key_tap SYSTEM - INTERFACE - ${sp_media_key_tap_loc} - ) -endif() From e002bba00249f284841292c345a3d1de09d83769 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Sat, 19 Jun 2021 03:51:50 +0400 Subject: [PATCH 24/29] Some cleanup of unneeded hacks qt5ct is removed since internal gtk integration is good enough Removed the ability to override path to qtwayland client headers since that hack is no longer used QXdgDesktopPortalThemePlugin is no longer linked since custom xdg-desktop-portal dialog implementation is present --- external/CMakeLists.txt | 3 - external/qt/CMakeLists.txt | 70 +++---------------- external/qt/qt_static_plugins/CMakeLists.txt | 1 - .../qt_static_plugins/qt_static_plugins.cpp | 10 +-- external/qt5ct_support/CMakeLists.txt | 18 ----- external/qt5ct_support/qt5ct/CMakeLists.txt | 40 ----------- .../qt5ct_qtplugin/CMakeLists.txt | 42 ----------- .../qt5ct_support/qt5ct_style/CMakeLists.txt | 42 ----------- options.cmake | 7 -- variables.cmake | 2 - 10 files changed, 10 insertions(+), 225 deletions(-) delete mode 100644 external/qt5ct_support/CMakeLists.txt delete mode 100644 external/qt5ct_support/qt5ct/CMakeLists.txt delete mode 100644 external/qt5ct_support/qt5ct_qtplugin/CMakeLists.txt delete mode 100644 external/qt5ct_support/qt5ct_style/CMakeLists.txt diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 00b6b01..91a7806 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -52,9 +52,6 @@ add_checked_subdirectory(openal) add_checked_subdirectory(openssl) add_checked_subdirectory(opus) add_checked_subdirectory(qt) -if (LINUX) - add_checked_subdirectory(qt5ct_support) -endif() add_checked_subdirectory(qr_code_generator) add_checked_subdirectory(ranges) add_checked_subdirectory(rlottie) diff --git a/external/qt/CMakeLists.txt b/external/qt/CMakeLists.txt index dea3ac2..bd51d20 100644 --- a/external/qt/CMakeLists.txt +++ b/external/qt/CMakeLists.txt @@ -28,35 +28,6 @@ if (DESKTOP_APP_USE_PACKAGED) target_link_libraries(external_qt INTERFACE Qt5::DBus) endif() - if (LINUX AND DESKTOP_APP_USE_PACKAGED_LAZY_PLATFORMTHEMES) - find_library(Qt5ThemeSupport_LIBRARY - NAMES - Qt5ThemeSupport - REQUIRED - ) - - find_path(Qt5ThemeSupport_INCLUDE_DIR - NAMES - QtThemeSupport/private/qgenericunixthemes_p.h - HINTS - ${Qt5Gui_INCLUDE_DIRS} - PATH_SUFFIXES - QtThemeSupport/${Qt5Gui_VERSION} - REQUIRED - ) - - target_link_libraries(external_qt - INTERFACE - ${Qt5ThemeSupport_LIBRARY} - ) - - target_include_directories(external_qt - INTERFACE - ${Qt5ThemeSupport_INCLUDE_DIR} - ${Qt5ThemeSupport_INCLUDE_DIR}/QtThemeSupport - ) - endif() - if (Qt5XkbCommonSupport_FOUND) target_link_libraries(external_qt INTERFACE Qt5::XkbCommonSupport) @@ -69,18 +40,10 @@ if (DESKTOP_APP_USE_PACKAGED) if (Qt5WaylandClient_FOUND) target_link_libraries(external_qt INTERFACE Qt5::WaylandClient) - if (DESKTOP_APP_QTWAYLANDCLIENT_PRIVATE_HEADERS) - target_include_directories(external_qt - INTERFACE - ${DESKTOP_APP_QTWAYLANDCLIENT_PRIVATE_HEADERS} - ${DESKTOP_APP_QTWAYLANDCLIENT_PRIVATE_HEADERS}/QtWaylandClient - ) - else() - target_include_directories(external_qt - INTERFACE - ${Qt5WaylandClient_PRIVATE_INCLUDE_DIRS} - ) - endif() + target_include_directories(external_qt + INTERFACE + ${Qt5WaylandClient_PRIVATE_INCLUDE_DIRS} + ) endif() else() target_include_directories(external_qt SYSTEM @@ -120,15 +83,6 @@ else() ) endif() - if (LINUX) - target_include_directories(external_qt SYSTEM - INTERFACE - ${qt_loc}/include/QtThemeSupport - ${qt_loc}/include/QtThemeSupport/${qt_version} - ${qt_loc}/include/QtThemeSupport/${qt_version}/QtThemeSupport - ) - endif() - target_compile_definitions(external_qt INTERFACE _REENTRANT @@ -161,13 +115,6 @@ else() ) endif() - if (LINUX) - target_compile_definitions(external_qt - INTERFACE - QT_THEME_SUPPORT_LIB - ) - endif() - if (WIN32) set(qt_lib_prefix "") set(qt_lib_suffix $<$:d>.lib) @@ -255,7 +202,6 @@ else() set(qt_libs_dbus_support lib/${qt_lib_prefix}Qt5LinuxAccessibilitySupport) set(qt_libs_dbus_plugins plugins/platforminputcontexts/${qt_lib_prefix}ibusplatforminputcontextplugin - plugins/platformthemes/${qt_lib_prefix}qxdgdesktopportal ) set(qt_libs_dbus_bearers plugins/bearer/${qt_lib_prefix}qconnmanbearer @@ -267,11 +213,11 @@ else() if (Qt5WaylandClient_FOUND) set(qt_libs_waylandclient lib/${qt_lib_prefix}Qt5WaylandClient) set(qt_libs_waylandclient_plugins - plugins/wayland-decoration-client/${qt_lib_prefix}bradient - plugins/wayland-shell-integration/${qt_lib_prefix}wl-shell - plugins/wayland-graphics-integration-client/${qt_lib_prefix}qt-plugin-wayland-egl - plugins/platforms/${qt_lib_prefix}qwayland-egl plugins/platforms/${qt_lib_prefix}qwayland-generic + plugins/platforms/${qt_lib_prefix}qwayland-egl + plugins/wayland-graphics-integration-client/${qt_lib_prefix}qt-plugin-wayland-egl + plugins/wayland-shell-integration/${qt_lib_prefix}wl-shell + plugins/wayland-decoration-client/${qt_lib_prefix}bradient ) endif() set(qt_libs diff --git a/external/qt/qt_static_plugins/CMakeLists.txt b/external/qt/qt_static_plugins/CMakeLists.txt index 921e41b..8764174 100644 --- a/external/qt/qt_static_plugins/CMakeLists.txt +++ b/external/qt/qt_static_plugins/CMakeLists.txt @@ -22,7 +22,6 @@ if (LINUX) target_link_libraries(external_qt_static_plugins PUBLIC desktop-app::external_nimf_qt5 - desktop-app::external_qt5ct_support ) if (NOT DESKTOP_APP_DISABLE_DBUS_INTEGRATION) diff --git a/external/qt/qt_static_plugins/qt_static_plugins.cpp b/external/qt/qt_static_plugins/qt_static_plugins.cpp index 34501ae..9f0244b 100644 --- a/external/qt/qt_static_plugins/qt_static_plugins.cpp +++ b/external/qt/qt_static_plugins/qt_static_plugins.cpp @@ -31,14 +31,13 @@ Q_IMPORT_PLUGIN(QSvgIconPlugin) Q_IMPORT_PLUGIN(QConnmanEnginePlugin) Q_IMPORT_PLUGIN(QNetworkManagerEnginePlugin) Q_IMPORT_PLUGIN(QIbusPlatformInputContextPlugin) -Q_IMPORT_PLUGIN(QXdgDesktopPortalThemePlugin) #endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION #ifndef DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION +Q_IMPORT_PLUGIN(QWaylandIntegrationPlugin) +Q_IMPORT_PLUGIN(QWaylandEglPlatformIntegrationPlugin) Q_IMPORT_PLUGIN(QWaylandEglClientBufferPlugin) Q_IMPORT_PLUGIN(QWaylandWlShellIntegrationPlugin) Q_IMPORT_PLUGIN(QWaylandBradientDecorationPlugin) -Q_IMPORT_PLUGIN(QWaylandIntegrationPlugin) -Q_IMPORT_PLUGIN(QWaylandEglPlatformIntegrationPlugin) #endif // !DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION #endif // Q_OS_WIN | Q_OS_MAC | Q_OS_UNIX #endif // !DESKTOP_APP_USE_PACKAGED @@ -54,9 +53,4 @@ Q_IMPORT_PLUGIN(QFcitx5PlatformInputContextPlugin) Q_IMPORT_PLUGIN(QHimePlatformInputContextPlugin) #endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION #endif // !DESKTOP_APP_USE_PACKAGED || DESKTOP_APP_USE_PACKAGED_LAZY - -#if !defined DESKTOP_APP_USE_PACKAGED || defined DESKTOP_APP_USE_PACKAGED_LAZY_PLATFORMTHEMES -Q_IMPORT_PLUGIN(Qt5CTPlatformThemePlugin) -Q_IMPORT_PLUGIN(Qt5CTStylePlugin) -#endif // !DESKTOP_APP_USE_PACKAGED || DESKTOP_APP_USE_PACKAGED_LAZY_PLATFORMTHEMES #endif // Q_OS_UNIX && !Q_OS_MAC diff --git a/external/qt5ct_support/CMakeLists.txt b/external/qt5ct_support/CMakeLists.txt deleted file mode 100644 index eea85e2..0000000 --- a/external/qt5ct_support/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -# 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(external_qt5ct_support INTERFACE IMPORTED GLOBAL) -add_library(desktop-app::external_qt5ct_support ALIAS external_qt5ct_support) - -add_subdirectory(qt5ct) -add_subdirectory(qt5ct_qtplugin) -add_subdirectory(qt5ct_style) - -target_link_libraries(external_qt5ct_support -INTERFACE - desktop-app::external_qt5ct_style - desktop-app::external_qt5ct_qtplugin -) diff --git a/external/qt5ct_support/qt5ct/CMakeLists.txt b/external/qt5ct_support/qt5ct/CMakeLists.txt deleted file mode 100644 index 44df85e..0000000 --- a/external/qt5ct_support/qt5ct/CMakeLists.txt +++ /dev/null @@ -1,40 +0,0 @@ -# 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 - -if (DESKTOP_APP_USE_PACKAGED AND NOT DESKTOP_APP_USE_PACKAGED_LAZY_PLATFORMTHEMES) - add_library(external_qt5ct INTERFACE IMPORTED GLOBAL) - add_library(desktop-app::external_qt5ct ALIAS external_qt5ct) -else() - add_library(external_qt5ct STATIC) - add_library(desktop-app::external_qt5ct ALIAS external_qt5ct) - init_target(external_qt5ct "(external)") - - set(qt5ct_loc ${third_party_loc}/qt5ct) - set(qt5ct_src ${qt5ct_loc}/src/qt5ct) - - set_target_properties(external_qt5ct PROPERTIES AUTOMOC ON) - - nice_target_sources(external_qt5ct ${qt5ct_src} - PRIVATE - qt5ct.cpp - qt5ct.h - ) - - target_include_directories(external_qt5ct - PRIVATE - ${qt5ct_src} - ) - - target_include_directories(external_qt5ct - PUBLIC - ${qt5ct_loc}/src - ) - - target_link_libraries(external_qt5ct - PRIVATE - desktop-app::external_qt - ) -endif() diff --git a/external/qt5ct_support/qt5ct_qtplugin/CMakeLists.txt b/external/qt5ct_support/qt5ct_qtplugin/CMakeLists.txt deleted file mode 100644 index 53de315..0000000 --- a/external/qt5ct_support/qt5ct_qtplugin/CMakeLists.txt +++ /dev/null @@ -1,42 +0,0 @@ -# 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 - -if (DESKTOP_APP_USE_PACKAGED AND NOT DESKTOP_APP_USE_PACKAGED_LAZY_PLATFORMTHEMES) - add_library(external_qt5ct_qtplugin INTERFACE IMPORTED GLOBAL) - add_library(desktop-app::external_qt5ct_qtplugin ALIAS external_qt5ct_qtplugin) -else() - add_library(external_qt5ct_qtplugin STATIC) - add_library(desktop-app::external_qt5ct_qtplugin ALIAS external_qt5ct_qtplugin) - init_target(external_qt5ct_qtplugin "(external)") - - set(qt5ct_loc ${third_party_loc}/qt5ct) - set(qt5ct_qtplugin_src ${qt5ct_loc}/src/qt5ct-qtplugin) - - set_target_properties(external_qt5ct_qtplugin PROPERTIES AUTOMOC ON) - - nice_target_sources(external_qt5ct_qtplugin ${qt5ct_qtplugin_src} - PRIVATE - main.cpp - qt5ctplatformtheme.cpp - qt5ctplatformtheme.h - ) - - target_include_directories(external_qt5ct_qtplugin - PRIVATE - ${qt5ct_qtplugin_src} - ) - - target_compile_definitions(external_qt5ct_qtplugin - PRIVATE - QT_STATICPLUGIN - ) - - target_link_libraries(external_qt5ct_qtplugin - PRIVATE - desktop-app::external_qt5ct - desktop-app::external_qt - ) -endif() diff --git a/external/qt5ct_support/qt5ct_style/CMakeLists.txt b/external/qt5ct_support/qt5ct_style/CMakeLists.txt deleted file mode 100644 index 4cb2da7..0000000 --- a/external/qt5ct_support/qt5ct_style/CMakeLists.txt +++ /dev/null @@ -1,42 +0,0 @@ -# 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 - -if (DESKTOP_APP_USE_PACKAGED AND NOT DESKTOP_APP_USE_PACKAGED_LAZY_PLATFORMTHEMES) - add_library(external_qt5ct_style INTERFACE IMPORTED GLOBAL) - add_library(desktop-app::external_qt5ct_style ALIAS external_qt5ct_style) -else() - add_library(external_qt5ct_style STATIC) - add_library(desktop-app::external_qt5ct_style ALIAS external_qt5ct_style) - init_target(external_qt5ct_style "(external)") - - set(qt5ct_loc ${third_party_loc}/qt5ct) - set(qt5ct_style_src ${qt5ct_loc}/src/qt5ct-style) - - set_target_properties(external_qt5ct_style PROPERTIES AUTOMOC ON) - - nice_target_sources(external_qt5ct_style ${qt5ct_style_src} - PRIVATE - plugin.cpp - qt5ctproxystyle.cpp - qt5ctproxystyle.h - ) - - target_include_directories(external_qt5ct_style - PRIVATE - ${qt5ct_style_src} - ) - - target_compile_definitions(external_qt5ct_style - PRIVATE - QT_STATICPLUGIN - ) - - target_link_libraries(external_qt5ct_style - PRIVATE - desktop-app::external_qt5ct - desktop-app::external_qt - ) -endif() diff --git a/options.cmake b/options.cmake index 82fb6e3..6cd9093 100644 --- a/options.cmake +++ b/options.cmake @@ -63,13 +63,6 @@ if (DESKTOP_APP_USE_PACKAGED_LAZY) ) endif() -if (DESKTOP_APP_USE_PACKAGED_LAZY_PLATFORMTHEMES) - target_compile_definitions(common_options - INTERFACE - DESKTOP_APP_USE_PACKAGED_LAZY_PLATFORMTHEMES - ) -endif() - if (DESKTOP_APP_USE_PACKAGED_FONTS) target_compile_definitions(common_options INTERFACE diff --git a/variables.cmake b/variables.cmake index 7a6eeb9..5c19c2c 100644 --- a/variables.cmake +++ b/variables.cmake @@ -36,7 +36,6 @@ option(DESKTOP_APP_USE_GLIBC_WRAPS "Use wraps for new GLIBC features." 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) -option(DESKTOP_APP_USE_PACKAGED_LAZY_PLATFORMTHEMES "Bundle recommended Qt platform themes for self-contained packages. (Linux only)" ${DESKTOP_APP_USE_PACKAGED_LAZY}) option(DESKTOP_APP_USE_PACKAGED_FFMPEG_STATIC "Link ffmpeg statically in packaged mode." OFF) option(DESKTOP_APP_DISABLE_SPELLCHECK "Disable spellcheck library." ${osx_special_target}) option(DESKTOP_APP_DISABLE_CRASH_REPORTS "Disable crash report generation." ${no_special_target}) @@ -44,7 +43,6 @@ option(DESKTOP_APP_DISABLE_AUTOUPDATE "Disable autoupdate." ${disable_autoupdate option(DESKTOP_APP_USE_HUNSPELL_ONLY "Disable system spellchecker and use bundled Hunspell only. (For debugging purposes)" OFF) option(DESKTOP_APP_USE_ENCHANT "Use Enchant instead of bundled Hunspell. (Linux only)" OFF) option(DESKTOP_APP_NO_PDB "Disable PDB file generation. (Windows only)" OFF) -set(DESKTOP_APP_QTWAYLANDCLIENT_PRIVATE_HEADERS "" CACHE STRING "QtWaylandClient headers location.") set(dont_bundle_fonts 0) if (DESKTOP_APP_USE_PACKAGED AND NOT DESKTOP_APP_USE_PACKAGED_LAZY) From 545f6bf2ce87da7be39f6c818d45df394a5654f5 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 22 Jun 2021 09:50:05 +0400 Subject: [PATCH 25/29] Add NuGet functions to add WebView / WinRT packages. --- nuget.cmake | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 nuget.cmake diff --git a/nuget.cmake b/nuget.cmake new file mode 100644 index 0000000..b600d2f --- /dev/null +++ b/nuget.cmake @@ -0,0 +1,126 @@ +# 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 + +function(nuget_add_package package_name package package_version) + if (NOT DEFINED NUGET_EXE_PATH) + # Thanks https://github.com/clarkezone/flutter_win_webview/blob/master/webview_popupauth/windows/CMakeLists.txt + find_program(NUGET_EXE NAMES nuget) + if (NOT NUGET_EXE) + message("NUGET.EXE not found.") + message(FATAL_ERROR "Please install this executable, and run CMake again.") + endif() + set(NUGET_EXE_PATH ${NUGET_EXE} PARENT_SCOPE) + else() + set(NUGET_EXE ${NUGET_EXE_PATH}) + endif() + + set(package_key NUGET_${package_name}_VERSION) + if (NOT DEFINED ${package_key}) + set(packages_loc ${CMAKE_BINARY_DIR}/packages) + file(MAKE_DIRECTORY ${packages_loc}) + + set(${package_key} ${package_version}) + execute_process( + COMMAND + ${NUGET_EXE} + install + ${package} + -Version ${package_version} + -ExcludeVersion + -OutputDirectory ${packages_loc} + ) + set(${package_name}_loc ${CMAKE_BINARY_DIR}/packages/${package} PARENT_SCOPE) + elseif ("${${package_key}}" != ${package_version}) + message(FATAL_ERROR "Package ${package_name} requested with both ${${package_key}} and ${package_version}") + endif() +endfunction() + +function(nuget_add_webview target_name) + nuget_add_package(webview2 "Microsoft.Web.WebView2" 1.0.864.35) + + set(webview2_loc_native ${webview2_loc}/build/native) + # target_link_libraries(${target_name} + # PRIVATE + # ${webview2_loc_native}/Microsoft.Web.WebView2.targets + # ${src_loc}/ForceStaticLink.targets + # ) + # + # This works, but just to be sure, manually link to static library. + # + target_include_directories(${target_name} + PRIVATE + ${webview2_loc_native}/include + ) + if (build_win64) + set(webview2_lib_folder x64) + else() + set(webview2_lib_folder x86) + endif() + target_link_libraries(${target_name} + PRIVATE + ${webview2_loc_native}/${webview2_lib_folder}/WebView2LoaderStatic.lib + ) + +endfunction() + +function(nuget_add_winrt target_name) + nuget_add_package(winrt "Microsoft.Windows.CppWinRT" 2.0.210505.3) + + set(gen_dst ${CMAKE_BINARY_DIR}/packages/gen) + file(MAKE_DIRECTORY ${gen_dst}/winrt) + + set(winrt_sdk_version ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}) + set(winrt_version_key ${gen_dst}/winrt/version_key) + set(winrt_version_test ${winrt_version_key}_test) + set(sdk_version_key ${gen_dst}/winrt/sdk_version_key) + set(sdk_version_test ${sdk_version_key}_test) + + execute_process( + COMMAND + ${winrt_loc}/bin/cppwinrt + /? + OUTPUT_FILE + ${winrt_version_test} + ) + execute_process( + COMMAND + echo + ${winrt_sdk_version} + OUTPUT_FILE + ${sdk_version_test} + ) + execute_process( + COMMAND + ${CMAKE_COMMAND} -E compare_files ${winrt_version_key} ${winrt_version_test} + RESULT_VARIABLE winrt_version_compare_result + ) + execute_process( + COMMAND + ${CMAKE_COMMAND} -E compare_files ${sdk_version_key} ${sdk_version_test} + RESULT_VARIABLE sdk_version_compare_result + ) + if (winrt_version_compare_result EQUAL 0 AND sdk_version_compare_result EQUAL 0) + message("Using existing WinRT headers.") + else() + message("Generating new WinRT headers.") + + execute_process( + COMMAND + ${winrt_loc}/bin/cppwinrt + -input ${winrt_sdk_version} + -output ${gen_dst} + COMMAND + cp ${winrt_version_test} ${winrt_version_key} + COMMAND + cp ${sdk_version_test} ${sdk_version_key} + ) + endif() + + target_include_directories(${target_name} + PRIVATE + ${gen_dst} + ) +endfunction() From 52d7dc3993dfcb305cf5500b9859c123868107fd Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 22 Jun 2021 19:44:05 +0400 Subject: [PATCH 26/29] Fix multiple usages of nuget_add_... --- nuget.cmake | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/nuget.cmake b/nuget.cmake index b600d2f..bae1b55 100644 --- a/nuget.cmake +++ b/nuget.cmake @@ -5,24 +5,27 @@ # https://github.com/desktop-app/legal/blob/master/LEGAL function(nuget_add_package package_name package package_version) - if (NOT DEFINED NUGET_EXE_PATH) + get_property(nuget_exe_defined GLOBAL PROPERTY nuget_exe_path_property SET) + if (NOT nuget_exe_defined) # Thanks https://github.com/clarkezone/flutter_win_webview/blob/master/webview_popupauth/windows/CMakeLists.txt find_program(NUGET_EXE NAMES nuget) if (NOT NUGET_EXE) message("NUGET.EXE not found.") message(FATAL_ERROR "Please install this executable, and run CMake again.") endif() - set(NUGET_EXE_PATH ${NUGET_EXE} PARENT_SCOPE) + message("Resolved NuGet executable: ${NUGET_EXE}") + set_property(GLOBAL PROPERTY nuget_exe_path_property ${NUGET_EXE}) else() - set(NUGET_EXE ${NUGET_EXE_PATH}) + get_property(NUGET_EXE GLOBAL PROPERTY nuget_exe_path_property) endif() - set(package_key NUGET_${package_name}_VERSION) - if (NOT DEFINED ${package_key}) + set(package_key nuget_${package_name}_version_property) + get_property(package_version_defined GLOBAL PROPERTY ${package_key} SET) + if (NOT package_version_defined) set(packages_loc ${CMAKE_BINARY_DIR}/packages) file(MAKE_DIRECTORY ${packages_loc}) - set(${package_key} ${package_version}) + set_property(GLOBAL PROPERTY ${package_key} ${package_version}) execute_process( COMMAND ${NUGET_EXE} @@ -32,10 +35,13 @@ function(nuget_add_package package_name package package_version) -ExcludeVersion -OutputDirectory ${packages_loc} ) - set(${package_name}_loc ${CMAKE_BINARY_DIR}/packages/${package} PARENT_SCOPE) - elseif ("${${package_key}}" != ${package_version}) - message(FATAL_ERROR "Package ${package_name} requested with both ${${package_key}} and ${package_version}") + else() + get_property(package_version_cached GLOBAL PROPERTY ${package_key}) + if (NOT (${package_version_cached} EQUAL ${package_version})) + message(FATAL_ERROR "Package ${package_name} requested with both ${package_version_cached} and ${package_version}") + endif() endif() + set(${package_name}_loc ${CMAKE_BINARY_DIR}/packages/${package} PARENT_SCOPE) endfunction() function(nuget_add_webview target_name) From c29450cbf1e59aefdbcbe46fd5f37e3172ce8725 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 22 Jun 2021 23:07:09 +0400 Subject: [PATCH 27/29] Add CoreMediaIO framework on macOS. --- options_mac.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/options_mac.cmake b/options_mac.cmake index 55fa5e3..f59c0c0 100644 --- a/options_mac.cmake +++ b/options_mac.cmake @@ -71,6 +71,7 @@ INTERFACE AVFoundation CoreAudio CoreVideo + CoreMediaIO QuartzCore AppKit CoreWLAN From 3ba5f8d46a9023705a76f5b860514d61cf23893e Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 24 Jun 2021 16:01:49 +0400 Subject: [PATCH 28/29] Enable /LARGEADDRESSAWARE for 32 bit Windows build. --- options_win.cmake | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/options_win.cmake b/options_win.cmake index bd43547..a263ff7 100644 --- a/options_win.cmake +++ b/options_win.cmake @@ -41,7 +41,12 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") if (build_win64) target_compile_options(common_options INTERFACE - /bigobj # scheme.cpp has too many sections. + /BIGOBJ # scheme.cpp has too many sections. + ) + else() + target_link_options(common_options + INTERFACE + /LARGEADDRESSAWARE # Allow more than 2 GB in 32 bit application.ß ) endif() elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") From c8fa5ef7149cabbef52411070fcc6d5bad96feae Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 24 Jun 2021 18:38:30 +0400 Subject: [PATCH 29/29] Fix /bigobj option on Windows (it is case sensitive). --- options_win.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/options_win.cmake b/options_win.cmake index a263ff7..cf94d56 100644 --- a/options_win.cmake +++ b/options_win.cmake @@ -41,7 +41,7 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") if (build_win64) target_compile_options(common_options INTERFACE - /BIGOBJ # scheme.cpp has too many sections. + /bigobj # scheme.cpp has too many sections. ) else() target_link_options(common_options