forked from OpenTOPAS/OpenTOPAS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeHandleExtensions.cmake
634 lines (518 loc) · 25 KB
/
CMakeHandleExtensions.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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
configure_file (
"${CMAKE_CURRENT_SOURCE_DIR}/extensions/TsExtensionManager.cc.in"
"${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc"
)
configure_file (
"${CMAKE_CURRENT_SOURCE_DIR}/extensions/TsExtensionManager.hh.in"
"${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.hh"
)
configure_file (
"${CMAKE_CURRENT_SOURCE_DIR}/extensions/CMakeLists.txt.in"
"${CMAKE_CURRENT_BINARY_DIR}/extensions/CMakeLists.txt"
)
# If there are user extensions, modify files to use them
set (TOPAS_EXTENSIONS_DIR "${TOPAS_EXTENSIONS_DIR}" CACHE PATH "/path/to/topas/extensions")
if (TOPAS_EXTENSIONS_DIR)
file(GLOB oldfiles "${CMAKE_CURRENT_BINARY_DIR}/extensions/*.cc" "${CMAKE_CURRENT_BINARY_DIR}/extensions/*.hh")
list(REMOVE_ITEM oldfiles "${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc")
list(REMOVE_ITEM oldfiles "${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.hh")
if (oldfiles)
file(REMOVE ${oldfiles})
endif()
foreach(onetopdir ${TOPAS_EXTENSIONS_DIR})
get_filename_component(ONE_EXTENSIONS_DIR "${onetopdir}" ABSOLUTE)
file(GLOB_RECURSE extfiles "${ONE_EXTENSIONS_DIR}/*.cc")
foreach(item ${extfiles})
if (${item} MATCHES "/\\.")
list(REMOVE_ITEM extfiles ${item})
endif()
endforeach(item)
if (NOT extfiles)
message (FATAL_ERROR "No extension files were found in directory: " ${ONE_EXTENSIONS_DIR})
else()
message ("Found extensions in directory: " ${ONE_EXTENSIONS_DIR})
SET(FILENAME_LIST "")
foreach (file ${extfiles})
string(FIND ${file} "/" slashposition REVERSE)
string(SUBSTRING ${file} ${slashposition} -1 filename)
string(FIND ${filename} "." dotposition)
math(EXPR dotposition "${dotposition}-1")
string(SUBSTRING ${filename} 1 ${dotposition} filename)
list(FIND FILENAME_LIST ${filename} is_in_list)
if (NOT ${is_in_list} STREQUAL "-1")
message (FATAL_ERROR "Attempt to add same extension file twice: ${filename}.cc")
endif()
SET(FILENAME_LIST ${FILENAME_LIST} ${filename})
# file(READ "${file}" contents LIMIT 120)
FILE (READ "${file}" contents)
STRING (REGEX REPLACE ";" "\\\\;" contents "${contents}")
STRING (REGEX REPLACE "\n" ";" contents "${contents}")
foreach (c IN LISTS contents)
STRING (STRIP "${c}" c)
if (NOT c STREQUAL "")
SET (contents "${c}")
break ()
endif ()
endforeach ()
string(SUBSTRING ${contents} 3 -1 contents)
string(FIND ${contents} " for " position)
if (${position} STREQUAL "-1")
message ("\nInvalid first line in file: ${filename}.cc")
message ("All cc files in the extensions directory must start with a special")
message ("comment line that describes the function of this class.")
message ("See TOPAS User Guide for details.\n")
message (FATAL_ERROR)
endif()
string(SUBSTRING ${contents} 0 ${position} key)
string(SUBSTRING ${contents} ${position} -1 valuestring)
string(SUBSTRING ${valuestring} 5 -1 valuestring)
string(FIND ${valuestring} "\n" position)
string(SUBSTRING ${valuestring} 0 ${position} valuestring)
string(TOLOWER ${valuestring} valuestringlower)
if (key STREQUAL "Component")
message ("${file} is a Component for ${valuestring}")
file(READ ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc EXT_CONTENTS)
string(REGEX REPLACE
"\#include \"TsParameterManager.hh\""
"\#include \"TsParameterManager.hh\"
\#include \"${filename}.hh\""
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"InstantiateComponent\\(TsParameterManager\\*, TsMaterialManager\\*, TsGeometryManager\\*, TsVGeometryComponent\\*, G4VPhysicalVolume\\*, G4String, G4String"
"InstantiateComponent(TsParameterManager* pM, TsMaterialManager* mM, TsGeometryManager* gM, TsVGeometryComponent* pgc, G4VPhysicalVolume* pv, G4String childCompType, G4String childName"
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"Insertion point for Components"
"Insertion point for Components
if (childCompType==\"${valuestringlower}\")
return new ${filename}(pM, this, mM, gM, pgc, pv, childName);"
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"TsExtensionManager\\(TsParameterManager\\*\\)"
"TsExtensionManager(TsParameterManager* pM)"
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"Insertion point for Component Type Names"
"Insertion point for Component Type Names
pM->RegisterComponentTypeName(\"${valuestring}\");"
EXT_CONTENTS "${EXT_CONTENTS}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc "${EXT_CONTENTS}")
elseif (key STREQUAL "Imaging to Material Converter")
message ("${file} is an Imaging to Material Converter for ${valuestring}")
file(READ ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc EXT_CONTENTS)
string(REGEX REPLACE
"\#include \"TsParameterManager.hh\""
"\#include \"TsParameterManager.hh\"
\#include \"${filename}.hh\""
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"InstantiateImagingToMaterial\\(TsParameterManager\\*, TsVGeometryComponent\\*, std::vector<G4Material\\*>\\*, G4String"
"InstantiateImagingToMaterial(TsParameterManager* pM, TsVGeometryComponent* geometryComponent, std::vector<G4Material*>* materialList, G4String converterName"
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"Insertion point for Imaging to Imaging To Material Converter"
"Insertion point for Imaging to Imaging To Material Converter
if (converterName==\"${valuestringlower}\")
return new ${filename}(pM, geometryComponent, materialList);"
EXT_CONTENTS "${EXT_CONTENTS}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc "${EXT_CONTENTS}")
elseif (key STREQUAL "Magnetic Field")
message ("${file} is a Magnetic Field for ${valuestring}")
file(READ ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc EXT_CONTENTS)
string(REGEX REPLACE
"\#include \"TsParameterManager.hh\""
"\#include \"TsParameterManager.hh\"
\#include \"${filename}.hh\""
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"InstantiateMagneticField\\(TsParameterManager\\*, TsGeometryManager\\*, TsVGeometryComponent\\*, G4String"
"InstantiateMagneticField(TsParameterManager* pM, TsGeometryManager* gM, TsVGeometryComponent* geometryComponent, G4String magneticFieldType"
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"Insertion point for Magnetic Fields"
"Insertion point for Magnetic Fields
if (magneticFieldType==\"${valuestringlower}\")
return new ${filename}(pM, gM, geometryComponent);"
EXT_CONTENTS "${EXT_CONTENTS}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc "${EXT_CONTENTS}")
elseif (key STREQUAL "ElectroMagnetic Field")
message ("${file} is a ElectroMagnetic Field for ${valuestring}")
file(READ ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc EXT_CONTENTS)
string(REGEX REPLACE
"\#include \"TsParameterManager.hh\""
"\#include \"TsParameterManager.hh\"
\#include \"${filename}.hh\""
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"InstantiateElectroMagneticField\\(TsParameterManager\\*, TsGeometryManager\\*, TsVGeometryComponent\\*, G4String"
"InstantiateElectroMagneticField(TsParameterManager* pM, TsGeometryManager* gM, TsVGeometryComponent* geometryComponent, G4String electroMagneticFieldType"
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"Insertion point for ElectroMagnetic Fields"
"Insertion point for ElectroMagnetic Fields
if (electroMagneticFieldType==\"${valuestringlower}\")
return new ${filename}(pM, gM, geometryComponent);"
EXT_CONTENTS "${EXT_CONTENTS}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc "${EXT_CONTENTS}")
elseif (key STREQUAL "Filter")
message ("${file} is a Filter for ${valuestring}")
file(READ ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc EXT_CONTENTS)
string(REGEX REPLACE
"\#include \"TsParameterManager.hh\""
"\#include \"TsParameterManager.hh\"
\#include \"${filename}.hh\""
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"InstantiateFilter\\(TsParameterManager\\*, TsMaterialManager\\*, TsGeometryManager\\*, TsFilterManager\\*, TsVGenerator\\*, TsVScorer\\*, TsVFilter\\* parentFilter"
"InstantiateFilter(TsParameterManager* pM, TsMaterialManager* mM, TsGeometryManager* gM, TsFilterManager* fM, TsVGenerator* generator, TsVScorer* scorer, TsVFilter* parentFilter"
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"\/\/G4String filtername;"
"G4String filterName;"
EXT_CONTENTS "${EXT_CONTENTS}")
# valuestring could be a semicolon-separated list of values
string(REPLACE "," ";" valuestring ${valuestring})
list(LENGTH valuestring listlength)
foreach (onevalue ${valuestring})
string(TOLOWER ${onevalue} onevaluelower)
string(REGEX REPLACE
"Insertion point for Filters"
"Insertion point for Filters
filterName = \"${onevaluelower}\";
pM->RegisterFilterName(filterName);
if (HaveFilterNamed(pM, generator, scorer, filterName))
parentFilter = new ${filename}(filterName, pM, mM, gM, fM, generator, scorer, parentFilter);"
EXT_CONTENTS "${EXT_CONTENTS}")
endforeach (onevalue)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc "${EXT_CONTENTS}")
elseif (key STREQUAL "Particle Source")
message ("${file} is a Particle Source for ${valuestring}")
file(READ ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc EXT_CONTENTS)
string(REGEX REPLACE
"\#include \"TsParameterManager.hh\""
"\#include \"TsParameterManager.hh\"
\#include \"${filename}.hh\""
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"InstantiateParticleSource\\(TsParameterManager\\*, TsSourceManager\\*, G4String, G4String"
"InstantiateParticleSource(TsParameterManager* pM, TsSourceManager* psM, G4String sourceType, G4String sourceName"
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"Insertion point for Particle Sources"
"Insertion point for Particle Sources
if (sourceType==\"${valuestringlower}\")
return new ${filename}(pM, psM, sourceName);"
EXT_CONTENTS "${EXT_CONTENTS}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc "${EXT_CONTENTS}")
elseif (key STREQUAL "Particle Generator")
message ("${file} is a Particle Generator for ${valuestring}")
file(READ ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc EXT_CONTENTS)
string(REGEX REPLACE
"\#include \"TsParameterManager.hh\""
"\#include \"TsParameterManager.hh\"
\#include \"${filename}.hh\""
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"InstantiateParticleGenerator\\(TsParameterManager\\*, TsGeometryManager\\*, TsGeneratorManager\\*, G4String, G4String"
"InstantiateParticleGenerator(TsParameterManager* pM, TsGeometryManager* gM, TsGeneratorManager* pgM, G4String generatorType, G4String generatorName"
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"Insertion point for Particle Generators"
"Insertion point for Particle Generators
if (generatorType==\"${valuestringlower}\")
return new ${filename}(pM, gM, pgM, generatorName);"
EXT_CONTENTS "${EXT_CONTENTS}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc "${EXT_CONTENTS}")
elseif (key STREQUAL "Scorer")
message ("${file} is a Scorer for ${valuestring}")
file(READ ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc EXT_CONTENTS)
string(REGEX REPLACE
"\#include \"TsParameterManager.hh\""
"\#include \"TsParameterManager.hh\"
\#include \"${filename}.hh\""
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"InstantiateScorer\\(TsParameterManager\\*, TsMaterialManager\\*, TsGeometryManager\\*, TsScoringManager\\*, G4String, G4String, G4String, G4String, G4bool"
"InstantiateScorer(TsParameterManager* pM, TsMaterialManager* mM, TsGeometryManager* gM, TsScoringManager* scM, G4String currentScorerName, G4String quantityName, G4String quantityNameLower, G4String outFileName, G4bool isSubScorer"
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"Insertion point for Scorers"
"Insertion point for Scorers
if (quantityNameLower==\"${valuestringlower}\")
return new ${filename}(pM, mM, gM, scM, this, currentScorerName, quantityName, outFileName, isSubScorer);"
EXT_CONTENTS "${EXT_CONTENTS}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc "${EXT_CONTENTS}")
elseif (key STREQUAL "Outcome Model")
message ("${file} is a Outcome Model for ${valuestring}")
file(READ ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc EXT_CONTENTS)
string(REGEX REPLACE
"\#include \"TsParameterManager.hh\""
"\#include \"TsParameterManager.hh\"
\#include \"${filename}.hh\""
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"InstantiateOutcomeModel\\(TsParameterManager\\*, G4String, G4String"
"InstantiateOutcomeModel(TsParameterManager* pM, G4String parmPrefix, G4String modelName"
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"Insertion point for Outcome Models"
"Insertion point for Outcome Models
if (modelName==\"${valuestringlower}\")
return new ${filename}(pM, parmPrefix);"
EXT_CONTENTS "${EXT_CONTENTS}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc "${EXT_CONTENTS}")
elseif (key STREQUAL "Physics List")
message ("${file} is a Physics List for ${valuestring}")
file(READ ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc EXT_CONTENTS)
string(REGEX REPLACE
"\#include \"TsParameterManager.hh\""
"\#include \"TsParameterManager.hh\"
\#include \"${filename}.hh\""
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"InstantiatePhysicsList\\(TsParameterManager\\*, G4String"
"InstantiatePhysicsList(TsParameterManager* pM, G4String physicsListName"
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"Insertion point for Physics Lists"
"Insertion point for Physics Lists
if (physicsListName==\"${valuestringlower}\")
return new ${filename}(pM);"
EXT_CONTENTS "${EXT_CONTENTS}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc "${EXT_CONTENTS}")
elseif (key STREQUAL "Physics Module")
message ("${file} is a Physics Module for ${valuestring}")
file(READ ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc EXT_CONTENTS)
string(REGEX REPLACE
"\#include \"TsParameterManager.hh\""
"\#include \"TsParameterManager.hh\"
\#include \"${filename}.hh\""
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"InstantiatePhysicsModule\\(TsParameterManager\\*, G4String"
"InstantiatePhysicsModule(TsParameterManager* pM, G4String physicsModuleName"
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"Insertion point for Physics Modules"
"Insertion point for Physics Modules
if (physicsModuleName==\"${valuestringlower}\")
return new CreatorWithPm<${filename}>(pM);"
EXT_CONTENTS "${EXT_CONTENTS}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc "${EXT_CONTENTS}")
elseif (key STREQUAL "BeginSession")
message ("${file} is user code for ${key}")
if (HasBeginSession)
message (FATAL_ERROR "Attempt to add second BeginSession class to same build.")
endif()
set(HasBeginSession 1)
file(READ ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc EXT_CONTENTS)
string(REGEX REPLACE
"\#include \"TsParameterManager.hh\""
"\#include \"TsParameterManager.hh\"
\#include \"${filename}.hh\""
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"BeginSession\\(TsParameterManager\\*\\)"
"BeginSession(TsParameterManager* pM)"
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"Insertion point for BeginSession"
"Insertion point for BeginSession
std::unique_ptr<${filename}> beginSessionPtr(new ${filename}(pM));"
EXT_CONTENTS "${EXT_CONTENTS}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc "${EXT_CONTENTS}")
elseif (key STREQUAL "BeginRun")
message ("${file} is user code for ${key}")
if (HasBeginRun)
message (FATAL_ERROR "Attempt to add second BeginRun class to same build.")
endif()
set(HasBeginRun 1)
file(READ ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc EXT_CONTENTS)
string(REGEX REPLACE
"\#include \"TsParameterManager.hh\""
"\#include \"TsParameterManager.hh\"
\#include \"${filename}.hh\""
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"BeginRun\\(TsParameterManager\\*\\)"
"BeginRun(TsParameterManager* pM)"
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"Insertion point for BeginRun"
"Insertion point for BeginRun
std::unique_ptr<${filename}> beginRunPtr(new ${filename}(pM));"
EXT_CONTENTS "${EXT_CONTENTS}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc "${EXT_CONTENTS}")
elseif (key STREQUAL "BeginHistory")
message ("${file} is user code for ${key}")
if (HasBeginHistory)
message (FATAL_ERROR "Attempt to add second BeginHistory class to same build.")
endif()
set(HasBeginHistory 1)
file(READ ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc EXT_CONTENTS)
string(REGEX REPLACE
"\#include \"TsParameterManager.hh\""
"\#include \"TsParameterManager.hh\"
\#include \"${filename}.hh\""
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"BeginHistory\\(TsParameterManager\\*, const G4Run\\*, const G4Event\\*"
"BeginHistory(TsParameterManager* pM, const G4Run* run, const G4Event* event"
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"Insertion point for BeginHistory"
"Insertion point for BeginHistory
std::unique_ptr<${filename}> beginHistoryPtr(new ${filename}(pM, run, event));"
EXT_CONTENTS "${EXT_CONTENTS}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc "${EXT_CONTENTS}")
elseif (key STREQUAL "EndHistory")
message ("${file} is user code for ${key}")
if (HasEndHistory)
message (FATAL_ERROR "Attempt to add second EndHistory class to same build.")
endif()
set(HasEndHistory 1)
file(READ ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc EXT_CONTENTS)
string(REGEX REPLACE
"\#include \"TsParameterManager.hh\""
"\#include \"TsParameterManager.hh\"
\#include \"${filename}.hh\""
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"EndHistory\\(TsParameterManager\\*, const G4Run\\*, const G4Event\\*"
"EndHistory(TsParameterManager* pM, const G4Run* run, const G4Event* event"
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"Insertion point for EndHistory"
"Insertion point for EndHistory
std::unique_ptr<${filename}> endHistoryPtr(new ${filename}(pM, run, event));"
EXT_CONTENTS "${EXT_CONTENTS}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc "${EXT_CONTENTS}")
elseif (key STREQUAL "EndRun")
message ("${file} is user code for ${key}")
if (HasEndRun)
message (FATAL_ERROR "Attempt to add second EndRun class to same build.")
endif()
set(HasEndRun 1)
file(READ ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc EXT_CONTENTS)
string(REGEX REPLACE
"\#include \"TsParameterManager.hh\""
"\#include \"TsParameterManager.hh\"
\#include \"${filename}.hh\""
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"EndRun\\(TsParameterManager\\*\\)"
"EndRun(TsParameterManager* pM)"
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"Insertion point for EndRun"
"Insertion point for EndRun
std::unique_ptr<${filename}> endRunPtr(new ${filename}(pM));"
EXT_CONTENTS "${EXT_CONTENTS}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc "${EXT_CONTENTS}")
elseif (key STREQUAL "EndRun2")
message ("${file} is user code for ${key}")
if (HasEndRun2)
message (FATAL_ERROR "Attempt to add second EndRun2 class to same build.")
endif()
set(HasEndRun2 1)
file(READ ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc EXT_CONTENTS)
string(REGEX REPLACE
"\#include \"TsParameterManager.hh\""
"\#include \"TsParameterManager.hh\"
\#include \"${filename}.hh\""
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"EndRun\\(TsParameterManager\\*\\)"
"EndRun(TsParameterManager* pM)"
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"Insertion point for SecondEndRun"
"Insertion point for SecondEndRun
std::unique_ptr<${filename}> secondEndRunPtr(new ${filename}(pM));"
EXT_CONTENTS "${EXT_CONTENTS}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc "${EXT_CONTENTS}")
elseif (key STREQUAL "EndRun3")
message ("${file} is user code for ${key}")
if (HasEndRun3)
message (FATAL_ERROR "Attempt to add second EndRun3 class to same build.")
endif()
set(HasEndRun3 1)
file(READ ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc EXT_CONTENTS)
string(REGEX REPLACE
"\#include \"TsParameterManager.hh\""
"\#include \"TsParameterManager.hh\"
\#include \"${filename}.hh\""
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"EndRun\\(TsParameterManager\\*\\)"
"EndRun(TsParameterManager* pM)"
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"Insertion point for ThirdEndRun"
"Insertion point for ThirdEndRun
std::unique_ptr<${filename}> thirdEndRunPtr(new ${filename}(pM));"
EXT_CONTENTS "${EXT_CONTENTS}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc "${EXT_CONTENTS}")
elseif (key STREQUAL "EndSession")
message ("${file} is user code for ${key}")
if (HasEndSession)
message (FATAL_ERROR "Attempt to add second EndSession class to same build.")
endif()
set(HasEndSession 1)
file(READ ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc EXT_CONTENTS)
string(REGEX REPLACE
"\#include \"TsParameterManager.hh\""
"\#include \"TsParameterManager.hh\"
\#include \"${filename}.hh\""
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"EndSession\\(TsParameterManager\\*\\)"
"EndSession(TsParameterManager* pM)"
EXT_CONTENTS "${EXT_CONTENTS}")
string(REGEX REPLACE
"Insertion point for EndSession"
"Insertion point for EndSession
std::unique_ptr<${filename}> endSessionPtr(new ${filename}(pM));"
EXT_CONTENTS "${EXT_CONTENTS}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/extensions/TsExtensionManager.cc "${EXT_CONTENTS}")
elseif (NOT key STREQUAL "Extra Class")
message ("\nInvalid first line in file: ${filename}.cc")
message ("All cc files in the extensions directory must start with a special")
message ("comment line that describes the function of this class.")
message ("See TOPAS User Guide for details.\n")
message (FATAL_ERROR)
endif()
configure_file (${file} "${CMAKE_CURRENT_BINARY_DIR}/extensions/${filename}.cc")
file(READ ${CMAKE_CURRENT_BINARY_DIR}/extensions/CMakeLists.txt EXT_CONTENTS)
string(REGEX REPLACE
"TsExtensionManager.hh"
"TsExtensionManager.hh
${filename}.cc"
EXT_CONTENTS "${EXT_CONTENTS}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/extensions/CMakeLists.txt "${EXT_CONTENTS}")
endforeach (file)
file(GLOB_RECURSE extheaders "${ONE_EXTENSIONS_DIR}/*.hh")
SET(FILENAME_LIST "")
foreach (header ${extheaders})
string(FIND ${header} "/" slashposition REVERSE)
string(SUBSTRING ${header} ${slashposition} -1 headername)
string(FIND ${headername} "." dotposition)
math(EXPR dotposition "${dotposition}-1")
string(SUBSTRING ${headername} 1 ${dotposition} headername)
list(FIND FILENAME_LIST ${headername} is_in_list)
if (NOT ${is_in_list} STREQUAL "-1")
message (FATAL_ERROR "Attempt to add same extension file twice: ${headername}.hh")
endif()
SET(FILENAME_LIST ${FILENAME_LIST} ${headername})
configure_file (${header} "${CMAKE_CURRENT_BINARY_DIR}/extensions/${headername}.hh")
file(READ ${CMAKE_CURRENT_BINARY_DIR}/extensions/CMakeLists.txt EXT_CONTENTS)
string(REGEX REPLACE
"TsExtensionManager.hh"
"TsExtensionManager.hh
${headername}.hh"
EXT_CONTENTS "${EXT_CONTENTS}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/extensions/CMakeLists.txt "${EXT_CONTENTS}")
endforeach (header)
endif()
endforeach(onetopdir)
endif()