diff options
| author | ruki <[email protected]> | 2022-11-03 22:52:10 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-11-03 13:06:03 +0800 |
| commit | f2ea9f6021fcb21ad0f8fc42d3bc78a3ae7d2283 (patch) | |
| tree | 753bf9e75b590e4e66a02496051b11f3d046add9 /xmake/rules/c++/modules/modules_support/clang.lua | |
| parent | f95014b8e8c6e32471cf8bfa97988519dac25950 (diff) | |
improve clang to support std modules
Diffstat (limited to 'xmake/rules/c++/modules/modules_support/clang.lua')
| -rw-r--r-- | xmake/rules/c++/modules/modules_support/clang.lua | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua index 100830046..e0a7b0228 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -66,21 +66,30 @@ end -- load module support for the current target function load(target) - -- get module and module cache flags local modulesflag = get_modulesflag(target) local builtinmodulemapflag = get_builtinmodulemapflag(target) local implicitmodulesflag = get_implicitmodulesflag(target) - local noimplicitmodulemapsflag = get_noimplicitmodulemapsflag(target) -- add module flags target:add("cxxflags", modulesflag) - - -- add the module cache directory target:add("cxxflags", builtinmodulemapflag, {force = true}) target:add("cxxflags", implicitmodulesflag, {force = true}) - target:add("cxxflags", noimplicitmodulemapsflag, {force = true}) + -- TODO fix default visibility for functions and variables [-fvisibility] differs in PCH file vs. current file + -- module.pcm cannot be loaded due to a configuration mismatch with the current compilation. + -- + -- it will happen in binary target depend ont shared target with modules, and enable release mode at same time. + target:set("symbols", "none") + + -- if use libc++, we need install libc++ and libc++abi + -- + -- on ubuntu: + -- sudo apt install libc++-dev libc++abi-15-dev + -- target:data_set("cxx.modules.use_libc++", table.contains(target:get("cxxflags"), "-stdlib=libc++")) + if target:data("cxx.modules.use_libc++") then + target:add("syslinks", "c++") + end end -- get includedirs for stl headers @@ -93,6 +102,10 @@ end function _get_toolchain_includedirs_for_stlheaders(includedirs, clang) local tmpfile = os.tmpfile() .. ".cc" io.writefile(tmpfile, "#include <vector>") + local argv = {"-E", "-x", "c++", tmpfile} + if target:data("cxx.modules.use_libc++") then + table.insert(argv, 1, "-stdlib=libc++") + end local result = try {function () return os.iorunv(clang, {"-E", "-x", "c++", tmpfile}) end} if result then for _, line in ipairs(result:split("\n", {plain = true})) do |
