/
CMakePluginGenerator.class.st
215 lines (162 loc) · 5.53 KB
/
CMakePluginGenerator.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
"
I am using for generating CMakeLists.txt (cmake config files) for specific plugin.
The direct use of my instances is not recommended.
Use CMakeVMGenerator and appropriate configuration to generate both VM and plugins cmake config files.
"
Class {
#name : #CMakePluginGenerator,
#superclass : #CMakeGenerator,
#instVars : [
'plugin',
'vmGen',
'internal',
'extraRules',
'doNotGenerate',
'externalDependencies'
],
#category : #CMakeVMMaker
}
{ #category : #accessing }
CMakePluginGenerator >> addCrossSources: sources [
^ self addSources: sources prefixed: '${pluginCross}/'
]
{ #category : #accessing }
CMakePluginGenerator >> addExternalDependency: aString [
"We need to collect external dependencies to internal plugins because we need to force its
resolve before, and if we just add teh dependency in executable some times is not enough.
check StackIPhoneConfig>>#configureFT2Plugin: as an example"
externalDependencies := externalDependencies copyWith: aString.
]
{ #category : #'cmake commands' }
CMakePluginGenerator >> addExternalLibrary: aLibrary [
self isInternal
ifTrue: [ vmGen addExternalLibrary: aLibrary ]
ifFalse: [ super addExternalLibrary: aLibrary ].
]
{ #category : #accessing }
CMakePluginGenerator >> addPlatformSources: sources [
^ self addSources: sources prefixed: '${pluginPlatform}/'
]
{ #category : #accessing }
CMakePluginGenerator >> config [
^ vmGen config
]
{ #category : #accessing }
CMakePluginGenerator >> configurationName [
^ vmGen configurationName
]
{ #category : #accessing }
CMakePluginGenerator >> doNotGenerate [
"Forcely exclude plugin form build. Use this method only for debugging purposes.
Front-end users should simply specify different list of plugins for building VM,
effectively excluding any unwanted stuff "
^doNotGenerate
]
{ #category : #accessing }
CMakePluginGenerator >> doNotGenerate: aValue [
"Forcely exclude plugin form build. Use this method only for debugging purposes.
Front-end users should simply specify different list of plugins for building VM,
effectively excluding any unwanted stuff "
doNotGenerate := aValue
]
{ #category : #accessing }
CMakePluginGenerator >> externalDependencies [
^ externalDependencies
]
{ #category : #'code generation' }
CMakePluginGenerator >> generate [
| name |
output := String new writeStream.
name := plugin moduleName.
#( vmGen config setGlobalOptions: self.
self
printHeader;
project: name;
"include directories generated for build"
include: '../directories.cmake'.
self set: 'CMAKE_CONFIGURATION_TYPES' to: 'Release'.
).
self message: (internal ifTrue: [ 'Adding internal plugin: '] ifFalse: ['Adding external plugin: ']) , name.
self
set: #pluginName toString: name;
set: #pluginSrc toString: '${srcPluginsDir}/', name;
set: #pluginCross toString: '${crossDir}/plugins/', name;
set: #pluginPlatform toString: '${targetPlatform}/plugins/', name.
"clear LINKLIBS variable"
self set: #LINKLIBS to: ''.
internal
ifTrue: [ self puts: 'add_definitions(-DSQUEAK_BUILTIN_PLUGIN)'].
self addSources: { name , '.c' } prefixed: '${pluginSrc}/'.
" default include directories for plugin "
self includeDirectories: '${pluginSrc} ${pluginCross} ${targetPlatform}/plugins/${pluginName}'.
"Not needed because there are already there (inherited from main configuration)"
"self addDefinitions: vmGen config compilerFlags."
" perform config's configureXYZ: message to apply per-plugin custom rules, if any "
vmGen config configurePlugin: plugin with: self.
extraRules ifNotNil: [ extraRules value: self ].
" generate a static lib for internal plugin, or shared for external"
internal ifTrue: [
self cmd: 'add_library' params: name , ' STATIC ${sources}'.
] ifFalse: [
self cmd: 'add_library' params: name , ' SHARED ${sources}'.
" self cmd: 'set_property' params: 'TARGET ' , name , ' PROPERTY LINK_FLAGS -bundle'"
].
vmGen config extraPluginSettings: self.
self isExternal ifTrue: [
self cmd: 'target_link_libraries'
params: self moduleName , ' ${LINKLIBS}'.
].
" see senders of #linkFlags "
self
cmd: 'set_property'
params: 'TARGET ', name, ' PROPERTY LINK_FLAGS "${linkFlags}"'.
"set dependencies"
self puts: 'IF (',self moduleName , '_dependencies)'.
self cmd: 'add_dependencies'
params: name , ' ${', self moduleName , '_dependencies}'.
self puts: 'ENDIF (',self moduleName , '_dependencies)'.
self saveFile.
]
{ #category : #'code generation' }
CMakePluginGenerator >> generate: aPlugin for: aCMakeVMGenerator internal: aBoolean extraRules: aBlock [
doNotGenerate := false.
internal := aBoolean.
plugin := aPlugin.
vmGen := aCMakeVMGenerator.
extraRules := aBlock.
^ self generate
]
{ #category : #initialization }
CMakePluginGenerator >> initialize [
super initialize.
externalDependencies := #().
]
{ #category : #testing }
CMakePluginGenerator >> isExternal [
^ internal not
]
{ #category : #accessing }
CMakePluginGenerator >> isInternal [
^ internal
]
{ #category : #accessing }
CMakePluginGenerator >> moduleName [
^plugin moduleName
]
{ #category : #accessing }
CMakePluginGenerator >> plugin [
^ plugin
]
{ #category : #accessing }
CMakePluginGenerator >> saveFile [
| reference |
reference := ((vmGen config dirFrom: vmGen buildDir) / plugin moduleName) ensureDirectory; yourself.
(FileStream forceNewFileNamed: (reference / self outputFileName) fullName)
nextPutAll: (self config fixLineEndsOf: output contents);
close.
]
{ #category : #accessing }
CMakePluginGenerator >> vmGenerator [
"Make it accessible from plugin generator side"
^ vmGen
]