From a7fcaa95fe3df21353465eafa180656259c3612d Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Sun, 11 Aug 2024 13:58:25 +0200 Subject: [PATCH] refactor xmake scripts --- xmake.lua | 2 +- xmake/editor.lua | 15 +++++ xmake/godot.lua | 26 ++++++++ xmake/target.lua | 65 ++++++++++++++++++++ godot.lua => xmake/tasks.lua | 111 ----------------------------------- 5 files changed, 107 insertions(+), 112 deletions(-) create mode 100644 xmake/editor.lua create mode 100644 xmake/godot.lua create mode 100644 xmake/target.lua rename godot.lua => xmake/tasks.lua (70%) diff --git a/xmake.lua b/xmake.lua index f6ee21a..fbec89d 100644 --- a/xmake.lua +++ b/xmake.lua @@ -18,4 +18,4 @@ GODOT_PROJECT_FOLDER = "demo" PUBLISH_FOLDER = "publish" -includes("godot.lua") \ No newline at end of file +includes("xmake/godot.lua") \ No newline at end of file diff --git a/xmake/editor.lua b/xmake/editor.lua new file mode 100644 index 0000000..1e505a9 --- /dev/null +++ b/xmake/editor.lua @@ -0,0 +1,15 @@ +target("Editor") + set_default(false) + + -- Disable building + on_build((function() end)) + + on_run( + (function(godot_project_folder) + return function(target) + local project_file = path.join(godot_project_folder, "project.godot") + os.execv("echo", {"godot", project_file}) + os.exec("godot " .. project_file) + end + end)(GODOT_PROJECT_FOLDER) + ) \ No newline at end of file diff --git a/xmake/godot.lua b/xmake/godot.lua new file mode 100644 index 0000000..f520ac5 --- /dev/null +++ b/xmake/godot.lua @@ -0,0 +1,26 @@ +------- project settings ------- + +-- project name +set_project(PROJECT_NAME) + +-- project version +set_version(VERSION) + +-- min version of xmake we need to run +-- NOTE: this is the version i used to develop this template, may not 100% correct +set_xmakever("2.9.0") + +add_rules("mode.debug", "mode.release") + +-- c++17 is required for godot 4.x, we use c++20 here +set_languages("c++20") + +-- use latest 4.x version by default +add_requires("godotcpp4") + + +includes("tasks.lua") + +includes("target.lua") + +includes("editor.lua") \ No newline at end of file diff --git a/xmake/target.lua b/xmake/target.lua new file mode 100644 index 0000000..5d245eb --- /dev/null +++ b/xmake/target.lua @@ -0,0 +1,65 @@ +-- more on https://xmake.io/#/manual/project_target +target(PROJECT_NAME) + set_kind("shared") + set_default(true) + + add_packages("godotcpp4") + + -- more on https://xmake.io/#/manual/project_target?id=targetadd_files + add_files("../src/**.cpp") + + -- change the output name + set_basename(PROJECT_NAME .. ".$(os)_$(mode)_$(arch)") + + -- libraries will saved in os level folder + set_targetdir("../" .. GODOT_PROJECT_FOLDER .. "/lib") + + -- where to save .obj files + -- we use a seprate folder, so that it will not populate the targer folder + set_objectdir("../build/.objs") + + -- where .d files are saved + set_dependir("../build/.deps") + + -- set_optimize("smallest") + + -- handlers + + -- before_run(function (target) end) + -- after_run(function (target) end) + -- before_build(function (target) end) + -- after_build(function (target) end) + -- before_clean(function (target) end) + -- after_clean(function (target) end) + + on_run( + (function(godot_project_folder) + return function(target) + os.execv("echo", {"godot --path", godot_project_folder}) + os.exec("godot --path " .. godot_project_folder) + end + end)(GODOT_PROJECT_FOLDER) + ) + + on_package(function(target) + import("core.base.task") + + target_platform = "Unknown" + + if is_plat("windows") then + target_platform = "Windows Desktop" + elseif is_plat("macosx") then + target_platform = "macOS" + elseif is_plat("linux") then + target_platform = "Linux/X11" + elseif is_plat("android") then + target_platform = "Android" + end + + task.run("export", {}, target_platform) + end) + + after_clean(function (target) + import("core.base.task") + task.run("clean-publish") + end) \ No newline at end of file diff --git a/godot.lua b/xmake/tasks.lua similarity index 70% rename from godot.lua rename to xmake/tasks.lua index 2cf85c9..b937bd5 100644 --- a/godot.lua +++ b/xmake/tasks.lua @@ -1,27 +1,3 @@ -------- project settings ------- - --- project name -set_project(PROJECT_NAME) - --- project version -set_version(VERSION) - --- min version of xmake we need to run --- NOTE: this is the version i used to develop this template, may not 100% correct -set_xmakever("2.9.0") - -add_rules("mode.debug", "mode.release") - --- c++17 is required for godot 4.x, we use c++20 here -set_languages("c++20") - --- use latest 4.x version by default -add_requires("godotcpp4") - - -------- custom tasks ------- - - -- NOTE: -- xmake cannot accept the global variables in on_xxx functions, so we use a wrapper function to bind it @@ -226,90 +202,3 @@ android.release.arm64 = "res://lib/libProjectName.android_release_arm64.so" description = "Generate gdextension file", } task_end() - - - - - -------- output settings ------- - --- more on https://xmake.io/#/manual/project_target -target(PROJECT_NAME) - set_kind("shared") - set_default(true) - - add_packages("godotcpp4") - - -- more on https://xmake.io/#/manual/project_target?id=targetadd_files - add_files("src/*.cpp") - - -- change the output name - set_basename(PROJECT_NAME .. ".$(os)_$(mode)_$(arch)") - - -- libraries will saved in os level folder - set_targetdir(GODOT_PROJECT_FOLDER .. "/lib") - - -- where to save .obj files - -- we use a seprate folder, so that it will not populate the targer folder - set_objectdir("build/.objs") - - -- where .d files are saved - set_dependir("build/.deps") - - -- set_optimize("smallest") - - -- handlers - - -- before_run(function (target) end) - -- after_run(function (target) end) - -- before_build(function (target) end) - -- after_build(function (target) end) - -- before_clean(function (target) end) - -- after_clean(function (target) end) - - on_run( - (function(godot_project_folder) - return function(target) - os.execv("echo", {"godot --path", godot_project_folder}) - os.exec("godot --path " .. godot_project_folder) - end - end)(GODOT_PROJECT_FOLDER) - ) - - on_package(function(target) - import("core.base.task") - - target_platform = "Unknown" - - if is_plat("windows") then - target_platform = "Windows Desktop" - elseif is_plat("macosx") then - target_platform = "macOS" - elseif is_plat("linux") then - target_platform = "Linux/X11" - elseif is_plat("android") then - target_platform = "Android" - end - - task.run("export", {}, target_platform) - end) - - after_clean(function (target) - import("core.base.task") - task.run("clean-publish") - end) - - -target("Editor") - set_default(false) - -- Disable building - on_build((function() end)) - on_run( - (function(godot_project_folder) - return function(target) - local project_file = path.join(godot_project_folder, "project.godot") - os.execv("echo", {"godot", project_file}) - os.exec("godot " .. project_file) - end - end)(GODOT_PROJECT_FOLDER) - ) \ No newline at end of file