Skip to content

Commit

Permalink
Merge pull request #2194 from Jarod42/vs_per_file_cdialect
Browse files Browse the repository at this point in the history
[vs*] Allow to have per-file `cdialect`/`cppdialect`.
  • Loading branch information
samsinsane authored Mar 22, 2024
2 parents b4d65e3 + 7e181b5 commit ac27f70
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 9 deletions.
49 changes: 49 additions & 0 deletions modules/vstudio/tests/vc2010/test_files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,55 @@
]]
end

--
-- Check handling of per-file cdialect.
--
function suite.onCDialect()
p.action.set("vs2019")
cdialect "c11"
files { "file.c", "file11.c", "file17.c" }
filter "files:file11.c"
cdialect "c11"
filter "files:file17.c"
cdialect "c17"
prepare()
test.capture [[
<ItemGroup>
<ClCompile Include="file.c" />
<ClCompile Include="file11.c">
<LanguageStandard_C>stdc11</LanguageStandard_C>
</ClCompile>
<ClCompile Include="file17.c">
<LanguageStandard_C>stdc17</LanguageStandard_C>
</ClCompile>
<ItemGroup>]]
end

--
-- Check handling of per-file cppdialect.
--
function suite.onCppDialect()
p.action.set("vs2017")
cppdialect "c++14"
files { "file.cpp", "file14.cpp", "file17.cpp" }
filter "files:file14.cpp"
cppdialect "c++14"
filter "files:file17.cpp"
cppdialect "c++17"
prepare()
test.capture [[
<ItemGroup>
<ClCompile Include="file.cpp" />
<ClCompile Include="file14.cpp">
<LanguageStandard>stdcpp14</LanguageStandard>
</ClCompile>
<ClCompile Include="file17.cpp">
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<ItemGroup>]]
end


--
-- Check handling of per-file optimization levels.
--
Expand Down
20 changes: 11 additions & 9 deletions modules/vstudio/vs2010_vcxproj.lua
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,8 @@
m.objectFileName,
m.clCompilePreprocessorDefinitions,
m.clCompileUndefinePreprocessorDefinitions,
m.languageStandard,
m.languageStandardC,
m.optimization,
m.forceIncludes,
m.forceUsings,
Expand Down Expand Up @@ -1485,7 +1487,7 @@

local contents = p.capture(function ()
p.push()
p.callArray(fileFunc, cfg, file)
p.callArray(fileFunc, nil, file)
m.conditionalElements = {}
for cfg in project.eachconfig(prj) do
local fcfg = fileconfig.getconfig(file, cfg)
Expand Down Expand Up @@ -1730,27 +1732,27 @@
end


function m.languageStandard(cfg)
function m.languageStandard(cfg, condition)
if _ACTION >= "vs2017" then
if (cfg.cppdialect == "C++14") then
m.element("LanguageStandard", nil, 'stdcpp14')
m.element("LanguageStandard", condition, 'stdcpp14')
elseif (cfg.cppdialect == "C++17") then
m.element("LanguageStandard", nil, 'stdcpp17')
m.element("LanguageStandard", condition, 'stdcpp17')
elseif (cfg.cppdialect == "C++20") then
m.element("LanguageStandard", nil, iif(_ACTION == "vs2017", 'stdcpplatest', 'stdcpp20'))
m.element("LanguageStandard", condition, iif(_ACTION == "vs2017", 'stdcpplatest', 'stdcpp20'))
elseif (cfg.cppdialect == "C++latest") then
m.element("LanguageStandard", nil, 'stdcpplatest')
m.element("LanguageStandard", condition, 'stdcpplatest')
end
end
end


function m.languageStandardC(cfg)
function m.languageStandardC(cfg, condition)
if _ACTION >= "vs2019" then
if (cfg.cdialect == "C11") then
m.element("LanguageStandard_C", nil, 'stdc11')
m.element("LanguageStandard_C", condition, 'stdc11')
elseif (cfg.cdialect == "C17") then
m.element("LanguageStandard_C", nil, 'stdc17')
m.element("LanguageStandard_C", condition, 'stdc17')
end
end
end
Expand Down

0 comments on commit ac27f70

Please sign in to comment.