-
Notifications
You must be signed in to change notification settings - Fork 65
/
CMakeGenerator.class.st
252 lines (194 loc) · 5.62 KB
/
CMakeGenerator.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
"
a base class for generating cmake files.
Mainly provides a helper methods of cmake commands api.
"
Class {
#name : #CMakeGenerator,
#superclass : #Object,
#instVars : [
'output'
],
#category : #CMakeVMMaker
}
{ #category : #'cmake commands' }
CMakeGenerator >> addDefinitions: aString [
^ self cmd: 'add_definitions' params: aString
]
{ #category : #'cmake commands' }
CMakeGenerator >> addDependency: aName [
self cmd: 'list'
params: 'APPEND ', self moduleName , '_dependencies ' , aName.
]
{ #category : #'cmake commands' }
CMakeGenerator >> addExternalLibraries: libs [
libs do: [:each | self addExternalLibrary: each ]
]
{ #category : #'cmake commands' }
CMakeGenerator >> addExternalLibrary: aLibrary [
self cmd: 'list'
params: 'APPEND LINKLIBS ' , aLibrary .
" self cmd: 'target_link_libraries'
params: self moduleName , ' ' , aLibrary.
"
]
{ #category : #'cmake commands' }
CMakeGenerator >> addFrameworks: aCollection [
"for mac only "
aCollection
do: [:each |
self cmd: 'find_library' params: each , '_FMWK ', each.
self addExternalLibrary: '${', each , '_FMWK}' ]
]
{ #category : #'cmake commands' }
CMakeGenerator >> addProperty: propertyString value: valueString [
self puts: 'set_target_properties(' , self moduleName , ' PROPERTIES ' , propertyString , ' "' , valueString, '")'
]
{ #category : #'sources management' }
CMakeGenerator >> addSource: aFileName [
^ self addSources: { aFileName }
]
{ #category : #'sources management' }
CMakeGenerator >> addSources: aFileNames [
^ self addSources: aFileNames prefixed: ''
]
{ #category : #'sources management' }
CMakeGenerator >> addSources: aFileNames prefixed: aPrefix [
| names |
names := aFileNames inject: '' into: [:res :each | res , ' "' , aPrefix, each, '"' ].
self puts: 'list(APPEND sources ', names , ')'
]
{ #category : #'cmake commands' }
CMakeGenerator >> addSubdirectory: aDir [
^ self cmd: 'add_subdirectory' qparams: aDir.
]
{ #category : #'cmake commands' }
CMakeGenerator >> addXCodeProperty: propertyString value: valueString [
self
addProperty: 'XCODE_ATTRIBUTE_' , propertyString
value: valueString
]
{ #category : #'code generation' }
CMakeGenerator >> captureOutputDuring: aBlock [
| old result |
old := output.
output := String new writeStream.
aBlock value.
result := output.
output := old.
^ result contents
]
{ #category : #'cmake commands' }
CMakeGenerator >> cmd: cmdName params: aString [
output nextPutAll: cmdName;
nextPut: $(;
nextPutAll: aString;
nextPut: $);
cr
]
{ #category : #'cmake commands' }
CMakeGenerator >> cmd: cmdName qparams: aString [
"quoted params"
output nextPutAll: cmdName;
nextPutAll: '("';
nextPutAll: aString;
nextPutAll: '")';
cr
]
{ #category : #'code generation' }
CMakeGenerator >> generate [
self subclassResponsibility.
]
{ #category : #'cmake commands' }
CMakeGenerator >> include: aFileName [
^ self cmd: 'include' params: aFileName
]
{ #category : #'cmake commands' }
CMakeGenerator >> includeDirectories: aString [
^ self cmd: 'include_directories' params: aString
]
{ #category : #'cmake commands' }
CMakeGenerator >> linkDirectories: aString [
^ self cmd: 'link_directories' params: aString
]
{ #category : #'cmake commands' }
CMakeGenerator >> message: aString [
self cmd: 'message' qparams: aString.
]
{ #category : #accessing }
CMakeGenerator >> moduleName [
self subclassResponsibility
]
{ #category : #accessing }
CMakeGenerator >> output [
^ output
]
{ #category : #accessing }
CMakeGenerator >> output: aStream [
output := aStream
]
{ #category : #accessing }
CMakeGenerator >> outputFileName [
^ 'CMakeLists.txt'
]
{ #category : #'as yet unclassified' }
CMakeGenerator >> printHeader [
self puts: '# This is automatically generated file using ', self configurationName, ' on ',
Date current asString, ' ' , Time current asString;
puts: 'cmake_minimum_required(VERSION 2.6.2)'
]
{ #category : #'cmake commands' }
CMakeGenerator >> project: aProjectName [
self cmd: 'project' qparams: aProjectName
]
{ #category : #'as yet unclassified' }
CMakeGenerator >> puts: aString [
output nextPutAll: aString; cr
]
{ #category : #'cmake commands' }
CMakeGenerator >> set: variableName to: aValueString [
self cmd: 'set' params: variableName , ' ' , aValueString
]
{ #category : #'cmake commands' }
CMakeGenerator >> set: variableName toString: aValueString [
^ self set: variableName to: '"', (aValueString copyReplaceAll: '"' with: '\"'), '"'
]
{ #category : #'cmake commands' }
CMakeGenerator >> setTargetProperties: properties [
self cmd: 'set_target_properties' params: self moduleName, ' PROPERTIES ', properties
]
{ #category : #'cmake commands' }
CMakeGenerator >> setTargetProperty: propertyString to: aString [
self
cmd: 'set_target_properties'
params: (String streamContents: [ :stream |
stream
nextPutAll: self moduleName;
nextPutAll: ' PROPERTIES ';
nextPutAll: propertyString;
space;
nextPutAll: aString ])
]
{ #category : #'cmake commands' }
CMakeGenerator >> setTargetProperty: propertyString toAll: aCollection [
^self
setTargetProperty: propertyString
to: (String streamContents: [ :stream |
aCollection
do: [ :each | stream nextPutAll: each ]
separatedBy: [ stream nextPut: $, ] ])
]
{ #category : #'cmake commands' }
CMakeGenerator >> setTargetProperty: propertyString toString: aString [
self
cmd: 'set_target_properties'
params: (String streamContents: [ :stream |
stream
nextPutAll: self moduleName;
nextPutAll: ' PROPERTIES ';
nextPutAll: propertyString;
space;
nextPut: $";
nextPutAll: (aString copyReplaceAll: '"' with: '\"');
nextPut: $"
])
]