From 1c8cfe49c50d469db67ad8769c038e9ab5e296e4 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Mon, 12 Jul 2021 00:11:19 +0400 Subject: [PATCH] Clang build fixes --- .../hime_qt/hime_im_client/CMakeLists.txt | 14 +++++ init_target.cmake | 2 +- linux_gtk_helper/linux_gtk_helper.cpp | 51 ++++++++++++++----- options_linux.cmake | 22 +++++--- variables.cmake | 2 +- 5 files changed, 70 insertions(+), 21 deletions(-) diff --git a/external/hime_qt/hime_im_client/CMakeLists.txt b/external/hime_qt/hime_im_client/CMakeLists.txt index 63773b0..9e70b1d 100644 --- a/external/hime_qt/hime_im_client/CMakeLists.txt +++ b/external/hime_qt/hime_im_client/CMakeLists.txt @@ -55,6 +55,20 @@ else() GTK_DISABLE_DEPRECATED ) + 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 diff --git a/init_target.cmake b/init_target.cmake index 3a4806b..19efc98 100644 --- a/init_target.cmake +++ b/init_target.cmake @@ -5,7 +5,7 @@ # https://github.com/desktop-app/legal/blob/master/LEGAL set(MAXIMUM_CXX_STANDARD cxx_std_20) -if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") set(MAXIMUM_CXX_STANDARD cxx_std_17) endif() diff --git a/linux_gtk_helper/linux_gtk_helper.cpp b/linux_gtk_helper/linux_gtk_helper.cpp index 231eb78..4cb4ea1 100644 --- a/linux_gtk_helper/linux_gtk_helper.cpp +++ b/linux_gtk_helper/linux_gtk_helper.cpp @@ -63,6 +63,10 @@ void (*gtk_color_chooser_set_use_alpha)( gboolean use_alpha); GType (*gtk_container_get_type)(void); void (*gtk_container_remove)(GtkContainer *container, GtkWidget *widget); +GtkWidget *(*gtk_dialog_add_button)( + GtkDialog *dialog, + const gchar *button_text, + gint response_id); GType (*gtk_dialog_get_type)(void); GtkWidget* (*gtk_dialog_get_widget_for_response)( GtkDialog *dialog, @@ -71,12 +75,7 @@ gint (*gtk_dialog_run)(GtkDialog *dialog); void (*gtk_file_chooser_add_filter)( GtkFileChooser *chooser, GtkFileFilter *filter); -GtkWidget *(*gtk_file_chooser_dialog_new)( - const gchar *title, - GtkWindow *parent, - GtkFileChooserAction action, - const gchar *first_button_text, - ...); +GType (*gtk_file_chooser_dialog_get_type)(void); gchar *(*gtk_file_chooser_get_current_folder)(GtkFileChooser *chooser); gchar *(*gtk_file_chooser_get_filename)(GtkFileChooser *chooser); GSList *(*gtk_file_chooser_get_filenames)(GtkFileChooser *chooser); @@ -179,6 +178,7 @@ void (*gtk_widget_set_visible)(GtkWidget *widget, gboolean visible); void (*gtk_widget_show)(GtkWidget *widget); GType (*gtk_window_get_type)(void); void (*gtk_window_set_title)(GtkWindow *window, const gchar *title); +void (*gtk_window_set_transient_for)(GtkWindow *window, GtkWindow *parent); void (*pango_font_description_free)(PangoFontDescription *desc); PangoFontDescription *(*pango_font_description_from_string)(const char *str); const char *(*pango_font_description_get_family)( @@ -264,11 +264,12 @@ bool Resolve() { && LOAD_SYMBOL(lib, gtk_color_chooser_set_use_alpha) && LOAD_SYMBOL(lib, gtk_container_get_type) && LOAD_SYMBOL(lib, gtk_container_remove) + && LOAD_SYMBOL(lib, gtk_dialog_add_button) && LOAD_SYMBOL(lib, gtk_dialog_get_type) && LOAD_SYMBOL(lib, gtk_dialog_get_widget_for_response) && LOAD_SYMBOL(lib, gtk_dialog_run) && LOAD_SYMBOL(lib, gtk_file_chooser_add_filter) - && LOAD_SYMBOL(lib, gtk_file_chooser_dialog_new) + && LOAD_SYMBOL(lib, gtk_file_chooser_dialog_get_type) && LOAD_SYMBOL(lib, gtk_file_chooser_get_current_folder) && LOAD_SYMBOL(lib, gtk_file_chooser_get_filename) && LOAD_SYMBOL(lib, gtk_file_chooser_get_filenames) @@ -325,6 +326,7 @@ bool Resolve() { && LOAD_SYMBOL(lib, gtk_widget_show) && LOAD_SYMBOL(lib, gtk_window_get_type) && LOAD_SYMBOL(lib, gtk_window_set_title) + && LOAD_SYMBOL(lib, gtk_window_set_transient_for) && LOAD_SYMBOL(lib, pango_font_description_free) && LOAD_SYMBOL(lib, pango_font_description_from_string) && LOAD_SYMBOL(lib, pango_font_description_get_family) @@ -546,12 +548,35 @@ GtkWidget *gtk_file_chooser_dialog_new( const gchar *first_button_text, ...) { GtkHelper::Resolve(); - __builtin_return( - __builtin_apply( - reinterpret_cast( - GtkHelper::gtk_file_chooser_dialog_new), - __builtin_apply_args(), - 1000)); + + va_list varargs; + va_start(varargs, first_button_text); + + const auto result = static_cast(g_object_new( + GtkHelper::gtk_file_chooser_dialog_get_type(), + "title", + title, + "action", + action, + nullptr)); + + if (parent) { + GtkHelper::gtk_window_set_transient_for(GTK_WINDOW(result), parent); + } + + auto button_text = first_button_text; + gint response_id; + while (button_text) { + response_id = va_arg(varargs, gint); + GtkHelper::gtk_dialog_add_button( + GTK_DIALOG(result), + button_text, + response_id); + button_text = va_arg(varargs, const gchar *); + } + + va_end(varargs); + return result; } gchar *gtk_file_chooser_get_current_folder(GtkFileChooser *chooser) { diff --git a/options_linux.cmake b/options_linux.cmake index ae687ff..e7b164f 100644 --- a/options_linux.cmake +++ b/options_linux.cmake @@ -16,17 +16,23 @@ INTERFACE -Wno-unused-function -Wno-switch -Wno-comment - -Wno-unused-but-set-variable -Wno-missing-field-initializers -Wno-sign-compare -Wno-attributes -Wno-parentheses - -Wno-stringop-overflow - -Wno-maybe-uninitialized - -Wno-error=class-memaccess $<$>:-Wno-register> ) +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + target_compile_options(common_options + INTERFACE + -Wno-unused-but-set-variable + -Wno-stringop-overflow + -Wno-maybe-uninitialized + -Wno-error=class-memaccess + ) +endif() + if (DESKTOP_APP_SPECIAL_TARGET) target_compile_options(common_options INTERFACE @@ -43,8 +49,12 @@ if (DESKTOP_APP_SPECIAL_TARGET) target_compile_options(common_options INTERFACE -g0) target_link_options(common_options INTERFACE -g0) else() - target_compile_options(common_options INTERFACE $,,-g -flto>) - target_link_options(common_options INTERFACE $,,-g -flto -fuse-linker-plugin>) + target_compile_options(common_options INTERFACE $,,-g>) + target_link_options(common_options INTERFACE $,,-g>) + if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + target_compile_options(common_options INTERFACE $,,-flto>) + target_link_options(common_options INTERFACE $,,-flto -fuse-linker-plugin>) + endif() endif() endif() diff --git a/variables.cmake b/variables.cmake index 80c336a..bff1d6e 100644 --- a/variables.cmake +++ b/variables.cmake @@ -95,7 +95,7 @@ else() report_bad_special_target() endif() endif() - if (DESKTOP_APP_SPECIAL_TARGET) + if (DESKTOP_APP_SPECIAL_TARGET AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU") set(CMAKE_AR "gcc-ar") set(CMAKE_RANLIB "gcc-ranlib") set(CMAKE_NM "gcc-nm")