3 import glob, multiprocessing, os, platform, readline
4 from distutils import spawn
6 ## --------------------
7 ## -- Various values --
8 ## --------------------
10 system_name = platform.system( )
11 process_count = multiprocessing.cpu_count( ) / 2
12 home_dir = os.environ[ "HOME" ]
14 ## ------------------------
15 ## -- Filename completer --
16 ## ------------------------
18 def filename_completer( text, state ):
19 return ( glob.glob( text + '*' ) + [ None ] )[ state ]
22 def get_filepath( message ):
23 readline.set_completer_delims( ' \t\n;' )
24 readline.parse_and_bind( "tab: complete" )
25 readline.set_completer( filename_completer )
26 return os.path.abspath( raw_input( message ) )
29 ## --------------------
30 ## -- File extractor --
31 ## --------------------
33 def file_extract( filename, outdir ):
35 for ext in [ ".zip", ".tar", ".tar.gz", ".tar.bz2" ]:
36 if filename[ len( filename ) - len( ext ) : ] == ext:
41 if real_ext == ".zip":
42 command = "unzip " + filename + " -d " + outdir
43 elif real_ext == ".tar":
44 command = "tar xf " + filename + " -C " + outdir + " --strip-components=1"
45 elif real_ext == ".tar.gz":
46 command = "tar xzf " + filename + " -C " + outdir + " --strip-components=1"
47 elif real_ext == ".tar.bz2":
48 command = "tar xjf " + filename + " -C " + outdir + " --strip-components=1"
51 print( "\tExtracting " + filename + "..." )
52 res = os.system( "mkdir -p " + outdir + " && " + command )
69 if system_name == "Linux":
74 home_dir + "/local/bin"
76 qmake_progs = [ "qmake", "qmake-qt4" ]
80 for prog in qmake_progs:
81 for loc in qmake_locations:
82 path = spawn.find_executable( loc + "/" + prog )
84 qmake_paths.append( path )
88 print( "Please choose one configuration for Qt4:" )
89 for i in range( len( qmake_paths ) ):
90 print( "\t" + str( i ) + ": " + qmake_paths[ i ] )
92 print( "\t" + str( len( qmake_paths ) + 0 ) + ": Give another installation path (path to qmake)." )
93 print( "\t" + str( len( qmake_paths ) + 1 ) + ": Build from scratch." )
95 while qmake_opt == -1:
96 qmake_opt = int( raw_input( "\t---> " ) )
97 if qmake_opt < 0 or qmake_opt > len( qmake_paths ) + 1:
104 if qmake_opt == len( qmake_paths ):
105 qmake_exec = get_filepath( "Choose your own Qt4 installation: " )
106 while not os.path.isfile( qmake_exec ):
107 qmake_exec = get_filepath( "Choose your own Qt4 installation: " )
109 elif qmake_opt == len( qmake_paths ) + 1:
110 qmake_src = get_filepath( "Choose your own Qt4 source file: " )
111 while not os.path.isfile( qmake_src ):
112 qmake_src = get_filepath( "Choose your own Qt4 source file: " )
115 qmake_exec = qmake_paths[ qmake_opt ]
118 ## --------------------
119 ## -- Look for CMake --
120 ## --------------------
124 if system_name == "Linux":
129 home_dir + "/local/bin"
131 cmake_progs = [ "cmake" ]
135 for prog in cmake_progs:
136 for loc in cmake_locations:
137 path = spawn.find_executable( loc + "/" + prog )
139 cmake_paths.append( path )
143 print( "Please choose one configuration for CMake:" )
144 for i in range( len( cmake_paths ) ):
145 print( "\t" + str( i ) + ": " + cmake_paths[ i ] )
147 print( "\t" + str( len( cmake_paths ) + 0 ) + ": Give another installation path (path to cmake)." )
148 print( "\t" + str( len( cmake_paths ) + 1 ) + ": Build from scratch." )
150 while cmake_opt == -1:
151 cmake_opt = int( raw_input( "\t---> " ) )
152 if cmake_opt < 0 or cmake_opt > len( cmake_paths ) + 1:
159 if cmake_opt == len( cmake_paths ):
160 cmake_exec = get_filepath( "Choose your own CMake installation: " )
161 while not os.path.isfile( cmake_exec ):
162 cmake_exec = get_filepath( "Choose your own CMake installation: " )
164 elif cmake_opt == len( cmake_paths ) + 1:
165 cmake_src = get_filepath( "Choose your own CMake source file: " )
166 while not os.path.isfile( cmake_src ):
167 cmake_src = get_filepath( "Choose your own CMake source file: " )
170 cmake_exec = cmake_paths[ cmake_opt ]
173 ## ------------------
174 ## -- Look for ITK --
175 ## ------------------
177 itk_src = get_filepath( "Choose your own ITK source file: " )
178 while not os.path.isfile( itk_src ):
179 itk_src = get_filepath( "Choose your own ITK source file: " )
182 ## ------------------
183 ## -- Look for VTK --
184 ## ------------------
186 vtk_src = get_filepath( "Choose your own VTK source file: " )
187 while not os.path.isfile( vtk_src ):
188 vtk_src = get_filepath( "Choose your own VTK source file: " )
191 ## --------------------------
192 ## -- Miscelaneous options --
193 ## --------------------------
195 build_prefix = get_filepath( "Build prefix: " )
196 install_prefix = get_filepath( "Installation prefix: " )
197 build_type = raw_input( "Build type [release/debug]: " ).lower( )
199 os.system( "mkdir -p " + build_prefix )
200 os.system( "mkdir -p " + install_prefix )
202 ## -------------------
203 ## -- Extract files --
204 ## -------------------
206 print( "Extracting source code... " )
207 if qmake_src <> None:
208 file_extract( qmake_src, build_prefix + "/qt4-source" )
210 if cmake_src <> None:
211 file_extract( cmake_src, build_prefix + "/cmake-source" )
213 file_extract( itk_src, build_prefix + "/itk-source" )
214 file_extract( vtk_src, build_prefix + "/vtk-source" )
221 if qmake_src <> None:
222 full = raw_input( "\tWould you like to perform a full Qt4 build [y/n]? " )
225 qt4_source = os.path.abspath( build_prefix + "/qt4-source" )
226 qt4_build = os.path.abspath( build_prefix + "/qt4-build" )
227 os.system( "mkdir -p " + qt4_build )
229 config_command = qt4_source + "/configure"
230 config_command += " -prefix " + install_prefix
231 config_command += " -" + build_type
232 config_command += " -opensource -shared -fast -no-webkit -optimized-qmake -confirm-license"
234 config_command += " -no-phonon -no-phonon-backend -no-openvg -nomake demos -nomake examples"
236 ## MACOS: -no-framework
239 res = os.system( "cd " + qt4_build + " && " + config_command )
241 print( "Error configuring Qt4." )
244 res = os.system( "cd " + qt4_build + " && make -j" + str( process_count ) )
246 print( "Error compiling Qt4." )
249 res = os.system( "cd " + qt4_build + " && make -j install" )
251 print( "Error installing Qt4." )
254 qmake_exec = install_prefix + "/bin/qmake"
261 if cmake_src <> None:
262 cmake_source = os.path.abspath( build_prefix + "/cmake-source" )
263 cmake_build = os.path.abspath( build_prefix + "/cmake-build" )
264 os.system( "mkdir -p " + cmake_build )
266 config_command = cmake_source + "/bootstrap"
267 config_command += " --prefix " + install_prefix
268 if qmake_exec <> None:
269 config_command += " --qt-gui --qt-qmake=" + qmake_exec
271 config_command += " --no-qt-gui"
275 res = os.system( "cd " + cmake_build + " && " + config_command )
277 print( "Error configuring CMake." )
280 res = os.system( "cd " + cmake_build + " && make -j" + str( process_count ) )
282 print( "Error compiling CMake." )
285 res = os.system( "cd " + cmake_build + " && make -j install" )
287 print( "Error installing CMake." )
290 cmake_exec = install_prefix + "/bin/cmake"
297 vtk_source = os.path.abspath( build_prefix + "/vtk-source" )
298 vtk_build = os.path.abspath( build_prefix + "/vtk-build" )
299 os.system( "mkdir -p " + vtk_build )
301 kitware_build = "MinSizeRel"
302 if build_type == "debug":
303 kitware_build = "Debug"
306 vtk_configure = cmake_exec
307 vtk_configure += " -DCMAKE_CXX_FLAGS:STRING=-std=c++11"
308 vtk_configure += " -DBUILD_DOCUMENTATION:BOOL=OFF"
309 vtk_configure += " -DBUILD_EXAMPLES:BOOL=OFF"
310 vtk_configure += " -DBUILD_SHARED_LIBS:BOOL=ON"
311 vtk_configure += " -DBUILD_TESTING:BOOL=OFF"
312 vtk_configure += " -DCMAKE_BUILD_TYPE:STRING=" + kitware_build
313 if qmake_exec <> None:
314 vtk_configure += " -DQT_QMAKE_EXECUTABLE:PATH=" + qmake_exec
315 vtk_configure += " -DModule_vtkGUISupportQt:BOOL=ON"
316 vtk_configure += " -DModule_vtkGUISupportQtOpenGL:BOOL=ON"
317 vtk_configure += " -DModule_vtkGUISupportQtSQL:BOOL=OFF"
318 vtk_configure += " -DModule_vtkGUISupportQtWebkit:BOOL=OFF"
320 vtk_configure += " -DCMAKE_INSTALL_PREFIX:PATH=" + install_prefix
321 vtk_configure += " " + vtk_source
324 res = os.system( "cd " + vtk_build + " && " + vtk_configure )
326 print( "Error configuring VTK." )
329 res = os.system( "cd " + vtk_build + " && make -j" + str( process_count ) )
331 print( "Error compiling VTK." )
334 res = os.system( "cd " + vtk_build + " && make -j install" )
336 print( "Error installing VTK." )
344 itk_source = os.path.abspath( build_prefix + "/itk-source" )
345 itk_build = os.path.abspath( build_prefix + "/itk-build" )
346 os.system( "mkdir -p " + itk_build )
348 kitware_build = "MinSizeRel"
349 if build_type == "debug":
350 kitware_build = "Debug"
353 itk_configure = cmake_exec
354 itk_configure += " -DCMAKE_CXX_FLAGS:STRING=-std=c++11"
355 itk_configure += " -DBUILD_DOCUMENTATION:BOOL=OFF"
356 itk_configure += " -DBUILD_EXAMPLES:BOOL=OFF"
357 itk_configure += " -DBUILD_SHARED_LIBS:BOOL=ON"
358 itk_configure += " -DBUILD_TESTING:BOOL=OFF"
359 itk_configure += " -DCMAKE_BUILD_TYPE:STRING=" + kitware_build
360 itk_configure += " -DModule_ITKReview:BOOL=ON"
361 itk_configure += " -DModule_ITKVtkGlue:BOOL=OFF"
362 itk_configure += " -DModule_ParabolicMorphology:BOOL=ON"
363 itk_configure += " -DCMAKE_INSTALL_PREFIX:PATH=" + install_prefix
364 itk_configure += " " + itk_source
367 res = os.system( "cd " + itk_build + " && " + itk_configure )
369 print( "Error configuring ITK." )
372 res = os.system( "cd " + itk_build + " && make -j" + str( process_count ) )
374 print( "Error compiling ITK." )
377 res = os.system( "cd " + itk_build + " && make -j install" )
379 print( "Error installing ITK." )