-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathframework.lua
146 lines (119 loc) · 4.84 KB
/
framework.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
-- http://shrine.teeworlds.com/bam/bam.html#6.4.3
-- http://teeworlds.com/trac/teeworlds/browser/trunk/bam.lua
-- http://teeworlds.com/trac/teeworlds/browser/trunk/other/sdl/sdl.lua
path_prefix = PathDir(ModuleFilename())
-- Import all Libraries/*/*.lua and add to dictionary Libraries
Libraries = {}
for i,n in ipairs(CollectDirs(path_prefix .. "/Libraries/")) do
name = PathFilename(PathBase(n))
Import(n .. "/" .. name .. ".lua")
end
object_base = Path(path_prefix .. "/Build/ObjectFiles/")
include_base = Path(path_prefix .. "/Include")
source_base = Path(path_prefix .. "/Source/*.cpp")
debug_settings = NewSettings()
debug_settings.config_name = "debug"
debug_settings.config_ext = "_d"
debug_settings.debug = 1
debug_settings.optimize = 0
debug_settings.cc.defines:Add("CONF_DEBUG")
release_settings = NewSettings()
release_settings.config_name = "release"
release_settings.config_ext = ""
release_settings.debug = 0
release_settings.optimize = 1
release_settings.cc.defines:Add("CONF_RELEASE")
function Intermediate_Output(settings, input)
return Path(object_base .. "/" .. PathBase(PathFilename(input)) .. settings.config_ext)
end
function CreateSettings(settings)
-- Intermediate directory for object files
settings.cc.Output = Intermediate_Output
-- Libraries
if family == "windows" then
-- Set compiler specific values
-- if config.compiler.value == "cl" then
-- settings.cc.flags:Add("/EHsc")
-- elseif config.compiler.value == "gcc" then
-- settings.cc.flags:Add("-Wall", "-fno-exceptions")
-- end
settings.cc.flags:Add("/EHsc")
settings.link.libs:Add("opengl32")
settings.link.libs:Add("glu32")
settings.link.libs:Add("ws2_32")
settings.link.libs:Add("gdi32")
settings.link.libs:Add("user32")
--settings.link.libs:Add("dsound")
settings.link.libs:Add("ole32")
settings.link.libs:Add("d3d9")
settings.cc.includes:Add(Path("%DXSDK_DIR%\\Include"))
elseif family == "unix" then
if platform == "macosx" then
settings.link.frameworks:Add("AGL")
settings.link.frameworks:Add("OpenGL")
settings.link.frameworks:Add("Carbon")
settings.link.frameworks:Add("AudioToolbox")
settings.link.frameworks:Add("CoreAudio")
settings.link.frameworks:Add("AudioUnit")
else
settings.link.libs:Add("asound")
settings.link.libs:Add("GLU")
settings.link.libs:Add("GL")
settings.link.libs:Add("pthread")
end
end
-- Add include directory
settings.cc.includes:Add(include_base)
return settings
end
function tableMerge(t1, t2)
for k,v in pairs(t2) do
if type(v) == "table" then
if type(t1[k] or false) == "table" then
tableMerge(t1[k] or {}, t2[k] or {})
else
t1[k] = v
end
else
t1[k] = v
end
end
return t1
end
function BuildFramework(settings)
-- Compile framework
--framework = Compile(settings, CollectRecursive(source_base))
framework = Compile(settings, Collect(path_prefix .. "/Source/*.cpp"),
CollectRecursive(path_prefix .. "/Source/Base/*.cpp",
path_prefix .. "/Source/Extra/*.cpp",
path_prefix .. "/Source/Graphics/*.cpp",
path_prefix .. "/Source/Input/*.cpp",
path_prefix .. "/Source/Math/*.cpp",
path_prefix .. "/Source/Resource/*.cpp"))
return framework
end
function BuildLibrary(settings, library)
lib_settings = settings:Copy()
lib_src = Collect(library.SourceFiles)
lib = Compile(lib_settings, lib_src)
return lib
end
DebugSettings = CreateSettings(debug_settings)
ReleaseSettings = CreateSettings(release_settings)
function BuildProject(name, required_libs, include_dir, source_files)
function DoBuild(settings)
CompiledLibs = {}
for i,n in ipairs(required_libs) do
CompiledLibs[i] = Libraries[n].Build(settings)
end
framework = BuildFramework(settings)
settings.cc.includes:Add(Path(path_prefix .. include_dir))
-- Compile Project
project = Compile(settings, source_files)
project_exe = Link(settings, name, project, CompiledLibs, framework)
project_target = PseudoTarget(name.."_"..settings.config_name, project_exe)
PseudoTarget(settings.config_name, project_target)
end
DoBuild(DebugSettings)
DoBuild(ReleaseSettings)
end