224 lines
6.4 KiB
Lua
224 lines
6.4 KiB
Lua
-- ==============================================
|
|
-- Extra2D - 2D Game Engine
|
|
-- Build System: Xmake
|
|
--
|
|
-- 支持平台:
|
|
-- - Windows (MinGW)
|
|
-- - Linux
|
|
-- - macOS
|
|
-- - Nintendo Switch
|
|
--
|
|
-- 窗口后端: GLFW
|
|
-- 渲染后端: OpenGL
|
|
-- ==============================================
|
|
|
|
-- 项目元信息
|
|
set_project("Extra2D")
|
|
set_version("1.2.0")
|
|
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}
|
|
|
|
-- 自动选择平台
|
|
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"
|
|
else
|
|
error("Unsupported platform: " .. target_plat .. ". Supported platforms: mingw, windows, linux, macosx, switch")
|
|
end
|
|
end
|
|
|
|
set_plat(target_plat)
|
|
|
|
-- 设置架构
|
|
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
|
|
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
|
|
|
|
-- ==============================================
|
|
-- 添加依赖包
|
|
-- ==============================================
|
|
|
|
if target_plat ~= "switch" then
|
|
add_requires("glm")
|
|
add_requires("nlohmann_json")
|
|
add_requires("glfw")
|
|
add_requires("zstd")
|
|
add_requires("lz4")
|
|
add_requires("zlib")
|
|
end
|
|
|
|
|
|
-- ==============================================
|
|
-- 加载构建目标
|
|
-- ==============================================
|
|
|
|
-- 加载引擎库定义
|
|
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_files("Tests/test_node.cpp")
|
|
add_files("Tests/test_scene_graph.cpp")
|
|
add_files("Tests/test_camera.cpp")
|
|
add_files("Tests/test_win_adapt.cpp")
|
|
add_files("Tests/test_action.cpp")
|
|
add_files("Tests/test_scene.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")
|
|
|
|
-- Vulkan SDK
|
|
local vulkanSdk = os.getenv("VULKAN_SDK")
|
|
if vulkanSdk then
|
|
add_includedirs(vulkanSdk .. "/Include", {public = true})
|
|
add_linkdirs(vulkanSdk .. "/Lib", {public = true})
|
|
add_links("vulkan-1", {public = true})
|
|
end
|
|
elseif plat == "linux" then
|
|
add_packages("glm", "nlohmann_json", "glfw", "zstd", "lz4", "zlib")
|
|
add_syslinks("dl", "pthread")
|
|
add_links("vulkan", {public = true})
|
|
elseif plat == "macosx" then
|
|
add_packages("glm", "nlohmann_json", "glfw", "zstd", "lz4", "zlib")
|
|
add_frameworks("Cocoa", "IOKit", "CoreVideo")
|
|
|
|
-- Vulkan SDK (MoltenVK)
|
|
local vulkanSdk = os.getenv("VULKAN_SDK")
|
|
if vulkanSdk then
|
|
add_includedirs(vulkanSdk .. "/include", {public = true})
|
|
add_linkdirs(vulkanSdk .. "/lib", {public = true})
|
|
add_links("vulkan", {public = true})
|
|
end
|
|
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()
|