diff --git a/xmake.lua b/xmake.lua index cacb449..cb16961 100644 --- a/xmake.lua +++ b/xmake.lua @@ -2,12 +2,7 @@ -- Extra2D - 2D Game Engine -- Build System: Xmake -- --- 支持平台: --- - Windows (MinGW) --- - Linux --- - macOS --- - Nintendo Switch --- +-- 支持平台: Windows (MinGW) -- 窗口后端: GLFW -- 渲染后端: OpenGL -- ============================================== @@ -35,73 +30,64 @@ option("debug_logs") 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 +set_plat("mingw") +set_arch("x86_64") -- ============================================== -- 添加依赖包 -- ============================================== -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 - +add_requires("glm") +add_requires("nlohmann_json") +add_requires("glfw") +add_requires("zstd") +add_requires("lz4") +add_requires("zlib") -- ============================================== --- 加载构建目标 +-- 引擎库目标 -- ============================================== --- 加载引擎库定义 -includes("xmake/engine.lua") +target("extra2d") + set_kind("static") --- 定义引擎库 -define_extra2d_engine() + -- 引擎核心源文件 + add_files("Extra2D/src/**.cpp") + + -- GLFW 窗口后端源文件 + add_files("Extra2D/src/platform/glfw/*.cpp") + + -- 头文件路径 + add_includedirs("Extra2D/include", {public = true}) + add_includedirs("Extra2D/include/extra2d/platform", {public = true}) + + -- Windows (MinGW) 平台配置 + add_packages("glm", "nlohmann_json", "glfw", "zstd", "lz4", "zlib", {public = true}) + add_syslinks("winmm", "imm32", "version", "setupapi", {public = true}) + + -- 启用压缩库 + add_defines("E2D_USE_ZSTD", "E2D_USE_LZ4", "E2D_USE_ZLIB", {public = true}) + + -- 编译器标志 (C 和 C++ 共用) + add_cxflags("-Wall", "-Wextra", {force = true}) + add_cxflags("-Wno-unused-variable", "-Wno-unused-function", "-Wno-unused-parameter", {force = true}) + add_cxflags("-Wno-strict-aliasing", "-Wno-implicit-fallthrough", {force = true}) + add_cxflags("-Wno-missing-field-initializers", {force = true}) + + -- C++ 专用编译器标志 + add_cxxflags("-Wno-deprecated-copy", "-Wno-class-memaccess", {force = true}) + + if is_mode("debug") then + add_defines("_DEBUG", {public = true}) + add_cxxflags("-O0", "-g", {force = true}) + else + add_defines("NDEBUG", {public = true}) + add_cxxflags("-O2", {force = true}) + end +target_end() -- ============================================== -- 测试目标 @@ -127,18 +113,8 @@ target("extra2d_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_packages("glm", "nlohmann_json", "glfw", "zstd", "lz4", "zlib") + add_syslinks("winmm", "imm32", "version", "setupapi") -- 编译器标志 add_cxflags("-Wall", "-Wextra", {force = true}) @@ -171,18 +147,8 @@ target("asset_packer") 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_packages("glm", "nlohmann_json", "glfw", "zstd", "lz4", "zlib") + add_syslinks("winmm", "imm32", "version", "setupapi") -- 编译器标志 add_cxflags("-Wall", "-Wextra", {force = true}) diff --git a/xmake/engine.lua b/xmake/engine.lua deleted file mode 100644 index e55683d..0000000 --- a/xmake/engine.lua +++ /dev/null @@ -1,74 +0,0 @@ --- ============================================== --- Extra2D 引擎库共享配置 --- 被主项目和示例共享使用 --- --- 窗口后端: GLFW --- 渲染后端: OpenGL --- ============================================== - --- 获取当前平台 -local function get_current_plat() - return get_config("plat") or os.host() -end - --- 定义 Extra2D 引擎库目标 -function define_extra2d_engine() - target("extra2d") - set_kind("static") - - -- 引擎核心源文件 - add_files("Extra2D/src/**.cpp") - - -- GLFW 窗口后端源文件 - add_files("Extra2D/src/platform/glfw/*.cpp") - - -- 头文件路径 - add_includedirs("Extra2D/include", {public = true}) - add_includedirs("Extra2D/include/extra2d/platform", {public = true}) - - -- 平台配置 - local plat = get_current_plat() - - if plat == "switch" then - -- Nintendo Switch 平台配置 - local devkitPro = os.getenv("DEVKITPRO") or "C:/devkitPro" - add_includedirs(devkitPro .. "/portlibs/switch/include", {public = true}) - add_linkdirs(devkitPro .. "/portlibs/switch/lib") - - -- GLFW 后端 - add_syslinks("glfw", "nx", "m", {public = true}) - elseif plat == "mingw" or plat == "windows" then - -- Windows (MinGW) 平台配置 - add_packages("glm", "nlohmann_json", "glfw", "zstd", "lz4", "zlib", {public = true}) - add_syslinks("winmm", "imm32", "version", "setupapi", {public = true}) - elseif plat == "linux" then - -- Linux 平台配置 - add_packages("glm", "nlohmann_json", "glfw", "zstd", "lz4", "zlib", {public = true}) - add_syslinks("dl", "pthread", {public = true}) - elseif plat == "macosx" then - -- macOS 平台配置 - add_packages("glm", "nlohmann_json", "glfw", "zstd", "lz4", "zlib", {public = true}) - add_frameworks("Cocoa", "IOKit", "CoreVideo", {public = true}) - end - - -- 启用压缩库 - add_defines("E2D_USE_ZSTD", "E2D_USE_LZ4", "E2D_USE_ZLIB", {public = true}) - - -- 编译器标志 (C 和 C++ 共用) - add_cxflags("-Wall", "-Wextra", {force = true}) - add_cxflags("-Wno-unused-variable", "-Wno-unused-function", "-Wno-unused-parameter", {force = true}) - add_cxflags("-Wno-strict-aliasing", "-Wno-implicit-fallthrough", {force = true}) - add_cxflags("-Wno-missing-field-initializers", {force = true}) - - -- C++ 专用编译器标志 - add_cxxflags("-Wno-deprecated-copy", "-Wno-class-memaccess", {force = true}) - - if is_mode("debug") then - add_defines("_DEBUG", {public = true}) - add_cxxflags("-O0", "-g", {force = true}) - else - add_defines("NDEBUG", {public = true}) - add_cxxflags("-O2", {force = true}) - end - target_end() -end diff --git a/xmake/toolchains/switch.lua b/xmake/toolchains/switch.lua deleted file mode 100644 index 6371d7b..0000000 --- a/xmake/toolchains/switch.lua +++ /dev/null @@ -1,47 +0,0 @@ --- ============================================== --- Nintendo Switch 工具链定义 --- ============================================== - -function define_switch_toolchain() - toolchain("switch") - set_kind("standalone") - set_description("Nintendo Switch devkitA64 toolchain") - - -- 检查 DEVKITPRO 环境变量(Windows 上使用 C:/devkitPro) - local devkitPro = os.getenv("DEVKITPRO") or "C:/devkitPro" - local devkitA64 = path.join(devkitPro, "devkitA64") - - -- 设置工具链路径 - set_toolset("cc", path.join(devkitA64, "bin/aarch64-none-elf-gcc.exe")) - set_toolset("cxx", path.join(devkitA64, "bin/aarch64-none-elf-g++.exe")) - set_toolset("ld", path.join(devkitA64, "bin/aarch64-none-elf-g++.exe")) - set_toolset("ar", path.join(devkitA64, "bin/aarch64-none-elf-gcc-ar.exe")) - set_toolset("strip", path.join(devkitA64, "bin/aarch64-none-elf-strip.exe")) - - -- 架构标志 - local arch_flags = "-march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE" - add_cxflags(arch_flags) - -- 使用 devkitPro 提供的 switch.specs 文件 - add_ldflags("-specs=" .. path.join(devkitPro, "libnx/switch.specs"), "-g", arch_flags) - - -- 定义 Switch 平台宏 - add_defines("__SWITCH__", "__NX__", "MA_SWITCH", "PFD_SWITCH") - - -- SimpleIni 配置:不使用 Windows API - add_defines("SI_NO_CONVERSION") - - -- libnx 路径 - 必须在工具链级别添加 - add_includedirs(path.join(devkitPro, "libnx/include")) - add_linkdirs(path.join(devkitPro, "libnx/lib")) - - -- portlibs 路径(EGL + 桌面 OpenGL + SDL2) - add_includedirs(path.join(devkitPro, "portlibs/switch/include")) - add_includedirs(path.join(devkitPro, "portlibs/switch/include/SDL2")) - add_linkdirs(path.join(devkitPro, "portlibs/switch/lib")) - - add_syslinks("nx", "m") - toolchain_end() -end - --- 定义工具链 -define_switch_toolchain()