Implement 'compileas' for vc2008

This commit is contained in:
Ben Ratzlaff 2019-09-13 21:05:49 -07:00
parent d0377b99f9
commit ebbc6de2d8
2 changed files with 157 additions and 7 deletions

View File

@ -181,6 +181,155 @@
]] ]]
end end
--
-- Check handling of per-file compileas options.
--
function suite.onCompileAs_C_as_CPP()
language "C"
files { "hello.c" }
filter {"files:hello.c"}
compileas "C++"
prepare()
test.capture [[
<Files>
<File
RelativePath="hello.c"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="2"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="2"
/>
</FileConfiguration>
</File>
</Files>
]]
end
-- make sure compileas is still omitted when it matches the language.
function suite.onCompileAs_C_as_CPP_in_CPP()
language "C++"
files { "hello.c" }
filter {"files:hello.c"}
compileas "C++"
prepare()
test.capture [[
<Files>
<File
RelativePath="hello.c"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="2"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="2"
/>
</FileConfiguration>
</File>
</Files>
]]
end
function suite.onCompileAs_C_as_CPP_release()
language "C"
files { "hello.c" }
filter {"files:hello.c", "configurations:release"}
compileas "C++"
prepare()
test.capture [[
<Files>
<File
RelativePath="hello.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="2"
/>
</FileConfiguration>
</File>
</Files>
]]
end
function suite.onCompileAs_CPP_as_C()
language "C++"
files { "hello.cpp" }
filter {"files:hello.cpp"}
compileas "C"
prepare()
test.capture [[
<Files>
<File
RelativePath="hello.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="1"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="1"
/>
</FileConfiguration>
</File>
</Files>
]]
end
function suite.onCompileAs_CPP_as_C_release()
language "C++"
files { "hello.cpp" }
filter {"files:hello.cpp", "configurations:release"}
compileas "C"
prepare()
test.capture [[
<Files>
<File
RelativePath="hello.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="1"
/>
</FileConfiguration>
</File>
</Files>
]]
end
-- --
-- A PCH source file should be marked as such. -- A PCH source file should be marked as such.

View File

@ -927,23 +927,24 @@
function m.compileAs(cfg, toolset) function m.compileAs(cfg, toolset)
local cfg, filecfg = config.normalize(cfg) local cfg, filecfg = config.normalize(cfg)
local c = p.languages.isc(cfg.language) local c = p.languages.isc(cfg.language)
local compileAs
if filecfg then if filecfg then
if path.iscfile(filecfg.name) ~= c then if filecfg.compileas then
compileAs = iif(p.languages.iscpp(filecfg.compileas), 2, 1)
elseif path.iscfile(filecfg.name) ~= c then
if path.iscppfile(filecfg.name) then if path.iscppfile(filecfg.name) then
local value = iif(c, 2, 1) compileAs = iif(c, 2, 1)
p.w('CompileAs="%s"', value)
end end
end end
else else
local compileAs
if toolset then if toolset then
compileAs = "0" compileAs = "0"
elseif c then elseif c then
compileAs = "1" compileAs = "1"
end end
if compileAs then end
p.w('CompileAs="%s"', compileAs) if compileAs then
end p.w('CompileAs="%s"', compileAs)
end end
end end