-
Notifications
You must be signed in to change notification settings - Fork 0
/
premake4.lua
297 lines (257 loc) · 8.32 KB
/
premake4.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
thirdPartyDir = "third-party"
thirdPartyLibs = {
FLEL = thirdPartyDir .. "/FLEL/util/bin/Edu.Wisc.Forest.Flel.Util.dll",
LSML = thirdPartyDir .. "/LSML/Landis.SpatialModeling.dll",
Landscapes = thirdPartyDir .. "/LSML/Landis.Landscapes.dll",
RasterIO = thirdPartyDir .. "/LSML/Landis.RasterIO.dll",
RasterIO_Gdal = thirdPartyDir .. "/LSML/Landis.RasterIO.Gdal.dll",
log4net = thirdPartyDir .. "/log4net/bin/log4net.dll",
Troschuetz = thirdPartyDir .. "/Troschuetz/Troschuetz.Random.dll"
}
buildDir = "build"
-- ==========================================================================
solution "LANDIS-II"
language "C#" -- by default, Premake uses "Any CPU" for platform
framework "3.5"
configurations { "Debug", "Release" }
configuration "Debug"
defines { "DEBUG" }
flags { "Symbols" }
targetdir ( buildDir .. "/Debug" )
configuration "Release"
flags { "OptimizeSize" }
targetdir ( buildDir .. "/Release" )
-- The core's API (referenced by LANDIS-II extensions)
project "Core"
location "core/src"
kind "SharedLib"
targetname "Landis.Core"
files {
"SharedAssemblyInfo.cs",
"core/src/*.cs"
}
links {
"System",
"System.Core",
thirdPartyLibs["FLEL"],
thirdPartyLibs["LSML"],
thirdPartyLibs["Troschuetz"]
}
-- The core's implementation
project "Core_Implementation"
location "core/src/Implementation"
kind "SharedLib"
targetname "Landis.Core.Implementation"
files {
"SharedAssemblyInfo.cs",
"core/src/Implementation/**.cs"
}
links {
"Core",
"System",
"System.Core",
thirdPartyLibs["FLEL"],
thirdPartyLibs["LSML"],
thirdPartyLibs["log4net"],
thirdPartyLibs["Troschuetz"]
}
-- Unit tests for Species module
project "Species_Tests"
location "core/test/species"
kind "SharedLib"
targetname "Landis.Species.Tests"
files {
"SharedAssemblyInfo.cs",
"test-util/Data.cs",
"core/test/ModuleData.cs",
"core/test/species/**.cs"
}
links {
"Core",
"Core_Implementation",
"nunit.framework",
"System",
"System.Core",
thirdPartyLibs["FLEL"]
}
-- Unit tests for Ecoregions module
project "Ecoregions_Tests"
location "core/test/ecoregions"
kind "SharedLib"
targetname "Landis.Ecoregions.Tests"
files {
"SharedAssemblyInfo.cs",
"test-util/Data.cs",
"core/test/ModuleData.cs",
"core/test/ecoregions/**.cs"
}
links {
"Core",
"Core_Implementation",
"nunit.framework",
"System",
"System.Core",
thirdPartyLibs["FLEL"],
thirdPartyLibs["LSML"],
thirdPartyLibs["RasterIO"]
}
-- Extension dataset library
project "Extension_Dataset"
location "ext-dataset/src"
kind "SharedLib"
targetname "Landis.Extensions.Dataset"
files {
"SharedAssemblyInfo.cs",
"ext-dataset/src/*.cs"
}
links {
"Core",
"System",
"System.Core",
"System.Xml",
thirdPartyLibs["FLEL"]
}
-- Extension administration tool
project "Extension_Admin"
location "ext-admin"
kind "ConsoleApp"
targetname "Landis.Extensions"
files {
"SharedAssemblyInfo.cs",
"ext-admin/*.cs"
}
links {
"Core",
"Extension_Dataset",
"System",
"System.Core",
"System.Xml",
thirdPartyLibs["FLEL"],
thirdPartyLibs["LSML"]
}
-- Console user interface
project "Console"
location "console"
kind "ConsoleApp"
targetname "Landis.Console"
files {
"SharedAssemblyInfo.cs",
"console/*.cs"
}
links {
"Core",
"Core_Implementation",
"Extension_Dataset",
"System",
"System.Configuration",
"System.Core",
thirdPartyLibs["FLEL"],
thirdPartyLibs["LSML"],
thirdPartyLibs["Landscapes"],
thirdPartyLibs["RasterIO"],
thirdPartyLibs["RasterIO_Gdal"],
thirdPartyLibs["log4net"]
}
-- ==========================================================================
newoption {
trigger = "dist",
description = 'Clean to distribution state (remove downloaded files too)'
}
-- ==========================================================================
-- Hook in a custom function that it's called *after*
-- the selected action is executed.
require "premake4_util"
afterAction_call(
function()
-- If generating Visual Studio files, add HintPath elements for references
-- with paths.
if string.startswith(_ACTION, "vs") then
modifyCSprojFiles()
-- Fetch LSML and GDAL C# bindings if they're not present
if not os.isfile(thirdPartyLibs["LSML"]) then
LSMLadmin("get")
end
-- If cleaning, then have LSML-admin clean too.
elseif _ACTION == "clean" then
LSMLadmin(iif(_OPTIONS["dist"], "distclean", "clean"))
end
end
)
-- The function below modifies the all the projects' *.csproj files, by
-- changing each Reference that has a path in its Include attribute to use
-- a HintPath element instead.
require "CSProjFile"
function modifyCSprojFiles()
for i, prj in ipairs(solution().projects) do
local csprojFile = CSprojFile(prj)
print("Modifying " .. csprojFile.relPath .. " ...")
csprojFile:readLines()
adjustReferencePaths(csprojFile)
print(" <HintPath> elements added to the project's references")
if _PREMAKE_VERSION == "4.3" then
-- In 4.3, the "framework" function doesn't work
addFramework(csprojFile)
print(" <TargetFrameworkVersion> element added to the project's properties")
end
if _ACTION == "vs2010" then
-- Target the full framework, not the Client profile
removeFrameworkProfile(csprojFile)
print(" <TargetFrameworkProfile> element removed")
end
-- Generate XML documentation for core API assembly (for inclusion in SDK)
if prj.name == "Core" then
enableXMLdocumentation(csprojFile)
print(" Enabled the generation of XML documentation file")
end
-- Add version number as "-X.Y" to the console's assembly name
if prj.name == "Console" then
local assemblyName = appendVersionToAssemblyName(csprojFile)
print(" Changed <AssemblyName> element to \"" .. assemblyName .. "\"")
end
ok, err = csprojFile:writeLines()
if not ok then
error(err, 0)
end
end -- for each project
end
-- ==========================================================================
-- Append the model's version # to the AssemblyName of a C# project
function appendVersionToAssemblyName(csprojFile)
-- Get model version (major.minor) from the shared assembly source file
local modelVersion = readAssemblyVersion("SharedAssemblyInfo.cs")
local majorMinor = string.match(modelVersion, "^(%d+\.%d+)")
local pattern = "^(%s*)<AssemblyName>(.*)</AssemblyName>"
for i, line in ipairs(csprojFile.lines) do
-- Look for <AssemblyName>Example.Assembly</AssemblyName>
local indent, name = string.match(line, pattern)
if indent then
name = name .. "-" .. majorMinor
csprojFile.lines[i] = string.format("%s<AssemblyName>%s</AssemblyName>",
indent, name)
return name
end
end
end
-- ==========================================================================
-- Read the AssemblyVersion attribute in a C# source file
function readAssemblyVersion(sourceFile)
local pattern = "AssemblyVersion%(\"(.*)\"%)"
for line in io.lines(sourceFile) do
local versionStr = string.match(line, pattern)
if versionStr then
return versionStr
end
end
end
-- ==========================================================================
-- Run the LSML-admin script with a specific action
function LSMLadmin(action)
local onWindows = runningOnWindows()
local scriptExt = iif(onWindows, "cmd", "sh")
local adminScript = thirdPartyDir .. "/LSML/LSML-admin." .. scriptExt
if onWindows then
adminScript = path.translate(adminScript, "\\")
end
print("Running " .. adminScript .. " '" .. action .. "'...")
os.execute(adminScript .. " " .. action)
end