Add per-file build options and forced includes to VC'2010

This commit is contained in:
Jason Perkins 2013-03-12 19:26:25 -04:00
parent f4f688e77c
commit 96cfdf5acc
3 changed files with 157 additions and 44 deletions

View File

@ -347,6 +347,7 @@
vc2010.customBuildFilesGroup(prj)
end
function vc2010.simplefilesgroup(prj, group)
local files = vc2010.getfilegroup(prj, group)
if #files > 0 then
@ -358,6 +359,7 @@
end
end
function vc2010.compilerfilesgroup(prj)
local files = vc2010.getfilegroup(prj, "ClCompile")
if #files > 0 then
@ -368,18 +370,14 @@
local condition = vc2010.condition(cfg)
local filecfg = config.getfileconfig(cfg, file.abspath)
if not filecfg or filecfg.flags.ExcludeFromBuild then
_p(3,'<ExcludedFromBuild %s>true</ExcludedFromBuild>', condition)
vc2010.excludedFromBuild(cfg, filecfg)
if filecfg then
vc2010.objectFileName(filecfg)
vc2010.forceIncludes(filecfg, condition)
vc2010.precompiledHeader(cfg, filecfg, condition)
vc2010.additionalCompileOptions(filecfg, condition)
end
local objectname = project.getfileobject(prj, file.abspath)
if objectname ~= path.getbasename(file.abspath) then
_p(3,'<ObjectFileName %s>$(IntDir)\\%s.obj</ObjectFileName>', condition, objectname)
end
if cfg.pchsource == file.abspath and not cfg.flags.NoPCH then
_p(3,'<PrecompiledHeader %s>Create</PrecompiledHeader>', condition)
end
end
_p(2,'</ClCompile>')
end
@ -387,6 +385,7 @@
end
end
function vc2010.customBuildFilesGroup(prj)
local files = vc2010.getfilegroup(prj, "CustomBuild")
if #files > 0 then
@ -413,6 +412,7 @@
end
end
function vc2010.getfilegroup(prj, group)
-- check for a cached copy before creating
local groups = prj.vc2010_file_groups
@ -480,29 +480,6 @@
end
--
-- Format and return a Visual Studio Condition attribute.
--
function vc2010.condition(cfg)
return string.format('Condition="\'$(Configuration)|$(Platform)\'==\'%s\'"', premake.esc(vstudio.projectConfig(cfg)))
end
--
-- Map Premake's project kinds to Visual Studio configuration types.
--
function vc2010.configType(cfg)
local map = {
SharedLib = "DynamicLibrary",
StaticLib = "StaticLibrary",
ConsoleApp = "Application",
WindowedApp = "Application"
}
return map[cfg.kind]
end
---------------------------------------------------------------------------
--
@ -548,6 +525,13 @@
end
function vc2010.additionalCompileOptions(cfg, condition)
if #cfg.buildoptions > 0 then
local opts = table.concat(cfg.buildoptions, " ")
vc2010.element(3, "AdditionalOptions", condition, '%s %%(AdditionalOptions)', opts)
end
end
function vc2010.additionalLinkOptions(cfg)
if #cfg.linkoptions > 0 then
local opts = table.concat(cfg.linkoptions, " ")
@ -656,6 +640,13 @@
end
function vc2010.excludedFromBuild(cfg, filecfg)
if not filecfg or filecfg.flags.ExcludeFromBuild then
_p(3,'<ExcludedFromBuild %s>true</ExcludedFromBuild>', vc2010.condition(cfg))
end
end
function vc2010.floatingPointModel(cfg)
if cfg.flags.FloatFast then
_p(3,'<FloatingPointModel>Fast</FloatingPointModel>')
@ -665,13 +656,13 @@
end
function vc2010.forceIncludes(cfg)
function vc2010.forceIncludes(cfg, condition)
if #cfg.forceincludes > 0 then
local includes = project.getrelative(cfg.project, cfg.forceincludes)
_x(3,'<ForcedIncludeFiles>%s</ForcedIncludeFiles>', table.concat(includes, ';'))
local includes = path.translate(project.getrelative(cfg.project, cfg.forceincludes))
vc2010.element(3, "ForcedIncludeFiles", condition, table.concat(includes, ';'))
end
if #cfg.forceusings > 0 then
local usings = project.getrelative(cfg.project, cfg.forceusings)
local usings = path.translate(project.getrelative(cfg.project, cfg.forceusings))
_x(3,'<ForcedUsingFiles>%s</ForcedUsingFiles>', table.concat(usings, ';'))
end
end
@ -794,6 +785,14 @@
end
function vc2010.objectFileName(filecfg)
local objectname = project.getfileobject(filecfg.project, filecfg.abspath)
if objectname ~= path.getbasename(filecfg.abspath) then
_p(3,'<ObjectFileName %s>$(IntDir)\\%s.obj</ObjectFileName>', vc2010.condition(filecfg.config), objectname)
end
end
function vc2010.omitFramePointers(cfg)
if cfg.flags.NoFramePointer then
_p(3,'<OmitFramePointers>true</OmitFramePointers>')
@ -844,12 +843,18 @@
end
function vc2010.precompiledHeader(cfg)
if not cfg.flags.NoPCH and cfg.pchheader then
_p(3,'<PrecompiledHeader>Use</PrecompiledHeader>')
_x(3,'<PrecompiledHeaderFile>%s</PrecompiledHeaderFile>', path.getname(cfg.pchheader))
function vc2010.precompiledHeader(cfg, filecfg, condition)
if filecfg then
if cfg.pchsource == filecfg.abspath and not cfg.flags.NoPCH then
vc2010.element(3, 'PrecompiledHeader', condition, 'Create')
end
else
_p(3,'<PrecompiledHeader>NotUsing</PrecompiledHeader>')
if not cfg.flags.NoPCH and cfg.pchheader then
_p(3,'<PrecompiledHeader>Use</PrecompiledHeader>')
_x(3,'<PrecompiledHeaderFile>%s</PrecompiledHeaderFile>', path.getname(cfg.pchheader))
else
_p(3,'<PrecompiledHeader>NotUsing</PrecompiledHeader>')
end
end
end
@ -965,3 +970,67 @@
end
_p(3,'<WarningLevel>Level%d</WarningLevel>', w)
end
---------------------------------------------------------------------------
--
-- Support functions
--
---------------------------------------------------------------------------
--
-- Format and return a Visual Studio Condition attribute.
--
function vc2010.condition(cfg)
return string.format('Condition="\'$(Configuration)|$(Platform)\'==\'%s\'"', premake.esc(vstudio.projectConfig(cfg)))
end
--
-- Map Premake's project kinds to Visual Studio configuration types.
--
function vc2010.configType(cfg)
local map = {
SharedLib = "DynamicLibrary",
StaticLib = "StaticLibrary",
ConsoleApp = "Application",
WindowedApp = "Application"
}
return map[cfg.kind]
end
--
-- Output an individual project XML element, with an optional configuration
-- condition.
--
-- @param depth
-- How much to indent the element.
-- @param name
-- The element name.
-- @param condition
-- An optional configuration condition, formatted with vc2010.condition().
-- @param value
-- The element value, which may contain printf formatting tokens.
-- @param ...
-- Optional additional arguments to satisfy any tokens in the value.
--
function vc2010.element(depth, name, condition, value, ...)
if select('#',...) == 0 then
value = premake.esc(value)
end
local format
if condition then
format = string.format('<%s %s>%s</%s>', name, condition, value, name)
else
format = string.format('<%s>%s</%s>', name, value, name)
end
_x(depth, format, ...)
end

View File

@ -551,7 +551,7 @@
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<ForcedIncludeFiles>stdafx.h;include/sys.h</ForcedIncludeFiles>
<ForcedIncludeFiles>stdafx.h;include\sys.h</ForcedIncludeFiles>
]]
end
@ -562,7 +562,7 @@
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<ForcedUsingFiles>stdafx.h;include/sys.h</ForcedUsingFiles>
<ForcedUsingFiles>stdafx.h;include\sys.h</ForcedUsingFiles>
]]
end

View File

@ -164,3 +164,47 @@
</ItemGroup>
]]
end
--
-- Check handling of per-file forced includes.
--
function suite.forcedIncludeFiles()
language "C++"
files { "hello.cpp" }
configuration "**.cpp"
forceincludes { "../include/force1.h", "../include/force2.h" }
prepare()
test.capture [[
<ItemGroup>
<ClCompile Include="hello.cpp">
<ForcedIncludeFiles Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\include\force1.h;..\include\force2.h</ForcedIncludeFiles>
<ForcedIncludeFiles Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\include\force1.h;..\include\force2.h</ForcedIncludeFiles>
</ClCompile>
</ItemGroup>
]]
end
--
-- Check handling of per-file command line build options.
--
function suite.additionalOptions()
language "C++"
files { "hello.cpp" }
configuration "**.cpp"
buildoptions { "/Xc" }
prepare()
test.capture [[
<ItemGroup>
<ClCompile Include="hello.cpp">
<AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">/Xc %(AdditionalOptions)</AdditionalOptions>
<AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">/Xc %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
</ItemGroup>
]]
end