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

View of /trunk/launch.tcl.in

Parent Directory Parent Directory Revision Log Revision Log


Revision 16991  Download Blame
File size: 50477 byte(s)
COMP: detect cygwin with uname not OSTYPE environment variable

See discussion here:

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

Properties

Name Value
svn:executable *

  Subversion  TortoiseSVN  ViewVC