/
CMakeVMGenerator.class.st
387 lines (280 loc) · 9.43 KB
/
CMakeVMGenerator.class.st
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
"
I am generating a cmake configuration file (CMakeLists.txt)
for building a Squeak Virtual Machine.
Usage:
CMakeVMGenerator new generate: CogMacOSConfig
or
CMakeVMGenerator new generate: (CogMacOSConfig new setOption: ... ; yourself)
you can provide any valid configuration instead of CogMacOSConfig for build.
Generator creating a '../build' directory (relative to current one)
and placing config files there.
Also, it expects that appropriate VM (re)sources can be found simplarily:
../platforms
../src
but these settings are just default ones and could be changed in config
(see senders of #topDir #buildDir and #srcDir )
Generator and cmake configs are designed so, that any file-system operations are performed in
<build> directory.
So, if you want to build multiple VMs , using same generated sources, but different configs, you can simply
use different build directories.
"
Class {
#name : #CMakeVMGenerator,
#superclass : #CMakeGenerator,
#instVars : [
'internalPlugins',
'externalPlugins',
'config'
],
#category : #CMakeVMMaker
}
{ #category : #'code generation' }
CMakeVMGenerator class >> generate: aConfigOrClass [
^self new
generate: aConfigOrClass;
yourself
]
{ #category : #'as yet unclassified' }
CMakeVMGenerator >> append: aString toAll: list [
"flatten the list, adding prefix for each element"
^ list inject: '' into: [:result :each | result, ' ', aString, each ].
]
{ #category : #accessing }
CMakeVMGenerator >> buildDir [
^ config buildDir
]
{ #category : #accessing }
CMakeVMGenerator >> config [
^ config
]
{ #category : #accessing }
CMakeVMGenerator >> configurationName [
^ config class name
]
{ #category : #accessing }
CMakeVMGenerator >> executableName [
^ 'Squeak'
]
{ #category : #'code generation' }
CMakeVMGenerator >> generate [
| intPlugins extPlugins |
output := String new writeStream.
config setGlobalOptions: self.
self
printHeader;
project: config executableName.
config setGlobalOptionsAfterDetermineSystem: self.
config setupDirectories: self.
self message: '${CMAKE_MODULE_PATH}'.
self set: 'CMAKE_CONFIGURATION_TYPES' to: 'Release'.
config preferredIncludes
do: [ :each | self includeDirectories: each ].
self includeDirectories: self includeDirs.
config standardIncludes
do: [:each | self includeDirectories: each ].
self addDefinitions: config compilerFlags.
config extraVMSettings: self.
self puts: 'add_executable(' , config executableName, ' ', config executableType, ' ' , self sources , ')'.
intPlugins := self generatePluginConfigs: config internalPlugins internal: true.
extPlugins := self generatePluginConfigs: config externalPlugins internal: false.
self processThirdpartyLibraries.
self processPlugins: intPlugins, extPlugins.
config setExtraTargetProperties: self.
self cmd: 'target_link_libraries'
params: self moduleName , ' ${LINKLIBS}'.
config postBuildActions: self.
self saveFile.
self generateBuildScript.
]
{ #category : #'code generation' }
CMakeVMGenerator >> generate: aConfigOrClass [
config := aConfigOrClass isBehavior ifTrue: [ aConfigOrClass new ] ifFalse: [aConfigOrClass].
^ self generate
]
{ #category : #'build script' }
CMakeVMGenerator >> generateBuildScript [
(FileStream forceNewFileNamed: (self buildDir / 'build.sh') fullName) nextPutAll: (config fixLineEndsOf: config buildScript); close.
]
{ #category : #'as yet unclassified' }
CMakeVMGenerator >> generateExportsH: libs [
| content |
content := String streamContents: [:str |
str nextPutAll: '/* This is automatically generated file using CVMMaker on ',
Date current asString, ' ' , Time current asString , ' */'; cr.
str nextPutAll:
'extern sqExport vm_exports[];
extern sqExport os_exports[];
'.
libs do: [:each |
str nextPutAll: 'extern sqExport ', each ,'_exports [];'; cr ].
str cr; nextPutAll: 'sqExport *pluginExports[] = {
vm_exports,
os_exports,
'.
libs do: [:each |
str nextPutAll: each ,'_exports,'; cr ].
str nextPutAll: 'NULL
};'
].
(FileStream forceNewFileNamed: (self buildDir /'sqNamedPrims.h') fullName) nextPutAll: (config fixLineEndsOf: content); close.
]
{ #category : #plugins }
CMakeVMGenerator >> generatePlugin: aPlugin internal: aBoolean extraRules: aBlock [
" this method called back from plugin"
^ CMakePluginGenerator new
generate: aPlugin for: self internal: aBoolean extraRules: aBlock
]
{ #category : #'processing plugins' }
CMakeVMGenerator >> generatePluginConfigs: plugins internal: bool [
"Answers a collection of CMakePluginGenerator instances"
^ plugins collect: [:each | | plugin |
plugin := Smalltalk at: each.
plugin generateFor: self internal: bool.
].
]
{ #category : #'processing plugins' }
CMakeVMGenerator >> generatePluginsSource: plugins internal: bool [
plugins do: [:each | | plugin gen |
plugin := Smalltalk at: each.
gen := plugin generateFor: self internal: bool.
].
]
{ #category : #'sources management' }
CMakeVMGenerator >> includeDirs [
^ '${crossDir}/vm ${srcVMDir} ${targetPlatform}/vm ${buildDir}'.
]
{ #category : #'as yet unclassified' }
CMakeVMGenerator >> internalPlugins: intList externalPlugins: extList [
internalPlugins := intList.
externalPlugins := extList.
]
{ #category : #accessing }
CMakeVMGenerator >> moduleName [
^config executableName
]
{ #category : #accessing }
CMakeVMGenerator >> platformName [
^ config platformName
]
{ #category : #'processing plugins' }
CMakeVMGenerator >> processExternalPlugins [
config externalPlugins do: [:each | | plugin gen |
plugin := Smalltalk at: each.
gen := plugin generateFor: self internal: false.
gen doNotGenerate ifFalse: [
self addSubdirectory: plugin moduleName.
]
].
]
{ #category : #'processing plugins' }
CMakeVMGenerator >> processInternalPlugins [
| libs |
libs := OrderedCollection new.
config internalPlugins collect: [:each | | plugin gen |
plugin := Smalltalk at: each.
gen := plugin generateFor: self internal: true.
gen doNotGenerate ifFalse: [
libs add: plugin moduleName.
self addSubdirectory: plugin moduleName.
].
].
self cmd: 'target_link_libraries' params: config executableName , ' ' ,
(libs inject: '' into: [:res :ea | res, ' ' , ea ]) .
self generateExportsH: libs.
]
{ #category : #'processing plugins' }
CMakeVMGenerator >> processInternalPlugins: pluginGenerators [
| libs |
libs := OrderedCollection new.
pluginGenerators do: [:gen |
gen doNotGenerate ifFalse: [
libs add: gen plugin moduleName.
self addSubdirectory: gen plugin moduleName.
].
].
self cmd: 'target_link_libraries' params: config executableName , ' ' ,
(libs inject: '' into: [:res :ea | res, ' ' , ea ]) .
self generateExportsH: libs.
]
{ #category : #'processing plugins' }
CMakeVMGenerator >> processPlugins: pluginGenerators [
| libs libDeps |
libs := OrderedCollection new.
libDeps := Dictionary new.
pluginGenerators do: [:gen |
gen doNotGenerate ifFalse: [
gen isInternal
ifTrue: [
libs add: gen plugin moduleName ]
ifFalse: [
"make main module to depend on external plugin, just to make sure it is built
before main module built"
self
cmd: 'add_dependencies'
params: config executableName, ' ' , gen plugin moduleName ].
gen externalDependencies
ifNotEmpty: [ :deps |
libDeps
at: gen plugin moduleName
put: (deps fold: [ :a :b | a, ' ', b ]) ].
self addSubdirectory: gen plugin moduleName ] ].
self cmd: 'target_link_libraries' params: config executableName , ' ' ,
(libs inject: '' into: [:res :ea | res, ' ' , ea ]).
libDeps keysAndValuesDo: [ :moduleName :dependencies |
self
cmd: 'add_dependencies'
params: moduleName, ' ', dependencies ].
self generateExportsH: libs.
]
{ #category : #'as yet unclassified' }
CMakeVMGenerator >> processThirdpartyLibraries [
config thirdpartyLibs do: [:each |
each generateFor: self ]
]
{ #category : #accessing }
CMakeVMGenerator >> saveFile [
config write: output contents toFile: (self outputFileName).
]
{ #category : #'as yet unclassified' }
CMakeVMGenerator >> setupMacros: gen [
self config cMakeMacros
ifNotNil: [ :macros | gen puts: macros ]
]
{ #category : #accessing }
CMakeVMGenerator >> sources [
self set: #coreSources to:
(self append: '${srcVMDir}/' toAll: config coreSources).
self set: #platformVMSources to:
(self append: '${targetPlatform}/vm/' toAll: config platformSources).
self set: #crossVMSources to:
(self append: '${crossDir}/vm/' toAll: config crossSources).
self set: #extraSources to: config extraSources.
^ '${coreSources} ${crossVMSources} ${platformVMSources} ${extraSources}'
]
{ #category : #'as yet unclassified' }
CMakeVMGenerator >> targetPropertyAt: aPropName put: aValue [
"set target's properties"
self cmd: 'set_property' params: 'TARGET ', config executableName ,
' PROPERTY ', aPropName , ' ' , aValue.
]
{ #category : #'as yet unclassified' }
CMakeVMGenerator >> targetPropertyAt: aPropName qput: aValue [
"set target's properties, put value in quotes"
^ self targetPropertyAt: aPropName put: (aValue copyReplaceAll: '"' with: '\"').
]
{ #category : #'thirdparty libs' }
CMakeVMGenerator >> thirdpartyDir [
^ self buildDir / self thirdpartyDirName
]
{ #category : #'thirdparty libs' }
CMakeVMGenerator >> thirdpartyDirName [
^ 'thirdParty'
]
{ #category : #accessing }
CMakeVMGenerator >> topDir [
| dir |
dir := self config topDir ifNil: [ FileSystem workingDirectory parent ].
dir isString
ifTrue: [ ^dir asFileReference ].
^ dir
]