summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-10-07 00:52:53 +0800
committerruki <[email protected]>2021-10-07 00:52:53 +0800
commitbf5cbeff9d3b65ad60789ef2119acc0b017f5fb9 (patch)
treed224111c5f32a53147a4ff9d7698d59b2bbf44a4
parentc360a739ba17f89f7f4d4f8ffbebc30576cd7dea (diff)
improve compile_commands
-rw-r--r--xmake/modules/core/tools/nvcc.lua4
-rw-r--r--xmake/plugins/project/clang/compile_commands.lua23
2 files changed, 23 insertions, 4 deletions
diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua
index d03a10865..25a589124 100644
--- a/xmake/modules/core/tools/nvcc.lua
+++ b/xmake/modules/core/tools/nvcc.lua
@@ -212,7 +212,7 @@ end
-- make the includedir flag
function nf_includedir(self, dir)
- return {"-I", dir}
+ return {"-I" .. path.translate(dir)}
end
-- make the sysincludedir flag
@@ -232,7 +232,7 @@ end
-- make the linkdir flag
function nf_linkdir(self, dir)
- return {"-L", dir}
+ return {"-L" .. path.translate(dir)}
end
-- make the rpathdir flag
diff --git a/xmake/plugins/project/clang/compile_commands.lua b/xmake/plugins/project/clang/compile_commands.lua
index 085d230ae..a3f893d90 100644
--- a/xmake/plugins/project/clang/compile_commands.lua
+++ b/xmake/plugins/project/clang/compile_commands.lua
@@ -34,7 +34,8 @@ end
-- https://github.com/xmake-io/xmake/issues/1050
function _translate_arguments(arguments)
local args = {}
- local is_msvc = path.basename(arguments[1]):lower() == "cl"
+ local cc = path.basename(arguments[1]):lower()
+ local is_include = false
for idx, arg in ipairs(arguments) do
-- see https://github.com/xmake-io/xmake/issues/1721
if idx == 1 and is_host("windows") and path.extension(arg) == "" then
@@ -53,8 +54,26 @@ function _translate_arguments(arguments)
end
-- @see use msvc-style flags for msvc to support language-server better
-- https://github.com/xmake-io/xmake/issues/1284
- if is_msvc and arg and arg:startswith("-") then
+ if cc == "cl" and arg and arg:startswith("-") then
arg = arg:gsub("^%-", "/")
+ elseif cc == "nvcc" and arg then
+ -- support -I path with spaces for nvcc
+ -- https://github.com/xmake-io/xmake/issues/1726
+ if is_include then
+ if arg and arg:find(' ', 1, true) then
+ arg = "\"" .. arg .. "\""
+ end
+ is_include = false
+ elseif arg:startswith("-I") then
+ local f = arg:sub(1, 2)
+ local v = arg:sub(3)
+ if v and v:find(' ', 1, true) then
+ arg = f .. "\"" .. v .. "\""
+ end
+ end
+ end
+ if arg == "-I" then
+ is_include = true
end
if arg then
table.insert(args, arg)