diff options
| author | ruki <[email protected]> | 2022-08-04 22:53:32 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-08-04 22:53:32 +0800 |
| commit | 312dccfb5ffae68ba471d9ebca5569589bb46988 (patch) | |
| tree | 641681c5674cf3a8d60944110c3552ce39afd9cc /xmake/rules/c++/modules/modules_support/clang.lua | |
| parent | fd44ddb961977eeed2b15637562da80174f1a5ee (diff) | |
improve to get toolchain includedirs
Diffstat (limited to 'xmake/rules/c++/modules/modules_support/clang.lua')
| -rw-r--r-- | xmake/rules/c++/modules/modules_support/clang.lua | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua index 44150ab21..865b20a75 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -54,20 +54,46 @@ function load(target) end end --- provide toolchain include dir for stl headerunit when p1689 is not supported -function toolchain_include_directories(target) +-- get includedirs for stl headers +-- +-- $ echo '#include <vector>' | clang -x c++ -E - | grep '/vector"' +-- # 1 "/usr/include/c++/11/vector" 1 3 +-- # 58 "/usr/include/c++/11/vector" 3 +-- # 59 "/usr/include/c++/11/vector" 3 +-- +function _get_toolchain_includedirs_for_stlheaders(includedirs, clang) + local tmpfile = os.tmpfile() .. ".cc" + io.writefile(tmpfile, "#include <vector>") + 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 + line = line:trim() + if line:startswith("#") and line:find("/vector\"", 1, true) then + local includedir = line:match("\"(.+)/vector\"") + if includedir and os.isdir(includedir) then + table.insert(includedirs, includedir) + break + end + end + end + end + os.tryrm(tmpfile) +end + +-- provide toolchain include directories for stl headerunit when p1689 is not supported +function toolchain_includedirs(target) local includedirs = _g.includedirs if includedirs == nil then includedirs = {} local clang, toolname = target:tool("cc") assert(toolname == "clang") + _get_toolchain_includedirs_for_stlheaders(includedirs, clang) local _, result = try {function () return os.iorunv(clang, {"-E", "-Wp,-v", "-xc", os.nuldev()}) end} if result then for _, line in ipairs(result:split("\n", {plain = true})) do line = line:trim() if os.isdir(line) then table.insert(includedirs, line) - break elseif line:startswith("End") then break end |
