premake / premake-core

Premake

Home Page:https://premake.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Toggling Visual Studio's new C++ Modules on/off in premake lua script

HerrDingenz opened this issue · comments

What problem will this solve?
I have an issue with Visual Studio projects using "c++latest" and precompiled headers. Visual Studio has some new options for projects regarding their C++modules which can be found in the project's properties under C/C++ -> Language. They are Enable Experimental C++ Standard Library Modules and Build ISO C++23 Standard Library Modules.

Whenever I make changes to the premake script and regenerate the project these options are set to the standard (enabled) and the code won't compile because of missing include of my precompiled header in their files. I always have to manually set those options again after generating the solution/project.

What might be a solution?
Two new commands for the premake lua script that describes the project which can be used to set those values.

enablemodules "yes"
buildstlmodules "yes"
enablemodules "no"
buildstlmodules "no"

This way I can set those values already when generating the project via premake.

What other alternatives have you already considered?
I don't see any alternatives, but to set those values manually in the project settings.

Anything else we should know?
Not really.

Can you share which settings that you are toggling so we can hunt down what in the project file would need to change?

Yeah sure. They are - like stated in my opening post - inside the Project settings under C/C++ -> Language
module_settings
Inside the project file itself it creates this

<ClCompile>
   ....
   <BuildStlModules>false</BuildStlModules>
</ClCompile>

when the option is set to No.

commented

I'm also stuck right now with this, it would be great to see this implemented soon

Edit: Got them working fine. As a temporary measure, add this:

require('vstudio')

local p = premake
local m = p.vstudio.vc2010

m.elements.clCompile = function(cfg)
	local calls = {
        function(cfg)
            m.element("ScanSourceForModuleDependencies", nil, "true");
        end,
        function(cfg)
            m.element("EnableModules", nil, "true");
        end,
        function(cfg)
            m.element("BuildStlModules", nil, "true");
        end,
		m.precompiledHeader,
		m.warningLevel,
		m.treatWarningAsError,
		m.disableSpecificWarnings,
		m.treatSpecificWarningsAsErrors,
		m.basicRuntimeChecks,
		m.clCompilePreprocessorDefinitions,
		m.clCompileUndefinePreprocessorDefinitions,
		m.clCompileAdditionalIncludeDirectories,
		m.clCompileAdditionalUsingDirectories,
		m.forceIncludes,
		m.debugInformationFormat,
		m.optimization,
		m.functionLevelLinking,
		m.intrinsicFunctions,
		m.justMyCodeDebugging,
		m.supportOpenMP,
		m.minimalRebuild,
		m.omitFramePointers,
		m.stringPooling,
		m.runtimeLibrary,
		m.omitDefaultLib,
		m.exceptionHandling,
		m.runtimeTypeInfo,
		m.bufferSecurityCheck,
		m.treatWChar_tAsBuiltInType,
		m.floatingPointModel,
		m.floatingPointExceptions,
		m.inlineFunctionExpansion,
		m.enableEnhancedInstructionSet,
		m.multiProcessorCompilation,
		m.additionalCompileOptions,
		m.compileAs,
		m.callingConvention,
		m.languageStandard,
		m.languageStandardC,
		m.conformanceMode,
		m.structMemberAlignment,
		m.useFullPaths,
		m.removeUnreferencedCodeData,
		m.compileAsWinRT,
		m.externalWarningLevel,
		m.externalAngleBrackets,
		m.scanSourceForModuleDependencies,
		m.useStandardPreprocessor,
	}

	if cfg.kind == p.STATICLIB then
		table.insert(calls, m.programDatabaseFileName)
	end

	return calls
end

There's probably a better way (overriding) but it's not as straight forward as just replacing the function.

I've got some time to sink my teeth into it, so I should be able to do that this week.