diff options
| author | ruki <[email protected]> | 2023-08-01 09:29:22 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-08-01 09:29:22 +0800 |
| commit | c252ce12fb66373fca38e96f3fd0b968c667d1ba (patch) | |
| tree | 5c15fae9c78f453ed1eb363f8bdb94086b0c02c2 /xmake/plugins | |
| parent | 05b62d2a23b5ad1cc8cf5df357f8c8cd0229e8c2 (diff) | |
| parent | 7070b3b0ad4b8cbc48acb014540d119eea774647 (diff) | |
Merge pull request #4020 from star-hengxing/compile_commands
improve compile_commands
Diffstat (limited to 'xmake/plugins')
| -rw-r--r-- | xmake/plugins/project/clang/compile_commands.lua | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/xmake/plugins/project/clang/compile_commands.lua b/xmake/plugins/project/clang/compile_commands.lua index e7034abe4..a5f298458 100644 --- a/xmake/plugins/project/clang/compile_commands.lua +++ b/xmake/plugins/project/clang/compile_commands.lua @@ -54,6 +54,32 @@ function _get_lsp() return lsp end +-- specify windows sdk verison +function _get_windows_sdk_arguments(target) + local args = {} + local msvc = target:toolchain("msvc") + if msvc then + local envs = msvc:runenvs() + local WindowsSdkDir = envs.WindowsSdkDir + local WindowsSDKVersion = envs.WindowsSDKVersion + if WindowsSdkDir and WindowsSDKVersion then + local includedirs = os.dirs(path.join(WindowsSdkDir, "Include", envs.WindowsSDKVersion, "*")) + for _, tool in ipairs({"atlmfc", "diasdk"}) do + local tool_dir = path.join(WindowsSdkDir, tool, "include") + if os.isdir(tool_dir) then + table.insert(includedirs, tool_dir) + end + end + + for _, dir in ipairs(includedirs) do + table.insert(args, "-imsvc") + table.insert(args, dir) + end + end + end + return args +end + -- translate external/system include flags, because some tools (vscode) do not support them yet. -- https://github.com/xmake-io/xmake/issues/1050 function _translate_arguments(arguments) @@ -120,7 +146,7 @@ function _translate_arguments(arguments) end -- make command -function _make_arguments(jsonfile, arguments, sourcefile) +function _make_arguments(jsonfile, arguments, sourcefile, target) -- attempt to get source file from arguments if not sourcefile then @@ -139,6 +165,11 @@ function _make_arguments(jsonfile, arguments, sourcefile) -- translate some unsupported arguments arguments = _translate_arguments(arguments) + local lsp = _get_lsp() + if lsp and lsp == "clangd" and target:is_plat("windows") then + table.join2(arguments, _get_windows_sdk_arguments(target)) + end + -- escape '"', '\' local arguments_escape = {} for _, arg in ipairs(arguments) do @@ -184,7 +215,7 @@ function _add_target_source_commands(jsonfile, target) for index, sourcefile in ipairs(sourcebatch.sourcefiles) do local objectfile = sourcebatch.objectfiles[index] local arguments = table.join(compiler.compargv(sourcefile, objectfile, {target = target, sourcekind = sourcekind})) - _make_arguments(jsonfile, arguments, sourcefile) + _make_arguments(jsonfile, arguments, sourcefile, target) end end end |
