Extra2D/xmake.lua

199 lines
5.4 KiB
Lua
Raw Normal View History

2026-02-11 19:40:26 +08:00
-- ==============================================
-- Extra2D - 2D Game Engine
-- Build System: Xmake
--
-- 支持平台:
-- - Windows (MinGW)
-- - Linux
-- - macOS
-- - Nintendo Switch
--
-- 窗口后端: GLFW
-- 渲染后端: OpenGL
2026-02-11 19:40:26 +08:00
-- ==============================================
-- 项目元信息
set_project("Extra2D")
set_version("1.2.0")
2026-02-11 19:40:26 +08:00
set_license("MIT")
-- 语言和编码设置
set_languages("c++17")
set_encodings("utf-8")
-- 构建模式
add_rules("mode.debug", "mode.release")
-- ==============================================
-- 构建选项
-- ==============================================
option("debug_logs")
set_default(false)
set_showmenu(true)
set_description("Enable debug logging")
option_end()
-- ==============================================
-- 平台检测与配置
-- ==============================================
local host_plat = os.host()
local target_plat = get_config("plat") or host_plat
local supported_plats = {mingw = true, windows = true, linux = true, macosx = true, switch = true}
2026-02-11 19:40:26 +08:00
-- 自动选择平台
2026-02-11 19:40:26 +08:00
if not supported_plats[target_plat] then
if host_plat == "windows" then
target_plat = "mingw"
elseif host_plat == "linux" then
target_plat = "linux"
elseif host_plat == "macosx" then
target_plat = "macosx"
2026-02-11 19:40:26 +08:00
else
error("Unsupported platform: " .. target_plat .. ". Supported platforms: mingw, windows, linux, macosx, switch")
2026-02-11 19:40:26 +08:00
end
end
set_plat(target_plat)
-- 设置架构
2026-02-11 19:40:26 +08:00
if target_plat == "switch" then
set_arch("arm64")
elseif target_plat == "mingw" or target_plat == "windows" then
set_arch("x86_64")
elseif target_plat == "linux" then
set_arch("x86_64")
elseif target_plat == "macosx" then
2026-02-11 19:40:26 +08:00
set_arch("x86_64")
end
-- ==============================================
-- 加载工具链配置
-- ==============================================
if target_plat == "switch" then
includes("xmake/toolchains/switch.lua")
set_toolchains("switch")
elseif target_plat == "mingw" then
set_toolchains("mingw")
end
-- ==============================================
-- 添加依赖包
2026-02-11 19:40:26 +08:00
-- ==============================================
if target_plat ~= "switch" then
add_requires("glm")
add_requires("nlohmann_json")
add_requires("glfw")
add_requires("zstd")
add_requires("lz4")
add_requires("zlib")
2026-02-11 19:40:26 +08:00
end
2026-02-11 19:40:26 +08:00
-- ==============================================
-- 加载构建目标
-- ==============================================
-- 加载引擎库定义
includes("xmake/engine.lua")
-- 定义引擎库
define_extra2d_engine()
-- ==============================================
-- 测试目标
-- ==============================================
target("extra2d_tests")
set_kind("binary")
set_default(false)
-- 测试源文件
add_files("Tests/test_framework.cpp")
add_files("Tests/test_main.cpp")
add_files("Tests/test_data_processor.cpp")
add_files("Tests/test_asset_cache.cpp")
add_files("Tests/test_asset_pack.cpp")
add_files("Tests/test_asset_service.cpp")
-- 头文件路径
add_includedirs("Extra2D/include", {public = true})
add_includedirs("Tests")
-- 依赖引擎库
add_deps("extra2d")
-- 平台配置
local plat = get_config("plat") or os.host()
if plat == "mingw" or plat == "windows" then
add_packages("glm", "nlohmann_json", "glfw", "zstd", "lz4", "zlib")
add_syslinks("winmm", "imm32", "version", "setupapi")
elseif plat == "linux" then
add_packages("glm", "nlohmann_json", "glfw", "zstd", "lz4", "zlib")
add_syslinks("dl", "pthread")
elseif plat == "macosx" then
add_packages("glm", "nlohmann_json", "glfw", "zstd", "lz4", "zlib")
add_frameworks("Cocoa", "IOKit", "CoreVideo")
end
-- 编译器标志
add_cxflags("-Wall", "-Wextra", {force = true})
add_cxflags("-Wno-unused-variable", "-Wno-unused-function", "-Wno-unused-parameter", {force = true})
if is_mode("debug") then
add_defines("_DEBUG")
add_cxxflags("-O0", "-g", {force = true})
else
add_defines("NDEBUG")
add_cxxflags("-O2", {force = true})
end
target_end()
-- ==============================================
-- 资源打包工具
-- ==============================================
target("asset_packer")
set_kind("binary")
set_default(false)
-- 源文件
add_files("Tools/asset_packer.cpp")
-- 头文件路径
add_includedirs("Extra2D/include")
-- 依赖引擎库
add_deps("extra2d")
-- 平台配置
local plat = get_config("plat") or os.host()
if plat == "mingw" or plat == "windows" then
add_packages("glm", "nlohmann_json", "glfw", "zstd", "lz4", "zlib")
add_syslinks("winmm", "imm32", "version", "setupapi")
elseif plat == "linux" then
add_packages("glm", "nlohmann_json", "glfw", "zstd", "lz4", "zlib")
add_syslinks("dl", "pthread")
elseif plat == "macosx" then
add_packages("glm", "nlohmann_json", "glfw", "zstd", "lz4", "zlib")
add_frameworks("Cocoa", "IOKit", "CoreVideo")
end
-- 编译器标志
add_cxflags("-Wall", "-Wextra", {force = true})
add_cxflags("-Wno-unused-variable", "-Wno-unused-function", "-Wno-unused-parameter", {force = true})
if is_mode("debug") then
add_defines("_DEBUG")
add_cxxflags("-O0", "-g", {force = true})
else
add_defines("NDEBUG")
add_cxxflags("-O2", {force = true})
end
target_end()