[Repository Listing] / [Slicer3] / oldtrunk / launch.tcl.in
 

View of /oldtrunk/launch.tcl.in

Parent Directory Parent Directory Revision Log Revision Log


Revision 15040  Download Blame
File size: 54280 byte(s)
ENH: implementing changes described in the email linked below.
http://massmail.spl.harvard.edu/public-archives/slicer-devel/2010/005338.html
1 #!/bin/sh
2 # the next line restarts using tclsh \
3 exec wish "$0" "$@"
4
5 #
6 # launch.tcl
7 #
8 # This script is used to set platform-specific variables for the shell
9 # that will be used to launch slicer.
10 #
11 # - what platform you're on so correct libs are loaded
12 # - what modules are present so they can be loaded
13 # - set all PATH, LD_LIBRARY_PATH, TCLLIBPATH, and other shell-level
14 # variables to reflect that state
15 #
16 # This is a tcl script rather than a .bat or .sh file so it can handle all
17 # the details in one place for all platforms.
18 #
19 # This script is used for both the slicer build directory and for the slicer
20 # install directory.
21 #
22 # Note: the version of this file called launch.tcl.in will be configured by
23 # cmake such that tokens between @ signs will be replaced by the variable
24 # from the cmake cache
25 #
26
27 # set default error code and info so we don't get confused later if no error has
28 # actually occurred...
29 set ::errorCode 0
30 set ::errorInfo ""
31
32 set ::EXIT_CODE_NO_ERROR 0
33 set ::EXIT_CODE_CHILD_KILLED 1
34 set ::EXIT_CODE_GENERIC_ERROR -1
35 set ::EXIT_CODE_VTK_ERROR -2
36 set ::EXIT_CODE_LAUNCHING_ERROR -3
37
38
39 #-------------------------------------------------------------------------------
40 # .PROC LogToFile
41 # Helper function.
42 # Use this function to write a string to launcher-log.txt
43 # .ARGS
44 # message to be logged
45 # .END
46 #-------------------------------------------------------------------------------
47 proc LogToFile { msg } {
48 set fd [open "launcher-log.txt" "w"]
49 puts $fd $msg
50 }
51
52 #-------------------------------------------------------------------------------
53 # .PROC ShowAndLogError
54 # Helper function.
55 # Use this function instead of puts to both log an error message and
56 # show it for the user in a popup window
57 # (The popup window is automatically closed after a few seconds to allow some
58 # time for the user to read, but allow application exit in a reasonable time
59 # for automated tests.)
60 # .ARGS
61 # message to be displayed
62 # .END
63 #-------------------------------------------------------------------------------
64 set ::LAUNCH(showErrorPopup) 1
65 proc ShowAndLogError { msg } {
66 set autoCloseTimeoutMs 10000
67 puts $msg
68 if { $::LAUNCH(showErrorPopup) } {
69 if { [catch "package require Tk" res] } {
70 puts "Error displaying error in a popup: $res"
71 } else {
72 after $autoCloseTimeoutMs {destroy .dialog1}
73 tk_dialog .dialog1 "Error" "$msg" error 0 OK
74 }
75 }
76 }
77
78 #-------------------------------------------------------------------------------
79 # .PROC StoreDirInEnvVar
80 # Helper function to safely store directory in environment variable.
81 # Makes sure that the environment variable is defined, even when the directory
82 # name is empty (to avoid "no such variable" script error)
83 # .ARGS
84 # environment variable name, directory path
85 # .END
86 #-------------------------------------------------------------------------------
87 proc StoreDirInEnvVar { envVarName dir } {
88 set dir [file normalize "$dir"]
89 if {$dir == ""} {
90 set dir " "
91 }
92 set ::env($envVarName) "$dir"
93 }
94
95 #-------------------------------------------------------------------------------
96 # .PROC launch_SetEnvironment
97 # Initialize environment variables
98 # .ARGS
99 # .END
100 #-------------------------------------------------------------------------------
101 proc launch_SetEnvironment {} {
102
103 #
104 # Slicer3_HOME: , find it relative to the location of this script
105 # -- when run by the launcher, this variable will be set already
106 # -- this environment variable can be relied on by slicer code to know "where it lives"
107 # e.g. the build or install dir, so resources and other files can be found
108 #
109 set wd [pwd]
110 cd [file dirname [file dirname [file dirname [info script]]]]
111 set ::Slicer3_HOME [pwd]
112 cd $wd
113 set ::env(Slicer3_HOME) $::Slicer3_HOME
114
115 if { [string match -nocase "windows*" $::tcl_platform(os)] } {
116 set ::Slicer3_HOME [file attributes $::Slicer3_HOME -shortname]
117 set ::env(Slicer3_HOME) $::Slicer3_HOME
118 }
119
120 #
121 # Indicate if Slicer was build with QT support
122 #
123 set ::Slicer3_USE_QT "@Slicer3_USE_QT@"
124 set ::Slicer3_USE_PYTHONQT "@Slicer3_USE_PYTHONQT@"
125
126 #
127 # set up variables for the OS Builds
128 #
129 set ::SOLARIS "solaris8"
130 set ::LINUX "linux-x86"
131 set ::LINUX_64 "linux-x86_64"
132 set ::DARWIN "darwin-ppc"
133 set ::DARWIN_X86 "darwin-x86"
134 set ::WINDOWS "win32"
135
136 #
137 # set the default locations for the main components
138 #
139 switch $::tcl_platform(os) {
140 "SunOS" { set ::env(BUILD) $::SOLARIS }
141 "GNU/kFreeBSD" {
142 if {$::tcl_platform(machine) == "x86_64"} {
143 set ::env(BUILD) $::LINUX_64
144 } else {
145 set ::env(BUILD) $::LINUX
146 }
147 }
148 "Linux" {
149 if {$::tcl_platform(machine) == "x86_64"} {
150 set ::env(BUILD) $::LINUX_64
151 } else {
152 set ::env(BUILD) $::LINUX
153 }
154 }
155 "Darwin" {
156 if {$::tcl_platform(machine) == "i386"} {
157 set ::env(BUILD) $::DARWIN_X86
158 } else {
159 set ::env(BUILD) $::DARWIN
160 }
161 }
162 default {
163 set ::env(BUILD) $::WINDOWS
164 }
165 }
166
167
168 if {$::tcl_platform(os) == "SunOS"} {
169 set isainfo [exec isainfo -b]
170 set SlicerBinaryBitness [exec file $::env(Slicer3_HOME)/bin/Slicer3-real | cut -d "," -f 1 | cut -d " " -f2 | cut -d "-" -f1]
171 if {$SlicerBinaryBitness == "32"} {
172 set ::BUILD(bitness) "32"
173 } elseif {$SlicerBinaryBitness == "64" && $isainfo == 64} {
174 set ::BUILD(bitness) "64"
175 } elseif {$SlicerBinaryBitness == "64" && $isainfo == 32} {
176 ShowAndLogError "You can't run a 64 bit program on a 32 bit kernel!"
177 exit $::EXIT_CODE_GENERIC_ERROR
178 }
179 }
180
181 #
182 # check if this is an install or a build directory
183 # - an install will have a copy of vtk in the bin directory
184 # - a build dirctory will not
185 #
186 set installed 0
187 set ext ""
188 if { [string match -nocase "windows*" $::tcl_platform(os)] } {
189 set ext ".exe"
190 }
191 # if you change something here, please change it in qSlicerCoreApplication too
192 if { [file exists $::env(Slicer3_HOME)/bin/vtkEncodeString$ext] } {
193 set installed 1
194 }
195
196 if { $installed } {
197
198
199 # if installed, everything is in the local tree
200 set slicer3Real "$::Slicer3_HOME/bin/Slicer3-real$ext"
201 set slicerQTReal "$::Slicer3_HOME/bin/SlicerQT-real$ext"
202 if { [file exists "$slicer3Real"] } {
203 set ::Slicer3_REAL $slicer3Real
204 } elseif { [file exists "$slicerQTReal"] } {
205 set ::Slicer3_REAL $slicerQTReal
206 }
207
208 set ::env(SANDBOX_BIN_DIR) ""
209
210 # additional system libs
211
212 set ::env(X11_LIB_DIR) ""
213 set ::env(SFW_LIB_DIR) ""
214 if { $::env(BUILD) == $::SOLARIS && $::BUILD(bitness) == "32"} {
215 set ::env(X11_LIB_DIR) /usr/X11/lib
216 set ::env(SFW_LIB_DIR) /usr/sfw/lib
217 } else {
218 set ::env(X11_LIB_DIR) /usr/X11/lib/64
219 set ::env(SFW_LIB_DIR) /usr/sfw/lib/64
220 }
221
222 # 3rd party toolkits
223
224 set ::env(VTK_DIR) $::env(Slicer3_HOME)/lib/vtk-@VTK_MAJOR_VERSION@.@VTK_MINOR_VERSION@
225 set ::env(VTK_BIN_DIR) $::env(Slicer3_HOME)/bin
226
227 set ::env(CTK_DIR) $::env(Slicer3_HOME)/lib/ctk-@CTK_MAJOR_VERSION@.@CTK_MINOR_VERSION@
228 set ::env(CTK_BIN_DIR) $::env(Slicer3_HOME)/bin
229 # TODO: where will PythonQt be in the install tree?
230 set ::env(PYTHONQT_DIR) $::env(Slicer3_HOME)/lib/PythonQt
231 set ::env(PYTHONQT_BIN_DIR) $::env(Slicer3_HOME)/bin
232
233 set ::env(KWWidgets_DIR) $::env(Slicer3_HOME)/lib/KWWidgets
234 set ::env(KWWidgets_LIB_DIR) $::env(Slicer3_HOME)/lib/KWWidgets
235 set ::env(KWWidgets_BIN_DIR) $::env(Slicer3_HOME)/bin
236
237 # TODO -- where will Qt be in the install tree?
238 set ::env(QT_LIB_DIR) $::env(Slicer3_HOME)/lib/Qt
239 # Let's make QT binaries available
240 set ::env(QT_BINARY_DIR) $::env(Slicer3_HOME)/bin
241
242 # On Mac each Qt library is a framework which needs DYLD_LIBRARY_PATH set for each
243 if {$::env(BUILD) == $::DARWIN || $::env(BUILD) == $::DARWIN_X86} {
244 set ::env(QT_FRAMEWORK_DIRS) [file normalize "@Slicer3_QT_FRAMEWORK_DIRS@"]
245 }
246
247 set ::env(ITK_BIN_DIR) $::env(Slicer3_HOME)/lib/InsightToolkit
248
249 set ::env(Teem_DIR) $::env(Slicer3_HOME)/lib/Teem-@Teem_VERSION_MAJOR@.@Teem_VERSION_MINOR@.@Teem_VERSION_PATCH@
250
251 set ::env(TCL_DIR) $::env(Slicer3_HOME)/lib/TclTk
252 set ::env(TCL_LIBRARY) "$::env(TCL_DIR)/lib/tcl@TCL_TK_VERSION_DOT@"
253 if {$::env(BUILD) == $::WINDOWS} {
254 set ::env(PYTHON_DIR) $::env(Slicer3_HOME)/lib/Python/PCbuild
255 } else {
256 set ::env(PYTHON_DIR) $::env(Slicer3_HOME)/lib/Python
257 }
258
259 set ::env(OpenIGTLink_DIR) $::env(Slicer3_HOME)/lib/igtl
260 set ::env(OpenIGTLink_LIB_DIR) $::env(Slicer3_HOME)/lib/igtl
261 set ::env(OpenIGTLink_BIN_DIR) $::env(Slicer3_HOME)/bin
262
263 set ::env(BatchMake_DIR) $::env(Slicer3_HOME)/lib/BatchMake
264 set ::env(BatchMake_LIB_DIR) $::env(Slicer3_HOME)/lib/BatchMake
265 set ::env(BatchMake_BIN_DIR) $::env(Slicer3_HOME)/bin
266 set ::env(bmModuleDescriptionParser_DIR) $::env(Slicer3_HOME)/lib/bmModuleDescriptionParser
267
268
269 # Slicer3 Libs
270
271 set ::env(FreeSurfer_DIR) $::env(Slicer3_HOME)/lib/FreeSurfer
272 set ::env(IGT_DIR) $::env(Slicer3_HOME)/lib/IGT
273 set ::env(ITKCommandIO_DIR) $::env(Slicer3_HOME)/lib/ITKCommandIO
274 set ::env(LoadableModule_DIR) $::env(Slicer3_HOME)/lib/LoadableModule
275 set ::env(MGHImageIO_DIR) $::env(Slicer3_HOME)/lib/MGHImageIO
276 set ::env(MRML_DIR) $::env(Slicer3_HOME)/lib/MRML
277 set ::env(MRMLCLI_DIR) $::env(Slicer3_HOME)/lib/MRMLCLI
278 set ::env(MRMLLogic_DIR) $::env(Slicer3_HOME)/lib/MRMLLogic
279 set ::env(MRMLDisplayableManager_DIR) $::env(Slicer3_HOME)/lib/MRMLDisplayableManager
280 set ::env(ModuleDescriptionParser_DIR) $::env(Slicer3_HOME)/lib/ModuleDescriptionParser
281 set ::env(MRMLIDImageIO_DIR) $::env(Slicer3_HOME)/lib/MRMLIDImageIO
282 set ::env(Qdec_DIR) $::env(Slicer3_HOME)/lib/Qdec
283 set ::env(RemoteIO_DIR) $::env(Slicer3_HOME)/lib/RemoteIO
284 set ::env(FileWatcher_DIR) $::env(Slicer3_HOME)/lib/FileWatcher
285 set ::env(SlicerIO_DIR) $::env(Slicer3_HOME)/lib/SlicerIO
286 set ::env(tclap_DIR) $::env(Slicer3_HOME)/lib/tclap
287 set ::env(vtkITK_DIR) $::env(Slicer3_HOME)/lib/vtkITK
288 set ::env(vtkTeem_DIR) $::env(Slicer3_HOME)/lib/vtkTeem
289 set ::env(qCTKWidgets_DIR) $::env(Slicer3_HOME)/lib/qCTKWidgets
290 set ::env(qVTKWidgets_DIR) $::env(Slicer3_HOME)/lib/qVTKWidgets
291 set ::env(qMRMLWidgets_DIR) $::env(Slicer3_HOME)/lib/qMRMLWidgets
292
293 set ::env(Slicer3_COMPILER_DIR) ""
294 if { $::env(BUILD) == $::SOLARIS } {
295 set ::env(Slicer3_COMPILER_DIR) $::env(Slicer3_HOME)/lib/Slicer3/CompilerLibs/$::BUILD(bitness)
296 }
297
298 # Slicer3 Base
299
300 set ::env(Slicer3_LIB_DIR) $::env(Slicer3_HOME)/lib/Slicer3
301 set ::env(Slicer3_BIN_DIR) $::env(Slicer3_HOME)/bin
302
303 set ::env(Slicer3_PLUGINS_DIR) $::env(Slicer3_HOME)/@Slicer3_INSTALL_PLUGINS_LIB_DIR@
304 set ::env(Slicer3_MODULES_DIR) $::env(Slicer3_HOME)/@Slicer3_INSTALL_MODULES_LIB_DIR@
305 set ::env(Slicer3_QTLOADABLEMODULES_DIR) $::env(Slicer3_HOME)/@Slicer3_INSTALL_QTLOADABLEMPYTHONQT_BIN_DIRODULES_LIB_DIR@
306
307 # QtDesigner variable
308 #
309 set ::env(Slicer3_QT_PLUGIN_PATH) "@Slicer3_INSTALL_LIB_DIR@"
310 set ::env(CTK_QT_PLUGIN_PATH) "$::env(CTK_BIN_DIR)"
311
312 } else {
313
314 # the not-installed case
315
316 set ::BUILD_SUBDIR ""
317 set ::VTK_BUILD_SUBDIR ""
318 set ::CTK_BUILD_SUBDIR ""
319 set ::KWWidgets_BUILD_SUBDIR ""
320 set ::ITK_BUILD_SUBDIR ""
321 set ::Teem_BUILD_SUBDIR ""
322 set ::OpenIGTLink_BUILD_SUBDIR ""
323 set ::BatchMake_BUILD_SUBDIR ""
324 set ::QtDesignerPlugins_BUILD_SUBDIR ""
325
326 if {$::env(BUILD) == $::WINDOWS} {
327 foreach buildType {"." Debug RelWithDebInfo Release MinSizeRel} {
328 set slicer3Real "$::Slicer3_HOME/bin/$buildType/Slicer3-real.exe"
329 set slicerQTReal "$::Slicer3_HOME/bin/$buildType/SlicerQT-real.exe"
330 if { [file exists "$slicer3Real"] } {
331 set ::Slicer3_REAL $slicer3Real
332 set ::BUILD_SUBDIR $buildType
333 } elseif { [file exists "$slicerQTReal"] } {
334 set ::Slicer3_REAL $slicerQTReal
335 set ::BUILD_SUBDIR $buildType
336 }
337 if { [file exists "@VTK_DIR@/bin/$buildType/vtkCommon.dll"] } {
338 set ::VTK_BUILD_SUBDIR $buildType
339 }
340 if { [file exists "@CTK_DIR@/CTK-build/bin/$buildType/CTKCore.dll"] } {
341 set ::CTK_BUILD_SUBDIR $buildType
342 }
343 if { [file exists "@KWWidgets_DIR@/bin/$buildType/KWWidgets.dll"] } {
344 set ::KWWidgets_BUILD_SUBDIR $buildType
345 }
346 if { [file exists "@ITK_DIR@/bin/$buildType/ITKCommon.dll"] } {
347 set ::ITK_BUILD_SUBDIR $buildType
348 }
349 if { [file exists "@Teem_DIR@/bin/$buildType/air.dll"] ||
350 [file exists "@Teem_DIR@/bin/$buildType/teem.dll"] } {
351 set ::Teem_BUILD_SUBDIR $buildType
352 }
353 if { [file exists "@OpenIGTLink_DIR@/bin/$buildType/OpenIGTLink.dll"] } {
354 set ::OpenIGTLink_BUILD_SUBDIR $buildType
355 }
356 if { [file exists "@BatchMake_DIR@/bin/$buildType/BatchMake.dll"] } {
357 set ::BatchMake_BUILD_SUBDIR $buildType
358 }
359 }
360 } else {
361 set slicer3Real "$::Slicer3_HOME/bin/Slicer3-real"
362 set slicerQTReal "$::Slicer3_HOME/bin/SlicerQT-real"
363 if { [file exists "$slicer3Real"] } {
364 set ::Slicer3_REAL $slicer3Real
365 } elseif { [file exists "$slicerQTReal"] } {
366 set ::Slicer3_REAL $slicerQTReal
367 }
368 }
369 set ::env(SANDBOX_BIN_DIR) ""
370
371
372 # additional system libs
373
374 if { $::env(BUILD) == $::SOLARIS && $::BUILD(bitness) == "32"} {
375 set ::env(X11_LIB_DIR) /usr/X11/lib
376 set ::env(SFW_LIB_DIR) /usr/sfw/lib
377 } else {
378 set ::env(X11_LIB_DIR) /usr/X11/lib/64
379 set ::env(SFW_LIB_DIR) /usr/sfw/lib/64
380 }
381
382 set ::env(Slicer3_COMPILER_DIR) ""
383 if { $::env(BUILD) == $::SOLARIS } {
384 set ::env(Slicer3_COMPILER_DIR) $::env(Slicer3_HOME)/lib/Slicer3/CompilerLibs/$::BUILD(bitness)
385 }
386
387
388 # 3rd party toolkits
389
390 set ::env(VTK_DIR) [file normalize "@VTK_DIR@"]
391 set ::env(VTK_BIN_DIR) [file normalize "@VTK_DIR@/bin/$::VTK_BUILD_SUBDIR"]
392
393 if { "@CTK_DIR@" != "" } {
394 set ::env(CTK_DIR) [file normalize "@CTK_DIR@"]
395 } else {
396 set ::env(CTK_DIR) "$::Slicer3_HOME/bin"
397 }
398 set ::env(CTK_BIN_DIR) [file normalize "@CTK_DIR@/CTK-build/bin/$::CTK_BUILD_SUBDIR"]
399 set ::env(PYTHONQT_DIR) [file normalize "@CTK_DIR@/CMakeExternals/Build/PythonQt/$::CTK_BUILD_SUBDIR"]
400 set ::env(PYTHONQT_BIN_DIR) [file normalize "@CTK_DIR@/CMakeExternals/Build/PythonQt/$::CTK_BUILD_SUBDIR"]
401
402 set ::env(KWWidgets_DIR) [file normalize "@KWWidgets_DIR@"]
403 set ::env(KWWidgets_LIB_DIR) [file normalize "@KWWidgets_DIR@/bin/$::KWWidgets_BUILD_SUBDIR"]
404 set ::env(KWWidgets_BIN_DIR) [file normalize "@KWWidgets_DIR@/bin/$::KWWidgets_BUILD_SUBDIR"]
405
406 if { "@QT_LIBRARY_DIR@" != "" } {
407 set ::env(QT_LIB_DIR) [file normalize "@QT_LIBRARY_DIR@"]
408 } else {
409 set ::env(QT_LIB_DIR) "$::Slicer3_HOME/bin"
410 }
411 # Let's make QT binaries available
412 StoreDirInEnvVar QT_BINARY_DIR "@QT_BINARY_DIR@"
413
414 if {$::env(BUILD) == $::DARWIN || $::env(BUILD) == $::DARWIN_X86} {
415 set ::env(QT_FRAMEWORK_DIRS) [file normalize "@QT_LIBRARY_DIR@"]
416 }
417
418 set ::env(ITK_BIN_DIR) [file normalize "@ITK_DIR@/bin/$::ITK_BUILD_SUBDIR"]
419
420 if { "@Slicer3_TCL_DIR@" != "" } {
421 # this is the variable used in superbuild
422 set ::env(TCL_DIR) [file normalize "@Slicer3_TCL_DIR@"]
423 } else {
424 set ::env(TCL_DIR) [file normalize [file dirname [file dirname "@TCL_LIBRARY@"]]]
425 }
426 set ::env(TCL_LIBRARY) "$::env(TCL_DIR)/lib/tcl@TCL_TK_VERSION_DOT@"
427
428 if { "@PYTHON_LIBRARY@" != "" } {
429 # this is the variable used in superbuild
430 if {$::env(BUILD) == $::WINDOWS} {
431 set ::env(PYTHON_DIR) [file normalize [file dirname "@PYTHON_LIBRARY@"]]
432 } else {
433 set ::env(PYTHON_DIR) [file normalize [file dirname [file dirname "@PYTHON_LIBRARY@"]]]
434 }
435 } else {
436 if {$::env(BUILD) == $::WINDOWS} {
437 set ::env(PYTHON_DIR) [file normalize [file dirname "@PYTHON_INCLUDE_PATH@"]/PCbuild]
438 } else {
439 set ::env(PYTHON_DIR) [file normalize [file dirname [file dirname "@PYTHON_INCLUDE_PATH@"]]]
440 }
441 }
442
443 set ::env(Teem_DIR) [file normalize "@Teem_DIR@/bin/$::Teem_BUILD_SUBDIR"]
444
445 set ::env(OpenIGTLink_DIR) [file normalize "@OpenIGTLink_DIR@"]
446 set ::env(OpenIGTLink_LIB_DIR) [file normalize "@OpenIGTLink_DIR@/bin/$::OpenIGTLink_BUILD_SUBDIR"]
447 set ::env(OpenIGTLink_BIN_DIR) [file normalize "@OpenIGTLink_DIR@/bin/$::OpenIGTLink_BUILD_SUBDIR"]
448
449 set ::env(BatchMake_DIR) [file normalize "@BatchMake_DIR@"]
450 set ::env(BatchMake_LIB_DIR) [file normalize "@BatchMake_DIR@/bin/$::BatchMake_BUILD_SUBDIR"]
451 set ::env(BatchMake_BIN_DIR) [file normalize "@BatchMake_DIR@/bin/$::BatchMake_BUILD_SUBDIR"]
452 set ::env(bmModuleDescriptionParser_DIR) $::env(BatchMake_BIN_DIR)
453
454
455 # Slicer3 Libs
456
457 set ::env(FreeSurfer_DIR) [file normalize "$::Slicer3_HOME/lib/$::BUILD_SUBDIR"]
458 set ::env(IGT_DIR) [file normalize "$::Slicer3_HOME/lib/$::BUILD_SUBDIR"]
459 set ::env(ITKCommandIO_DIR) [file normalize "$::Slicer3_HOME/lib/$::BUILD_SUBDIR"]
460 set ::env(LoadableModule_DIR) [file normalize "$::Slicer3_HOME/lib/$::BUILD_SUBDIR"]
461 set ::env(MGHImageIO_DIR) [file normalize "$::Slicer3_HOME/lib/$::BUILD_SUBDIR"]
462 set ::env(MRML_DIR) [file normalize "$::Slicer3_HOME/lib/$::BUILD_SUBDIR"]
463 set ::env(MRMLCLI_DIR) [file normalize "$::Slicer3_HOME/lib/$::BUILD_SUBDIR"]
464 set ::env(MRMLLogic_DIR) [file normalize "$::Slicer3_HOME/lib/$::BUILD_SUBDIR"]
465 set ::env(MRMLDisplayableManager_DIR) [file normalize "$::Slicer3_HOME/lib/$::BUILD_SUBDIR"]
466 set ::env(ModuleDescriptionParser_DIR) [file normalize "$::Slicer3_HOME/lib/$::BUILD_SUBDIR"]
467 set ::env(MRMLIDImageIO_DIR) [file normalize "$::Slicer3_HOME/lib/$::BUILD_SUBDIR"]
468 set ::env(Qdec_DIR) [file normalize "$::Slicer3_HOME/lib/$::BUILD_SUBDIR"]
469 set ::env(RemoteIO_DIR) [file normalize "$::Slicer3_HOME/lib/$::BUILD_SUBDIR"]
470 set ::env(FileWatcher_DIR) [file normalize "$::Slicer3_HOME/lib/$::BUILD_SUBDIR"]
471 set ::env(SlicerIO_DIR) [file normalize "$::Slicer3_HOME/lib/$::BUILD_SUBDIR"]
472 set ::env(tclap_DIR) [file normalize "$::Slicer3_HOME/lib/$::BUILD_SUBDIR"]
473 set ::env(vtkITK_DIR) [file normalize "$::Slicer3_HOME/lib/$::BUILD_SUBDIR"]
474 set ::env(vtkTeem_DIR) [file normalize "$::Slicer3_HOME/lib/$::BUILD_SUBDIR"]
475 set ::env(qCTKWidgets_DIR) [file normalize "$::Slicer3_HOME/lib/$::BUILD_SUBDIR"]
476 set ::env(qMRMLWidgets_DIR) [file normalize "$::Slicer3_HOME/lib/$::BUILD_SUBDIR"]
477 set ::env(qVTKWidgets_DIR) [file normalize "$::Slicer3_HOME/lib/$::BUILD_SUBDIR"]
478
479
480 # Slicer3 Base
481
482 set ::env(Slicer3_BIN_DIR) [file normalize "$::Slicer3_HOME/bin/$::BUILD_SUBDIR"]
483 set ::env(Slicer3_LIB_DIR) [file normalize "$::Slicer3_HOME/lib/$::BUILD_SUBDIR"]
484
485 set ::env(Slicer3_PLUGINS_DIR) [file normalize "$::env(Slicer3_HOME)/@Slicer3_INSTALL_PLUGINS_LIB_DIR@/$::BUILD_SUBDIR"]
486 set ::env(Slicer3_MODULES_DIR) [file normalize "$::env(Slicer3_HOME)/@Slicer3_INSTALL_MODULES_LIB_DIR@/$::BUILD_SUBDIR"]
487 set ::env(Slicer3_QTLOADABLEMODULES_DIR) [file normalize "$::env(Slicer3_HOME)/@Slicer3_INSTALL_QTLOADABLEMODULES_LIB_DIR@/$::BUILD_SUBDIR"]
488
489
490 # QtDesigner variable
491 StoreDirInEnvVar Slicer3_QT_PLUGIN_PATH "$::Slicer3_HOME/bin"
492 StoreDirInEnvVar CTK_QT_PLUGIN_PATH "$::env(CTK_DIR)/CTK-build/bin"
493
494 }
495
496 set ::env(Slicer3_VERSION) @Slicer3_VERSION_PATCH@
497
498 # If reportVTKErrors is nonzero, then we check for VTK errors and
499 # if a VTK error is found then launcher returns with error (causing the test to FAIL)
500 set ::LAUNCH(reportVTKErrors) 0
501 if {"@LAUNCHER_REPORT_VTK_ERRORS@"=="ON"} {
502 set ::LAUNCH(reportVTKErrors) 1
503 }
504 }
505
506 #-------------------------------------------------------------------------------
507 # .PROC launch_ParseArgs
508 # Setup launch options by parsing command-line parameters
509 # .ARGS
510 # command-line parameter list
511 # .END
512 #-------------------------------------------------------------------------------
513 proc launch_ParseArgs {argv} {
514
515 set ::LAUNCH(showSplash) 1
516 set ::LAUNCH(launchCommand) ""
517 set ::LAUNCH(launchDesigner) 0
518 set ::LAUNCH(detach) 0
519
520 #
521 # look for launcher-specific arguments
522 # --launch <program>
523 # or
524 # --launch-script <script.tcl>
525 # (this is a special case that runs the script
526 # in this interp and then exits)
527 #
528 # --designer - Attempt to start Qt Designer
529 #
530 # --no-error-popup - Don't display errors in a popup
531 #
532 # --detach - Run the command without monitoring the stdio
533 #
534 # and obey --no-splash, but don't swallow it (pass it on to slicer)
535 #
536
537 set argv0 [lindex $::argv 0]
538 set argv1 [lindex $::argv 1]
539 switch -glob -- $argv0 {
540 "--launch" {
541 if { $argv1 == "" } {
542 error "--launch requires argument of program to run"
543 } else {
544 set ::LAUNCH(launchCommand) $argv1
545 regsub -all "\\\\" $::LAUNCH(launchCommand) "/" ::LAUNCH(launchCommand)
546 set ::argv [lreplace $::argv 0 1]
547
548 # don't show splash if running a custom command
549 set ::LAUNCH(showSplash) 0
550 }
551 }
552 "--designer" {
553 if { $::Slicer3_USE_QT != "ON" } {
554 ShowAndLogError "Failed to start Qt Designer - Slicer is *NOT* built with QT Support"
555 exit $::EXIT_CODE_GENERIC_ERROR
556 }
557 set ::LAUNCH(launchDesigner) 1
558 set ::argv [lreplace $::argv 0 1]
559 set ::LAUNCH(showSplash) 0
560 }
561 "*.slicer" -
562 "--launch-script" {
563 set ::argv [lreplace $::argv 0 1]
564 uplevel #0 source $argv1
565 exit $::EXIT_CODE_NO_ERROR
566 }
567 }
568
569 # check for the arguments
570 set newargs ""
571 foreach arg $::argv {
572 switch -- $arg {
573 "--help" -
574 "-h" -
575 "--no_splash" -
576 "--no-splash" {
577 set ::LAUNCH(showSplash) 0
578 lappend newargs $arg ;# pass arg to Slicer3-real
579 }
580 "--test_mode" -
581 "--test-mode" {
582 set ::LAUNCH(showSplash) 0
583 lappend newargs $arg ;# pass arg to Slicer3-real
584 }
585 "--detach" {
586 set ::LAUNCH(detach) 1
587 }
588 "--no-error-popup" {
589 set ::LAUNCH(showErrorPopup) 0
590 }
591 default {
592 # escape any pipe characters
593 regsub -all "\\|" $arg "\\\\|" arg
594 lappend newargs $arg
595 }
596 }
597 }
598 set ::argv $newargs
599 }
600
601
602 #-------------------------------------------------------------------------------
603 # .PROC launch_SetPaths
604 # Setup system path variables to find Slicer libraries
605 # .ARGS
606 # .END
607 #-------------------------------------------------------------------------------
608 proc launch_SetPaths {} {
609
610 foreach var {LD_LIBRARY_PATH TCLLIBPATH DYLD_LIBRARY_PATH PATH} {
611 # if it is an empty string or doesn't exist, set the environment variable
612 if { ![info exists ::env($var)] || $::env($var) == "" } {
613 set ::env($var) " "
614 }
615 }
616
617 #
618 # add the necessary library directories, both Base and Modules, to the
619 # LD_LIBRARY_PATH environment variable
620 #
621 #
622 # set the base library paths for this build
623 #
624 if {$::env(BUILD) == $::SOLARIS ||
625 $::env(BUILD) == $::LINUX_64 ||
626 $::env(BUILD) == $::LINUX} {
627 # add vtk, slicer, and tcl bins
628 set ::env(LD_LIBRARY_PATH) $::env(VTK_BIN_DIR):$::env(LD_LIBRARY_PATH)
629 set ::env(LD_LIBRARY_PATH) $::env(CTK_DIR):$::env(LD_LIBRARY_PATH)
630 set ::env(LD_LIBRARY_PATH) $::env(CTK_BIN_DIR):$::env(LD_LIBRARY_PATH)
631 set ::env(LD_LIBRARY_PATH) $::env(PYTHONQT_DIR):$::env(LD_LIBRARY_PATH)
632 set ::env(LD_LIBRARY_PATH) $::env(PYTHONQT_BIN_DIR):$::env(LD_LIBRARY_PATH)
633 set ::env(LD_LIBRARY_PATH) $::env(KWWidgets_LIB_DIR):$::env(LD_LIBRARY_PATH)
634 set ::env(LD_LIBRARY_PATH) $::env(QT_LIB_DIR):$::env(LD_LIBRARY_PATH)
635 set ::env(LD_LIBRARY_PATH) $::env(OpenIGTLink_LIB_DIR):$::env(LD_LIBRARY_PATH)
636 set ::env(LD_LIBRARY_PATH) $::env(BatchMake_LIB_DIR):$::env(LD_LIBRARY_PATH)
637 set ::env(LD_LIBRARY_PATH) $::env(bmModuleDescriptionParser_DIR):$::env(LD_LIBRARY_PATH)
638 set ::env(LD_LIBRARY_PATH) $::env(ITK_BIN_DIR):$::env(LD_LIBRARY_PATH)
639 set ::env(LD_LIBRARY_PATH) $::env(TCL_DIR)/lib:$::env(LD_LIBRARY_PATH)
640 set ::env(LD_LIBRARY_PATH) $::env(TCL_DIR)/lib/itcl@INCR_TCL_VERSION_DOT@:$::env(LD_LIBRARY_PATH)
641 set ::env(LD_LIBRARY_PATH) $::env(TCL_DIR)/lib/itk@INCR_TCL_VERSION_DOT@:$::env(LD_LIBRARY_PATH)
642 set ::env(LD_LIBRARY_PATH) $::env(Teem_DIR):$::env(LD_LIBRARY_PATH)
643 set ::env(LD_LIBRARY_PATH) $::env(VTK_DIR):$::env(LD_LIBRARY_PATH)
644 set ::env(LD_LIBRARY_PATH) $::env(PYTHON_DIR)/lib:$::env(LD_LIBRARY_PATH)
645 set ::env(LD_LIBRARY_PATH) $::env(FreeSurfer_DIR):$::env(LD_LIBRARY_PATH)
646 set ::env(LD_LIBRARY_PATH) $::env(IGT_DIR):$::env(LD_LIBRARY_PATH)
647 set ::env(LD_LIBRARY_PATH) $::env(ITKCommandIO_DIR):$::env(LD_LIBRARY_PATH)
648 set ::env(LD_LIBRARY_PATH) $::env(LoadableModule_DIR):$::env(LD_LIBRARY_PATH)
649 set ::env(LD_LIBRARY_PATH) $::env(MGHImageIO_DIR):$::env(LD_LIBRARY_PATH)
650 set ::env(LD_LIBRARY_PATH) $::env(MRML_DIR):$::env(LD_LIBRARY_PATH)
651 set ::env(LD_LIBRARY_PATH) $::env(MRMLCLI_DIR):$::env(LD_LIBRARY_PATH)
652 set ::env(LD_LIBRARY_PATH) $::env(MRMLLogic_DIR):$::env(LD_LIBRARY_PATH)
653 set ::env(LD_LIBRARY_PATH) $::env(MRMLDisplayableManager_DIR):$::env(LD_LIBRARY_PATH)
654 set ::env(LD_LIBRARY_PATH) $::env(ModuleDescriptionParser_DIR):$::env(LD_LIBRARY_PATH)
655 set ::env(LD_LIBRARY_PATH) $::env(MRMLIDImageIO_DIR):$::env(LD_LIBRARY_PATH)
656 set ::env(LD_LIBRARY_PATH) $::env(Qdec_DIR):$::env(LD_LIBRARY_PATH)
657 set ::env(LD_LIBRARY_PATH) $::env(RemoteIO_DIR):$::env(LD_LIBRARY_PATH)
658 set ::env(LD_LIBRARY_PATH) $::env(FileWatcher_DIR):$::env(LD_LIBRARY_PATH)
659 set ::env(LD_LIBRARY_PATH) $::env(SlicerIO_DIR):$::env(LD_LIBRARY_PATH)
660 set ::env(LD_LIBRARY_PATH) $::env(tclap_DIR):$::env(LD_LIBRARY_PATH)
661 set ::env(LD_LIBRARY_PATH) $::env(vtkITK_DIR):$::env(LD_LIBRARY_PATH)
662 set ::env(LD_LIBRARY_PATH) $::env(vtkTeem_DIR):$::env(LD_LIBRARY_PATH)
663 set ::env(LD_LIBRARY_PATH) $::env(qCTKWidgets_DIR):$::env(LD_LIBRARY_PATH)
664 set ::env(LD_LIBRARY_PATH) $::env(qVTKWidgets_DIR):$::env(LD_LIBRARY_PATH)
665 set ::env(LD_LIBRARY_PATH) $::env(qMRMLWidgets_DIR):$::env(LD_LIBRARY_PATH)
666 set ::env(LD_LIBRARY_PATH) $::env(Slicer3_LIB_DIR):$::env(LD_LIBRARY_PATH)
667 set ::env(LD_LIBRARY_PATH) $::env(Slicer3_PLUGINS_DIR):$::env(LD_LIBRARY_PATH)
668 set ::env(LD_LIBRARY_PATH) $::env(Slicer3_MODULES_DIR):$::env(LD_LIBRARY_PATH)
669 set ::env(LD_LIBRARY_PATH) $::env(Slicer3_QTLOADABLEMODULES_DIR):$::env(LD_LIBRARY_PATH)
670 set ::env(LD_LIBRARY_PATH) $::env(X11_LIB_DIR):$::env(LD_LIBRARY_PATH)
671 set ::env(LD_LIBRARY_PATH) $::env(SFW_LIB_DIR):$::env(LD_LIBRARY_PATH)
672 set ::env(LD_LIBRARY_PATH) $::env(Slicer3_COMPILER_DIR):$::env(LD_LIBRARY_PATH)
673 set ::env(PATH) "$::env(PATH):$::env(TCL_DIR)/bin"
674 set ::env(PATH) "$::env(PATH):$::env(Teem_DIR)"
675 set ::env(PATH) "$::env(Slicer3_BIN_DIR):$::env(PATH)"
676 set ::env(PATH) "$::env(Slicer3_PLUGINS_DIR):$::env(PATH)"
677 set ::env(PATH) "$::env(Slicer3_MODULES_DIR):$::env(PATH)"
678 set ::env(PATH) "$::env(Slicer3_QTLOADABLEMODULES_DIR):$::env(PATH)"
679 set ::env(PATH) "$::env(QT_BINARY_DIR):$::env(PATH)"
680 set ::env(QTDESIGNER_EXE) "designer"
681 set ::env(QT_PLUGIN_PATH) "$::env(CTK_QT_PLUGIN_PATH):$::env(Slicer3_QT_PLUGIN_PATH)"
682 } elseif {$::env(BUILD) == $::DARWIN || $::env(BUILD) == $::DARWIN_X86} {
683 # add vtk, slicer, and tcl bins
684 set ::env(DYLD_LIBRARY_PATH) $::env(VTK_BIN_DIR):$::env(DYLD_LIBRARY_PATH)
685 set ::env(DYLD_LIBRARY_PATH) $::env(CTK_DIR):$::env(DYLD_LIBRARY_PATH)
686 set ::env(DYLD_LIBRARY_PATH) $::env(CTK_BIN_DIR):$::env(DYLD_LIBRARY_PATH)
687 set ::env(DYLD_LIBRARY_PATH) $::env(PYTHONQT_DIR):$::env(DYLD_LIBRARY_PATH)
688 set ::env(DYLD_LIBRARY_PATH) $::env(PYTHONQT_BIN_DIR):$::env(DYLD_LIBRARY_PATH)
689 set ::env(DYLD_LIBRARY_PATH) $::env(KWWidgets_LIB_DIR):$::env(DYLD_LIBRARY_PATH)
690 set ::env(DYLD_LIBRARY_PATH) $::env(QT_LIB_DIR):$::env(DYLD_LIBRARY_PATH)
691 set ::env(DYLD_LIBRARY_PATH) $::env(QT_FRAMEWORK_DIRS)$::env(DYLD_LIBRARY_PATH)
692 set ::env(DYLD_LIBRARY_PATH) $::env(OpenIGTLink_LIB_DIR):$::env(DYLD_LIBRARY_PATH)
693 set ::env(DYLD_LIBRARY_PATH) $::env(BatchMake_LIB_DIR):$::env(DYLD_LIBRARY_PATH)
694 set ::env(DYLD_LIBRARY_PATH) $::env(bmModuleDescriptionParser_DIR):$::env(DYLD_LIBRARY_PATH)
695 set ::env(DYLD_LIBRARY_PATH) $::env(ITK_BIN_DIR):$::env(DYLD_LIBRARY_PATH)
696 set ::env(DYLD_LIBRARY_PATH) $::env(TCL_DIR)/lib:$::env(DYLD_LIBRARY_PATH)
697 set ::env(DYLD_LIBRARY_PATH) $::env(TCL_DIR)/lib/itcl@INCR_TCL_VERSION_DOT@:$::env(DYLD_LIBRARY_PATH)
698 set ::env(DYLD_LIBRARY_PATH) $::env(TCL_DIR)/lib/itk@INCR_TCL_VERSION_DOT@:$::env(DYLD_LIBRARY_PATH)
699 set ::env(DYLD_LIBRARY_PATH) $::env(Teem_DIR):$::env(DYLD_LIBRARY_PATH)
700 set ::env(DYLD_LIBRARY_PATH) $::env(VTK_DIR):$::env(DYLD_LIBRARY_PATH)
701 set ::env(DYLD_LIBRARY_PATH) $::env(PYTHON_DIR)/lib:$::env(DYLD_LIBRARY_PATH)
702 set ::env(DYLD_LIBRARY_PATH) $::env(FreeSurfer_DIR):$::env(DYLD_LIBRARY_PATH)
703 set ::env(DYLD_LIBRARY_PATH) $::env(IGT_DIR):$::env(DYLD_LIBRARY_PATH)
704 set ::env(DYLD_LIBRARY_PATH) $::env(ITKCommandIO_DIR):$::env(DYLD_LIBRARY_PATH)
705 set ::env(DYLD_LIBRARY_PATH) $::env(LoadableModule_DIR):$::env(DYLD_LIBRARY_PATH)
706 set ::env(DYLD_LIBRARY_PATH) $::env(MGHImageIO_DIR):$::env(DYLD_LIBRARY_PATH)
707 set ::env(DYLD_LIBRARY_PATH) $::env(MRML_DIR):$::env(DYLD_LIBRARY_PATH)
708 set ::env(DYLD_LIBRARY_PATH) $::env(MRMLCLI_DIR):$::env(DYLD_LIBRARY_PATH)
709 set ::env(DYLD_LIBRARY_PATH) $::env(MRMLLogic_DIR):$::env(DYLD_LIBRARY_PATH)
710 set ::env(DYLD_LIBRARY_PATH) $::env(MRMLDisplayableManager_DIR):$::env(DYLD_LIBRARY_PATH)
711 set ::env(DYLD_LIBRARY_PATH) $::env(ModuleDescriptionParser_DIR):$::env(DYLD_LIBRARY_PATH)
712 set ::env(DYLD_LIBRARY_PATH) $::env(MRMLIDImageIO_DIR):$::env(DYLD_LIBRARY_PATH)
713 set ::env(DYLD_LIBRARY_PATH) $::env(Qdec_DIR):$::env(DYLD_LIBRARY_PATH)
714 set ::env(DYLD_LIBRARY_PATH) $::env(RemoteIO_DIR):$::env(DYLD_LIBRARY_PATH)
715 set ::env(DYLD_LIBRARY_PATH) $::env(FileWatcher_DIR):$::env(DYLD_LIBRARY_PATH)
716 set ::env(DYLD_LIBRARY_PATH) $::env(SlicerIO_DIR):$::env(DYLD_LIBRARY_PATH)
717 set ::env(DYLD_LIBRARY_PATH) $::env(tclap_DIR):$::env(DYLD_LIBRARY_PATH)
718 set ::env(DYLD_LIBRARY_PATH) $::env(vtkITK_DIR):$::env(DYLD_LIBRARY_PATH)
719 set ::env(DYLD_LIBRARY_PATH) $::env(vtkTeem_DIR):$::env(DYLD_LIBRARY_PATH)
720 set ::env(DYLD_LIBRARY_PATH) $::env(qCTKWidgets_DIR):$::env(DYLD_LIBRARY_PATH)
721 set ::env(DYLD_LIBRARY_PATH) $::env(qVTKWidgets_DIR):$::env(DYLD_LIBRARY_PATH)
722 set ::env(DYLD_LIBRARY_PATH) $::env(qMRMLWidgets_DIR):$::env(DYLD_LIBRARY_PATH)
723 set ::env(DYLD_LIBRARY_PATH) $::env(Slicer3_LIB_DIR):$::env(DYLD_LIBRARY_PATH)
724 set ::env(DYLD_LIBRARY_PATH) $::env(Slicer3_PLUGINS_DIR):$::env(DYLD_LIBRARY_PATH)
725 set ::env(DYLD_LIBRARY_PATH) $::env(Slicer3_MODULES_DIR):$::env(DYLD_LIBRARY_PATH)
726 set ::env(DYLD_LIBRARY_PATH) $::env(Slicer3_QTLOADABLEMODULES_DIR):$::env(DYLD_LIBRARY_PATH)
727 set ::env(PATH) "$::env(PATH):$::env(TCL_DIR)/bin"
728 set ::env(PATH) "$::env(PATH):$::env(Teem_DIR)"
729 set ::env(PATH) "$::env(Slicer3_BIN_DIR):$::env(PATH)"
730 set ::env(PATH) "$::env(Slicer3_PLUGINS_DIR):$::env(PATH)"
731 set ::env(PATH) "$::env(Slicer3_MODULES_DIR):$::env(PATH)"
732 set ::env(PATH) "$::env(Slicer3_QTLOADABLEMODULES_DIR):$::env(PATH)"
733 set ::env(PATH) "$::env(QT_BINARY_DIR):$::env(PATH)"
734 set ::env(QTDESIGNER_EXE) "Designer.app"
735 set ::env(QT_PLUGIN_PATH) "$::env(CTK_QT_PLUGIN_PATH):$::env(Slicer3_QT_PLUGIN_PATH)"
736 } elseif {$::env(BUILD) == $::WINDOWS} {
737 # add vtk, slicer, and tcl bins
738 set ::env(Path) $::env(VTK_BIN_DIR)\;$::env(Path)
739 set ::env(Path) $::env(CTK_BIN_DIR)\;$::env(Path)
740 set ::env(Path) $::env(PYTHONQT_BIN_DIR)\;$::env(Path)
741 set ::env(Path) $::env(KWWidgets_BIN_DIR)\;$::env(Path)
742 set ::env(Path) $::env(QT_LIB_DIR)\;$::env(Path)
743 set ::env(Path) $::env(OpenIGTLink_BIN_DIR)\;$::env(Path)
744 set ::env(Path) $::env(BatchMake_BIN_DIR)\;$::env(Path)
745 set ::env(Path) $::env(bmModuleDescriptionParser_DIR)\;$::env(Path)
746 set ::env(Path) $::env(ITK_BIN_DIR)\;$::env(Path)
747
748 # TODO: TCL_DIR for super-build is not calculated correctly
749 # - specify both version so tkinter can load on windows where there is no rpath
750 # and on traditional non-rpath slicer builds
751 set ::env(Path) $::env(TCL_DIR)/bin\;$::env(Path)
752 set ::env(Path) $::env(TCL_DIR)/lib/itcl@INCR_TCL_VERSION_DOT@\;$::env(Path)
753 set ::env(Path) $::env(TCL_DIR)/lib/itk@INCR_TCL_VERSION_DOT@\;$::env(Path)
754
755 set ::env(Path) $::env(TCL_DIR)/../tcl-build/bin\;$::env(Path)
756 set ::env(Path) $::env(TCL_DIR)/../lib/itcl@INCR_TCL_VERSION_DOT@\;$::env(Path)
757 set ::env(Path) $::env(TCL_DIR)/../lib/itk@INCR_TCL_VERSION_DOT@\;$::env(Path)
758
759 set ::env(Path) $::env(Teem_DIR)\;$::env(Path)
760 set ::env(Path) $::env(PYTHON_DIR)\;$::env(Path)
761 set ::env(Path) $::env(VTK_DIR)\;$::env(Path)
762 set ::env(Path) $::env(FreeSurfer_DIR)\;$::env(Path)
763 set ::env(Path) $::env(IGT_DIR)\;$::env(Path)
764 set ::env(Path) $::env(ITKCommandIO_DIR)\;$::env(Path)
765 set ::env(Path) $::env(LoadableModule_DIR)\;$::env(Path)
766 set ::env(Path) $::env(MGHImageIO_DIR)\;$::env(Path)
767 set ::env(Path) $::env(MRML_DIR)\;$::env(Path)
768 set ::env(Path) $::env(MRMLCLI_DIR)\;$::env(Path)
769 set ::env(Path) $::env(MRMLLogic_DIR)\;$::env(Path)
770 set ::env(Path) $::env(MRMLDisplayableManager_DIR)\;$::env(Path)
771 set ::env(Path) $::env(ModuleDescriptionParser_DIR)\;$::env(Path)
772 set ::env(Path) $::env(MRMLIDImageIO_DIR)\;$::env(Path)
773 set ::env(Path) $::env(Qdec_DIR)\;$::env(Path)
774 set ::env(Path) $::env(RemoteIO_DIR)\;$::env(Path)
775 set ::env(Path) $::env(FileWatcher_DIR)\;$::env(Path)
776 set ::env(Path) $::env(SlicerIO_DIR)\;$::env(Path)
777 set ::env(Path) $::env(tclap_DIR)\;$::env(Path)
778 set ::env(Path) $::env(vtkITK_DIR)\;$::env(Path)
779 set ::env(Path) $::env(vtkTeem_DIR)\;$::env(Path)
780 set ::env(Path) $::env(qCTKWidgets_DIR)\;$::env(Path)
781 set ::env(Path) $::env(qVTKWidgets_DIR)\;$::env(Path)
782 set ::env(Path) $::env(qMRMLWidgets_DIR)\;$::env(Path)
783 set ::env(Path) $::env(Slicer3_BIN_DIR)\;$::env(Path)
784 set ::env(Path) $::env(Slicer3_LIB_DIR)\;$::env(Path)
785 set ::env(Path) $::env(Slicer3_PLUGINS_DIR)\;$::env(Path)
786 set ::env(Path) $::env(Slicer3_MODULES_DIR)\;$::env(Path)
787 set ::env(Path) $::env(Slicer3_QTLOADABLEMODULES_DIR)\;$::env(Path)
788 set ::env(Path) $::env(QT_BINARY_DIR)\;$::env(Path)
789 set ::env(QTDESIGNER_EXE) "designer.exe"
790 set ::env(QT_PLUGIN_PATH) $::env(CTK_QT_PLUGIN_PATH)\;$::env(Slicer3_QT_PLUGIN_PATH)
791 } else {
792 ShowAndLogError "Libraries: unknown build $::env(BUILD)"
793 }
794
795 # set the base tcl/tk library paths, using the previously defined TCL_LIB_DIR
796 set ::env(TCL_LIBRARY) "$::env(TCL_DIR)/lib/tcl@TCL_TK_VERSION_DOT@"
797 set ::env(TK_LIBRARY) "$::env(TCL_DIR)/lib/tk@TCL_TK_VERSION_DOT@"
798
799 #
800 # add the default search locations for tcl packages
801 #
802 set ::env(TCLLIBPATH) "$::env(VTK_DIR)/Wrapping/Tcl $::env(TCLLIBPATH)"
803 set ::env(TCLLIBPATH) "$::env(KWWidgets_DIR)/Wrapping/Tcl $::env(TCLLIBPATH)"
804 if { [info exists ::env(OpenIGTLink_DIR] } {
805 set ::env(TCLLIBPATH) "$::env(OpenIGTLink_DIR)/Wrapping/Tcl $::env(TCLLIBPATH)"
806 }
807 set ::env(TCLLIBPATH) "$::env(Slicer3_HOME)/Base/Wrapping/Tcl/vtkSlicerBase $::env(TCLLIBPATH)"
808 set ::env(TCLLIBPATH) "$::env(TCL_DIR)/lib/itcl@INCR_TCL_VERSION_DOT@ $::env(TCLLIBPATH)"
809 set ::env(TCLLIBPATH) "$::env(TCL_DIR)/lib/itk@INCR_TCL_VERSION_DOT@ $::env(TCLLIBPATH)"
810 set ::env(TCLLIBPATH) "$::env(TCL_DIR)/lib/iwidgets4.0.1 $::env(TCLLIBPATH)"
811 set ::env(TCLLIBPATH) "$::env(TCL_DIR)/lib/blt2.4 $::env(TCLLIBPATH)"
812
813 #
814 # add the default search locations for python packages for a slicer build of python
815 #
816
817 if { "@Slicer3_USE_SYSTEM_PYTHON@" != "ON" } {
818 if {$::env(BUILD) == $::WINDOWS} {
819 set SEP ";"
820 set ::env(PYTHON_DIR) "$::env(PYTHON_DIR)/.."
821 } else {
822 set SEP ":"
823 }
824
825 set ::env(PYTHONHOME) "$::env(PYTHON_DIR)"
826
827 # check for existing variable to avoid empty entries in PYTHONPATH
828 if { ![info exists ::env(PYTHONPATH)] } {
829 set ::env(PYTHONPATH) "$::env(PYTHON_DIR)/lib"
830 } else {
831 set ::env(PYTHONPATH) "$::env(PYTHON_DIR)/lib$SEP$::env(PYTHONPATH)"
832 }
833 set ::env(PYTHONPATH) "$::env(PYTHON_DIR)/lib/lib-tk$SEP$::env(PYTHONPATH)"
834 set ::env(PYTHONPATH) "$::env(PYTHON_DIR)/lib/site-packages$SEP$::env(PYTHONPATH)"
835 set ::env(PYTHONPATH) "$::env(PYTHON_DIR)/lib/site-packages/numpy$SEP$::env(PYTHONPATH)"
836 set ::env(PYTHONPATH) "$::env(PYTHON_DIR)/lib/site-packages/numpy/lib$SEP$::env(PYTHONPATH)"
837 set ::env(PYTHONPATH) "$::env(PYTHON_DIR)/lib/site-packages/numpy/core$SEP$::env(PYTHONPATH)"
838 set ::env(PYTHONPATH) "$::env(PYTHON_DIR)/lib/python2.6$SEP$::env(PYTHONPATH)"
839 set ::env(PYTHONPATH) "$::env(PYTHON_DIR)/lib/python2.6/site-packages$SEP$::env(PYTHONPATH)"
840 set ::env(PYTHONPATH) "$::env(PYTHON_DIR)/lib/python2.6/lib-tk$SEP$::env(PYTHONPATH)"
841 set ::env(PYTHONPATH) "$::env(PYTHON_DIR)/lib/python2.6/site-packages/numpy/lib$SEP$::env(PYTHONPATH)"
842 set ::env(PYTHONPATH) "$::env(PYTHON_DIR)/lib/python2.6/site-packages/numpy/core$SEP$::env(PYTHONPATH)"
843 set ::env(PYTHONPATH) "$::env(Slicer3_HOME)/lib/Slicer3/SlicerBaseGUI/Python$SEP$::env(PYTHONPATH)"
844 set ::env(PYTHONPATH) "$::env(Slicer3_HOME)/lib/site-packages$SEP$::env(PYTHONPATH)"
845 set ::env(PYTHONPATH) "$::env(VTK_BIN_DIR)$SEP$::env(PYTHONPATH)"
846 set ::env(PYTHONPATH) "$::env(Slicer3_HOME)/lib/FreeSurfer$SEP$::env(PYTHONPATH)"
847 set ::env(PYTHONPATH) "$::env(Slicer3_HOME)/lib/MRML$SEP$::env(PYTHONPATH)"
848 set ::env(PYTHONPATH) "$::env(Slicer3_HOME)/lib/MRMLLogic$SEP$::env(PYTHONPATH)"
849 set ::env(PYTHONPATH) "$::env(Slicer3_HOME)/lib/RemoteIO$SEP$::env(PYTHONPATH)"
850 set ::env(PYTHONPATH) "$::env(Slicer3_HOME)/lib/vtkTeem$SEP$::env(PYTHONPATH)"
851 }
852 }
853
854 #-------------------------------------------------------------------------------
855 # .PROC launch_SplashScreen
856 # Show splash screen (optional)
857 # .ARGS
858 # .END
859 #-------------------------------------------------------------------------------
860 proc launch_SplashScreen {} {
861
862 if { $::LAUNCH(showSplash) } {
863
864 if { ($::env(BUILD) == $::DARWIN || $::env(BUILD) == $::DARWIN_X86) || [catch "package require Tk"] } {
865 puts "Setting up launch environment..."
866 set $::LAUNCH(showSplash) 0
867 return
868 }
869
870 wm withdraw .
871 launch_SplashShow
872 }
873
874 # windows always has a display, so get rid of the default window
875 if { [string match -nocase "windows*" $::tcl_platform(os)] } {
876 wm withdraw .
877 }
878 }
879
880
881 #-------------------------------------------------------------------------------
882 # .PROC SplashKill
883 # Release the application grab on the splash window, destroy the window, and delete the image.
884 # .ARGS
885 # .END
886 #-------------------------------------------------------------------------------
887 proc launch_SplashKill {} {
888
889 # because this is called from bgerror, don't cause any errors
890 if {[info command .splash] != ""} {
891 # release the grab
892 grab release .splash
893 destroy .splash
894 }
895 }
896
897 #-------------------------------------------------------------------------------
898 # .PROC launch_SplashAnimate
899 # Animate splash screen by drawing dots.
900 # .ARGS
901 # delay before displaying a new point
902 # .END
903 #-------------------------------------------------------------------------------
904 proc launch_SplashAnimate { {delayms 100} } {
905 if {[info command .splash] != ""} {
906 set dots [.splash.v cget -text]
907 if { $dots == "**********" } {
908 set dots "*"
909 } else {
910 set dots *$dots
911 }
912 .splash.v configure -text $dots
913 update
914 after $delayms "launch_SplashAnimate $delayms"
915 }
916 }
917
918 #-------------------------------------------------------------------------------
919 # .PROC SplashShow
920 # Builds and displays a splash screen, .splash
921 # .ARGS
922 # int delayms how long to show the splash screen, defaults to 7000, in milliseconds
923 # .END
924 #-------------------------------------------------------------------------------
925 proc launch_SplashShow { {delayms 7000} } {
926
927 set oscaling [tk scaling]
928 # ignore screen based default scaling and pick scale so words show up nicely inside box
929 tk scaling 1.5
930 set width 500
931 set height 200
932 set splashfont [font create -family Helvetica -size 10]
933 set splashfontb [font create -family Helvetica -size 10 -weight bold]
934 toplevel .splash -relief raised -borderwidth 6 -width $width -height $height -bg white
935 wm overrideredirect .splash 1
936 set xcorner [expr [winfo screenwidth .splash]/2-($width/2)]
937 set ycorner [expr [winfo screenheight .splash]/2-($height/2)]
938 wm geometry .splash +$xcorner+$ycorner
939
940 label .splash.t1 -text "3D Slicer starting up..." -bg white -font $splashfontb
941 label .splash.t2 -text "" -bg white -fg red -font $splashfont
942 label .splash.v -text "" -bg white -fg darkblue -font $splashfont
943
944 place .splash.t1 -relx 0.5 -rely 0.30 -anchor center
945 #place .splash.t2 -relx 0.5 -rely 0.50 -anchor center
946 place .splash.v -relx 0.5 -rely 0.60 -anchor center
947 update
948
949 after 100 "launch_SplashAnimate 300"
950
951 bind .splash <1> launch_SplashKill
952 after 10000 launch_SplashKill
953 tk scaling $oscaling
954 }
955
956 #-------------------------------------------------------------------------------
957 # .PROC launch_FileEvent
958 # helper proc to handle text coming from the child process
959 # if output is set to 0, a variable ::globallines has to exist to buffer the lines
960 # .ARGS
961 # file pointer, output enable switch
962 # .END
963 #-------------------------------------------------------------------------------
964 set ::count 0
965 proc launch_FileEvent {fp {output 1}} {
966 if {[eof $fp]} {
967 set ret [catch "close $fp" res]
968 set ::saved_errorCode $::errorCode
969 set ::saved_errorInfo $::errorInfo
970 set ::saved_result $res
971 set ::saved_return $ret
972 set ::END 1
973 } else {
974 gets $fp line
975 if {$output == 1} {
976 puts $line
977 } else {
978 if {$line != ""} {
979 append ::globallines $line
980 }
981 }
982 launch_SplashKill ;# just in case the pre-splash screen is still up
983 }
984 }
985
986 #-------------------------------------------------------------------------------
987 # .PROC launch_RunProgram
988 # run the actual program
989 # - check for a --launch argument for a replacement main app, otherwise run Slicer3-real
990 # - process the arguments to adjust the escape characters
991 # - launch the main app as a child process and monitor the stdout and return codes
992 # .ARGS
993 # .END
994 #-------------------------------------------------------------------------------
995 proc launch_RunProgram {} {
996
997 #
998 # change from tcl escape to shell escape for command line arguments
999 # that contain spaces -- note that shell notation only works for a single
1000 # level of nesting
1001 # - change backslashes to forward slashes (for windows paths)
1002 # - escape the spaces in each of the arguments (non-windows only)
1003 # - handle any escaped | where the \ was changed to / by mistake
1004 #
1005 regsub -all "\\\\" $::argv "/" ::argv
1006 regsub -all "/\\|" $::argv "\\\\|" ::argv
1007 if {$::env(BUILD) != $::WINDOWS} {
1008 set newargv ""
1009 foreach a $::argv {
1010 regsub -all " " $a "\\\ " a
1011 lappend newargv $a
1012 }
1013 set ::argv $newargv
1014 }
1015
1016 if {$::env(BUILD) != $::WINDOWS} {
1017 # turn curly braces into quotes
1018 regsub -all "{|}" $::argv "\\\"" ::argv
1019 }
1020
1021 #
1022 # If launchDesigner True,
1023 # let's update launchCommand with the complete path to Qt Designer
1024 #
1025
1026 if { $::LAUNCH(launchDesigner)} {
1027 set ::LAUNCH(launchCommand) $::env(QT_BINARY_DIR)/$::env(QTDESIGNER_EXE)
1028 puts "Starting $::LAUNCH(launchCommand)"
1029 puts "Loading plugins from $::env(Slicer3_QT_PLUGIN_PATH)/designer and $::env(CTK_QT_PLUGIN_PATH)"
1030 }
1031
1032 #
1033 # launch the slicer main script as a sub-process and monitor the output
1034 # - process is started with the 'open' command through a pipe
1035 # - the file_event callback is triggered when subprocess has written to stdout
1036 # - pipe is closed when process exits, causing launcher to exit too.
1037 #
1038 # why? well, some messages only go to console stdout and we don't want to lose them.
1039 # Also, on windows if you block waiting for the process to exit the launcher would
1040 # be "Not Responding" and things like screen savers and power management might not
1041 # work right.
1042 #
1043
1044 #
1045 # determine the correct arguments and executable for the platform
1046 #
1047 if { $::LAUNCH(launchCommand) == "" } {
1048 if { [catch { set ::LAUNCH(launchCommand) $::Slicer3_REAL } res] } {
1049 ShowAndLogError "Failed to execute Slicer3_REAL: $res"
1050 exit $::EXIT_CODE_GENERIC_ERROR
1051 }
1052 }
1053
1054 set ::errorCode ""
1055 set ::errorInfo "" ;# reset error info so we are sure to get errors from the
1056 # launch and not leftovers from previous 'catch' calls
1057
1058 # detach mode: start the executable and then go away
1059 if { $::LAUNCH(detach) } {
1060 exec $::LAUNCH(launchCommand) $::argv &
1061 exit $::EXIT_CODE_NO_ERROR
1062 }
1063
1064 if {$::env(BUILD) == $::WINDOWS} {
1065 if { [catch { set fp [open "| \"$::LAUNCH(launchCommand)\" $::argv" r] } res] } {
1066 ShowAndLogError "Failed to execute $::LAUNCH(launchCommand): $res"
1067 exit $::EXIT_CODE_GENERIC_ERROR
1068 }
1069 } else {
1070 if { [catch { set fp [open "| sh -c \"'$::LAUNCH(launchCommand)' $::argv \" |& cat" r] } res] } {
1071 ShowAndLogError "Failed to execute $::LAUNCH(launchCommand): $res"
1072 exit $::EXIT_CODE_GENERIC_ERROR
1073 }
1074 }
1075
1076 #
1077 # now go into a loop waiting for the child process
1078 # - the launch_FileEvent handles output from the child and
1079 # also detects when the child exits and sets global variables
1080 # to handle the return code
1081 #
1082 fileevent $fp readable "launch_FileEvent $fp"
1083 set ::END 0
1084 while { ![catch "pid $fp"] && ![eof $fp] } {
1085 vwait ::END
1086 }
1087
1088 #
1089 # get the actual exit code of the child process
1090 #
1091 # strip the tcl stack information from the end of the errorInfo string
1092 set index [string last " while executing" $::saved_errorInfo]
1093 set result ""
1094 if { $index != -1 } {
1095 set result [string range $::saved_errorInfo 0 $index]
1096 }
1097
1098 set codeString [lindex $::saved_errorCode 0]
1099 switch $codeString {
1100 "" -
1101 "NONE" {
1102 set code "$::EXIT_CODE_NO_ERROR"
1103 }
1104 "CHILDKILLED" {
1105 set code "$::EXIT_CODE_CHILD_KILLED"
1106 set result "$result\n$::saved_errorCode"
1107 }
1108 "CHILDSTATUS" {
1109 set code [lindex $::saved_errorCode 2]
1110 }
1111 default {
1112 set code "$::EXIT_CODE_GENERIC_ERROR"
1113 set result "Exceptional errorCode: $::saved_errorCode, $::saved_errorCode\n$::saved_errorInfo"
1114 }
1115 }
1116
1117 # If the process returned without errors, but there are VTK errors in the output, then return with error code
1118 if { $code == "$::EXIT_CODE_NO_ERROR" && $::LAUNCH(reportVTKErrors) != 0 } {
1119 set vtkErrorString "ERROR: In "
1120 if { [string first $vtkErrorString $result] != -1 } {
1121 set code "$::EXIT_CODE_VTK_ERROR"
1122 set result "VTK error\n $result"
1123 }
1124 }
1125
1126 if { $result != "" } {
1127 if {$code != "$::EXIT_CODE_NO_ERROR"} {
1128 ShowAndLogError "Launch $::LAUNCH(launchCommand) returned with error: $result"
1129 } else {
1130 puts "$result"
1131 }
1132
1133 }
1134 exit $code
1135 }
1136
1137 #-------------------------------------------------------------------------------
1138 # .PROC launch_ImportModulePaths
1139 # run the program with the argument --print-module-paths to get the module path from
1140 # registry so dependencies can be set before the actual program launch
1141 # .ARGS
1142 # .END
1143 #-------------------------------------------------------------------------------
1144 proc launch_ImportModulePaths {} {
1145
1146 set ::globallines "" ; # reset buffer for global lines
1147
1148 if { ![info exists ::Slicer3_REAL] || ![file exists $::Slicer3_REAL] } {
1149 puts "No Slicer3-real executable, so not adding module paths"
1150 return
1151 }
1152
1153 if { [string match "*QT*" $::Slicer3_REAL] } {
1154 # TODO: qt version doesn't respond to the --print-module-paths
1155 return
1156 }
1157
1158 # run the program with argument --print-module-paths
1159 if {$::env(BUILD) == $::WINDOWS} {
1160 set fp [open "| \"$::Slicer3_REAL\" --print-module-paths" r]
1161 } else {
1162 set fp [open "| sh -c \"'$::Slicer3_REAL' --print-module-paths \" |& cat" r]
1163 }
1164
1165 # call the helper but do not pass thru output directly!
1166 fileevent $fp readable "launch_FileEvent $fp 0"
1167 set ::END 0
1168 while { ![catch "pid $fp"] && ![eof $fp] } {
1169 vwait ::END
1170 }
1171
1172 # we should have the module paths now
1173
1174 # parse the svn revision of the version file
1175 set dp [open "$::env(Slicer3_HOME)/lib/Slicer3/Slicer3Version.txt" r]
1176 set data [read $dp]
1177 close $dp
1178
1179 set exp {svnrevision ([0-9]+)}
1180
1181 foreach {lines} [regexp -line $exp $data matched svnrevision] {
1182 if {$lines==1} {
1183 # find only one line
1184 # substitute @SVN@ in $result with the found svnrevision
1185 set newpath [string map [list \@SVN\@ $svnrevision] $::globallines]
1186 }
1187 }
1188 # set the dependencies
1189 if {$::env(BUILD) == $::SOLARIS ||
1190 $::env(BUILD) == $::LINUX_64 ||
1191 $::env(BUILD) == $::LINUX} {
1192 set ::env(LD_LIBRARY_PATH) ":$::env(LD_LIBRARY_PATH)"
1193 set ::env(LD_LIBRARY_PATH) "$newpath$::env(LD_LIBRARY_PATH)"
1194 set ::env(PATH) "$::env(PATH):$newpath"
1195 } elseif {$::env(BUILD) == $::DARWIN || $::env(BUILD) == $::DARWIN_X86} {
1196 set ::env(DYLD_LIBRARY_PATH) ":$::env(DYLD_LIBRARY_PATH)"
1197 set ::env(DYLD_LIBRARY_PATH) "$newpath$::env(DYLD_LIBRARY_PATH)"
1198 set ::env(PATH) "$::env(PATH):$newpath"
1199 } elseif {$::env(BUILD) == $::WINDOWS} {
1200 set newpath [string map [list : \;] $newpath] ; # really needed?
1201 set ::env(Path) $newpath\;$::env(Path)
1202 }
1203
1204 }
1205
1206
1207 ######
1208 ####### The actual steps for launching:
1209 ######
1210
1211 if { [catch launch_SetEnvironment res] } {
1212 ShowAndLogError "launch_SetEnvironment failed: $res"
1213 exit $::EXIT_CODE_LAUNCHING_ERROR
1214 }
1215 if { [catch {launch_ParseArgs $argv} res] } {
1216 ShowAndLogError "launch_ParseArgs failed: $res"
1217 exit $::EXIT_CODE_LAUNCHING_ERROR
1218 }
1219 if { [catch launch_SplashScreen res] } {
1220 ShowAndLogError "launch_SplashScreen failed: $res"
1221 }
1222 if { [catch launch_SetPaths res] } {
1223 ShowAndLogError "launch_SetPaths failed: $res"
1224 exit $::EXIT_CODE_LAUNCHING_ERROR
1225 }
1226 if { [catch launch_ImportModulePaths res] } {
1227 ShowAndLogError "launch_ImportModulePaths failed: $res"
1228 exit $::EXIT_CODE_LAUNCHING_ERROR
1229 }
1230 # run program until it exits and then exit this script with the ouput
1231 if { [catch launch_RunProgram res] } {
1232 ShowAndLogError "launch_RunProgram failed: $res"
1233 exit $::EXIT_CODE_LAUNCHING_ERROR
1234 }

Properties

Name Value
svn:executable *

  Subversion  TortoiseSVN  ViewVC