|
| 1 | +set_project("EUI-NEO") |
| 2 | +set_version("0.5.5") |
| 3 | +set_xmakever("2.9.0") |
| 4 | +set_languages("c99", "cxx17") |
| 5 | + |
| 6 | +option("window_backend", {default = "glfw", values = {"glfw", "sdl2"}, description = "Window backend: glfw or sdl2"}) |
| 7 | +option("render_backend", {default = "opengl", values = {"auto", "opengl", "vulkan"}, description = "Render backend: auto, opengl, or vulkan"}) |
| 8 | +option("shared", {default = false, description = "Build eui_neo as a shared library instead of a static library."}) |
| 9 | +option("modules", {default = true, description = "Build optional EUI-NEO modules when their directories are present."}) |
| 10 | +option("markdown", {default = true, description = "Enable MD4C Markdown parsing support."}) |
| 11 | +option("vulkan_low_latency", {default = false, description = "Prefer low-latency Vulkan presentation when available."}) |
| 12 | + |
| 13 | +local render_backend = get_config("render_backend") or "opengl" |
| 14 | +if render_backend == "auto" then |
| 15 | + if find_package("vulkan") then |
| 16 | + render_backend = "vulkan" |
| 17 | + else |
| 18 | + render_backend = "opengl" |
| 19 | + print("Vulkan SDK not found; falling back to OpenGL.") |
| 20 | + end |
| 21 | +end |
| 22 | + |
| 23 | +local window_backend = get_config("window_backend") or "glfw" |
| 24 | +local build_shared = get_config("shared") and true or false |
| 25 | +local build_modules = get_config("modules") and true or false |
| 26 | +local enable_markdown = get_config("markdown") and true or false |
| 27 | +local vk_low_latency = get_config("vulkan_low_latency") and true or false |
| 28 | + |
| 29 | +print("EUI render backend: requested=%s, resolved=%s", get_config("render_backend") or "opengl", render_backend) |
| 30 | +print("EUI window backend: %s", window_backend) |
| 31 | + |
| 32 | +add_requires("freetype", {configs = {png = true, zlib = true, bzip2 = false, harfbuzz = false, brotli = false}}) |
| 33 | +add_requires("libpng", "zlib") |
| 34 | + |
| 35 | +if window_backend == "glfw" then |
| 36 | + add_requires("glfw", {configs = {shared = false}}) |
| 37 | +end |
| 38 | +if window_backend == "sdl2" then |
| 39 | + add_requires("sdl2", {configs = {shared = false}}) |
| 40 | +end |
| 41 | +if render_backend == "vulkan" then |
| 42 | + add_requires("vulkan") |
| 43 | +end |
| 44 | +if not is_plat("windows") then |
| 45 | + add_requires("libcurl", {configs = {shared = false}}) |
| 46 | +end |
| 47 | + |
| 48 | +if render_backend == "opengl" then |
| 49 | + target("eui_glad") |
| 50 | + set_kind("static") |
| 51 | + add_files("3rd/glad/src/glad.c", |
| 52 | + {force = {cxflags = {is_plat("windows") and "/TC" or ""}}}) |
| 53 | + add_includedirs("3rd/glad/include", {public = true}) |
| 54 | + target_end() |
| 55 | +end |
| 56 | + |
| 57 | +if enable_markdown then |
| 58 | + target("eui_md4c") |
| 59 | + set_kind("static") |
| 60 | + add_files("3rd/md4c/src/md4c.c", |
| 61 | + {force = {cxflags = {is_plat("windows") and "/TC" or ""}}}) |
| 62 | + add_includedirs("3rd/md4c/src", {public = true}) |
| 63 | + target_end() |
| 64 | +end |
| 65 | + |
| 66 | +target("eui_neo") |
| 67 | + set_kind(build_shared and "shared" or "static") |
| 68 | + set_group("framework") |
| 69 | + |
| 70 | + add_files( |
| 71 | + "core/platform/async.cpp", |
| 72 | + "core/platform/json.cpp", |
| 73 | + "core/platform/network.cpp", |
| 74 | + "core/platform/performance_stats.cpp", |
| 75 | + "core/platform/platform.cpp", |
| 76 | + "core/render/image.cpp", |
| 77 | + "core/render/image_facade.cpp", |
| 78 | + "core/render/image_source.cpp", |
| 79 | + "core/render/primitive.cpp", |
| 80 | + "core/render/render_backend.cpp", |
| 81 | + "core/render/shadertoy.cpp", |
| 82 | + "core/render/shadertoy_json.cpp", |
| 83 | + "core/render/shadertoy_primitive.cpp", |
| 84 | + "core/render/stb_image_impl.cpp", |
| 85 | + "core/render/text.cpp", |
| 86 | + "core/window/window_backend.cpp" |
| 87 | + ) |
| 88 | + |
| 89 | + local c_flags = {} |
| 90 | + if is_plat("windows") then |
| 91 | + table.insert(c_flags, "/TC") |
| 92 | + end |
| 93 | + |
| 94 | + local bridge_flags = table.copy(c_flags) |
| 95 | + if is_plat("macosx") then |
| 96 | + table.insert(bridge_flags, "-x") |
| 97 | + table.insert(bridge_flags, "objective-c") |
| 98 | + end |
| 99 | + |
| 100 | + add_files("3rd/yyjson-0.12.0/src/yyjson.c", {force = {cxflags = c_flags}}) |
| 101 | + add_files("core/platform/native_bridge.c", "core/platform/tray_bridge.c", |
| 102 | + {force = {cxflags = bridge_flags}}) |
| 103 | + |
| 104 | + if render_backend == "opengl" then |
| 105 | + add_files( |
| 106 | + "core/render/opengl/opengl_backend.cpp", |
| 107 | + "core/render/opengl/opengl_image.cpp", |
| 108 | + "core/render/opengl/opengl_primitives.cpp", |
| 109 | + "core/render/opengl/opengl_shadertoy.cpp", |
| 110 | + "core/render/opengl/opengl_text.cpp" |
| 111 | + ) |
| 112 | + elseif render_backend == "vulkan" then |
| 113 | + add_files( |
| 114 | + "core/render/vulkan/vulkan_backend.cpp", |
| 115 | + "core/render/vulkan/vulkan_cache.cpp", |
| 116 | + "core/render/vulkan/vulkan_primitives.cpp", |
| 117 | + "core/render/vulkan/vulkan_polygon.cpp", |
| 118 | + "core/render/vulkan/vulkan_shadertoy.cpp", |
| 119 | + "core/render/vulkan/vulkan_text.cpp", |
| 120 | + "core/render/vulkan/vulkan_image.cpp" |
| 121 | + ) |
| 122 | + end |
| 123 | + |
| 124 | + if window_backend == "glfw" then |
| 125 | + add_files("core/platform/ime_bridge.c", |
| 126 | + {force = {cxflags = bridge_flags}}) |
| 127 | + end |
| 128 | + |
| 129 | + add_includedirs("include", ".", "3rd/tray", {public = true}) |
| 130 | + add_includedirs("3rd/yyjson-0.12.0/src") |
| 131 | + add_includedirs("3rd") |
| 132 | + |
| 133 | + add_defines("YYJSON_DISABLE_WRITER=1") |
| 134 | + if render_backend == "opengl" then |
| 135 | + add_defines("EUI_RENDER_BACKEND_OPENGL=1", {public = true}) |
| 136 | + elseif render_backend == "vulkan" then |
| 137 | + add_defines("EUI_RENDER_BACKEND_VULKAN=1", {public = true}) |
| 138 | + if vk_low_latency then |
| 139 | + add_defines("EUI_VULKAN_LOW_LATENCY_PRESENT=1") |
| 140 | + end |
| 141 | + end |
| 142 | + if window_backend == "sdl2" then |
| 143 | + add_defines("EUI_WINDOW_BACKEND_SDL2=1", {public = true}) |
| 144 | + end |
| 145 | + |
| 146 | + if is_plat("windows") then |
| 147 | + add_defines("EUI_TRAY_WINAPI=1", "NOMINMAX", {public = true}) |
| 148 | + add_syslinks("winmm", "urlmon", "shell32", "user32", "imm32", "pdh", "comdlg32", {public = true}) |
| 149 | + elseif is_plat("macosx") then |
| 150 | + add_defines("EUI_TRAY_APPKIT=1", {public = true}) |
| 151 | + add_frameworks("Cocoa", {public = true}) |
| 152 | + add_syslinks("objc", {public = true}) |
| 153 | + end |
| 154 | + |
| 155 | + if enable_markdown then |
| 156 | + add_defines("EUI_HAS_MD4C=1", {public = true}) |
| 157 | + add_deps("eui_md4c") |
| 158 | + end |
| 159 | + |
| 160 | + add_packages("freetype", "libpng", "zlib", {public = true}) |
| 161 | + if render_backend == "opengl" then |
| 162 | + add_deps("eui_glad") |
| 163 | + if is_plat("windows") then |
| 164 | + add_syslinks("opengl32", {public = true}) |
| 165 | + elseif is_plat("linux") then |
| 166 | + add_syslinks("GL", {public = true}) |
| 167 | + elseif is_plat("macosx") then |
| 168 | + add_frameworks("OpenGL", {public = true}) |
| 169 | + end |
| 170 | + elseif render_backend == "vulkan" then |
| 171 | + add_packages("vulkan", {public = true}) |
| 172 | + end |
| 173 | + if window_backend == "glfw" then |
| 174 | + add_packages("glfw", {public = true}) |
| 175 | + elseif window_backend == "sdl2" then |
| 176 | + add_packages("sdl2", {public = true}) |
| 177 | + end |
| 178 | + add_packages("libcurl", {public = true, optional = true}) |
| 179 | + if not is_plat("windows", "mingw") and has_package("libcurl") then |
| 180 | + add_defines("EUI_HAS_CURL=1", {public = true}) |
| 181 | + end |
| 182 | + |
| 183 | + if not is_plat("windows", "mingw") then |
| 184 | + add_syslinks("pthread", {public = true}) |
| 185 | + end |
| 186 | + |
| 187 | + add_installfiles("include/(**)", {prefixdir = "include"}) |
| 188 | + add_installfiles("components/(**.h)", {prefixdir = "include/components"}) |
| 189 | + add_installfiles("core/(**.h)", {prefixdir = "include/core"}) |
| 190 | + add_installfiles("3rd/stb_image.h", "3rd/nanosvg.h", "3rd/nanosvgrast.h", {prefixdir = "include/3rd"}) |
| 191 | + add_installfiles("3rd/tray/tray.h", {prefixdir = "include/3rd/tray"}) |
| 192 | + if render_backend == "opengl" then |
| 193 | + add_installfiles("3rd/glad/include/(**.h)", {prefixdir = "include"}) |
| 194 | + end |
| 195 | + if enable_markdown then |
| 196 | + add_installfiles("3rd/md4c/src/md4c.h", {prefixdir = "include"}) |
| 197 | + end |
| 198 | + |
| 199 | + if is_plat("windows") then |
| 200 | + add_cxflags("/utf-8") |
| 201 | + if not is_mode("debug") then |
| 202 | + add_cxflags("/O1", "/GS-", "/sdl-", "/wd4819") |
| 203 | + end |
| 204 | + else |
| 205 | + if not is_mode("debug") then |
| 206 | + add_cxxflags("-Os", "-fno-exceptions", "-fno-rtti") |
| 207 | + end |
| 208 | + end |
| 209 | +target_end() |
| 210 | + |
| 211 | +if build_modules then |
| 212 | + if os.exists("modules/keyboard/keyboard.h") then |
| 213 | + target("eui_module_keyboard") |
| 214 | + set_kind("headeronly") |
| 215 | + set_group("modules") |
| 216 | + add_includedirs("modules/keyboard", {public = true}) |
| 217 | + add_deps("eui_neo") |
| 218 | + target_end() |
| 219 | + end |
| 220 | + |
| 221 | + if os.exists("modules/media/media.h") then |
| 222 | + target("eui_module_media") |
| 223 | + set_kind("headeronly") |
| 224 | + set_group("modules") |
| 225 | + add_includedirs("modules/media", {public = true}) |
| 226 | + add_deps("eui_neo") |
| 227 | + target_end() |
| 228 | + end |
| 229 | + |
| 230 | + if os.exists("modules/serial/serial.h") then |
| 231 | + target("eui_module_serial") |
| 232 | + set_kind("static") |
| 233 | + set_group("modules") |
| 234 | + add_files("modules/serial/serial.cpp") |
| 235 | + add_includedirs("modules/serial", {public = true}) |
| 236 | + add_deps("eui_neo") |
| 237 | + if is_plat("windows") then |
| 238 | + add_cxflags("/utf-8") |
| 239 | + if not is_mode("debug") then |
| 240 | + add_cxflags("/O1", "/GS-", "/sdl-", "/wd4819") |
| 241 | + end |
| 242 | + else |
| 243 | + if not is_mode("debug") then |
| 244 | + add_cxxflags("-Os", "-fno-exceptions", "-fno-rtti") |
| 245 | + end |
| 246 | + end |
| 247 | + target_end() |
| 248 | + end |
| 249 | +end |
0 commit comments