Split configuration baking into its own file; prep for file config work

This commit is contained in:
Jason Perkins 2011-05-16 15:37:48 -04:00
parent 29c531f600
commit dba4adab62
6 changed files with 85 additions and 70 deletions

View File

@ -21,7 +21,8 @@
"base/tree.lua",
"base/solution.lua",
"base/project.lua",
"base/configs.lua",
"base/config.lua",
"base/bake.lua",
"base/api.lua",
"base/cmdline.lua",
"tools/dotnet.lua",

View File

@ -344,7 +344,7 @@
_p(4,'OutputFile="$(OutDir)\\%s"', cfg.buildtarget.name)
_p(4,'LinkIncremental="%s"',
iif(premake.config.should_link_incrementally(cfg) , 2, 1))
iif(premake.config.isincrementallink(cfg) , 2, 1))
_p(4,'AdditionalLibraryDirectories="%s"', table.concat(premake.esc(path.translate(cfg.libdirs, '\\')) , ";"))
@ -394,14 +394,14 @@
_p(4,'AdditionalLibraryDirectories="%s"', premake.esc(path.translate(table.concat(cfg.libdirs , ";"))))
end
local addlOptions = {}
if cfg.platform == "x32" then
table.insert(addlOptions, "/MACHINE:X86")
elseif cfg.platform == "x64" then
table.insert(addlOptions, "/MACHINE:X64")
end
addlOptions = table.join(addlOptions, cfg.linkoptions)
if #addlOptions > 0 then
local addlOptions = {}
if cfg.platform == "x32" then
table.insert(addlOptions, "/MACHINE:X86")
elseif cfg.platform == "x64" then
table.insert(addlOptions, "/MACHINE:X64")
end
addlOptions = table.join(addlOptions, cfg.linkoptions)
if #addlOptions > 0 then
_p(4,'AdditionalOptions="%s"', table.concat(premake.esc(addlOptions), " "))
end
end

View File

@ -155,7 +155,7 @@
if cfg.kind ~= "StaticLib" then
_p(2,'<LinkIncremental '..if_config_and_platform() ..'>%s</LinkIncremental>'
,premake.esc(cfginfo.name)
,tostring(premake.config.should_link_incrementally(cfg)))
,tostring(premake.config.isincrementallink(cfg)))
end
end

View File

@ -1,59 +1,16 @@
--
-- configs.lua
-- base/bake.lua
--
-- Functions for working with configuration objects (which can include
-- projects and solutions).
-- Takes all the configuration information provided by the project scripts
-- and stored in the solution->project->block hierarchy and flattens it all
-- down into one object per configuration. These objects are cached with the
-- project, and can be retrieved by calling the getconfig() or eachconfig().
--
-- This script also contains the configuration "baking" logic (though I
-- would like to eventually move this out to a different file):
-- Once the project scripts have been run, flatten all of the configuration
-- data down into simpler objects, keeping only the settings that apply to
-- the current runtime environment.
--
-- Copyright (c) 2008-2010 Jason Perkins and the Premake project
-- Copyright (c) 2008-2011 Jason Perkins and the Premake project
--
premake.config = { }
function premake.config.isoptimizedbuild(flags)
return flags.Optimize or flags.OptimizeSize or flags.OptimizeSpeed
end
function premake.config.should_link_incrementally(cfg)
if cfg.kind == "StaticLib"
or premake.config.isoptimizedbuild(cfg.flags)
or cfg.flags.NoIncrementalLink then
return false
end
return true
end
--
-- Determine if a configuration represents a "debug" or "release" build.
-- This controls the runtime library selected for Visual Studio builds
-- (and might also be useful elsewhere).
--
-- @param cfg
-- The configuration object to test.
-- @returns
-- True if the configuration represents a debug build; false otherwise.
--
function premake.config.isdebugbuild(cfg)
-- If any of the optimize flags are set, it's a release a build
if cfg.flags.Optimize or cfg.flags.OptimizeSize or cfg.flags.OptimizeSpeed then
return false
end
-- If symbols are not defined, it's a release build
if not cfg.flags.Symbols then
return false
end
return true
end
-------------------------------------------------------------------------
-- Configuration Baking Logic
-------------------------------------------------------------------------
premake.bake = { }
local bake = premake.bake
-- do not copy these fields into the configurations
local nocopy =
@ -668,7 +625,8 @@
end
end
end
--
-- Takes the configuration information stored in solution->project->block
-- hierarchy and flattens it all down into one object per configuration.
@ -702,9 +660,9 @@
end
end
--This loop finds the projects that a configuration is connected to
--via its "uses" field. It will then copy any usage project information from that
--usage project to the configuration in question.
-- This loop finds the projects that a configuration is connected to
-- via its "uses" field. It will then copy any usage project information from that
-- usage project to the configuration in question.
for sln in premake.solution.each() do
for prjIx, prj in ipairs(sln.projects) do
if(not prj.usage) then

56
src/base/config.lua Normal file
View File

@ -0,0 +1,56 @@
--
-- configs.lua
--
-- Functions for working with configuration objects (which can include
-- projects and solutions).
--
-- Copyright (c) 2008-2011 Jason Perkins and the Premake project
--
premake.config = { }
local config = premake.config
--
-- Determine if a configuration represents a "debug" or "release" build.
-- This controls the runtime library selected for Visual Studio builds
-- (and might also be useful elsewhere).
--
function premake.config.isdebugbuild(cfg)
-- If any of the optimize flags are set, it's a release a build
if cfg.flags.Optimize or cfg.flags.OptimizeSize or cfg.flags.OptimizeSpeed then
return false
end
-- If symbols are not defined, it's a release build
if not cfg.flags.Symbols then
return false
end
return true
end
--
-- Determines if this configuration can be linked incrementally.
--
function premake.config.isincrementallink(cfg)
if cfg.kind == "StaticLib"
or config.isoptimizedbuild(cfg.flags)
or cfg.flags.NoIncrementalLink then
return false
end
return true
end
--
-- Determine if this configuration uses one of the optimize flags.
-- Optimized builds get different treatment, such as full linking
-- instead of incremental.
--
function premake.config.isoptimizedbuild(flags)
return flags.Optimize or flags.OptimizeSize or flags.OptimizeSpeed
end

View File

@ -59,23 +59,23 @@
function suite.shouldIncrementallyLink_staticLib_returnsFalse()
kind "StaticLib"
prepare()
return test.isfalse(premake.config.should_link_incrementally(cfg))
return test.isfalse(premake.config.isincrementallink(cfg))
end
function suite.shouldIncrementallyLink_optimizeFlagSet_returnsFalse()
flags { "Optimize" }
prepare()
return test.isfalse(premake.config.should_link_incrementally(cfg))
return test.isfalse(premake.config.isincrementallink(cfg))
end
function suite.shouldIncrementallyLink_NoIncrementalLinkFlag_returnsFalse()
flags { "NoIncrementalLink" }
prepare()
return test.isfalse(premake.config.should_link_incrementally(cfg))
return test.isfalse(premake.config.isincrementallink(cfg))
end
function suite.shouldIncrementallyLink_notStaticLib_NoIncrementalLinkFlag_noOptimiseFlag_returnsTrue()
prepare()
return test.istrue(premake.config.should_link_incrementally(cfg))
return test.istrue(premake.config.isincrementallink(cfg))
end