Skip to content

Commit

Permalink
简单兼容下clang-cl
Browse files Browse the repository at this point in the history
  • Loading branch information
actboy168 committed Mar 24, 2023
1 parent ad76002 commit 4170e2b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
16 changes: 10 additions & 6 deletions scripts/compiler/msvc.lua
@@ -1,3 +1,5 @@
local globals = require "globals"

local function format_path(path)
if path:match " " then
return '"'..path..'"'
Expand Down Expand Up @@ -79,7 +81,7 @@ function cl.update_flags(flags, _, cxxflags, attribute, name)
else
flags[#flags+1] = attribute.crt == 'dynamic' and '/MD' or '/MT'
end
if attribute.lto ~= "off" then
if globals.cc ~= "clang-cl" and attribute.lto ~= "off" then
flags[#flags+1] = "/GL"
end
if attribute.rtti == "off" then
Expand All @@ -96,28 +98,30 @@ function cl.update_ldflags(ldflags, attribute, name)
end
if attribute.lto ~= "off" then
ldflags[#ldflags+1] = '/INCREMENTAL:NO'
ldflags[#ldflags+1] = '/LTCG' -- TODO: msvc2017 has bug for /LTCG:incremental
if globals.cc ~= "clang-cl" then
ldflags[#ldflags+1] = '/LTCG' -- TODO: msvc2017 has bug for /LTCG:incremental
end
end
end

function cl.rule_c(w, name, flags, cflags)
w:rule('c_'..name, ([[cl /nologo /showIncludes -c $in /Fo$out %s %s]]):format(flags, cflags),
w:rule('c_'..name, ([[$cc /nologo /showIncludes -c $in /Fo$out %s %s]]):format(flags, cflags),
{
description = 'Compile C $out',
deps = 'msvc',
})
end

function cl.rule_cxx(w, name, flags, cxxflags)
w:rule('cxx_'..name, ([[cl /nologo /showIncludes -c $in /Fo$out %s %s]]):format(flags, cxxflags),
w:rule('cxx_'..name, ([[$cc /nologo /showIncludes -c $in /Fo$out %s %s]]):format(flags, cxxflags),
{
description = 'Compile C++ $out',
deps = 'msvc',
})
end

function cl.rule_dll(w, name, ldflags)
w:rule('link_'..name, ([[cl /nologo @$out.rsp /link %s /out:$out /DLL /IMPLIB:$implib]]):format(ldflags),
w:rule('link_'..name, ([[$cc /nologo @$out.rsp /link %s /out:$out /DLL /IMPLIB:$implib]]):format(ldflags),
{
description = 'Link Dll $out',
rspfile = "$out.rsp",
Expand All @@ -127,7 +131,7 @@ function cl.rule_dll(w, name, ldflags)
end

function cl.rule_exe(w, name, ldflags)
w:rule('link_'..name, ([[cl /nologo @$out.rsp /link %s /out:$out]]):format(ldflags),
w:rule('link_'..name, ([[$cc /nologo @$out.rsp /link %s /out:$out]]):format(ldflags),
{
description = 'Link Exe $out',
rspfile = "$out.rsp",
Expand Down
6 changes: 5 additions & 1 deletion scripts/writer.lua
Expand Up @@ -939,8 +939,12 @@ function m.generate()
if not globals.prebuilt then
local msvc = require "msvc_util"
msvc.createEnvConfig(globals.arch, arguments.what == "rebuild")
ninja:variable("msvc_deps_prefix", msvc.getPrefix())
ninja:variable("msvc_deps_prefix", globals.cc == "clang-cl"
and "Note: including file:"
or msvc.getPrefix()
)
end
ninja:variable("cc", globals.cc or "cl")
else
local compiler = globals.cc or globals.compiler
if globals.hostshell == "cmd" then
Expand Down

0 comments on commit 4170e2b

Please sign in to comment.