Skip to content

Commit

Permalink
Merge pull request #27 from qudix/dev/xmake
Browse files Browse the repository at this point in the history
feat: xmake | support plugin installation and packaging
  • Loading branch information
shad0wshayd3 authored Oct 12, 2024
2 parents 46a6225 + aab2069 commit 07d8f5d
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CommonLibF4/include/REL/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ template <class CharT>
struct fmt::formatter<REL::Version, CharT> : formatter<std::string, CharT>
{
template <class FormatContext>
auto format(const REL::Version& a_version, FormatContext& a_ctx)
auto format(const REL::Version& a_version, FormatContext& a_ctx) const
{
return formatter<std::string, CharT>::format(a_version.string(), a_ctx);
}
Expand Down
66 changes: 66 additions & 0 deletions CommonLibF4/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ option("f4se_xbyak", function()
add_defines("F4SE_SUPPORT_XBYAK=1")
end)

-- require packages
if has_config("f4se_xbyak") then
add_requires("xbyak")
end

-- define targets
target("commonlibf4", function()
set_kind("static")

-- set build by default
set_default(path.directory(os.scriptdir()) == os.projectdir())

-- set build group
set_group("commonlibf4")

Expand Down Expand Up @@ -141,6 +149,15 @@ rule("commonlibf4.plugin")
target:set("arch", "x64")
target:set("kind", "shared")

target:add("installfiles", target:targetfile(), { prefixdir = "F4SE/Plugins" })
target:add("installfiles", target:symbolfile(), { prefixdir = "F4SE/Plugins" })

if os.getenv("XSE_FO4_MODS_PATH") then
target:set("installdir", path.join(os.getenv("XSE_FO4_MODS_PATH"), target:name()))
elseif os.getenv("XSE_FO4_GAME_PATH") then
target:set("installdir", path.join(os.getenv("XSE_FO4_GAME_PATH"), "Data"))
end

local conf = target:extraconf("rules", "commonlibf4.plugin")
local conf_dir = path.join(target:autogendir(), "rules", "commonlibf4", "plugin")

Expand Down Expand Up @@ -186,3 +203,52 @@ rule("commonlibf4.plugin")
add_file("plugin.cpp", PLUGIN_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)
2 changes: 1 addition & 1 deletion xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ set_encodings("utf-8")
add_rules("mode.debug", "mode.releasedbg")

-- require packages
add_requires("rsm-binary-io", "rsm-mmio", "xbyak")
add_requires("rsm-binary-io", "rsm-mmio")
add_requires("spdlog", { configs = { header_only = false, wchar = true, std_format = true } })

-- include subprojects
Expand Down

0 comments on commit 07d8f5d

Please sign in to comment.