Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add better support for C++ #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions export-compile-commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,20 @@ function m.getIncludeDirs(cfg)
return flags
end

function m.getCommonFlags(cfg)
function m.getCommonFlags(prj, cfg)
local toolset = m.getToolset(cfg)
local flags = toolset.getcppflags(cfg)
flags = table.join(flags, toolset.getdefines(cfg.defines))
flags = table.join(flags, toolset.getundefines(cfg.undefines))
-- can't use toolset.getincludedirs because some tools that consume
-- compile_commands.json have problems with relative include paths
flags = table.join(flags, m.getIncludeDirs(cfg))
flags = table.join(flags, toolset.getcflags(cfg))
flags = table.join(flags, toolset.getforceincludes(cfg))
if project.iscpp(prj) then
flags = table.join(flags, toolset.getcxxflags(cfg))
else
flags = table.join(flags, toolset.getcflags(cfg))
end
return table.join(flags, cfg.buildoptions)
end

Expand All @@ -42,18 +47,25 @@ function m.getDependenciesPath(prj, cfg, node)
end

function m.getFileFlags(prj, cfg, node)
return table.join(m.getCommonFlags(cfg), {
return table.join(m.getCommonFlags(prj, cfg), {
'-o', m.getObjectPath(prj, cfg, node),
'-MF', m.getDependenciesPath(prj, cfg, node),
'-c', node.abspath
})
end

function m.generateCompileCommand(prj, cfg, node)
local toolset = m.getToolset(cfg)
if project.iscpp(prj) then
command = toolset.tools['cxx']
else
command = toolset.tools['cc']
end

return {
directory = prj.location,
file = node.abspath,
command = 'cc '.. table.concat(m.getFileFlags(prj, cfg, node), ' ')
command = command .. ' '.. table.concat(m.getFileFlags(prj, cfg, node), ' ')
}
end

Expand Down