| 1 | module c |
| 2 | |
| 3 | import sokol.memory as _ |
| 4 | |
| 5 | #flag -I @VEXEROOT/thirdparty/sokol |
| 6 | #flag -I @VEXEROOT/thirdparty/sokol/util |
| 7 | #flag freebsd -I /usr/local/include |
| 8 | #flag darwin -fobjc-arc |
| 9 | |
| 10 | // Platform-specific library linking |
| 11 | // X11 is the default on Linux |
| 12 | // Use `-d sokol_wayland` to enable Wayland support |
| 13 | #flag linux -DSOKOL_GLCORE |
| 14 | $if sokol_wayland ? { |
| 15 | #flag linux -lwayland-client -lwayland-egl -lxkbcommon -lxkbcommon-x11 -lEGL -lGL -lpthread -lm -ldl -lX11 -lXi -lXcursor |
| 16 | } $else { |
| 17 | // EGL is used instead of GLX on X11 to get consistent vsync under XWayland. |
| 18 | // GLX vsync is often ignored by XWayland compositors, causing frame pacing |
| 19 | // jitter. EGL honours the swap interval reliably on both native X11 and |
| 20 | // XWayland sessions. |
| 21 | #flag linux -lX11 -lXi -lXcursor -lEGL -lGL -lpthread -lm -ldl |
| 22 | } |
| 23 | #flag freebsd -DSOKOL_GLCORE |
| 24 | #flag freebsd -L/usr/local/lib -lX11 -lGL -lXcursor -lXi |
| 25 | #flag openbsd -DSOKOL_GLCORE |
| 26 | #flag openbsd -I/usr/X11R6/include -L/usr/X11R6/lib -lX11 -lGL -lXcursor -lXi |
| 27 | #flag windows -DSOKOL_GLCORE |
| 28 | #flag windows -lgdi32 |
| 29 | |
| 30 | $if windows { |
| 31 | #flag windows -lopengl32 |
| 32 | $if msvc { |
| 33 | $if livemain ? { |
| 34 | #define SOKOL_DLL |
| 35 | } |
| 36 | $if sharedlive ? { |
| 37 | #define SOKOL_DLL |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | // Note that -lm is needed *only* for sokol_gl.h's usage of sqrtf(), |
| 43 | // but without -lm, this fails: |
| 44 | // `v -cc gcc ~/.vmodules/sdl/examples/sdl_opengl_and_sokol/` |
| 45 | // With tcc, this succeeds with or without -lm: |
| 46 | // `v ~/.vmodules/sdl/examples/sdl_opengl_and_sokol/` |
| 47 | $if !tinyc { |
| 48 | #flag linux -lm |
| 49 | } |
| 50 | |
| 51 | // METAL |
| 52 | $if macos { |
| 53 | $if darwin_sokol_glcore33 ? { |
| 54 | #flag darwin -DSOKOL_GLCORE -framework OpenGL -framework Cocoa -framework QuartzCore |
| 55 | } $else { |
| 56 | #flag -DSOKOL_METAL |
| 57 | #flag -framework Metal -framework Cocoa -framework MetalKit -framework QuartzCore |
| 58 | } |
| 59 | } |
| 60 | $if ios { |
| 61 | #flag -DSOKOL_METAL |
| 62 | #flag -framework Foundation -framework Metal -framework MetalKit -framework UIKit |
| 63 | } |
| 64 | |
| 65 | $if emscripten ? { |
| 66 | #flag -DSOKOL_GLES3 |
| 67 | #flag -DSOKOL_NO_ENTRY |
| 68 | #flag -s ERROR_ON_UNDEFINED_SYMBOLS=0 |
| 69 | #flag -s USE_WEBGL2 |
| 70 | $if !prod { |
| 71 | #flag -s ASSERTIONS=1 |
| 72 | } |
| 73 | $if prod { |
| 74 | #flag -s ASSERTIONS=0 |
| 75 | } |
| 76 | // See https://emscripten.org/docs/tools_reference/settings_reference.html#modularize |
| 77 | // Note that it makes it impossible to use `v -os wasm32_emscripten -o file.html program.v` , due to: |
| 78 | // https://github.com/emscripten-core/emscripten/issues/7950 |
| 79 | // #flag -s MODULARIZE |
| 80 | } |
| 81 | |
| 82 | // D3D |
| 83 | //#flag windows -DSOKOL_D3D11 |
| 84 | #flag windows -DSOKOL_GLCORE |
| 85 | |
| 86 | // for simplicity, all header includes are here because import order matters and we dont have any way |
| 87 | // to ensure import order with V yet |
| 88 | |
| 89 | // TODO: should not be defined for android graphic (apk/aab using sokol) builds, but we have no ways to undefine |
| 90 | //#define SOKOL_NO_ENTRY |
| 91 | #flag linux -DSOKOL_NO_ENTRY |
| 92 | #flag darwin -DSOKOL_NO_ENTRY |
| 93 | #flag windows -DSOKOL_NO_ENTRY |
| 94 | #flag windows -DSOKOL_WIN32_FORCE_MAIN |
| 95 | #flag freebsd -DSOKOL_NO_ENTRY |
| 96 | #flag openbsd -DSOKOL_NO_ENTRY |
| 97 | #flag solaris -DSOKOL_NO_ENTRY |
| 98 | // TODO: end |
| 99 | |
| 100 | #flag linux -ldl |
| 101 | |
| 102 | // To allow for thirdparty initializing window / acceleration contexts |
| 103 | // but still be able to use sokol.gfx e.g. SDL+sokol_gfx |
| 104 | $if !no_sokol_app ? { |
| 105 | $if linux && sokol_wayland ? { |
| 106 | // Enable Wayland on Linux (when explicitly enabled with -d sokol_wayland) |
| 107 | #define SOKOL_WAYLAND |
| 108 | #flag -I@VEXEROOT/thirdparty/sokol |
| 109 | } $else $if linux { |
| 110 | // Explicitly disable Wayland on Linux when not using sokol_wayland |
| 111 | #define SOKOL_DISABLE_WAYLAND |
| 112 | // Force EGL instead of GLX so that eglSwapBuffers provides consistent |
| 113 | // vsync pacing on both native X11 and XWayland sessions. |
| 114 | #define SOKOL_FORCE_EGL |
| 115 | } |
| 116 | |
| 117 | $if macos { |
| 118 | $if sharedlive ? { |
| 119 | } $else { |
| 120 | // The live-reload dylib should reuse the host app's sokol_app symbols on macOS. |
| 121 | #define SOKOL_APP_IMPL |
| 122 | } |
| 123 | } $else $if windows { |
| 124 | $if sharedlive ? { |
| 125 | } $else { |
| 126 | // On Windows, the live-reload DLL links back to the host executable's |
| 127 | // import library, so it should not embed its own sokol_app backend. |
| 128 | #define SOKOL_APP_IMPL |
| 129 | } |
| 130 | } $else { |
| 131 | #define SOKOL_APP_IMPL |
| 132 | } |
| 133 | |
| 134 | @[use_once] |
| 135 | #include "sokol_app.h" |
| 136 | } |
| 137 | |
| 138 | $if windows && sharedlive ? { |
| 139 | } $else { |
| 140 | @[use_once] |
| 141 | #define SOKOL_GFX_IMPL |
| 142 | } |
| 143 | #define SOKOL_NO_DEPRECATED |
| 144 | #include "sokol_gfx.h" |
| 145 | |
| 146 | $if windows && sharedlive ? { |
| 147 | } $else { |
| 148 | @[use_once] |
| 149 | #define SOKOL_IMPL |
| 150 | } |
| 151 | #include "util/sokol_gl.h" |
| 152 | |
| 153 | #include "sokol_v.post.h" |
| 154 | |