diff options
| author | star9029 <[email protected]> | 2023-07-29 20:34:24 +0800 |
|---|---|---|
| committer | star9029 <[email protected]> | 2023-07-29 20:34:24 +0800 |
| commit | 495ae60c63e442805f38b5c80e70e586d97600e5 (patch) | |
| tree | 97214ff7b3f2edde9c6875b54b1eef43039a40bb | |
| parent | 05b62d2a23b5ad1cc8cf5df357f8c8cd0229e8c2 (diff) | |
improve compile_commands
| -rw-r--r-- | xmake/plugins/project/clang/compile_commands.lua | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/xmake/plugins/project/clang/compile_commands.lua b/xmake/plugins/project/clang/compile_commands.lua index e7034abe4..e3521db5c 100644 --- a/xmake/plugins/project/clang/compile_commands.lua +++ b/xmake/plugins/project/clang/compile_commands.lua @@ -54,6 +54,31 @@ 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 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 + 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 +145,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 +164,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 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 +214,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 |
