Fix build on some Vala compiler versions

See https://gitlab.gnome.org/GNOME/vala/-/issues/1474 and https://gitlab.gnome.org/GNOME/vala/-/issues/1478
This commit is contained in:
Marvin W 2023-08-24 20:18:26 +02:00 committed by fiaxh
parent 2fba24ccae
commit 9eafe4139d
8 changed files with 54 additions and 4 deletions

View file

@ -6,6 +6,11 @@ find_packages(LIBDINO_PACKAGES REQUIRED
GObject GObject
) )
set(LIBDINO_DEFINITIONS)
if(LIBDINO_VERSION VERSION_EQUAL "0.56.11")
set(LIBDINO_DEFINITIONS ${LIBDINO_DEFINITIONS} VALA_0_56_11)
endif()
vala_precompile(LIBDINO_VALA_C vala_precompile(LIBDINO_VALA_C
SOURCES SOURCES
src/application.vala src/application.vala
@ -76,6 +81,8 @@ GENERATE_VAPI
dino dino
GENERATE_HEADER GENERATE_HEADER
dino dino
DEFINITIONS
${LIBDINO_DEFINITIONS}
) )
add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/exports/dino_i18n.h" add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/exports/dino_i18n.h"

View file

@ -89,7 +89,12 @@ public class ModuleIdentity<T> : Object {
} }
public T? cast(StreamInteractionModule module) { public T? cast(StreamInteractionModule module) {
#if VALA_0_56_11
// We can't typecheck due to compiler bug
return (T) module;
#else
return module.get_type().is_a(typeof(T)) ? (T?) module : null; return module.get_type().is_a(typeof(T)) ? (T?) module : null;
#endif
} }
public bool matches(StreamInteractionModule module) { public bool matches(StreamInteractionModule module) {

View file

@ -111,9 +111,24 @@ endif()
if(GTK4_VERSION VERSION_GREATER_EQUAL "4.8") if(GTK4_VERSION VERSION_GREATER_EQUAL "4.8")
set(MAIN_DEFINITIONS ${MAIN_DEFINITIONS} GTK_4_8) set(MAIN_DEFINITIONS ${MAIN_DEFINITIONS} GTK_4_8)
endif() endif()
if(GTK4_VERSION VERSION_GREATER_EQUAL "4.12")
set(MAIN_DEFINITIONS ${MAIN_DEFINITIONS} GTK_4_12)
endif()
if(Adwaita_VERSION VERSION_GREATER_EQUAL "1.2") if(Adwaita_VERSION VERSION_GREATER_EQUAL "1.2")
set(MAIN_DEFINITIONS ${MAIN_DEFINITIONS} Adw_1_2) set(MAIN_DEFINITIONS ${MAIN_DEFINITIONS} Adw_1_2)
endif() endif()
if(VALA_VERSION VERSION_GREATER_EQUAL "0.56.5" AND VALA_VERSION VERSION_LESS "0.58")
set(MAIN_DEFINITIONS ${MAIN_DEFINITIONS} VALA_0_56_GREATER_5)
endif()
if(VALA_VERSION VERSION_GREATER_EQUAL "0.56.11" AND VALA_VERSION VERSION_LESS "0.58")
set(MAIN_DEFINITIONS ${MAIN_DEFINITIONS} VALA_0_56_GREATER_11)
endif()
if(VALA_VERSION VERSION_EQUAL "0.56.11")
set(MAIN_DEFINITIONS ${MAIN_DEFINITIONS} VALA_0_56_11)
endif()
if(VALA_VERSION VERSION_EQUAL "0.56.12")
set(MAIN_DEFINITIONS ${MAIN_DEFINITIONS} VALA_0_56_12)
endif()
vala_precompile(MAIN_VALA_C vala_precompile(MAIN_VALA_C
SOURCES SOURCES

View file

@ -103,7 +103,13 @@ private const string force_color_css = "%s { color: %s; }";
public static Gtk.CssProvider force_css(Gtk.Widget widget, string css) { public static Gtk.CssProvider force_css(Gtk.Widget widget, string css) {
var p = new Gtk.CssProvider(); var p = new Gtk.CssProvider();
try { try {
#if GTK_4_12 && (VALA_0_56_GREATER_11 || VALA_0_58)
p.load_from_string(css);
#elif (VALA_0_56_11 || VALA_0_56_12)
p.load_from_data(css, css.length);
#else
p.load_from_data(css.data); p.load_from_data(css.data);
#endif
widget.get_style_context().add_provider(p, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); widget.get_style_context().add_provider(p, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
} catch (GLib.Error err) { } catch (GLib.Error err) {
// handle err // handle err

View file

@ -454,7 +454,7 @@ public class Dino.Ui.AvatarPicture : Gtk.Widget {
label.insert_after(this, null); label.insert_after(this, null);
label.attributes = new Pango.AttrList(); label.attributes = new Pango.AttrList();
label.attributes.insert(Pango.attr_foreground_new(uint16.MAX, uint16.MAX, uint16.MAX)); label.attributes.insert(Pango.attr_foreground_new(uint16.MAX, uint16.MAX, uint16.MAX));
#if GTK_4_8 && VALA_0_58 #if GTK_4_8 && (VALA_0_56_GREATER_5 || VALA_0_58)
picture.content_fit = Gtk.ContentFit.COVER; picture.content_fit = Gtk.ContentFit.COVER;
#elif GTK_4_8 #elif GTK_4_8
picture.@set("content-fit", 2); picture.@set("content-fit", 2);

View file

@ -8,7 +8,7 @@ class Dino.Ui.FixedRatioPicture : Gtk.Widget {
public int max_height { get; set; default = int.MAX; } public int max_height { get; set; default = int.MAX; }
public File file { get { return inner.file; } set { inner.file = value; } } public File file { get { return inner.file; } set { inner.file = value; } }
public Gdk.Paintable paintable { get { return inner.paintable; } set { inner.paintable = value; } } public Gdk.Paintable paintable { get { return inner.paintable; } set { inner.paintable = value; } }
#if GTK_4_8 && VALA_0_58 #if GTK_4_8 && (VALA_0_56_GREATER_5 || VALA_0_58)
public Gtk.ContentFit content_fit { get { return inner.content_fit; } set { inner.content_fit = value; } } public Gtk.ContentFit content_fit { get { return inner.content_fit; } set { inner.content_fit = value; } }
#endif #endif
private Gtk.Picture inner = new Gtk.Picture(); private Gtk.Picture inner = new Gtk.Picture();

View file

@ -9,6 +9,11 @@ find_packages(ENGINE_PACKAGES REQUIRED
set(ENGINE_EXTRA_OPTIONS ${MAIN_EXTRA_OPTIONS} --vapidir=${CMAKE_CURRENT_SOURCE_DIR}/vapi) set(ENGINE_EXTRA_OPTIONS ${MAIN_EXTRA_OPTIONS} --vapidir=${CMAKE_CURRENT_SOURCE_DIR}/vapi)
set(ENGINE_DEFINITIONS)
if(VALA_VERSION VERSION_EQUAL "0.56.11")
set(ENGINE_DEFINITIONS ${ENGINE_DEFINITIONS} VALA_0_56_11)
endif()
vala_precompile(ENGINE_VALA_C vala_precompile(ENGINE_VALA_C
SOURCES SOURCES
"src/core/direct_tls_xmpp_stream.vala" "src/core/direct_tls_xmpp_stream.vala"
@ -152,6 +157,8 @@ CUSTOM_VAPIS
"${CMAKE_CURRENT_SOURCE_DIR}/src/glib_fixes.vapi" "${CMAKE_CURRENT_SOURCE_DIR}/src/glib_fixes.vapi"
OPTIONS OPTIONS
${ENGINE_EXTRA_OPTIONS} ${ENGINE_EXTRA_OPTIONS}
DEFINITIONS
${ENGINE_DEFINITIONS}
) )
add_custom_target(xmpp-vala-vapi add_custom_target(xmpp-vala-vapi

View file

@ -10,7 +10,12 @@ namespace Xmpp {
} }
public T? cast(XmppStreamFlag flag) { public T? cast(XmppStreamFlag flag) {
#if VALA_0_56_11
// We can't typecheck due to compiler bug
return (T) module;
#else
return flag.get_type().is_a(typeof(T)) ? (T?) flag : null; return flag.get_type().is_a(typeof(T)) ? (T?) flag : null;
#endif
} }
public bool matches(XmppStreamFlag module) { public bool matches(XmppStreamFlag module) {
@ -34,7 +39,12 @@ namespace Xmpp {
} }
public T? cast(XmppStreamModule module) { public T? cast(XmppStreamModule module) {
#if VALA_0_56_11
// We can't typecheck due to compiler bug
return (T) module;
#else
return module.get_type().is_a(typeof(T)) ? (T?) module : null; return module.get_type().is_a(typeof(T)) ? (T?) module : null;
#endif
} }
public bool matches(XmppStreamModule module) { public bool matches(XmppStreamModule module) {