diff options
| author | Arthur LAURENT <[email protected]> | 2024-02-08 16:24:35 +0100 |
|---|---|---|
| committer | Arthur LAURENT <[email protected]> | 2024-02-08 16:25:02 +0100 |
| commit | 3af5f89b0c56d83e31a645c5a9ff440f900d6a58 (patch) | |
| tree | 19298a4bbbb0bc35bc47e3c44167a3fc4c9bb025 | |
| parent | b0819c9bc05ed539d6f84f07eb8bf2ee89b1e40c (diff) | |
add support of xmake package for modules
| -rw-r--r-- | xmake/actions/package/local/main.lua | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/xmake/actions/package/local/main.lua b/xmake/actions/package/local/main.lua index 90495dae4..858059ac1 100644 --- a/xmake/actions/package/local/main.lua +++ b/xmake/actions/package/local/main.lua @@ -95,6 +95,7 @@ function _package_library(target) local binarydir = path.join(packagedir, target:plat(), target:arch(), config.mode(), "bin") local librarydir = path.join(packagedir, target:plat(), target:arch(), config.mode(), "lib") local headerdir = path.join(packagedir, target:plat(), target:arch(), config.mode(), "include") + local modulesdir = path.join(packagedir, target:plat(), target:arch(), config.mode(), "modules") -- copy the library file to the output directory local targetfile = target:targetfile() @@ -142,6 +143,32 @@ function _package_library(target) end end + -- copy modules + if target:data("cxx.has_modules") then + import(".rules.c++.modules.modules_support.compiler_support") + import(".rules.c++.modules.modules_support.builder") + + local modules = compiler_support.localcache():get2(target:name(), "c++.modules") + builder.generate_metadata(target, modules) + + local sourcebatch = target:sourcebatches()["c++.build.modules.install"] + if sourcebatch and sourcebatch.sourcefiles then + for _, sourcefile in ipairs(sourcebatch.sourcefiles) do + local fileconfig = target:fileconfig(sourcefile) + local install = fileconfig and fileconfig.public or false + if install then + local modulehash = compiler_support.get_modulehash(target, sourcefile) + local prefixdir = path.join(modulesdir, modulehash) + os.vcp(sourcefile, path.join(prefixdir, path.filename(sourcefile))) + local metafile = compiler_support.get_metafile(target, sourcefile) + if os.exists(metafile) then + os.vcp(metafile, path.join(prefixdir, path.filename(metafile))) + end + end + end + end + end + -- generate xmake.lua local file = io.open(path.join(packagedir, "xmake.lua"), "w") if file then @@ -261,6 +288,80 @@ function _package_headeronly(target) print("package(%s): %s generated", packagename, packagedir) end +function _package_moduleonly(target) + import(".rules.c++.modules.modules_support.compiler_support") + import(".rules.c++.modules.modules_support.builder") + + -- get the output directory + local packagedir = target:packagedir() + local packagename = target:name():lower() + local headerdir = path.join(packagedir, target:plat(), target:arch(), config.mode(), "include") + local modulesdir = path.join(packagedir, target:plat(), target:arch(), config.mode(), "modules") + + local modules = compiler_support.localcache():get2(target:name(), "c++.modules") + builder.generate_metadata(target, modules) + + -- copy headers + local srcheaders, dstheaders = target:headerfiles(headerdir) + if srcheaders and dstheaders then + local i = 1 + for _, srcheader in ipairs(srcheaders) do + local dstheader = dstheaders[i] + if dstheader then + os.vcp(srcheader, dstheader) + end + i = i + 1 + end + end + + -- copy modules + local sourcebatch = target:sourcebatches()["c++.build.modules.install"] + if sourcebatch and sourcebatch.sourcefiles then + for _, sourcefile in ipairs(sourcebatch.sourcefiles) do + local modulehash = compiler_support.get_modulehash(target, sourcefile) + local prefixdir = path.join(modulesdir, modulehash) + os.vcp(sourcefile, path.join(prefixdir, path.filename(sourcefile))) + local metafile = compiler_support.get_metafile(target, sourcefile) + if os.exists(metafile) then + os.vcp(metafile, path.join(prefixdir, path.filename(metafile))) + end + end + end + + -- generate xmake.lua + local file = io.open(path.join(packagedir, "xmake.lua"), "w") + if file then + local deps = _get_librarydeps(target) + file:print("package(\"%s\")", packagename) + local homepage = option.get("homepage") + if homepage then + file:print(" set_homepage(\"%s\")", homepage) + end + local description = option.get("description") or ("The " .. packagename .. " package") + file:print(" set_description(\"%s\")", description) + if target:license() then + file:print(" set_license(\"%s\")", target:license()) + end + if #deps > 0 then + file:print(" add_deps(\"%s\")", table.concat(deps, "\", \"")) + end + file:print("") + file:print([[ + on_load(function (package) + package:set("installdir", path.join(os.scriptdir(), package:plat(), package:arch(), package:mode())) + end) + + on_fetch(function (package) + local result = {} + result.includedirs = package:installdir("include") + return result + end)]]) + file:close() + end + + -- show tips + print("package(%s): %s generated", packagename, packagedir) +end -- do package target function _do_package_target(target) if not target:is_phony() then @@ -269,6 +370,7 @@ function _do_package_target(target) binary = _package_binary , static = _package_library , shared = _package_library + , moduleonly = _package_moduleonly , headeronly = _package_headeronly } local kind = target:kind() |
