From d01ae9bb8127f106d29214bb1b62b7bf3a6ca7c8 Mon Sep 17 00:00:00 2001 From: Qudix <17361645+Qudix@users.noreply.github.com> Date: Sat, 12 Oct 2024 08:41:55 -0500 Subject: [PATCH 1/2] feat: don't build by default when subproject --- xmake.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/xmake.lua b/xmake.lua index 5830912bf..c87965913 100644 --- a/xmake.lua +++ b/xmake.lua @@ -1,9 +1,6 @@ -- set minimum xmake version set_xmakever("2.8.2") --- make extras available -includes("xmake-extra.lua") - -- set project set_project("commonlibsse") set_arch("x64") @@ -12,7 +9,10 @@ set_warnings("allextra") set_encodings("utf-8") -- add rules -add_rules("mode.debug", "mode.release") +add_rules("mode.debug", "mode.releasedbg") + +-- make extras available +includes("xmake-extra.lua") -- define options option("skyrim_ae") @@ -40,6 +40,9 @@ target("commonlibsse") -- set target kind set_kind("static") + -- set build by default + set_default(os.scriptdir() == os.projectdir()) + -- add packages add_packages("rsm-binary-io", "spdlog", { public = true }) From 13bd5496df5ef969606883c9e54b53e83f6f0041 Mon Sep 17 00:00:00 2001 From: Qudix <17361645+Qudix@users.noreply.github.com> Date: Sat, 12 Oct 2024 08:42:16 -0500 Subject: [PATCH 2/2] feat: add support for plugin install and package --- xmake-extra.lua | 90 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 74 insertions(+), 16 deletions(-) diff --git a/xmake-extra.lua b/xmake-extra.lua index e2ec0fff6..03d2bf9f8 100644 --- a/xmake-extra.lua +++ b/xmake-extra.lua @@ -37,7 +37,7 @@ bool SKSEPlugin_Query(const SKSE::QueryInterface* a_skse, SKSE::PluginInfo* a_in #endif ]] -local PLUGIN_VERSION_FILE = [[ +local PLUGIN_RC_FILE = [[ #include 1 VERSIONINFO @@ -91,24 +91,33 @@ rule("commonlibsse.plugin") target:set("arch", "x64") target:set("kind", "shared") + target:add("installfiles", target:targetfile(), { prefixdir = "SKSE/Plugins" }) + target:add("installfiles", target:symbolfile(), { prefixdir = "SKSE/Plugins" }) + + if os.getenv("XSE_TES5_MODS_PATH") then + target:set("installdir", path.join(os.getenv("XSE_TES5_MODS_PATH"), target:name())) + elseif os.getenv("XSE_TES5_GAME_PATH") then + target:set("installdir", path.join(os.getenv("XSE_TES5_GAME_PATH"), "Data")) + end + local conf = target:extraconf("rules", "commonlibsse.plugin") local conf_dir = path.join(target:autogendir(), "rules", "commonlibsse", "plugin") local conf_map = { - PLUGIN_AUTHOR = conf.author or "", - PLUGIN_DESCRIPTION = conf.description or "", - PLUGIN_EMAIL = conf.email or "", - PLUGIN_LICENSE = (target:license() or "Unknown") .. " License", - PLUGIN_NAME = conf.name or target:name(), - PLUGIN_VERSION = target:version() or "0.0.0", - PLUGIN_VERSION_MAJOR = semver.new(target:version() or "0.0.0"):major(), - PLUGIN_VERSION_MINOR = semver.new(target:version() or "0.0.0"):minor(), - PLUGIN_VERSION_PATCH = semver.new(target:version() or "0.0.0"):patch(), - PROJECT_NAME = project.name() or "", - PROJECT_VERSION = project.version() or "0.0.0", - PROJECT_VERSION_MAJOR = semver.new(project.version() or "0.0.0"):major(), - PROJECT_VERSION_MINOR = semver.new(project.version() or "0.0.0"):minor(), - PROJECT_VERSION_PATCH = semver.new(project.version() or "0.0.0"):patch(), + PLUGIN_AUTHOR = conf.author or "", + PLUGIN_DESCRIPTION = conf.description or "", + PLUGIN_EMAIL = conf.email or "", + PLUGIN_LICENSE = (target:license() or "Unknown") .. " License", + PLUGIN_NAME = conf.name or target:name(), + PLUGIN_VERSION = target:version() or "0.0.0", + PLUGIN_VERSION_MAJOR = semver.new(target:version() or "0.0.0"):major(), + PLUGIN_VERSION_MINOR = semver.new(target:version() or "0.0.0"):minor(), + PLUGIN_VERSION_PATCH = semver.new(target:version() or "0.0.0"):patch(), + PROJECT_NAME = project.name() or "", + PROJECT_VERSION = project.version() or "0.0.0", + PROJECT_VERSION_MAJOR = semver.new(project.version() or "0.0.0"):major(), + PROJECT_VERSION_MINOR = semver.new(project.version() or "0.0.0"):minor(), + PROJECT_VERSION_PATCH = semver.new(project.version() or "0.0.0"):patch(), } local conf_parse = function(a_str) @@ -135,5 +144,54 @@ rule("commonlibsse.plugin") end add_file("plugin.cpp", PLUGIN_FILE) - add_file("version.rc", PLUGIN_VERSION_FILE) + add_file("version.rc", PLUGIN_RC_FILE) + end) + + on_install(function(target) + local srcfiles, dstfiles = target:installfiles() + if srcfiles and #srcfiles > 0 and dstfiles and #dstfiles > 0 then + for idx, srcfile in ipairs(srcfiles) do + os.trycp(srcfile, dstfiles[idx]) + end + end + end) + + on_package(function(target) + import("core.project.config") + import("core.project.project") + import("utils.archive") + + local archive_name = target:name() .. "-" .. (target:version() or "0.0.0") .. ".zip" + print("packing %s .. ", archive_name) + + local root_dir = path.join(os.tmpdir(), "packages", project.name() or "", target:name()) + os.tryrm(root_dir) + + local srcfiles, dstfiles = target:installfiles(path.join(root_dir, "Data")) + if srcfiles and #srcfiles > 0 and dstfiles and #dstfiles > 0 then + for idx, srcfile in ipairs(srcfiles) do + os.trycp(srcfile, dstfiles[idx]) + end + else + return + end + + local archive_path = path.join(config.buildir(), "packages", archive_name) + local old_dir = os.cd(root_dir) + local archive_files = os.files("**") + os.cd(old_dir) + archive.archive(path.absolute(archive_path), archive_files, { curdir = root_dir }) + end) + + after_build(function(target) + import("core.project.depend") + import("core.project.project") + import("core.project.task") + + depend.on_changed(function() + local srcfiles, dstfiles = target:installfiles() + if srcfiles and #srcfiles > 0 and dstfiles and #dstfiles > 0 then + task.run("install") + end + end, { changed = target:is_rebuilt(), files = { target:targetfile() } }) end)