diff options
| author | ruki <[email protected]> | 2022-09-30 00:35:06 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-09-30 00:35:06 +0800 |
| commit | 23dd9bd16bc980c557f2752c399c0f759a2ca9ee (patch) | |
| tree | f5e296d0f5b8a73e3e4d8d4cd2b03af9fe08ca07 | |
| parent | d4b5d624463329172d9c6a7d358b561130b8254b (diff) | |
improve compile_flags
| -rw-r--r-- | xmake/plugins/project/clang/compile_flags.lua | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/xmake/plugins/project/clang/compile_flags.lua b/xmake/plugins/project/clang/compile_flags.lua index 3f521b916..75f6130a8 100644 --- a/xmake/plugins/project/clang/compile_flags.lua +++ b/xmake/plugins/project/clang/compile_flags.lua @@ -24,23 +24,19 @@ import("core.project.project") import("core.language.language") -- make the object -function _make_object(target, sourcefile, objectfile) +function _make_object(target, flags, sourcefile, objectfile) -- get the source file kind local sourcekind = language.sourcekind_of(sourcefile) - -- make the object for the *.o/obj? ignore it directly - if sourcekind == "obj" or sourcekind == "lib" then - return - end - -- get compile arguments local arguments = compiler.compflags(sourcefile, {target = target}) for i, flag in ipairs(arguments) do -- only export the -I*/-D* flags - if not g_flags[flag] and string.find(flag, '^-[ID]') then - g_flags[flag] = true - table.insert(g_flags, flag) + if flag == "-I" or flag == "/I" or flag == "-isystem" then + table.insert(flags, flag .. " " .. arguments[i + 1]) + elseif flag:find('^-[ID]') or flag:find("-isystem", 1, true) then + table.insert(flags, flag) end end @@ -49,14 +45,14 @@ function _make_object(target, sourcefile, objectfile) end -- make objects -function _make_objects(target, sourcekind, sourcebatch) +function _make_objects(target, flags, sourcekind, sourcebatch) for index, objectfile in ipairs(sourcebatch.objectfiles) do - _make_object(target, sourcebatch.sourcefiles[index], objectfile) + _make_object(target, flags, sourcebatch.sourcefiles[index], objectfile) end end -- make target -function _make_target(target) +function _make_target(target, flags) -- TODO -- disable precompiled header first @@ -67,19 +63,20 @@ function _make_target(target) for _, sourcebatch in pairs(target:sourcebatches()) do local sourcekind = sourcebatch.sourcekind if sourcekind then - _make_objects(target, sourcekind, sourcebatch) + _make_objects(target, flags, sourcekind, sourcebatch) end end end -- make all -function _make_all() +function _make_all(flags) _g.firstline = true for _, target in pairs(project.targets()) do if not target:is_phony() and target:is_default() then - _make_target(target) + _make_target(target, flags) end end + return table.unique(flags) end -- generate compilation databases for clang-based tools(compile_flags.txt) @@ -93,12 +90,12 @@ function make(outputdir) local oldir = os.cd(os.projectdir()) -- make all - g_flags = {} - _make_all() + local flags = {} + flags = _make_all(flags) -- write to file local flagfile = io.open(path.join(outputdir, "compile_flags.txt"), "w") - for i, flag in ipairs(g_flags) do + for i, flag in ipairs(flags) do flagfile:write(flag, '\n') end flagfile:close() |
