diff options
| author | ruki <[email protected]> | 2020-11-18 00:08:26 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-11-18 00:08:26 +0800 |
| commit | 3755fe7dce45586dbe9c72b62358a08bc5d07e5c (patch) | |
| tree | af6f314d69cf43a0dac572efcddb6f5c901b2e7e | |
| parent | 37933e44724b9f7cdd9f78b1524ccbe55dd88844 (diff) | |
disable external includes for cmake
| -rw-r--r-- | xmake/plugins/project/clang/compile_commands.lua | 22 | ||||
| -rw-r--r-- | xmake/plugins/project/cmake/cmakelists.lua | 7 |
2 files changed, 27 insertions, 2 deletions
diff --git a/xmake/plugins/project/clang/compile_commands.lua b/xmake/plugins/project/clang/compile_commands.lua index d23c22669..02872fa2d 100644 --- a/xmake/plugins/project/clang/compile_commands.lua +++ b/xmake/plugins/project/clang/compile_commands.lua @@ -28,6 +28,25 @@ function _escape_path(p) return os.args(p, {escape = true, nowrap = true}) 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) + local args = {} + for _, arg in ipairs(arguments) do + if arg:find("-isystem", 1, true) then + arg = arg:replace("-isystem", "-I") + elseif arg:find("[%-/]external:I") then + arg = arg:gsub("[%-/]external:I", "-I") + elseif arg:find("[%-/]external:W") or arg:find("[%-/]experimental:external") then + arg = nil + end + if arg then + table.insert(args, arg) + end + end + return args +end + -- make the object function _make_object(jsonfile, target, sourcefile, objectfile) @@ -42,6 +61,9 @@ function _make_object(jsonfile, target, sourcefile, objectfile) -- get compile arguments local arguments = table.join(compiler.compargv(sourcefile, objectfile, {target = target, sourcekind = sourcekind})) + -- translate some unsupported arguments + arguments = _translate_arguments(arguments) + -- escape '"', '\' local arguments_escape = {} for _, arg in ipairs(arguments) do diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua index a90e58d28..c3b3616d8 100644 --- a/xmake/plugins/project/cmake/cmakelists.lua +++ b/xmake/plugins/project/cmake/cmakelists.lua @@ -183,10 +183,13 @@ function _add_target_include_directories(cmakelists, target) end -- add target system include directories +-- we disable system/external includes first, because cmake doesn’t seem to be able to support msvc /external:I +-- https://github.com/xmake-io/xmake/issues/1050 function _add_target_sysinclude_directories(cmakelists, target) local includedirs = _get_configs_from_target(target, "sysincludedirs") if #includedirs > 0 then - cmakelists:print("target_include_directories(%s SYSTEM PRIVATE", target:name()) + -- TODO should be `SYSTEM PRIVATE` + cmakelists:print("target_include_directories(%s PRIVATE", target:name()) for _, includedir in ipairs(includedirs) do cmakelists:print(" " .. _get_unix_path(includedir)) end @@ -194,7 +197,7 @@ function _add_target_sysinclude_directories(cmakelists, target) end local includedirs_interface = target:get("sysincludedirs", {interface = true}) if includedirs_interface then - cmakelists:print("target_include_directories(%s SYSTEM INTERFACE", target:name()) + cmakelists:print("target_include_directories(%s INTERFACE", target:name()) for _, headerdir in ipairs(includedirs_interface) do cmakelists:print(" " .. _get_unix_path(headerdir)) end |
