launch.tcl.in 51.2 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/sh
# the next line restarts using tclsh \
    exec wish "$0" "$@"

#
# launch.tcl
#
# This script is used to set platform-specific variables for the shell
# that will be used to launch slicer.
#
# - what platform you're on so correct libs are loaded
# - what modules are present so they can be loaded
# - set all PATH, LD_LIBRARY_PATH, TCLLIBPATH, and other shell-level
#   variables to reflect that state
#   
# This is a tcl script rather than a .bat or .sh file so it can handle all 
# the details in one place for all platforms.
#
19
20
# This script is used for both the slicer build directory and for the slicer
# install directory.
21
22
23
24
25
#
# Note: the version of this file called launch.tcl.in will be configured by 
# cmake such that tokens between @ signs will be replaced by the variable 
# from the cmake cache
#
26
27
28
29
30

# set default error code and info so we don't get confused later if no error has
# actually occurred...
set ::errorCode 0
set ::errorInfo ""
31

32
33
34
35
36
set ::EXIT_CODE_NO_ERROR 0
set ::EXIT_CODE_CHILD_KILLED 1
set ::EXIT_CODE_GENERIC_ERROR -1
set ::EXIT_CODE_VTK_ERROR -2
set ::EXIT_CODE_LAUNCHING_ERROR -3
37

38
39
40
41
42
43
44
45
46
47
48
49
50
51

#-------------------------------------------------------------------------------
# .PROC LogToFile
# Helper function.
# Use this function to write a string to launcher-log.txt
# .ARGS
# message to be logged
# .END
#-------------------------------------------------------------------------------
proc LogToFile { msg } {
  set fd [open "launcher-log.txt" "w"]
  puts $fd $msg
}

52
53
54
#-------------------------------------------------------------------------------
# .PROC ShowAndLogError
# Helper function.
55
56
57
58
59
# Use this function instead of puts to both log an error message and
# show it for the user in a popup window
# (The popup window is automatically closed after a few seconds to allow some
# time for the user to read, but allow application exit in a reasonable time
# for automated tests.)
60
61
62
63
64
# .ARGS
# message to be displayed
# .END
#-------------------------------------------------------------------------------
set ::LAUNCH(showErrorPopup) 1
65
66
67
proc ShowAndLogError { msg } {
    set autoCloseTimeoutMs 10000 
    puts $msg
68
69
70
71
72
73
74
    if { $::LAUNCH(showErrorPopup) } {
        if { [catch "package require Tk" res] } {
            puts "Error displaying error in a popup: $res"
        } else {
            after $autoCloseTimeoutMs {destroy .dialog1}
            tk_dialog .dialog1 "Error" "$msg" error 0 OK
        }
75
    }
76
77
}

78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#-------------------------------------------------------------------------------
# .PROC StoreDirInEnvVar
# Helper function to safely store directory in environment variable.
# Makes sure that the environment variable is defined, even when the directory
# name is empty (to avoid "no such variable" script error)
# .ARGS
# environment variable name, directory path
# .END
#-------------------------------------------------------------------------------
proc StoreDirInEnvVar { envVarName dir } {
    set dir [file normalize "$dir"] 
    if {$dir == ""} {
        set dir " "
    }
    set ::env($envVarName) "$dir"
93
94
}

95
96
97
98
99
100
101
#-------------------------------------------------------------------------------
# .PROC launch_SetEnvironment
# Initialize environment variables
# .ARGS
# .END
#-------------------------------------------------------------------------------
proc launch_SetEnvironment {} {
102

103
    #
104
    # Slicer_HOME: , find it relative to the location of this script
105
106
107
108
109
110
    # -- when run by the launcher, this variable will be set already
    # -- this environment variable can be relied on by slicer code to know "where it lives"
    #    e.g. the build or install dir, so resources and other files can be found
    #
    set wd [pwd]
    cd [file dirname [file dirname [file dirname [info script]]]]
111
    set ::Slicer_HOME [pwd]
112
    cd $wd
113
    set ::env(Slicer_HOME) $::Slicer_HOME
114
115
    
    if { [string match -nocase "windows*" $::tcl_platform(os)] } {
116
117
      set ::Slicer_HOME [file attributes $::Slicer_HOME -shortname]
      set ::env(Slicer_HOME) $::Slicer_HOME
118
119
120
121
122
    }
    
    #
    # Indicate if Slicer was build with QT support
    #
123
    set ::Slicer_USE_PYTHONQT "@Slicer_USE_PYTHONQT@"
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
    
    #
    # set up variables for the OS Builds
    # 
    set ::SOLARIS "solaris8"
    set ::LINUX "linux-x86"
    set ::LINUX_64 "linux-x86_64"
    set ::DARWIN "darwin-ppc"
    set ::DARWIN_X86 "darwin-x86"
    set ::WINDOWS "win32"
    
    #
    # set the default locations for the main components
    #
    switch $::tcl_platform(os) {
        "SunOS" { set ::env(BUILD) $::SOLARIS }
140
        "GNU/kFreeBSD" {
141
            if {$::tcl_platform(machine) == "x86_64"} {
142
                set ::env(BUILD) $::LINUX_64
143
144
145
            } else {
                set ::env(BUILD) $::LINUX
            }
146
147
148
149
150
151
152
153
        }
        "Linux" {
            if {$::tcl_platform(machine) == "x86_64"} {
                set ::env(BUILD) $::LINUX_64
            } else {
                set ::env(BUILD) $::LINUX
            }
        }
154
155
156
157
158
159
        "Darwin" { 
            if {$::tcl_platform(machine) == "i386"} {
                set ::env(BUILD) $::DARWIN_X86
            } else {
                set ::env(BUILD) $::DARWIN 
            }
160
        }
161
162
        default { 
            set ::env(BUILD) $::WINDOWS 
163
164
        }
    }
165
166
167
168
    
    
    if {$::tcl_platform(os) == "SunOS"} {
      set isainfo [exec isainfo -b]
169
      set SlicerBinaryBitness [exec file $::env(Slicer_HOME)/bin/Slicer3-real | cut -d "," -f 1 | cut -d " " -f2 | cut -d "-" -f1]
170
        if {$SlicerBinaryBitness == "32"} {
171
            set ::BUILD(bitness) "32"
172
        } elseif {$SlicerBinaryBitness == "64" && $isainfo == 64} {
173
            set ::BUILD(bitness) "64"
174
        } elseif {$SlicerBinaryBitness == "64" && $isainfo == 32} {
175
    	ShowAndLogError "You can't run a 64 bit program on a 32 bit kernel!"
176
    	exit $::EXIT_CODE_GENERIC_ERROR
177
178
179
180
181
182
183
184
185
186
187
188
        }
    }	
    
    #
    # check if this is an install or a build directory
    # - an install will have a copy of vtk in the bin directory
    # - a build dirctory will not
    #
    set installed 0
    set ext ""
    if { [string match -nocase "windows*" $::tcl_platform(os)] } {
      set ext ".exe"
189
    }
190
    # if you change something here, please change it in qSlicerCoreApplication too
191
    if { [file exists $::env(Slicer_HOME)/bin/unu$ext] } {
192
      set installed 1
193
    }
194
195
196
197
198
    
    if { $installed } {
    
    
      # if installed, everything is in the local tree
199
200
      set slicer3Real "$::Slicer_HOME/bin/Slicer3-real$ext"
      set slicerQTReal "$::Slicer_HOME/bin/SlicerQT-real$ext"
201
      if { [file exists "$slicer3Real"] } {
202
        set ::Slicer_REAL $slicer3Real
203
      } elseif { [file exists "$slicerQTReal"] } {
204
        set ::Slicer_REAL $slicerQTReal
205
      }
206
207
208
209
210
211
212
213
214
215
216
217
218
    
      set ::env(SANDBOX_BIN_DIR)   ""
    
      # additional system libs
    
      set ::env(X11_LIB_DIR) ""
      set ::env(SFW_LIB_DIR) ""
      if { $::env(BUILD) == $::SOLARIS && $::BUILD(bitness) == "32"} {
        set ::env(X11_LIB_DIR) /usr/X11/lib
        set ::env(SFW_LIB_DIR) /usr/sfw/lib
      } else {
        set ::env(X11_LIB_DIR) /usr/X11/lib/64
        set ::env(SFW_LIB_DIR) /usr/sfw/lib/64
219
      }
220
221
222
    
      # 3rd party toolkits
    
223
224
      set ::env(VTK_DIR)            $::env(Slicer_HOME)/lib/vtk-@VTK_MAJOR_VERSION@.@VTK_MINOR_VERSION@
      set ::env(VTK_BIN_DIR)        $::env(Slicer_HOME)/bin
225
      
226
227
      set ::env(CTK_DIR)            $::env(Slicer_HOME)/lib/ctk-@CTK_MAJOR_VERSION@.@CTK_MINOR_VERSION@
      set ::env(CTK_BIN_DIR)        $::env(Slicer_HOME)/bin
228
      # TODO: where will PythonQt be in the install tree?
229
230
      set ::env(PYTHONQT_DIR)       $::env(Slicer_HOME)/lib/PythonQt
      set ::env(PYTHONQT_BIN_DIR)   $::env(Slicer_HOME)/bin
231
232
    
      # TODO -- where will Qt be in the install tree?
233
      set ::env(QT_LIB_DIR)         $::env(Slicer_HOME)/lib/Qt
234
      # Let's make QT binaries available
235
      set ::env(QT_BINARY_DIR)         $::env(Slicer_HOME)/bin
236
237
238

      # On Mac each Qt library is a framework which needs DYLD_LIBRARY_PATH set for each
      if {$::env(BUILD) ==  $::DARWIN || $::env(BUILD) == $::DARWIN_X86} { 
239
        set ::env(QT_FRAMEWORK_DIRS)  [file normalize "@Slicer_QT_FRAMEWORK_DIRS@"]
240
      }
241
    
242
      set ::env(ITK_BIN_DIR)        $::env(Slicer_HOME)/lib/InsightToolkit
243
    
244
      set ::env(Teem_DIR)           $::env(Slicer_HOME)/lib/Teem-@Teem_VERSION_MAJOR@.@Teem_VERSION_MINOR@.@Teem_VERSION_PATCH@
245
    
246
      set ::env(TCL_DIR)            $::env(Slicer_HOME)/lib/TclTk
247
248
      set ::env(TCL_LIBRARY)        "$::env(TCL_DIR)/lib/tcl@TCL_TK_VERSION_DOT@"
      if {$::env(BUILD) == $::WINDOWS} {
249
        set ::env(PYTHON_DIR)         $::env(Slicer_HOME)/lib/Python/PCbuild
250
      } else {
251
        set ::env(PYTHON_DIR)         $::env(Slicer_HOME)/lib/Python
252
      }
253
    
254
255
256
      set ::env(OpenIGTLink_DIR)      $::env(Slicer_HOME)/lib/igtl
      set ::env(OpenIGTLink_LIB_DIR)  $::env(Slicer_HOME)/lib/igtl
      set ::env(OpenIGTLink_BIN_DIR)  $::env(Slicer_HOME)/bin
257
    
258
259
260
261
      set ::env(BatchMake_DIR)      $::env(Slicer_HOME)/lib/BatchMake
      set ::env(BatchMake_LIB_DIR)  $::env(Slicer_HOME)/lib/BatchMake
      set ::env(BatchMake_BIN_DIR)  $::env(Slicer_HOME)/bin
      set ::env(bmModuleDescriptionParser_DIR)        $::env(Slicer_HOME)/lib/bmModuleDescriptionParser
262
263
264

      set ::env(LibArchive_DIR)     $::env(Slicer_HOME)/lib
      set ::env(LibArchive_LIB_DIR)  $::env(Slicer_HOME)/lib
265
266
267
    
      # Slicer3 Libs
    
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
      set ::env(FreeSurfer_DIR)     $::env(Slicer_HOME)/lib/FreeSurfer
      set ::env(IGT_DIR)            $::env(Slicer_HOME)/lib/IGT
      set ::env(ITKCommandIO_DIR)   $::env(Slicer_HOME)/lib/ITKCommandIO
      set ::env(MGHImageIO_DIR)     $::env(Slicer_HOME)/lib/MGHImageIO
      set ::env(MRML_DIR)           $::env(Slicer_HOME)/lib/MRML
      set ::env(MRMLCLI_DIR)        $::env(Slicer_HOME)/lib/MRMLCLI
      set ::env(MRMLLogic_DIR)      $::env(Slicer_HOME)/lib/MRMLLogic
      set ::env(MRMLDisplayableManager_DIR)   $::env(Slicer_HOME)/lib/MRMLDisplayableManager
      set ::env(ModuleDescriptionParser_DIR)  $::env(Slicer_HOME)/lib/ModuleDescriptionParser
      set ::env(MRMLIDImageIO_DIR)  $::env(Slicer_HOME)/lib/MRMLIDImageIO
      set ::env(Qdec_DIR)           $::env(Slicer_HOME)/lib/Qdec
      set ::env(FileWatcher_DIR)    $::env(Slicer_HOME)/lib/FileWatcher
      set ::env(tclap_DIR)          $::env(Slicer_HOME)/lib/tclap
      set ::env(vtkITK_DIR)         $::env(Slicer_HOME)/lib/vtkITK
      set ::env(vtkTeem_DIR)        $::env(Slicer_HOME)/lib/vtkTeem
      set ::env(qCTKWidgets_DIR)    $::env(Slicer_HOME)/lib/qCTKWidgets
      set ::env(qVTKWidgets_DIR)    $::env(Slicer_HOME)/lib/qVTKWidgets
      set ::env(qMRMLWidgets_DIR)   $::env(Slicer_HOME)/lib/qMRMLWidgets
286
    
287
      set ::env(Slicer_COMPILER_DIR) ""
288
      if { $::env(BUILD) == $::SOLARIS } {
289
        set ::env(Slicer_COMPILER_DIR) $::env(Slicer_HOME)/lib/Slicer3/CompilerLibs/$::BUILD(bitness)
290
      }
291
292
293
    
      # Slicer3 Base
    
294
295
      set ::env(Slicer_LIB_DIR)    $::env(Slicer_HOME)/lib/Slicer3
      set ::env(Slicer_BIN_DIR)    $::env(Slicer_HOME)/bin
296
    
297
      set ::env(Slicer_PLUGINS_DIR)            $::env(Slicer_HOME)/@Slicer_INSTALL_PLUGINS_LIB_DIR@
298
      set ::env(Slicer_QTLOADABLEMODULES_DIR)  $::env(Slicer_HOME)/@Slicer_INSTALL_QTLOADABLEMODULES_LIB_DIR@
299
300
301
    
      # QtDesigner variable
      #
302
      set ::env(Slicer_QT_PLUGIN_PATH)  "@Slicer_INSTALL_LIB_DIR@"
303
304
      set ::env(CTK_QT_PLUGIN_PATH) "$::env(CTK_BIN_DIR)"
      
305
306
307
308
309
310
    } else {
    
      # the not-installed case
    
      set ::BUILD_SUBDIR  ""
      set ::VTK_BUILD_SUBDIR  ""
311
      set ::CTK_BUILD_SUBDIR  ""
312
313
314
315
      set ::ITK_BUILD_SUBDIR  ""
      set ::Teem_BUILD_SUBDIR  ""
      set ::OpenIGTLink_BUILD_SUBDIR  ""
      set ::BatchMake_BUILD_SUBDIR  ""
316
      set ::QtDesignerPlugins_BUILD_SUBDIR  ""
317
      set ::LibArchive_BUILD_SUBDIR ""
318
319
320
    
      if {$::env(BUILD) == $::WINDOWS} {
        foreach buildType {"." Debug RelWithDebInfo Release MinSizeRel} {
321
322
          set slicer3Real "$::Slicer_HOME/bin/$buildType/Slicer3-real.exe"
          set slicerQTReal "$::Slicer_HOME/bin/$buildType/SlicerQT-real.exe"
323
          if { [file exists "$slicer3Real"] } {
324
            set ::Slicer_REAL $slicer3Real
325
326
            set ::BUILD_SUBDIR $buildType
          } elseif { [file exists "$slicerQTReal"] } {
327
            set ::Slicer_REAL $slicerQTReal
328
329
            set ::BUILD_SUBDIR $buildType
          }
330
          if { [file exists "@VTK_DIR@/bin/$buildType/vtkCommon.dll"] } {
331
332
            set ::VTK_BUILD_SUBDIR $buildType
          }
jcfr's avatar
jcfr committed
333
          if { [file exists "@CTK_DIR@/CTK-build/bin/$buildType/CTKCore.dll"] } {
334
335
            set ::CTK_BUILD_SUBDIR $buildType
          }
336
337
338
339
340
341
342
343
344
345
346
347
348
          if { [file exists "@ITK_DIR@/bin/$buildType/ITKCommon.dll"] } {
            set ::ITK_BUILD_SUBDIR $buildType
          }
          if { [file exists "@Teem_DIR@/bin/$buildType/air.dll"] ||
                 [file exists "@Teem_DIR@/bin/$buildType/teem.dll"] } {
            set ::Teem_BUILD_SUBDIR $buildType
          }
          if { [file exists "@OpenIGTLink_DIR@/bin/$buildType/OpenIGTLink.dll"] } {
            set ::OpenIGTLink_BUILD_SUBDIR $buildType
          }
          if { [file exists "@BatchMake_DIR@/bin/$buildType/BatchMake.dll"] } {
            set ::BatchMake_BUILD_SUBDIR $buildType
          }
349
350
351
          if { [file exists "@LibArchive_DIR@/bin/$buildType/archive.dll"] } {
            set ::LibArchive_BUILD_SUBDIR $buildType
          }
352
353
        }
      } else {
354
355
        set slicer3Real "$::Slicer_HOME/bin/Slicer3-real"
        set slicerQTReal "$::Slicer_HOME/bin/SlicerQT-real"
356
        if { [file exists "$slicer3Real"] } {
357
            set ::Slicer_REAL $slicer3Real
358
        } elseif { [file exists "$slicerQTReal"] } {
359
            set ::Slicer_REAL $slicerQTReal
360
        }
361
362
363
364
365
366
367
368
369
370
371
372
      }
      set ::env(SANDBOX_BIN_DIR)   ""
    
    
      # additional system libs
    
      if { $::env(BUILD) == $::SOLARIS && $::BUILD(bitness) == "32"} {
        set ::env(X11_LIB_DIR) /usr/X11/lib
        set ::env(SFW_LIB_DIR) /usr/sfw/lib
      } else {
        set ::env(X11_LIB_DIR) /usr/X11/lib/64
        set ::env(SFW_LIB_DIR) /usr/sfw/lib/64
373
      }
374
    
375
      set ::env(Slicer_COMPILER_DIR) ""
376
      if { $::env(BUILD) == $::SOLARIS } {
377
        set ::env(Slicer_COMPILER_DIR) $::env(Slicer_HOME)/lib/Slicer3/CompilerLibs/$::BUILD(bitness)
378
      }
379
380
381
382
383
384
    
    
      # 3rd party toolkits
    
      set ::env(VTK_DIR)            [file normalize "@VTK_DIR@"]
      set ::env(VTK_BIN_DIR)        [file normalize "@VTK_DIR@/bin/$::VTK_BUILD_SUBDIR"]
385
      
386
387
388
      if { "@CTK_DIR@" != "" } {
        set ::env(CTK_DIR)         [file normalize "@CTK_DIR@"]
      } else {
389
        set ::env(CTK_DIR)         "$::Slicer_HOME/bin"
390
      }
391
      set ::env(CTK_BIN_DIR)        [file normalize "@CTK_DIR@/CTK-build/bin/$::CTK_BUILD_SUBDIR"]
392
      set ::env(PYTHONQT_DIR)       [file normalize "@CTK_DIR@/CMakeExternals/Build/PythonQt/$::CTK_BUILD_SUBDIR"]
393
      set ::env(PYTHONQT_BIN_DIR)        [file normalize "@CTK_DIR@/CMakeExternals/Build/PythonQt/$::CTK_BUILD_SUBDIR"]
394
395
396
397
    
      if { "@QT_LIBRARY_DIR@" != "" } {
        set ::env(QT_LIB_DIR)         [file normalize "@QT_LIBRARY_DIR@"]
      } else {
398
        set ::env(QT_LIB_DIR)         "$::Slicer_HOME/bin"
399
      }
400
401
      # Let's make QT binaries available
      StoreDirInEnvVar QT_BINARY_DIR "@QT_BINARY_DIR@"
402
403
404
405
      
      if {$::env(BUILD) ==  $::DARWIN || $::env(BUILD) == $::DARWIN_X86} { 
        set ::env(QT_FRAMEWORK_DIRS)  [file normalize "@QT_LIBRARY_DIR@"]
      }
406
407
408
    
      set ::env(ITK_BIN_DIR)        [file normalize "@ITK_DIR@/bin/$::ITK_BUILD_SUBDIR"]
    
409
      if { "@Slicer_TCL_DIR@" != "" } {
410
        # this is the variable used in superbuild
411
        set ::env(TCL_DIR)          [file normalize "@Slicer_TCL_DIR@"]
412
413
414
      } else {
        set ::env(TCL_DIR)          [file normalize [file dirname [file dirname "@TCL_LIBRARY@"]]]
      }
415
      set ::env(TCL_LIBRARY)        "$::env(TCL_DIR)/lib/tcl@TCL_TK_VERSION_DOT@"
416
417
418

      if { "@PYTHON_LIBRARY@" != "" } {
        # this is the variable used in superbuild
419
        if {$::env(BUILD) == $::WINDOWS} {
420
          set ::env(PYTHON_DIR)         [file normalize [file dirname "@PYTHON_LIBRARY@"]]
421
422
423
        } else {
          set ::env(PYTHON_DIR)         [file normalize [file dirname [file dirname "@PYTHON_LIBRARY@"]]]
        }
424
425
426
427
428
429
      } else { 
          if {$::env(BUILD) == $::WINDOWS} {
            set ::env(PYTHON_DIR)         [file normalize [file dirname "@PYTHON_INCLUDE_PATH@"]/PCbuild]
          } else {
            set ::env(PYTHON_DIR)         [file normalize [file dirname [file dirname "@PYTHON_INCLUDE_PATH@"]]]
          }
430
      }
431
432
433
434
435
436
437
438
439
440
441
    
      set ::env(Teem_DIR)           [file normalize "@Teem_DIR@/bin/$::Teem_BUILD_SUBDIR"]
    
      set ::env(OpenIGTLink_DIR)      [file normalize "@OpenIGTLink_DIR@"]
      set ::env(OpenIGTLink_LIB_DIR)  [file normalize "@OpenIGTLink_DIR@/bin/$::OpenIGTLink_BUILD_SUBDIR"]
      set ::env(OpenIGTLink_BIN_DIR)  [file normalize "@OpenIGTLink_DIR@/bin/$::OpenIGTLink_BUILD_SUBDIR"]
    
      set ::env(BatchMake_DIR)      [file normalize "@BatchMake_DIR@"]
      set ::env(BatchMake_LIB_DIR)  [file normalize "@BatchMake_DIR@/bin/$::BatchMake_BUILD_SUBDIR"]
      set ::env(BatchMake_BIN_DIR)  [file normalize "@BatchMake_DIR@/bin/$::BatchMake_BUILD_SUBDIR"]
      set ::env(bmModuleDescriptionParser_DIR) $::env(BatchMake_BIN_DIR)
442
443
      
      set ::env(LibArchive_DIR)      [file normalize "@LibArchive_DIR@"]
444
445
446
447
448
      if {$::env(BUILD) == $::WINDOWS} {
        set ::env(LibArchive_LIB_DIR)  [file normalize "@LibArchive_DIR@/bin/$::LibArchive_BUILD_SUBDIR"]
      } else {
        set ::env(LibArchive_LIB_DIR)  [file normalize "@LibArchive_DIR@/"]
      }
449
      
450
451
      # Slicer3 Libs
    
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
      set ::env(FreeSurfer_DIR)     [file normalize "$::Slicer_HOME/lib/$::BUILD_SUBDIR"]
      set ::env(IGT_DIR)            [file normalize "$::Slicer_HOME/lib/$::BUILD_SUBDIR"]
      set ::env(ITKCommandIO_DIR)   [file normalize "$::Slicer_HOME/lib/$::BUILD_SUBDIR"]
      set ::env(MGHImageIO_DIR)     [file normalize "$::Slicer_HOME/lib/$::BUILD_SUBDIR"]
      set ::env(MRML_DIR)           [file normalize "$::Slicer_HOME/lib/$::BUILD_SUBDIR"]
      set ::env(MRMLCLI_DIR)        [file normalize "$::Slicer_HOME/lib/$::BUILD_SUBDIR"]
      set ::env(MRMLLogic_DIR)      [file normalize "$::Slicer_HOME/lib/$::BUILD_SUBDIR"]
      set ::env(MRMLDisplayableManager_DIR)      [file normalize "$::Slicer_HOME/lib/$::BUILD_SUBDIR"]
      set ::env(ModuleDescriptionParser_DIR)     [file normalize "$::Slicer_HOME/lib/$::BUILD_SUBDIR"]
      set ::env(MRMLIDImageIO_DIR)  [file normalize "$::Slicer_HOME/lib/$::BUILD_SUBDIR"]
      set ::env(Qdec_DIR)           [file normalize "$::Slicer_HOME/lib/$::BUILD_SUBDIR"]
      set ::env(FileWatcher_DIR)    [file normalize "$::Slicer_HOME/lib/$::BUILD_SUBDIR"]
      set ::env(tclap_DIR)          [file normalize "$::Slicer_HOME/lib/$::BUILD_SUBDIR"]
      set ::env(vtkITK_DIR)         [file normalize "$::Slicer_HOME/lib/$::BUILD_SUBDIR"]
      set ::env(vtkTeem_DIR)        [file normalize "$::Slicer_HOME/lib/$::BUILD_SUBDIR"]
      set ::env(qCTKWidgets_DIR)    [file normalize "$::Slicer_HOME/lib/$::BUILD_SUBDIR"]
      set ::env(qMRMLWidgets_DIR)   [file normalize "$::Slicer_HOME/lib/$::BUILD_SUBDIR"]
      set ::env(qVTKWidgets_DIR)    [file normalize "$::Slicer_HOME/lib/$::BUILD_SUBDIR"]
470
471
472
473
      
    
      # Slicer3 Base
    
474
475
      set ::env(Slicer_BIN_DIR)    [file normalize "$::Slicer_HOME/bin/$::BUILD_SUBDIR"]
      set ::env(Slicer_LIB_DIR)    [file normalize "$::Slicer_HOME/lib/$::BUILD_SUBDIR"]
476
    
477
478
      set ::env(Slicer_PLUGINS_DIR) [file normalize "$::env(Slicer_HOME)/@Slicer_INSTALL_PLUGINS_LIB_DIR@/$::BUILD_SUBDIR"]
      set ::env(Slicer_QTLOADABLEMODULES_DIR) [file normalize "$::env(Slicer_HOME)/@Slicer_INSTALL_QTLOADABLEMODULES_LIB_DIR@/$::BUILD_SUBDIR"]
479
480
481
    
    
      # QtDesigner variable  
482
      StoreDirInEnvVar Slicer_QT_PLUGIN_PATH "$::Slicer_HOME/bin"
483
      StoreDirInEnvVar CTK_QT_PLUGIN_PATH "$::env(CTK_DIR)/CTK-build/bin"
484
485
486
      
    }
    
487
    set ::env(Slicer_VERSION)    @Slicer_VERSION_PATCH@
488
489
490
491
    
    # If reportVTKErrors is nonzero, then we check for VTK errors and
    # if a VTK error is found then launcher returns with error (causing the test to FAIL)
    set ::LAUNCH(reportVTKErrors) 0
492
    if {"@LAUNCHER_REPORT_VTK_ERRORS@"=="ON"} {
493
      set ::LAUNCH(reportVTKErrors) 1
494
    }
495
496
}

497
498
499
500
501
502
503
#-------------------------------------------------------------------------------
# .PROC launch_ParseArgs
# Setup launch options by parsing command-line parameters 
# .ARGS
# command-line parameter list
# .END
#-------------------------------------------------------------------------------
504
505
506
507
proc launch_ParseArgs {argv} {

  set ::LAUNCH(showSplash) 1
  set ::LAUNCH(launchCommand) ""
508
  set ::LAUNCH(launchDesigner) 0
pieper's avatar
pieper committed
509
  set ::LAUNCH(detach) 0
510
511
512
513
514
515
516
517
518

  # 
  # look for launcher-specific arguments
  #  --launch <program>
  # or 
  #  --launch-script <script.tcl>
  #    (this is a special case that runs the script
  #     in this interp and then exits)
  #
519
  #  --designer - Attempt to start Qt Designer
520
  #
521
522
523
  #  --no-error-popup - Don't display errors in a popup
  #
  #  --detach - Run the command without monitoring the stdio
524
  #
525
  # and obey --no-splash and --no-main-window, but don't swallow them (pass on to slicer)
526
527
528
529
  #

  set argv0 [lindex $::argv 0]
  set argv1 [lindex $::argv 1]
530
  switch -glob -- $argv0 {
531
532
533
534
535
    "--launch" {
      if { $argv1 == "" } {
        error "--launch requires argument of program to run"
      } else {
          set ::LAUNCH(launchCommand) $argv1
536
          regsub -all "\\\\" $::LAUNCH(launchCommand) "/" ::LAUNCH(launchCommand)
537
538
539
540
541
          set ::argv [lreplace $::argv 0 1]

          # don't show splash if running a custom command
          set ::LAUNCH(showSplash) 0
      }
542
    }
543
544
545
546
547
    "--designer" {
      set ::LAUNCH(launchDesigner) 1
      set ::argv [lreplace $::argv 0 1]
      set ::LAUNCH(showSplash) 0
    }
548
    "*.slicer" -
549
550
551
    "--launch-script" {
      set ::argv [lreplace $::argv 0 1]
      uplevel #0 source $argv1
552
      exit $::EXIT_CODE_NO_ERROR
553
554
    }
  }
555

556
557
  # check for the arguments
  set newargs ""
558
559
  foreach arg $::argv {
    switch -- $arg {
560
561
      "--help" -
      "-h" -
562
563
      "--no-main-window" -
      "--no_main_window" -
564
      "--no_splash" -
565
566
      "--no-splash" {
          set ::LAUNCH(showSplash) 0
567
          lappend newargs $arg ;# pass arg to Slicer3-real
568
      }
569
      "--test_mode" -
570
571
572
573
      "--test-mode" {
        set ::LAUNCH(showSplash) 0
        lappend newargs $arg ;# pass arg to Slicer3-real
      }
574
575
      "--detach" {
        set ::LAUNCH(detach) 1
576
      }      
577
578
579
      "--no-error-popup" {
        set ::LAUNCH(showErrorPopup) 0
      }      
580
      default {
581
582
        # escape any pipe characters 
        regsub -all "\\|" $arg "\\\\|" arg
583
584
        lappend newargs $arg
      }
585
    }
586
  }
587
  set ::argv $newargs
588
589
}

590

591
592
593
594
595
596
597
#-------------------------------------------------------------------------------
# .PROC launch_SetPaths
# Setup system path variables to find Slicer libraries 
# .ARGS
# .END
#-------------------------------------------------------------------------------
proc launch_SetPaths {} {
598

599
    foreach var {LD_LIBRARY_PATH TCLLIBPATH DYLD_LIBRARY_PATH PATH} {
600
601
602
603
604
        # if it is an empty string or doesn't exist, set the environment variable
        if { ![info exists ::env($var)] || $::env($var) == "" } {
            set ::env($var) " "
        }
    }
605
606
607
608
609
610
611
612
613
614
615
616

    #
    # add the necessary library directories, both Base and Modules, to the 
    # LD_LIBRARY_PATH environment variable
    #
    #
    # set the base library paths for this build 
    # 
    if {$::env(BUILD) == $::SOLARIS ||
        $::env(BUILD) == $::LINUX_64 || 
        $::env(BUILD) == $::LINUX} {
        # add vtk, slicer, and tcl bins
617
            set ::env(LD_LIBRARY_PATH) $::env(VTK_BIN_DIR):$::env(LD_LIBRARY_PATH)
618
            set ::env(LD_LIBRARY_PATH) $::env(CTK_DIR):$::env(LD_LIBRARY_PATH)
619
            set ::env(LD_LIBRARY_PATH) $::env(CTK_BIN_DIR):$::env(LD_LIBRARY_PATH)
620
            set ::env(LD_LIBRARY_PATH) $::env(PYTHONQT_DIR):$::env(LD_LIBRARY_PATH)
621
            set ::env(LD_LIBRARY_PATH) $::env(PYTHONQT_BIN_DIR):$::env(LD_LIBRARY_PATH)
622
            set ::env(LD_LIBRARY_PATH) $::env(QT_LIB_DIR):$::env(LD_LIBRARY_PATH)
623
            set ::env(LD_LIBRARY_PATH) $::env(OpenIGTLink_LIB_DIR):$::env(LD_LIBRARY_PATH)
624
625
            set ::env(LD_LIBRARY_PATH) $::env(BatchMake_LIB_DIR):$::env(LD_LIBRARY_PATH)
            set ::env(LD_LIBRARY_PATH) $::env(bmModuleDescriptionParser_DIR):$::env(LD_LIBRARY_PATH)
626
            set ::env(LD_LIBRARY_PATH) $::env(BatchMake_LIB_DIR)/lib:$::env(LD_LIBRARY_PATH)
627
628
            set ::env(LD_LIBRARY_PATH) $::env(ITK_BIN_DIR):$::env(LD_LIBRARY_PATH)
            set ::env(LD_LIBRARY_PATH) $::env(TCL_DIR)/lib:$::env(LD_LIBRARY_PATH)
barre's avatar
barre committed
629
630
            set ::env(LD_LIBRARY_PATH) $::env(TCL_DIR)/lib/itcl@INCR_TCL_VERSION_DOT@:$::env(LD_LIBRARY_PATH)
            set ::env(LD_LIBRARY_PATH) $::env(TCL_DIR)/lib/itk@INCR_TCL_VERSION_DOT@:$::env(LD_LIBRARY_PATH)
631
            set ::env(LD_LIBRARY_PATH) $::env(Teem_DIR):$::env(LD_LIBRARY_PATH)
632
            set ::env(LD_LIBRARY_PATH) $::env(VTK_DIR):$::env(LD_LIBRARY_PATH)
633
            set ::env(LD_LIBRARY_PATH) $::env(PYTHON_DIR)/lib:$::env(LD_LIBRARY_PATH)
634
635
636
637
638
            set ::env(LD_LIBRARY_PATH) $::env(FreeSurfer_DIR):$::env(LD_LIBRARY_PATH)
            set ::env(LD_LIBRARY_PATH) $::env(IGT_DIR):$::env(LD_LIBRARY_PATH)
            set ::env(LD_LIBRARY_PATH) $::env(ITKCommandIO_DIR):$::env(LD_LIBRARY_PATH)
            set ::env(LD_LIBRARY_PATH) $::env(MGHImageIO_DIR):$::env(LD_LIBRARY_PATH)
            set ::env(LD_LIBRARY_PATH) $::env(MRML_DIR):$::env(LD_LIBRARY_PATH)
639
            set ::env(LD_LIBRARY_PATH) $::env(MRMLCLI_DIR):$::env(LD_LIBRARY_PATH)
640
641
            set ::env(LD_LIBRARY_PATH) $::env(MRMLLogic_DIR):$::env(LD_LIBRARY_PATH)
            set ::env(LD_LIBRARY_PATH) $::env(MRMLDisplayableManager_DIR):$::env(LD_LIBRARY_PATH)
642
643
644
            set ::env(LD_LIBRARY_PATH) $::env(ModuleDescriptionParser_DIR):$::env(LD_LIBRARY_PATH)
            set ::env(LD_LIBRARY_PATH) $::env(MRMLIDImageIO_DIR):$::env(LD_LIBRARY_PATH)
            set ::env(LD_LIBRARY_PATH) $::env(Qdec_DIR):$::env(LD_LIBRARY_PATH)
645
            set ::env(LD_LIBRARY_PATH) $::env(FileWatcher_DIR):$::env(LD_LIBRARY_PATH)
646
647
648
            set ::env(LD_LIBRARY_PATH) $::env(tclap_DIR):$::env(LD_LIBRARY_PATH)
            set ::env(LD_LIBRARY_PATH) $::env(vtkITK_DIR):$::env(LD_LIBRARY_PATH)
            set ::env(LD_LIBRARY_PATH) $::env(vtkTeem_DIR):$::env(LD_LIBRARY_PATH)
649
650
651
            set ::env(LD_LIBRARY_PATH) $::env(qCTKWidgets_DIR):$::env(LD_LIBRARY_PATH)
            set ::env(LD_LIBRARY_PATH) $::env(qVTKWidgets_DIR):$::env(LD_LIBRARY_PATH)
            set ::env(LD_LIBRARY_PATH) $::env(qMRMLWidgets_DIR):$::env(LD_LIBRARY_PATH)
652
653
654
            set ::env(LD_LIBRARY_PATH) $::env(Slicer_LIB_DIR):$::env(LD_LIBRARY_PATH)
            set ::env(LD_LIBRARY_PATH) $::env(Slicer_PLUGINS_DIR):$::env(LD_LIBRARY_PATH)
            set ::env(LD_LIBRARY_PATH) $::env(Slicer_QTLOADABLEMODULES_DIR):$::env(LD_LIBRARY_PATH)
655
            set ::env(LD_LIBRARY_PATH) $::env(X11_LIB_DIR):$::env(LD_LIBRARY_PATH)
656
            set ::env(LD_LIBRARY_PATH) $::env(SFW_LIB_DIR):$::env(LD_LIBRARY_PATH)
657
            set ::env(LD_LIBRARY_PATH) $::env(Slicer_COMPILER_DIR):$::env(LD_LIBRARY_PATH)
658
            set ::env(PATH) "$::env(PATH):$::env(TCL_DIR)/bin"
659
            set ::env(PATH) "$::env(PATH):$::env(Teem_DIR)"
660
661
662
            set ::env(PATH) "$::env(Slicer_BIN_DIR):$::env(PATH)"
            set ::env(PATH) "$::env(Slicer_PLUGINS_DIR):$::env(PATH)"
            set ::env(PATH) "$::env(Slicer_QTLOADABLEMODULES_DIR):$::env(PATH)"
663
664
            set ::env(PATH) "$::env(QT_BINARY_DIR):$::env(PATH)"
            set ::env(QTDESIGNER_EXE) "designer"
665
            set ::env(QT_PLUGIN_PATH) "$::env(CTK_QT_PLUGIN_PATH):$::env(Slicer_QT_PLUGIN_PATH)"
666
        } elseif {$::env(BUILD) ==  $::DARWIN || $::env(BUILD) == $::DARWIN_X86} { 
667
            # add vtk, slicer, and tcl bins
668
            set ::env(DYLD_LIBRARY_PATH) $::env(VTK_BIN_DIR):$::env(DYLD_LIBRARY_PATH)
669
            set ::env(DYLD_LIBRARY_PATH) $::env(CTK_DIR):$::env(DYLD_LIBRARY_PATH)
670
            set ::env(DYLD_LIBRARY_PATH) $::env(CTK_BIN_DIR):$::env(DYLD_LIBRARY_PATH)
671
            set ::env(DYLD_LIBRARY_PATH) $::env(PYTHONQT_DIR):$::env(DYLD_LIBRARY_PATH)
672
            set ::env(DYLD_LIBRARY_PATH) $::env(PYTHONQT_BIN_DIR):$::env(DYLD_LIBRARY_PATH)
673
            set ::env(DYLD_LIBRARY_PATH) $::env(QT_LIB_DIR):$::env(DYLD_LIBRARY_PATH)
674
            set ::env(DYLD_LIBRARY_PATH) $::env(QT_FRAMEWORK_DIRS)$::env(DYLD_LIBRARY_PATH)
675
            set ::env(DYLD_LIBRARY_PATH) $::env(OpenIGTLink_LIB_DIR):$::env(DYLD_LIBRARY_PATH)
676
677
            set ::env(DYLD_LIBRARY_PATH) $::env(BatchMake_LIB_DIR):$::env(DYLD_LIBRARY_PATH)
            set ::env(DYLD_LIBRARY_PATH) $::env(bmModuleDescriptionParser_DIR):$::env(DYLD_LIBRARY_PATH)
678
            set ::env(DYLD_LIBRARY_PATH) $::env(LibArchive_LIB_DIR)/lib:$::env(LD_LIBRARY_PATH)
679
680
            set ::env(DYLD_LIBRARY_PATH) $::env(ITK_BIN_DIR):$::env(DYLD_LIBRARY_PATH)
            set ::env(DYLD_LIBRARY_PATH) $::env(TCL_DIR)/lib:$::env(DYLD_LIBRARY_PATH)
barre's avatar
barre committed
681
682
            set ::env(DYLD_LIBRARY_PATH) $::env(TCL_DIR)/lib/itcl@INCR_TCL_VERSION_DOT@:$::env(DYLD_LIBRARY_PATH)
            set ::env(DYLD_LIBRARY_PATH) $::env(TCL_DIR)/lib/itk@INCR_TCL_VERSION_DOT@:$::env(DYLD_LIBRARY_PATH)
683
            set ::env(DYLD_LIBRARY_PATH) $::env(Teem_DIR):$::env(DYLD_LIBRARY_PATH)
684
            set ::env(DYLD_LIBRARY_PATH) $::env(VTK_DIR):$::env(DYLD_LIBRARY_PATH)
685
            set ::env(DYLD_LIBRARY_PATH) $::env(PYTHON_DIR)/lib:$::env(DYLD_LIBRARY_PATH)
686
687
688
689
690
            set ::env(DYLD_LIBRARY_PATH) $::env(FreeSurfer_DIR):$::env(DYLD_LIBRARY_PATH)
            set ::env(DYLD_LIBRARY_PATH) $::env(IGT_DIR):$::env(DYLD_LIBRARY_PATH)
            set ::env(DYLD_LIBRARY_PATH) $::env(ITKCommandIO_DIR):$::env(DYLD_LIBRARY_PATH)
            set ::env(DYLD_LIBRARY_PATH) $::env(MGHImageIO_DIR):$::env(DYLD_LIBRARY_PATH)
            set ::env(DYLD_LIBRARY_PATH) $::env(MRML_DIR):$::env(DYLD_LIBRARY_PATH)
691
            set ::env(DYLD_LIBRARY_PATH) $::env(MRMLCLI_DIR):$::env(DYLD_LIBRARY_PATH)
692
693
            set ::env(DYLD_LIBRARY_PATH) $::env(MRMLLogic_DIR):$::env(DYLD_LIBRARY_PATH)
            set ::env(DYLD_LIBRARY_PATH) $::env(MRMLDisplayableManager_DIR):$::env(DYLD_LIBRARY_PATH)
694
695
696
            set ::env(DYLD_LIBRARY_PATH) $::env(ModuleDescriptionParser_DIR):$::env(DYLD_LIBRARY_PATH)
            set ::env(DYLD_LIBRARY_PATH) $::env(MRMLIDImageIO_DIR):$::env(DYLD_LIBRARY_PATH)
            set ::env(DYLD_LIBRARY_PATH) $::env(Qdec_DIR):$::env(DYLD_LIBRARY_PATH)
697
            set ::env(DYLD_LIBRARY_PATH) $::env(FileWatcher_DIR):$::env(DYLD_LIBRARY_PATH)
698
699
700
            set ::env(DYLD_LIBRARY_PATH) $::env(tclap_DIR):$::env(DYLD_LIBRARY_PATH)
            set ::env(DYLD_LIBRARY_PATH) $::env(vtkITK_DIR):$::env(DYLD_LIBRARY_PATH)
            set ::env(DYLD_LIBRARY_PATH) $::env(vtkTeem_DIR):$::env(DYLD_LIBRARY_PATH)
701
702
703
            set ::env(DYLD_LIBRARY_PATH) $::env(qCTKWidgets_DIR):$::env(DYLD_LIBRARY_PATH)
            set ::env(DYLD_LIBRARY_PATH) $::env(qVTKWidgets_DIR):$::env(DYLD_LIBRARY_PATH)
            set ::env(DYLD_LIBRARY_PATH) $::env(qMRMLWidgets_DIR):$::env(DYLD_LIBRARY_PATH)
704
705
706
            set ::env(DYLD_LIBRARY_PATH) $::env(Slicer_LIB_DIR):$::env(DYLD_LIBRARY_PATH)
            set ::env(DYLD_LIBRARY_PATH) $::env(Slicer_PLUGINS_DIR):$::env(DYLD_LIBRARY_PATH)
            set ::env(DYLD_LIBRARY_PATH) $::env(Slicer_QTLOADABLEMODULES_DIR):$::env(DYLD_LIBRARY_PATH)
707
708
            set ::env(PATH) "$::env(PATH):$::env(TCL_DIR)/bin"
            set ::env(PATH) "$::env(PATH):$::env(Teem_DIR)"
709
710
711
            set ::env(PATH) "$::env(Slicer_BIN_DIR):$::env(PATH)"
            set ::env(PATH) "$::env(Slicer_PLUGINS_DIR):$::env(PATH)"
            set ::env(PATH) "$::env(Slicer_QTLOADABLEMODULES_DIR):$::env(PATH)"
712
            set ::env(PATH) "$::env(QT_BINARY_DIR):$::env(PATH)"
713
            set ::env(QTDESIGNER_EXE) "Designer.app/Contents/MacOS/Designer"
714
            set ::env(QT_PLUGIN_PATH) "$::env(CTK_QT_PLUGIN_PATH):$::env(Slicer_QT_PLUGIN_PATH)"
715
716
        } elseif {$::env(BUILD) == $::WINDOWS} {
            # add vtk, slicer, and tcl bins
717
            set ::env(Path) $::env(VTK_BIN_DIR)\;$::env(Path)
718
            set ::env(Path) $::env(CTK_BIN_DIR)\;$::env(Path)
719
            set ::env(Path) $::env(PYTHONQT_BIN_DIR)\;$::env(Path)
720
            set ::env(Path) $::env(QT_LIB_DIR)\;$::env(Path)
721
            set ::env(Path) $::env(OpenIGTLink_BIN_DIR)\;$::env(Path)
722
723
            set ::env(Path) $::env(BatchMake_BIN_DIR)\;$::env(Path)
            set ::env(Path) $::env(bmModuleDescriptionParser_DIR)\;$::env(Path)
724
            set ::env(Path) $::env(LibArchive_LIB_DIR)\;$::env(Path)
725
            set ::env(Path) $::env(ITK_BIN_DIR)\;$::env(Path)
726
727
728
729

            # TODO: TCL_DIR for super-build is not calculated correctly 
            # - specify both version so tkinter can load on windows where there is no rpath
            #   and on traditional non-rpath slicer builds
730
            set ::env(Path) $::env(TCL_DIR)/bin\;$::env(Path)
731
732
            set ::env(Path) $::env(TCL_DIR)/lib/itcl@INCR_TCL_VERSION_DOT@\;$::env(Path)
            set ::env(Path) $::env(TCL_DIR)/lib/itk@INCR_TCL_VERSION_DOT@\;$::env(Path)
733
734
735
736
737

            set ::env(Path) $::env(TCL_DIR)/../tcl-build/bin\;$::env(Path)
            set ::env(Path) $::env(TCL_DIR)/../lib/itcl@INCR_TCL_VERSION_DOT@\;$::env(Path)
            set ::env(Path) $::env(TCL_DIR)/../lib/itk@INCR_TCL_VERSION_DOT@\;$::env(Path)

738
            set ::env(Path) $::env(Teem_DIR)\;$::env(Path)
739
            set ::env(Path) $::env(PYTHON_DIR)\;$::env(Path)
740
            set ::env(Path) $::env(VTK_DIR)\;$::env(Path)
741
742
743
744
745
            set ::env(Path) $::env(FreeSurfer_DIR)\;$::env(Path)
            set ::env(Path) $::env(IGT_DIR)\;$::env(Path)
            set ::env(Path) $::env(ITKCommandIO_DIR)\;$::env(Path)
            set ::env(Path) $::env(MGHImageIO_DIR)\;$::env(Path)
            set ::env(Path) $::env(MRML_DIR)\;$::env(Path)
746
            set ::env(Path) $::env(MRMLCLI_DIR)\;$::env(Path)
747
748
            set ::env(Path) $::env(MRMLLogic_DIR)\;$::env(Path)
            set ::env(Path) $::env(MRMLDisplayableManager_DIR)\;$::env(Path)
749
750
751
            set ::env(Path) $::env(ModuleDescriptionParser_DIR)\;$::env(Path)
            set ::env(Path) $::env(MRMLIDImageIO_DIR)\;$::env(Path)
            set ::env(Path) $::env(Qdec_DIR)\;$::env(Path)
752
            set ::env(Path) $::env(FileWatcher_DIR)\;$::env(Path)
753
754
755
            set ::env(Path) $::env(tclap_DIR)\;$::env(Path)
            set ::env(Path) $::env(vtkITK_DIR)\;$::env(Path)
            set ::env(Path) $::env(vtkTeem_DIR)\;$::env(Path)
756
757
758
            set ::env(Path) $::env(qCTKWidgets_DIR)\;$::env(Path)
            set ::env(Path) $::env(qVTKWidgets_DIR)\;$::env(Path)
            set ::env(Path) $::env(qMRMLWidgets_DIR)\;$::env(Path)
759
760
761
762
            set ::env(Path) $::env(Slicer_BIN_DIR)\;$::env(Path)
            set ::env(Path) $::env(Slicer_LIB_DIR)\;$::env(Path)
            set ::env(Path) $::env(Slicer_PLUGINS_DIR)\;$::env(Path)
            set ::env(Path) $::env(Slicer_QTLOADABLEMODULES_DIR)\;$::env(Path)
763
764
            set ::env(Path) $::env(QT_BINARY_DIR)\;$::env(Path)
            set ::env(QTDESIGNER_EXE) "designer.exe"
765
            set ::env(QT_PLUGIN_PATH) $::env(CTK_QT_PLUGIN_PATH)\;$::env(Slicer_QT_PLUGIN_PATH)
766
        } else {
767
            ShowAndLogError "Libraries: unknown build $::env(BUILD)"
768
769
770
        }

    # set the base tcl/tk library paths, using the previously defined TCL_LIB_DIR
771
772
    set ::env(TCL_LIBRARY) "$::env(TCL_DIR)/lib/tcl@TCL_TK_VERSION_DOT@"
    set ::env(TK_LIBRARY) "$::env(TCL_DIR)/lib/tk@TCL_TK_VERSION_DOT@"
773
774
775
776

    #
    # add the default search locations for tcl packages
    #
777
    set ::env(TCLLIBPATH) "$::env(VTK_DIR)/Wrapping/Tcl $::env(TCLLIBPATH)"
778
    if { [info exists ::env(OpenIGTLink_DIR] } {
779
      set ::env(TCLLIBPATH) "$::env(OpenIGTLink_DIR)/Wrapping/Tcl $::env(TCLLIBPATH)"
780
    }
781
    set ::env(TCLLIBPATH) "$::env(Slicer_HOME)/Base/Wrapping/Tcl/vtkSlicerBase $::env(TCLLIBPATH)"
782
783
    set ::env(TCLLIBPATH) "$::env(TCL_DIR)/lib/itcl@INCR_TCL_VERSION_DOT@ $::env(TCLLIBPATH)"
    set ::env(TCLLIBPATH) "$::env(TCL_DIR)/lib/itk@INCR_TCL_VERSION_DOT@ $::env(TCLLIBPATH)"
784
785
    set ::env(TCLLIBPATH) "$::env(TCL_DIR)/lib/iwidgets4.0.1 $::env(TCLLIBPATH)"
    set ::env(TCLLIBPATH) "$::env(TCL_DIR)/lib/blt2.4 $::env(TCLLIBPATH)"
786
787

    #
788
    # add the default search locations for python packages for a slicer build of python
789
    #
790

791
    if { "@Slicer_USE_SYSTEM_PYTHON@" != "ON" } {
792
793
794
795
796
797
      if {$::env(BUILD) == $::WINDOWS} {
        set SEP ";"
        set ::env(PYTHON_DIR) "$::env(PYTHON_DIR)/.."
      } else {
        set SEP ":"
      }
798

799
      set ::env(PYTHONHOME) "$::env(PYTHON_DIR)"
800
801
802
803
804
805
806

      # check for existing variable to avoid empty entries in PYTHONPATH
      if { ![info exists ::env(PYTHONPATH)] } {
        set ::env(PYTHONPATH) "$::env(PYTHON_DIR)/lib"
      } else {
        set ::env(PYTHONPATH) "$::env(PYTHON_DIR)/lib$SEP$::env(PYTHONPATH)"
      }
807
808
809
810
      
      set ::env(PYTHONPATH) "$::env(Slicer_HOME)/bin/Python$SEP$::env(PYTHONPATH)"
      set ::env(PYTHONPATH) "$::env(Slicer_HOME)/lib/Slicer3$SEP$::env(PYTHONPATH)"
      set ::env(PYTHONPATH) "$::env(Slicer_HOME)/lib/Slicer3/QTScriptedModules$SEP$::env(PYTHONPATH)"
811
      set ::env(PYTHONPATH) "$::env(Slicer_HOME)/lib/Slicer3/QTLoadableModules$SEP$::env(PYTHONPATH)"
812
      
813
      set ::env(PYTHONPATH) "$::env(PYTHON_DIR)/lib/lib-tk$SEP$::env(PYTHONPATH)"
814
815
      set ::env(PYTHONPATH) "$::env(PYTHON_DIR)/lib/site-packages$SEP$::env(PYTHONPATH)"
      set ::env(PYTHONPATH) "$::env(PYTHON_DIR)/lib/site-packages/numpy$SEP$::env(PYTHONPATH)"
816
      set ::env(PYTHONPATH) "$::env(PYTHON_DIR)/lib/site-packages/numpy/lib$SEP$::env(PYTHONPATH)"
817
      set ::env(PYTHONPATH) "$::env(PYTHON_DIR)/lib/site-packages/numpy/core$SEP$::env(PYTHONPATH)"
818
819
820
821
      set ::env(PYTHONPATH) "$::env(PYTHON_DIR)/lib/python2.6$SEP$::env(PYTHONPATH)"
      set ::env(PYTHONPATH) "$::env(PYTHON_DIR)/lib/python2.6/site-packages$SEP$::env(PYTHONPATH)"
      set ::env(PYTHONPATH) "$::env(PYTHON_DIR)/lib/python2.6/lib-tk$SEP$::env(PYTHONPATH)"
      set ::env(PYTHONPATH) "$::env(PYTHON_DIR)/lib/python2.6/site-packages/numpy/lib$SEP$::env(PYTHONPATH)"
822
      set ::env(PYTHONPATH) "$::env(PYTHON_DIR)/lib/python2.6/site-packages/numpy/core$SEP$::env(PYTHONPATH)"
823
824
      set ::env(PYTHONPATH) "$::env(Slicer_HOME)/lib/Slicer3/SlicerBaseGUI/Python$SEP$::env(PYTHONPATH)"
      set ::env(PYTHONPATH) "$::env(Slicer_HOME)/lib/site-packages$SEP$::env(PYTHONPATH)"
825
      set ::env(PYTHONPATH) "$::env(VTK_BIN_DIR)$SEP$::env(PYTHONPATH)"
826
827
828
829
	  set ::env(PYTHONPATH) "$::env(Slicer_HOME)/lib/FreeSurfer$SEP$::env(PYTHONPATH)"
      set ::env(PYTHONPATH) "$::env(Slicer_HOME)/lib/MRML$SEP$::env(PYTHONPATH)"
      set ::env(PYTHONPATH) "$::env(Slicer_HOME)/lib/MRMLLogic$SEP$::env(PYTHONPATH)"
      set ::env(PYTHONPATH) "$::env(Slicer_HOME)/lib/vtkTeem$SEP$::env(PYTHONPATH)"
830
      set ::env(PYTHONPATH) "$::env(Slicer_HOME)/bin$SEP$::env(PYTHONPATH)"
831
    }
832
833
}

834
835
836
837
838
839
#-------------------------------------------------------------------------------
# .PROC launch_SplashScreen
# Show splash screen (optional) 
# .ARGS
# .END
#-------------------------------------------------------------------------------
840
proc launch_SplashScreen {} {
841

842
  if { $::LAUNCH(showSplash) } {
843

844
845
    if { ($::env(BUILD) ==  $::DARWIN || $::env(BUILD) == $::DARWIN_X86) || [catch "package require Tk"] } {
      puts "Setting up launch environment..."
846
847
      set $::LAUNCH(showSplash) 0
      return
848
849
    }

850
    wm withdraw .
851
852
    launch_SplashShow
  }
853
854
  
  # windows always has a display, so get rid of the default window
855
856
857
  if { [string match -nocase "windows*" $::tcl_platform(os)] } {
    wm withdraw .
  }
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
}


#-------------------------------------------------------------------------------
# .PROC SplashKill
# Release the application grab on the splash window, destroy the window, and delete the image.
# .ARGS
# .END
#-------------------------------------------------------------------------------
proc launch_SplashKill {} { 

    # because this is called from bgerror, don't cause any errors 
    if {[info command .splash] != ""} {
        # release the grab
        grab release .splash
        destroy .splash
    }
}

877
878
879
880
881
882
883
#-------------------------------------------------------------------------------
# .PROC launch_SplashAnimate
# Animate splash screen by drawing dots. 
# .ARGS
# delay before displaying a new point
# .END
#-------------------------------------------------------------------------------
884
885
886
887
888
889
890
891
892
proc launch_SplashAnimate { {delayms 100} } {
  if {[info command .splash] != ""} {
    set dots [.splash.v cget -text]
    if { $dots == "**********" } { 
      set dots "*" 
    } else {
      set dots *$dots
    }
    .splash.v configure -text $dots
893
    update
894
895
896
897
    after $delayms "launch_SplashAnimate $delayms"
  }
}

898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
#-------------------------------------------------------------------------------
# .PROC SplashShow
# Builds and displays a splash screen, .splash
# .ARGS
# int delayms how long to show the splash screen, defaults to 7000, in milliseconds
# .END
#-------------------------------------------------------------------------------
proc launch_SplashShow { {delayms 7000} } {

    set oscaling [tk scaling]
    # ignore screen based default scaling and pick scale so words show up nicely inside box
    tk scaling 1.5
    set width 500
    set height 200
    set splashfont [font create -family Helvetica -size 10]
    set splashfontb [font create -family Helvetica -size 10 -weight bold]
    toplevel .splash -relief raised -borderwidth 6 -width $width -height $height -bg white
    wm overrideredirect .splash 1
916
917
918
    set xcorner [expr [winfo screenwidth .splash]/2-($width/2)]
    set ycorner [expr [winfo screenheight .splash]/2-($height/2)]
    wm geometry .splash +$xcorner+$ycorner
919

920
    label .splash.t1 -text "3D Slicer starting up..." -bg white -font $splashfontb
921
922
    label .splash.t2 -text "" -bg white -fg red -font $splashfont
    label .splash.v -text "" -bg white -fg darkblue -font $splashfont
923
924

    place .splash.t1 -relx 0.5 -rely 0.30 -anchor center
925
926
    #place .splash.t2 -relx 0.5 -rely 0.50 -anchor center
    place .splash.v -relx 0.5 -rely 0.60 -anchor center
927
928
    update

929
930
    after 100 "launch_SplashAnimate 300" 

931
    bind .splash <1> launch_SplashKill
932
    after 10000 launch_SplashKill
933
    tk scaling $oscaling
934
}
935

936
937
#-------------------------------------------------------------------------------
# .PROC launch_FileEvent
938
# helper proc to handle text coming from the child process
939
# if output is set to 0, a variable ::globallines has to exist to buffer the lines
940
941
942
943
# .ARGS
# file pointer, output enable switch
# .END
#-------------------------------------------------------------------------------
944
set ::count 0
945
proc launch_FileEvent {fp {output 1}} {
946
    if {[eof $fp]} {
947
948
949
950
951
        set ret [catch "close $fp" res]
        set ::saved_errorCode $::errorCode
        set ::saved_errorInfo $::errorInfo
        set ::saved_result $res
        set ::saved_return $ret
952
953
954
        set ::END 1
    } else {
        gets $fp line
955
956
957
958
959
960
961
        if {$output == 1} {
            puts $line
        } else {
            if {$line != ""} {
                append ::globallines $line
            }
        }
962
        launch_SplashKill ;# just in case the pre-splash screen is still up
963
964
965
    }
}

966
967
#-------------------------------------------------------------------------------
# .PROC launch_RunProgram
968
969
970
971
# run the actual program 
# - check for a --launch argument for a replacement main app, otherwise run Slicer3-real
# - process the arguments to adjust the escape characters
# - launch the main app as a child process and monitor the stdout and return codes
972
973
974
# .ARGS
# .END
#-------------------------------------------------------------------------------
975
976
proc launch_RunProgram {} {

977
978
979
980
981
    #
    # change from tcl escape to shell escape for command line arguments 
    # that contain spaces -- note that shell notation only works for a single
    # level of nesting
    # - change backslashes to forward slashes (for windows paths)
982
    # - escape the spaces in each of the arguments (non-windows only)
983
    # - handle any escaped | where the \ was changed to / by mistake
984
985
    #
    regsub -all "\\\\" $::argv "/" ::argv
986
    regsub -all "/\\|" $::argv "\\\\|" ::argv
987
988
989
990
991
992
993
    if {$::env(BUILD) != $::WINDOWS} {
      set newargv ""
      foreach a $::argv {
          regsub -all " " $a "\\\ " a
          lappend newargv $a
      }
      set ::argv $newargv
994
    }
995
996
997
998
999

    if {$::env(BUILD) != $::WINDOWS} {
      # turn curly braces into quotes
      regsub -all "{|}" $::argv "\\\"" ::argv
    }
1000

1001
1002
1003
1004
1005
1006
1007
1008
    #
    # If launchDesigner True,
    # let's update launchCommand with the complete path to Qt Designer
    #
    
    if { $::LAUNCH(launchDesigner)} {
      set ::LAUNCH(launchCommand) $::env(QT_BINARY_DIR)/$::env(QTDESIGNER_EXE)
      puts "Starting $::LAUNCH(launchCommand)"
1009
      puts "Loading plugins from $::env(Slicer_QT_PLUGIN_PATH)/designer and $::env(CTK_QT_PLUGIN_PATH)"
1010
    }
1011

1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
    #
    # launch the slicer main script as a sub-process and monitor the output
    # - process is started with the 'open' command through a pipe
    # - the file_event callback is triggered when subprocess has written to stdout
    # - pipe is closed when process exits, causing launcher to exit too.
    #
    # why? well, some messages only go to console stdout and we don't want to lose them.
    # Also, on windows if you block waiting for the process to exit the launcher would
    # be "Not Responding" and things like screen savers and power management might not 
    # work right.
    #

1024
1025
    # 
    # determine the correct arguments and executable for the platform
1026
    #
1027
    if { $::LAUNCH(launchCommand) == "" } {          
1028
1029
        if { [catch { set ::LAUNCH(launchCommand) $::Slicer_REAL } res] } {
            ShowAndLogError "Failed to execute Slicer_REAL: $res"
1030
            exit $::EXIT_CODE_GENERIC_ERROR
1031
        }