-
Notifications
You must be signed in to change notification settings - Fork 3
/
MummyCMakeMacros.cmake
369 lines (313 loc) · 12.6 KB
/
MummyCMakeMacros.cmake
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
MACRO(ADD_CSHARP_EXECUTABLE ace_ExeName ace_DependentTargets ace_References ace_LinkResources ace_SnkFile)
IF("${ARGN}" STREQUAL "")
MESSAGE(FATAL_ERROR "ADD_CSHARP_EXECUTABLE requires at least one optional argument.")
ENDIF("${ARGN}" STREQUAL "")
IF(DEFINED MUMMY_ADD_CSHARP_SRCDIR)
SET(ace_SrcDir "${MUMMY_ADD_CSHARP_SRCDIR}")
ELSE()
SET(ace_SrcDir "${CMAKE_CURRENT_SOURCE_DIR}")
ENDIF()
IF(DEFINED MUMMY_ADD_CSHARP_BINDIR)
SET(ace_BinDir "${MUMMY_ADD_CSHARP_BINDIR}")
ELSE()
SET(ace_BinDir "${CMAKE_CURRENT_BINARY_DIR}")
ENDIF()
SET(ace_ExeDir "${ace_BinDir}/${CMAKE_CFG_INTDIR}")
IF(CMAKE_RUNTIME_OUTPUT_DIRECTORY)
SET(ace_ExeDir "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}")
ELSEIF(EXECUTABLE_OUTPUT_PATH)
SET(ace_ExeDir "${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}")
ENDIF()
SET(ace_CscRefs "")
SET(ace_CMakeRefs "")
FOREACH(ace_r ${ace_References})
SET(ace_rr "${ace_r}")
IF(NOT "${ace_rr}" MATCHES "^System\\.")
IF(NOT "${ace_rr}" MATCHES "/")
SET(ace_rr "${ace_ExeDir}/${ace_rr}")
ENDIF(NOT "${ace_rr}" MATCHES "/")
IF(NOT "${ace_rr}" MATCHES "dll$")
SET(ace_rr "${ace_rr}.dll")
ENDIF(NOT "${ace_rr}" MATCHES "dll$")
SET(ace_CMakeRefs ${ace_CMakeRefs} "${ace_rr}")
ENDIF(NOT "${ace_rr}" MATCHES "^System\\.")
IF(WIN32)
STRING(REGEX REPLACE "/" "\\\\" ace_rr "${ace_rr}")
ENDIF(WIN32)
SET(ace_CscRefs ${ace_CscRefs} "/reference:${ace_rr}")
ENDFOREACH(ace_r)
SET(ace_CscLinkResourceArgs "")
FOREACH(ace_lr ${ace_LinkResources})
SET(ace_item "${ace_lr}")
IF(NOT "${ace_item}" MATCHES "/")
SET(ace_item "${ace_ExeDir}/${ace_item}")
ENDIF(NOT "${ace_item}" MATCHES "/")
IF(WIN32)
STRING(REGEX REPLACE "/" "\\\\" ace_item "${ace_item}")
ENDIF(WIN32)
SET(ace_CscLinkResourceArgs ${ace_CscLinkResourceArgs} "/linkresource:${ace_item}")
ENDFOREACH(ace_lr)
SET(ace_CscArgs "")
FOREACH(ace_f ${ARGN})
SET(ace_CscArgs "${ace_CscArgs}\"${ace_f}\"\n")
ENDFOREACH(ace_f)
SET(ace_CscOut "${ace_ExeDir}/${ace_ExeName}.exe")
SET(ace_CscDoc "${ace_ExeDir}/${ace_ExeName}.xml")
IF(WIN32)
STRING(REGEX REPLACE "/" "\\\\" ace_CscArgs "${ace_CscArgs}")
STRING(REGEX REPLACE "/" "\\\\" ace_CscOut "${ace_CscOut}")
STRING(REGEX REPLACE "/" "\\\\" ace_CscDoc "${ace_CscDoc}")
ENDIF(WIN32)
IF(CMAKE_CONFIGURATION_TYPES AND DEFINED MUMMY_ADD_CSHARP_CONFIG)
STRING(REPLACE "${CMAKE_CFG_INTDIR}" "${MUMMY_ADD_CSHARP_CONFIG}"
ace_CscLinkResourceArgs "${ace_CscLinkResourceArgs}")
FOREACH(ace_f ${ace_CscLinkResourceArgs})
SET(ace_CscArgs "${ace_CscArgs}\"${ace_f}\"\n")
ENDFOREACH(ace_f)
SET(ace_CscLinkResourceArgs "")
ENDIF()
IF(NOT "${ace_SnkFile}" STREQUAL "")
SET(ace_f "${ace_SnkFile}")
IF(WIN32)
STRING(REGEX REPLACE "/" "\\\\" ace_f "${ace_f}")
ENDIF(WIN32)
# If the keyfile name ends in ".pub.snk" then it's a public key
# half of a strong name signature and we should add the "delaysign"
# flag. Otherwise, assume it's a full key pair for a strong name
# signature and just specify the keyfile.
#
IF(ace_f MATCHES "\\.pub\\.snk$")
SET(ace_CscArgs "${ace_CscArgs}/delaysign+\n")
ENDIF(ace_f MATCHES "\\.pub\\.snk$")
SET(ace_CscArgs "${ace_CscArgs}/keyfile:\"${ace_f}\"\n")
ENDIF(NOT "${ace_SnkFile}" STREQUAL "")
SET(CscArgs ${ace_CscArgs})
CONFIGURE_FILE(
"${ace_SrcDir}/CscArgs.txt.in"
"${ace_BinDir}/${ace_ExeName}.CscArgs.txt"
@ONLY
)
IF(csc_EXECUTABLE)
ADD_CUSTOM_COMMAND(
OUTPUT "${ace_ExeDir}/${ace_ExeName}.exe"
DEPENDS ${ARGN} "${ace_BinDir}/${ace_ExeName}.CscArgs.txt" ${ace_CMakeRefs}
COMMAND ${csc_EXECUTABLE}
ARGS ${CSC_DEBUG_FLAG} ${CSC_PLATFORM_FLAG}
"/out:${ace_CscOut}" "/doc:${ace_CscDoc}" "/target:exe"
${ace_CscLinkResourceArgs}
${ace_CscRefs}
"@${ace_BinDir}/${ace_ExeName}.CscArgs.txt"
COMMENT "Building C# executable '${ace_ExeName}'..."
)
ADD_CUSTOM_TARGET(
"${ace_ExeName}" ALL
DEPENDS "${ace_ExeDir}/${ace_ExeName}.exe"
)
IF(NOT "${ace_DependentTargets}" STREQUAL "")
ADD_DEPENDENCIES("${ace_ExeName}" ${ace_DependentTargets})
ENDIF(NOT "${ace_DependentTargets}" STREQUAL "")
ENDIF(csc_EXECUTABLE)
ENDMACRO(ADD_CSHARP_EXECUTABLE)
MACRO(ADD_CSHARP_LIBRARY acl_LibName acl_DependentTargets acl_References acl_LinkResources acl_SnkFile)
IF("${ARGN}" STREQUAL "")
MESSAGE(FATAL_ERROR "ADD_CSHARP_LIBRARY requires at least one optional argument.")
ENDIF("${ARGN}" STREQUAL "")
IF(DEFINED MUMMY_ADD_CSHARP_SRCDIR)
SET(acl_SrcDir "${MUMMY_ADD_CSHARP_SRCDIR}")
ELSE()
SET(acl_SrcDir "${CMAKE_CURRENT_SOURCE_DIR}")
ENDIF()
IF(DEFINED MUMMY_ADD_CSHARP_BINDIR)
SET(acl_BinDir "${MUMMY_ADD_CSHARP_BINDIR}")
ELSE()
SET(acl_BinDir "${CMAKE_CURRENT_BINARY_DIR}")
ENDIF()
SET(acl_ExeDir "${acl_BinDir}/${CMAKE_CFG_INTDIR}")
IF(CMAKE_RUNTIME_OUTPUT_DIRECTORY)
SET(acl_ExeDir "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}")
ELSEIF(EXECUTABLE_OUTPUT_PATH)
SET(acl_ExeDir "${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}")
ENDIF()
SET(acl_CscRefs "")
SET(acl_CMakeRefs "")
FOREACH(acl_r ${acl_References})
SET(acl_rr "${acl_r}")
IF(NOT "${acl_rr}" MATCHES "^System\\.")
IF(NOT "${acl_rr}" MATCHES "/")
SET(acl_rr "${acl_ExeDir}/${acl_rr}")
ENDIF(NOT "${acl_rr}" MATCHES "/")
IF(NOT "${acl_rr}" MATCHES "dll$")
SET(acl_rr "${acl_rr}.dll")
ENDIF(NOT "${acl_rr}" MATCHES "dll$")
SET(acl_CMakeRefs ${acl_CMakeRefs} "${acl_rr}")
ENDIF(NOT "${acl_rr}" MATCHES "^System\\.")
IF(WIN32)
STRING(REGEX REPLACE "/" "\\\\" acl_rr "${acl_rr}")
ENDIF(WIN32)
SET(acl_CscRefs ${acl_CscRefs} "/reference:${acl_rr}")
ENDFOREACH(acl_r)
SET(acl_CscLinkResourceArgs "")
FOREACH(acl_lr ${acl_LinkResources})
SET(acl_item "${acl_lr}")
IF(NOT "${acl_item}" MATCHES "/")
SET(acl_item "${acl_ExeDir}/${acl_item}")
ENDIF(NOT "${acl_item}" MATCHES "/")
IF(WIN32)
STRING(REGEX REPLACE "/" "\\\\" acl_item "${acl_item}")
ENDIF(WIN32)
SET(acl_CscLinkResourceArgs ${acl_CscLinkResourceArgs} "/linkresource:${acl_item}")
ENDFOREACH(acl_lr)
SET(acl_CscArgs "")
FOREACH(acl_f ${ARGN})
SET(acl_CscArgs "${acl_CscArgs}\"${acl_f}\"\n")
ENDFOREACH(acl_f)
SET(acl_CscOut "${acl_ExeDir}/${acl_LibName}.dll")
SET(acl_CscDoc "${acl_ExeDir}/${acl_LibName}.xml")
IF(WIN32)
STRING(REGEX REPLACE "/" "\\\\" acl_CscArgs "${acl_CscArgs}")
STRING(REGEX REPLACE "/" "\\\\" acl_CscOut "${acl_CscOut}")
STRING(REGEX REPLACE "/" "\\\\" acl_CscDoc "${acl_CscDoc}")
ENDIF(WIN32)
IF(CMAKE_CONFIGURATION_TYPES AND DEFINED MUMMY_ADD_CSHARP_CONFIG)
STRING(REPLACE "${CMAKE_CFG_INTDIR}" "${MUMMY_ADD_CSHARP_CONFIG}"
acl_CscLinkResourceArgs "${acl_CscLinkResourceArgs}")
FOREACH(acl_f ${acl_CscLinkResourceArgs})
SET(acl_CscArgs "${acl_CscArgs}\"${acl_f}\"\n")
ENDFOREACH()
SET(acl_CscLinkResourceArgs "")
ENDIF()
IF(NOT "${acl_SnkFile}" STREQUAL "")
SET(acl_f "${acl_SnkFile}")
IF(WIN32)
STRING(REGEX REPLACE "/" "\\\\" acl_f "${acl_f}")
ENDIF(WIN32)
# If the keyfile name ends in ".pub.snk" then it's a public key
# half of a strong name signature and we should add the "delaysign"
# flag. Otherwise, assume it's a full key pair for a strong name
# signature and just specify the keyfile.
#
IF(acl_f MATCHES "\\.pub\\.snk$")
SET(acl_CscArgs "${acl_CscArgs}/delaysign+\n")
ENDIF(acl_f MATCHES "\\.pub\\.snk$")
SET(acl_CscArgs "${acl_CscArgs}/keyfile:\"${acl_f}\"\n")
ENDIF(NOT "${acl_SnkFile}" STREQUAL "")
SET(CscArgs ${acl_CscArgs})
CONFIGURE_FILE(
"${acl_SrcDir}/CscArgs.txt.in"
"${acl_BinDir}/${acl_LibName}.CscArgs.txt"
@ONLY
)
IF(csc_EXECUTABLE)
ADD_CUSTOM_COMMAND(
OUTPUT "${acl_ExeDir}/${acl_LibName}.dll"
DEPENDS ${ARGN} "${acl_BinDir}/${acl_LibName}.CscArgs.txt" ${acl_CMakeRefs}
COMMAND ${csc_EXECUTABLE}
ARGS ${CSC_DEBUG_FLAG} ${CSC_PLATFORM_FLAG}
"/out:${acl_CscOut}" "/doc:${acl_CscDoc}" "/target:library"
${acl_CscLinkResourceArgs}
${acl_CscRefs}
"@${acl_BinDir}/${acl_LibName}.CscArgs.txt"
COMMENT "Building C# library '${acl_LibName}'..."
)
ADD_CUSTOM_TARGET(
"${acl_LibName}" ALL
DEPENDS "${acl_ExeDir}/${acl_LibName}.dll"
)
IF(NOT "${acl_DependentTargets}" STREQUAL "")
ADD_DEPENDENCIES("${acl_LibName}" ${acl_DependentTargets})
ENDIF(NOT "${acl_DependentTargets}" STREQUAL "")
ENDIF(csc_EXECUTABLE)
ENDMACRO(ADD_CSHARP_LIBRARY)
MACRO(ADD_CSHARP_TEST testname)
IF(mono_EXECUTABLE)
ADD_TEST(${testname} ${mono_EXECUTABLE} ${ARGN})
ELSE(mono_EXECUTABLE)
ADD_TEST(${testname} ${ARGN})
ENDIF(mono_EXECUTABLE)
ENDMACRO(ADD_CSHARP_TEST)
MACRO(ADD_EXPORTLAYER_LIBRARY ael_WrappedLibName ael_DependentLibs)
IF("${ARGN}" STREQUAL "")
MESSAGE(FATAL_ERROR "ADD_EXPORTLAYER_LIBRARY requires at least one optional argument.")
ENDIF("${ARGN}" STREQUAL "")
ADD_LIBRARY(
"${ael_WrappedLibName}.Unmanaged" SHARED
${ARGN}
)
TARGET_LINK_LIBRARIES("${ael_WrappedLibName}.Unmanaged" ${ael_DependentLibs})
ADD_DEPENDENCIES("${ael_WrappedLibName}.Unmanaged" "${ael_WrappedLibName}")
ENDMACRO(ADD_EXPORTLAYER_LIBRARY)
MACRO(WRAP_CLASSES_FOR_CSHARP wcfc_WrappedLibName wcfc_DependentTargets wcfc_DependentLibs)
IF("${ARGN}" STREQUAL "")
MESSAGE(FATAL_ERROR "WRAP_CLASSES_FOR_CSHARP requires at least one optional argument.")
ENDIF("${ARGN}" STREQUAL "")
SET(wcfc_SrcDir "${CMAKE_CURRENT_SOURCE_DIR}")
SET(wcfc_BinDir "${CMAKE_CURRENT_BINARY_DIR}")
CONFIGURE_FILE(
"${wcfc_SrcDir}/MummySettings.xml.in"
"${wcfc_BinDir}/xml/${wcfc_WrappedLibName}.MummySettings.xml"
@ONLY
)
CONFIGURE_FILE(
"${wcfc_SrcDir}/WrappedObject.cs.in"
"${wcfc_BinDir}/csharp/${wcfc_WrappedLibName}.WrappedObject.cs"
@ONLY
)
MAKE_DIRECTORY("${wcfc_BinDir}/export-layer")
SET(wcfc_CsharpFiles "${wcfc_BinDir}/csharp/${wcfc_WrappedLibName}.WrappedObject.cs")
SET(wcfc_ExportLayerFiles "")
SET(wcfc_GccxmlIncludes "")
FOREACH(instruction ${ARGN})
IF("${instruction}" MATCHES "(.+),(.+)")
STRING(REGEX REPLACE "(.+),(.+)" "\\1" wcfc_Class "${instruction}")
STRING(REGEX REPLACE "(.+),(.+)" "\\2" wcfc_Header "${instruction}")
ELSE("${instruction}" MATCHES "(.+),(.+)")
MESSAGE(FATAL_ERROR "WRAP_CLASSES_FOR_CSHARP arg instruction='${instruction}' does not match expected regular expression. Optional arguments to WRAP_CLASSES_FOR_CSHARP should follow the pattern 'class,header'...")
ENDIF("${instruction}" MATCHES "(.+),(.+)")
STRING(REGEX REPLACE "::" "_" wcfc_FileBaseName "${wcfc_Class}")
IF("${wcfc_Class}" MATCHES "^.*::([^:]+)$")
STRING(REGEX REPLACE "^.*::([^:]+)$" "\\1" wcfc_ClassName "${wcfc_Class}")
ELSE("${wcfc_Class}" MATCHES "^.*::([^:]+)$")
SET(wcfc_ClassName "${wcfc_Class}")
ENDIF("${wcfc_Class}" MATCHES "^.*::([^:]+)$")
SET(wcfc_GccxmlFile "${wcfc_BinDir}/xml/${wcfc_FileBaseName}.xml")
SET(wcfc_CsharpFile "${wcfc_BinDir}/csharp/${wcfc_FileBaseName}.cs")
SET(wcfc_ExportLayerFile "${wcfc_BinDir}/export-layer/${wcfc_FileBaseName}EL.cxx")
CONFIGURE_FILE(
"${wcfc_SrcDir}/gccxml.cxx.in"
"${wcfc_BinDir}/xml/${wcfc_FileBaseName}_gccxml.cxx"
@ONLY
)
ADD_CUSTOM_COMMAND(
OUTPUT ${wcfc_GccxmlFile}
COMMAND ${gccxml_EXECUTABLE}
ARGS
-fxml=${wcfc_GccxmlFile}
-fxml-start=_cable_
${wcfc_GccxmlIncludes}
-DCABLE_CONFIGURATION
--gccxml-compiler ${CMAKE_CXX_COMPILER}
${wcfc_BinDir}/xml/${wcfc_FileBaseName}_gccxml.cxx
DEPENDS
${wcfc_BinDir}/xml/${wcfc_FileBaseName}_gccxml.cxx
${wcfc_Header}
${gccxml_EXECUTABLE}
)
ADD_CUSTOM_COMMAND(
OUTPUT ${wcfc_CsharpFile} ${wcfc_ExportLayerFile}
COMMAND ${mummy_EXECUTABLE}
ARGS
--settings-file ${wcfc_BinDir}/xml/${wcfc_WrappedLibName}.MummySettings.xml
--gccxml-file ${wcfc_GccxmlFile}
--csharp-file ${wcfc_CsharpFile}
--export-layer-file ${wcfc_ExportLayerFile}
DEPENDS
${wcfc_BinDir}/xml/${wcfc_WrappedLibName}.MummySettings.xml
${wcfc_GccxmlFile}
${mummy_EXECUTABLE}
)
SET(wcfc_CsharpFiles ${wcfc_CsharpFiles} "${wcfc_CsharpFile}")
SET(wcfc_ExportLayerFiles ${wcfc_ExportLayerFiles} "${wcfc_ExportLayerFile}")
ENDFOREACH(instruction)
ADD_CSHARP_LIBRARY(${wcfc_WrappedLibName} ${wcfc_DependentTargets} "" "" "" ${wcfc_CsharpFiles})
ADD_EXPORTLAYER_LIBRARY(${wcfc_WrappedLibName} ${wcfc_DependentLibs} "${wcfc_ExportLayerFiles}")
ENDMACRO(WRAP_CLASSES_FOR_CSHARP)