/
CMakeVMGeneratorForSqueak.class.st
239 lines (195 loc) · 7.73 KB
/
CMakeVMGeneratorForSqueak.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
"
A CMakeVMGeneratorForSqueak overides some CMakeVMGenerator methos for squeak compatibility.
"
Class {
#name : #CMakeVMGeneratorForSqueak,
#superclass : #CMakeGeneratorForSqueak,
#instVars : [
'internalPlugins',
'externalPlugins',
'config'
],
#category : #CMakeVMMakerSqueak
}
{ #category : #'as yet unclassified' }
CMakeVMGeneratorForSqueak class >> generateByTemplate: aConfigOrClass [
^self new
generateByTemplate: aConfigOrClass;
yourself
]
{ #category : #'as yet unclassified' }
CMakeVMGeneratorForSqueak >> append: aString toAll: list [
"flatten the list, adding prefix for each element"
^ list inject: '' into: [:result :each | result, ' ', aString, each ].
]
{ #category : #'as yet unclassified' }
CMakeVMGeneratorForSqueak >> buildDir [
^ config buildDir
]
{ #category : #accessing }
CMakeVMGeneratorForSqueak >> config [
^ config
]
{ #category : #accessing }
CMakeVMGeneratorForSqueak >> config: aCPlatformConfigForSqueak [
config:=aCPlatformConfigForSqueak
"accessor method needed for testing"
]
{ #category : #'as yet unclassified' }
CMakeVMGeneratorForSqueak >> configurationName [
^ config class name
]
{ #category : #'as yet unclassified' }
CMakeVMGeneratorForSqueak >> generateBuildScript [
(FileStream forceNewFileNamed: (self buildDir / 'build.sh') fullName) nextPutAll: (config fixLineEndsOf: config buildScript); close.
]
{ #category : #'code generation' }
CMakeVMGeneratorForSqueak >> generateByTemplate [
"The bulk of CMake generation happens here.
See CPlatformConfigForSqueak>>initialize for CMake output. that occurs prior to this method. (This may change on refactoring)
Think Seaside renderOn composition.
"
| extPlugins intPlugins |
self flag: 'tty'. "refactor so that the cascade reflects CMake terminilogy"
output := String new writeStream.
config templates: OrderedCollection new.
config
setGlobalOptions: self;
cmakePrefixPath;
cmakeIncludePath;
cmakeLibraryPath;
cmakeIncludeModules;
cmakeCFlags;
cmakeAddDefinitions;
cmakeWriteDirectoriesDotCmake: self;
cmakeIncludeDirectories: self; "<---"
preferredIncludes; "<---why 3 of em?"
standardIncludes; "<---"
setGlobalOptionsAfterDetermineSystem: self;
extraVMSettings: self; "<--catch-all method. os/platform specific"
setCoreSources: self;
setPlatformSources: self;
setCrossSources: self;
setExtraSources;
cmakeSetSourceFilesProperties;
cmakeListAppend:'LINKLIBS' elements: (config externalLibs);
cmakeAddExecutableNameOptionSource: self;
setExecutableOutputPath;
addVMPlugins: self.
config templates do: [:each | self puts: each content].
config templates: OrderedCollection new.
extPlugins := self generatePluginConfigs: config internalPlugins internal: true.
intPlugins := self generatePluginConfigs: config externalPlugins internal: false.
self flag:'tty: pharo code would download and install libraries. I think detection belongs in CMake and user should set up their own system for squeak. '.
" self processThirdpartyLibraries. "
self processPlugins: intPlugins, extPlugins.
self config templates addLast:((CMakeCommand new) command:'target_link_libraries' params:(self moduleName , ' ${LINKLIBS}')).
" self cmd: 'target_link_libraries'
params: self moduleName , ' ${LINKLIBS}'."
config postBuildActions: self..
config templates do: [:each | self puts: each content].
self saveFile.
self generateBuildScript
]
{ #category : #'as yet unclassified' }
CMakeVMGeneratorForSqueak >> generateByTemplate: aConfigOrClass [
config := aConfigOrClass isBehavior ifTrue: [ aConfigOrClass new ] ifFalse: [aConfigOrClass].
^ self generateByTemplate
]
{ #category : #'as yet unclassified' }
CMakeVMGeneratorForSqueak >> 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 : #'as yet unclassified' }
CMakeVMGeneratorForSqueak >> generatePlugin: aPlugin internal: aBoolean extraRules: aBlock [
" this method called back from plugin"
^ CMakePluginGeneratorForSqueak new
generate: aPlugin for: self internal: aBoolean extraRules: aBlock
]
{ #category : #'as yet unclassified' }
CMakeVMGeneratorForSqueak >> generatePluginConfigs: plugins internal: bool [
"Answers a collection of CMakePluginGenerator instances"
^ plugins collect: [:each | | plugin |
plugin := Smalltalk at: each.
plugin generateFor: self internal: bool.
].
]
{ #category : #'sources management' }
CMakeVMGeneratorForSqueak >> includeDirs [
^ '${crossDir}/vm ${srcVMDir} ${targetPlatform}/vm ${buildDir}'.
]
{ #category : #accessing }
CMakeVMGeneratorForSqueak >> moduleName [
^config executableName
]
{ #category : #'as yet unclassified' }
CMakeVMGeneratorForSqueak >> processPlugins: pluginGenerators [
| libs libDeps |
self flag:'tty think this trhough. Is it redundant? answer NO. This adds plugin information to the master CMakeLists.txt file. '.
self flag: 'tty: gen configDotCMake and gen configDotCmakeEmpty should be moved out of CMakePluginGeneratorForSqueak and placed in the wrapper for the Plugin itself. (can it be?)'.
libs := OrderedCollection new.
libDeps := Dictionary new.
pluginGenerators do: [:gen |
gen doNotGenerate ifFalse: [
self puts: (gen configDotCMake at: (gen plugin name) ifAbsent:[gen configDotCmakeEmpty]). "THIS COULD BE A BUG. ONLY FileCopyPlugin is returning ConfigDotFilePlugin data"
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' }
CMakeVMGeneratorForSqueak >> processThirdpartyLibraries [
self flag:'tty'. "This generate call must be transformed to generateByTemplateFor:"
config thirdpartyLibs do: [:each |
each generateFor: self ]
]
{ #category : #'as yet unclassified' }
CMakeVMGeneratorForSqueak >> saveFile [
config write: output contents toFile: (self outputFileName).
]
{ #category : #'as yet unclassified' }
CMakeVMGeneratorForSqueak >> sources [
self flag: 'tty'. "code smell. I have moved the 'self set:' stuff to addCMakeExectuableTemplate: aMaker"
" 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}'
]