Adding bam build system.
This commit is contained in:
parent
9835082b67
commit
f67f89715a
5 changed files with 335 additions and 0 deletions
77
.bam/functions.lua
Normal file
77
.bam/functions.lua
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
|
||||
local _systems = {
|
||||
"Win32",
|
||||
-- "Linux"
|
||||
}
|
||||
|
||||
|
||||
-- Returns a string of all supported systems
|
||||
function supported_systems()
|
||||
return table.concat(_systems, ', ')
|
||||
end
|
||||
|
||||
|
||||
-- Detect what system we currently are on.
|
||||
function system()
|
||||
|
||||
local win = os.getenv('OS')
|
||||
|
||||
if win:lower():match('windows') then
|
||||
return _systems[1]
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Defines a module
|
||||
-- path: base path to source files.
|
||||
-- src: table of source files.
|
||||
function Module(path, src)
|
||||
local r = {}
|
||||
for k, v in pairs(src) do
|
||||
r[k] = path .. "/" .. v
|
||||
end
|
||||
return r
|
||||
end
|
||||
|
||||
-- Copy a directory src to dst
|
||||
-- src = "path/to/a", dest = "path/to/b" -> the whole content
|
||||
-- of "a" will be copied to "path/to/b"
|
||||
function CopyDir(dst, src)
|
||||
local r = {}
|
||||
local base = PathDir(src)
|
||||
local files = CollectRecursive(Path(src) .. "/*")
|
||||
|
||||
for k, v in pairs(files) do
|
||||
local rdir = PathDir(v:sub(base:len() + 1))
|
||||
r[k] = CopyToDirectory(PathJoin(dst, rdir), v)
|
||||
end
|
||||
return r
|
||||
end
|
||||
|
||||
-- Build example binary.
|
||||
-- This function Imports "examples/<name>/bam.lua"
|
||||
-- that file must define a table "src" that contains the source files.
|
||||
function BuildExample(settings, name, dependencies)
|
||||
|
||||
Import("examples/" .. name .. "/bam.lua")
|
||||
|
||||
exe = Link(settings, "examples/" .. name, Compile(settings, src))
|
||||
|
||||
if dependencies ~= nil and #dependencies > 0 then
|
||||
AddDependency(exe, dependencies)
|
||||
end
|
||||
|
||||
return exe
|
||||
end
|
||||
|
||||
-- Build examples binaries.
|
||||
-- Just a wrapper for BuildExample. taking a table of names instead.
|
||||
function BuildExamples(settings, names, dependencies)
|
||||
|
||||
local r = {}
|
||||
for i = 1, #names do
|
||||
r[i] = BuildExample(settings, names[i], dependencies)
|
||||
end
|
||||
return r
|
||||
end
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,5 +1,7 @@
|
|||
|
||||
build/
|
||||
.bam/*
|
||||
!.bam/*.lua
|
||||
|
||||
# Thumbnail databases (Windows)
|
||||
Thumbs.db
|
||||
|
|
|
|||
249
bam.lua
Normal file
249
bam.lua
Normal file
|
|
@ -0,0 +1,249 @@
|
|||
--------------------------------
|
||||
-- --
|
||||
-- Spectre build config --
|
||||
-- --
|
||||
--------------------------------
|
||||
Import(".bam/functions.lua")
|
||||
CheckVersion("0.5")
|
||||
|
||||
--------------------------------
|
||||
-- --
|
||||
-- Environment Setup --
|
||||
-- --
|
||||
--------------------------------
|
||||
|
||||
-- OS Detection
|
||||
TARGET_OS = system()
|
||||
if TARGET_OS == nil then
|
||||
print ("System not supported" )
|
||||
print ("Supported systems are: " .. supported_systems() )
|
||||
return 1
|
||||
end
|
||||
|
||||
-- paths used when building.
|
||||
paths = {
|
||||
build = "build",
|
||||
object = "obj",
|
||||
examples = "examples"
|
||||
}
|
||||
|
||||
--------------------------------
|
||||
-- --
|
||||
-- Global Build Settings --
|
||||
-- --
|
||||
--------------------------------
|
||||
|
||||
global_settings = NewSettings();
|
||||
|
||||
-- Build type
|
||||
--------------------------------
|
||||
global_settings.debug = 1
|
||||
global_settings.optimize = 0
|
||||
|
||||
if ScriptArgs.type ~= nil and ScriptArgs.type:match("^release") then
|
||||
global_settings.debug = 0
|
||||
if ScriptArgs.type == "release-fast" then
|
||||
global_settings.optimize = 1
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Output configuration
|
||||
--------------------------------
|
||||
global_settings.lib.prefix = Path(paths.build) .. "/"
|
||||
|
||||
global_settings.link.Output = function(settings, input)
|
||||
return Path(PathJoin(paths.build, input))
|
||||
end
|
||||
|
||||
global_settings.cc.Output = function(settings, input)
|
||||
return Path(PathJoin(PathJoin(paths.build, paths.object), PathBase(input)))
|
||||
end
|
||||
|
||||
-- Compiler configuration
|
||||
--------------------------------
|
||||
|
||||
-- MSVC complains about exception handler without this flag.
|
||||
if global_settings.cc.exe_cxx == "cl" then
|
||||
global_settings.cc.flags:Add('/EHsc')
|
||||
end
|
||||
|
||||
--------------------------------
|
||||
-- --
|
||||
-- Engine configuration --
|
||||
-- --
|
||||
--------------------------------
|
||||
|
||||
local settings = global_settings
|
||||
|
||||
settings.cc.includes:Add("include/")
|
||||
settings.cc.includes:Add("source/")
|
||||
|
||||
-- FreeType2
|
||||
if TARGET_OS == "Win32" then
|
||||
settings.cc.includes:Add("vendor/FreeType2/include")
|
||||
|
||||
-- Staticly link freetype on windows.
|
||||
settings.link.libpath:Add("vendor/FreeType2/lib/x86")
|
||||
else
|
||||
settings.cc.includes:Add("/usr/include/freetype2")
|
||||
end
|
||||
|
||||
-- STB
|
||||
settings.cc.includes:Add("vendor/stb/include")
|
||||
|
||||
-- Source files
|
||||
--------------------------------
|
||||
|
||||
local system_module = Module("source/System", {
|
||||
"File.cpp",
|
||||
"MessageHandler.cpp",
|
||||
"MessageQueue.cpp",
|
||||
"SystemEvent.cpp",
|
||||
"Log.cpp"
|
||||
})
|
||||
|
||||
local platform_common_module = Module("source/Platform", {
|
||||
"PlatformDisplay.cpp"
|
||||
})
|
||||
|
||||
|
||||
-- if TARGET_OS == "Win32" then -- Needed later for unix.
|
||||
platform_spec_module = Module("source/Platform/Win32", {
|
||||
"Win32Application.cpp",
|
||||
"Win32Display.cpp",
|
||||
"Win32GLContext.cpp",
|
||||
"Win32Input.cpp",
|
||||
"Win32Internal.cpp",
|
||||
"Win32Keyboard.cpp",
|
||||
"Win32Misc.cpp",
|
||||
"Win32Mouse.cpp",
|
||||
"Win32MsgBuffer.cpp",
|
||||
"Win32System.cpp",
|
||||
"glad_wgl.c"
|
||||
})
|
||||
--end
|
||||
|
||||
local input_module = Module("source/Input", {
|
||||
"InputDevice.cpp",
|
||||
"InputEvent.cpp",
|
||||
"InputListener.cpp",
|
||||
"InputModule.cpp",
|
||||
"Keyboard.cpp",
|
||||
"Mouse.cpp"
|
||||
})
|
||||
|
||||
local display_module = Module("source/Display", {
|
||||
"Display.cpp",
|
||||
"DisplayDescription.cpp",
|
||||
"DisplayMode.cpp",
|
||||
"GLContext.cpp"
|
||||
})
|
||||
|
||||
local graphics_module = Module("source/Graphics", {
|
||||
-- Primitives
|
||||
"Vertex2D.cpp",
|
||||
"Transformable.cpp",
|
||||
"Sprite.cpp",
|
||||
|
||||
-- Rendering
|
||||
"BatchRenderer2D.cpp",
|
||||
"DefaultRenderer2D.cpp",
|
||||
"Renderable2D.cpp",
|
||||
"Renderer2D.cpp",
|
||||
"RenderState.cpp",
|
||||
"Shader.cpp",
|
||||
"ShaderProgram.cpp",
|
||||
"Texture.cpp",
|
||||
|
||||
-- Text
|
||||
"Font/FontDriver.cpp",
|
||||
"Font/FreeTypeDriver.cpp",
|
||||
"Font/FreeTypeError.cpp",
|
||||
"Font.cpp",
|
||||
"Text.cpp",
|
||||
|
||||
-- Image
|
||||
"Image.cpp",
|
||||
"ImageLoader.cpp",
|
||||
|
||||
"OpenGL.cpp",
|
||||
"GL/glad.c",
|
||||
"GL/CheckError.cpp",
|
||||
})
|
||||
|
||||
local core_module = Module("source/Core", {
|
||||
"String.cpp"
|
||||
})
|
||||
|
||||
local math_module = Module("source/Math", {
|
||||
"Color.cpp",
|
||||
"Logarithm.cpp",
|
||||
"Math.cpp",
|
||||
"Transform.cpp"
|
||||
})
|
||||
|
||||
local game_module = Module("source", {
|
||||
"Game/FPSCounter.cpp",
|
||||
"Game/GameTime.cpp",
|
||||
"Game.cpp",
|
||||
})
|
||||
|
||||
local scene_module = Module("source/Scene", {
|
||||
"Camera2D.cpp"
|
||||
})
|
||||
|
||||
-- Build target
|
||||
--------------------------------
|
||||
|
||||
local obj = Compile(settings, {
|
||||
system_module,
|
||||
platform_common_module,
|
||||
platform_spec_module,
|
||||
input_module,
|
||||
display_module,
|
||||
graphics_module,
|
||||
core_module,
|
||||
math_module,
|
||||
game_module,
|
||||
scene_module
|
||||
})
|
||||
|
||||
local libspectre = StaticLibrary(settings,
|
||||
"spectre",
|
||||
obj
|
||||
)
|
||||
|
||||
--------------------------------
|
||||
-- --
|
||||
-- Examples --
|
||||
-- --
|
||||
--------------------------------
|
||||
|
||||
local example_settings = global_settings
|
||||
|
||||
-- Include spectre headers.
|
||||
example_settings.cc.includes:Add("include/")
|
||||
|
||||
-- Link with spectre.
|
||||
example_settings.link.extrafiles:Add(libspectre)
|
||||
|
||||
if TARGET_OS == "Win32" then
|
||||
|
||||
-- Windows needs to link against these.
|
||||
example_settings.link.libs:Add("opengl32", "gdi32", "user32")
|
||||
|
||||
if example_settings.debug > 0 then
|
||||
example_settings.link.libs:Add("freetype-d-s")
|
||||
else
|
||||
example_settings.link.libs:Add("freetype-s")
|
||||
end
|
||||
end
|
||||
|
||||
-- For now, to get examples working
|
||||
-- we copy the whole assets directory.
|
||||
assets = CopyDir(PathJoin(paths.build, paths.examples), "assets")
|
||||
|
||||
BuildExamples(example_settings, {
|
||||
"text"
|
||||
}, assets)
|
||||
7
examples/text/bam.lua
Normal file
7
examples/text/bam.lua
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
local base = PathDir(ModuleFilename())
|
||||
|
||||
src ={
|
||||
base .. "/main.cpp",
|
||||
base .. "/Game.cpp"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue