From cfaba49683fb76c218f60c28ccb0afbaa1353cd2 Mon Sep 17 00:00:00 2001 From: Leah Lundqvist Date: Mon, 12 Apr 2021 18:35:06 +0200 Subject: [PATCH] ios: move `sokol` declarations out of builder, and support non-sokol apps too (#9703) --- vlib/sokol/c/declaration.c.v | 10 ++++++++-- vlib/v/builder/cc.v | 5 ----- vlib/v/gen/c/cmain.v | 5 ++++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/vlib/sokol/c/declaration.c.v b/vlib/sokol/c/declaration.c.v index fdf9214b83..cb95fa3f49 100644 --- a/vlib/sokol/c/declaration.c.v +++ b/vlib/sokol/c/declaration.c.v @@ -12,8 +12,14 @@ pub const ( #flag freebsd -L/usr/local/lib -lX11 -lGL -lXcursor -lXi #flag windows -lgdi32 // METAL -#flag darwin -DSOKOL_METAL -#flag darwin -framework Metal -framework Cocoa -framework MetalKit -framework QuartzCore +$if darwin { + #flag -DSOKOL_METAL + #flag -framework Metal -framework Cocoa -framework MetalKit -framework QuartzCore +} +$if ios { + #flag -DSOKOL_METAL + #flag -framework Foundation -framework Metal -framework MetalKit -framework UIKit +} // OPENGL #flag linux -DSOKOL_GLCORE33 #flag freebsd -DSOKOL_GLCORE33 diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v index 6de42d380e..9090c64a20 100644 --- a/vlib/v/builder/cc.v +++ b/vlib/v/builder/cc.v @@ -202,11 +202,6 @@ fn (mut v Builder) setup_ccompiler_options(ccompiler string) { '-Wno-format-nonliteral', ] if v.pref.os == .ios { - ccoptions.args << '-framework Foundation' - ccoptions.args << '-framework UIKit' - ccoptions.args << '-framework Metal' - ccoptions.args << '-framework MetalKit' - ccoptions.args << '-DSOKOL_METAL' ccoptions.args << '-fobjc-arc' } ccoptions.debug_mode = v.pref.is_debug diff --git a/vlib/v/gen/c/cmain.v b/vlib/v/gen/c/cmain.v index 50dea5e198..9cfab64545 100644 --- a/vlib/v/gen/c/cmain.v +++ b/vlib/v/gen/c/cmain.v @@ -12,7 +12,10 @@ pub fn (mut g Gen) gen_c_main() { } g.out.writeln('') main_fn_start_pos := g.out.len - if (g.pref.os == .android && g.pref.is_apk) || g.pref.os == .ios { + + is_sokol := 'sokol' in g.table.imports + + if (g.pref.os == .android && g.pref.is_apk) || (g.pref.os == .ios && is_sokol) { g.gen_c_android_sokol_main() } else { g.gen_c_main_header()