112 lines
2.7 KiB
Lua
112 lines
2.7 KiB
Lua
-- A Generic Solution Definition.
|
|
|
|
-- A solution is composed of multiple libraries, themself composed of
|
|
-- multiple projects (at least the library itself and a test executable).
|
|
|
|
require "library"
|
|
require "itertools"
|
|
require "utils"
|
|
|
|
Solution = {
|
|
-- Factory for the standard Library.
|
|
Library = Library,
|
|
-- List of libraries, with their default configuration override.
|
|
libraries = {
|
|
NoLibraryDefined = {}
|
|
},
|
|
-- The name of the solution
|
|
name = "Unknown",
|
|
-- List of default configurations and their options.
|
|
configurations = {
|
|
Debug = {},
|
|
Release = {},
|
|
Retail = {}
|
|
},
|
|
-- List of the default options.
|
|
defaults = {
|
|
language = "C++",
|
|
},
|
|
-- Suffix to add to the platform.
|
|
suffix = "",
|
|
-- subdirectory under the platform directory.
|
|
subdir = "",
|
|
libraries = {}
|
|
}
|
|
|
|
function Solution:New(o)
|
|
o = o or {}
|
|
setmetatable(o, self)
|
|
self.__index = self
|
|
return o
|
|
end
|
|
|
|
-- Return a new Library with this config.
|
|
function Solution:GetLibrary(config)
|
|
return self.Library:New(config)
|
|
end
|
|
|
|
-- Return the configuration for the library "name".
|
|
function Solution:GetConfig(name)
|
|
return baseconfig
|
|
end
|
|
|
|
-- Apply the options for the configuration "name"
|
|
function Solution:GenerateConfiguration(name, options)
|
|
configuration { name }
|
|
for option, value in pairs(options) do
|
|
_G[option](value)
|
|
end
|
|
end
|
|
|
|
-- Generate all configurations.
|
|
function Solution:GenerateConfigurations()
|
|
assert(self.configurations)
|
|
configurations(collect(iterkeys(self.configurations)))
|
|
for config, options in pairs(self.configurations) do
|
|
self:GenerateConfiguration(config, options)
|
|
end
|
|
if self.defaults then
|
|
self:GenerateConfiguration("*", self.defaults)
|
|
end
|
|
end
|
|
|
|
function Solution:AddLibrary(name, config)
|
|
local baseconfig = {
|
|
name = name,
|
|
platform = self.platform,
|
|
suffix = self.suffix,
|
|
subdir = self.subdir,
|
|
extensions = self.extensions
|
|
}
|
|
if config then updatetable(baseconfig, config) end
|
|
local library = self.Library:New(baseconfig)
|
|
library:Initialize()
|
|
table.insert(self.libraries, library)
|
|
return library
|
|
end
|
|
|
|
-- Generate all libraries.
|
|
function Solution:GenerateLibraries()
|
|
for lib in iter(self.libraries) do
|
|
lib:Generate()
|
|
end
|
|
end
|
|
|
|
-- Generate the solution.
|
|
function Solution:Generate()
|
|
solution(self.name)
|
|
location ( cwdrelative(self.location) )
|
|
self:GenerateConfigurations()
|
|
self:GenerateLibraries()
|
|
end
|
|
|
|
local registry = {}
|
|
-- Register a specific solution for this platform.
|
|
function RegisterSolution(type, solution)
|
|
registry[type] = solution
|
|
end
|
|
|
|
-- Return the registered solution for this platform.
|
|
function GetSolution(type, config)
|
|
return registry[type]:New(config)
|
|
end
|