Skip to content

Commit

Permalink
Implemented VS API for toggling of C++20 modules and STL module build (
Browse files Browse the repository at this point in the history
  • Loading branch information
nickclark2016 authored Oct 30, 2023
1 parent 2f6617c commit b94b9d7
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 0 deletions.
20 changes: 20 additions & 0 deletions modules/vstudio/_preload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,26 @@
}
}

p.api.register {
name = "enablemodules",
scope = { "config" },
kind = "string",
allowed = {
"On",
"Off"
}
}

p.api.register {
name = "buildstlmodules",
scope = { "config" },
kind = "string",
allowed = {
"On",
"Off"
}
}

--
-- Decide when the full module should be loaded.
--
Expand Down
26 changes: 26 additions & 0 deletions modules/vstudio/tests/vc2019/test_compile_settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,29 @@
<UseStandardPreprocessor>false</UseStandardPreprocessor>
]]
end

function suite.enableModulesOff()
enablemodules 'Off'
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<ExternalWarningLevel>Level3</ExternalWarningLevel>
<EnableModules>false</EnableModules>
]]
end

function suite.enableModulesOn()
enablemodules 'On'
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<ExternalWarningLevel>Level3</ExternalWarningLevel>
<EnableModules>true</EnableModules>
]]
end
26 changes: 26 additions & 0 deletions modules/vstudio/tests/vc2022/test_compile_settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,29 @@ function suite.TreatAngleIncludeAsExternalOffFile()
<TreatAngleIncludeAsExternal>false</TreatAngleIncludeAsExternal>
]]
end

function suite.BuildStlModulesOff()
buildstlmodules 'Off'
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<ExternalWarningLevel>Level3</ExternalWarningLevel>
<BuildStlModules>false</BuildStlModules>
]]
end

function suite.BuildStlModulesOn()
buildstlmodules 'On'
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<ExternalWarningLevel>Level3</ExternalWarningLevel>
<BuildStlModules>true</BuildStlModules>
]]
end
20 changes: 20 additions & 0 deletions modules/vstudio/vs2010_vcxproj.lua
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,8 @@
m.externalAngleBrackets,
m.scanSourceForModuleDependencies,
m.useStandardPreprocessor,
m.enableModules,
m.buildStlModules,
}

if cfg.kind == p.STATICLIB then
Expand Down Expand Up @@ -3029,6 +3031,24 @@
end


function m.enableModules(cfg)
if _ACTION >= "vs2019" then
if cfg.enablemodules then
m.element("EnableModules", nil, iif(cfg.enablemodules == "On", "true", "false"))
end
end
end


function m.buildStlModules(cfg)
if _ACTION >= "vs2022" then
if cfg.buildstlmodules then
m.element("BuildStlModules", nil, iif(cfg.buildstlmodules == "On", "true", "false"))
end
end
end


function m.externalAngleBrackets(cfg, condition)
if _ACTION >= "vs2019" then
if cfg.externalanglebrackets == p.OFF then
Expand Down
24 changes: 24 additions & 0 deletions website/docs/buildstlmodules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Sets whether or not the compiler should build STL modules.

```lua
buildstlmodules("value")
```

### Parameters ###

`value` is one of:

- `On`
- `Off`

### Applies To ###

The `config` scope.

### Availability ###

Premake 5.0.0 beta 3 or later for Visual Studio 2022 and later.

### See Also ###

* [enablemodules](enablemodules.md)
20 changes: 20 additions & 0 deletions website/docs/enablemodules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Sets whether or not the compiler should enable C++20 modules.

```lua
enablemodules("value")
```

### Parameters ###

`value` is one of:

- `On`
- `Off`

### Applies To ###

The `config` scope.

### Availability ###

Premake 5.0.0 beta 3 or later for Visual Studio 2019 and later.
2 changes: 2 additions & 0 deletions website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ module.exports = {
'buildoptions',
'buildoutputs',
'buildrule',
'buildstlmodules',
'callingconvention',
'cdialect',
'characterset',
Expand Down Expand Up @@ -139,6 +140,7 @@ module.exports = {
'embed',
'embedandsign',
'enabledefaultcompileitems',
'enablemodules',
'enableunitybuild',
'enablewarnings',
'endian',
Expand Down

0 comments on commit b94b9d7

Please sign in to comment.