Salome HOME
Replaced obsolete test main_test.py by a new test for SALOME
[tools/solverlab.git] / CoreFlows / configure
1 #!/usr/bin/env python
2
3 import optparse
4 import os
5 import sys
6 import subprocess
7 import pdb
8     
9 TrueFalseStr=("False","True")
10 TrueFalse={'no':False, 'yes':True}
11
12 def GetCDMATHOptions(options):
13     res=" -DCDMATH_DIR="+options.cdmath_dir
14     return res
15
16 def GetPETSC_DIROptions(options):
17     res=' -DPETSC_DIR='+options.petsc_dir
18     return res
19
20 def GetDebugOptions(options):
21         if options.debug == True:
22             res=" -DCMAKE_BUILD_TYPE=Debug "
23         else:
24                 res=""
25         return res
26
27 def GetPETSC_ARCHOptions(options):
28         res=' -DPETSC_ARCH="'+options.petsc_arch+'"'
29         return res
30
31 def GetInstallPrefix(options):
32     res=" -DCMAKE_INSTALL_PREFIX="+options.install_prefix
33     return res
34
35 def GetPythonOptions(options):
36     res=" -DCOREFLOWS_WITH_PYTHON="+TrueFalseStr[options.python]
37     return res
38
39 def GetPackagesOptions(options):
40     res=" -DCOREFLOWS_WITH_PACKAGE="+TrueFalseStr[options.packages]
41     return res
42
43 def GetDocOptions(options):
44     res=" -DCOREFLOWS_WITH_DOCUMENTATION="+TrueFalseStr[options.doc]
45     return res
46
47 def GetGuiOptions(options):
48     res=" -DCOREFLOWS_WITH_GUI="+TrueFalseStr[options.gui]
49     return res
50
51 def GetEclipseOptions(options):
52         res=" -G\"Eclipse CDT4 - Unix Makefiles\""*(options.create_eclipse_project)
53         return res
54
55 def GetCmakeExecOption(options):
56     cmakeExecutable=options.path_to_cmake_exec
57     return cmakeExecutable
58
59 def CheckOptions(parser):
60     options, arguments = parser.parse_args()
61     for stringToCheck in ['cdmath_dir', 'petsc_dir', 'petsc_arch']:
62         if options.__dict__[stringToCheck] is None:
63             parser.error("cannot determine "+stringToCheck)
64
65 def printDocumentationInstructions(options):
66         if options.doc:
67                 print "\n\t$ make doc\n\tto create the documentation."
68         return
69
70
71 def ForgeCMakeCommand(options):
72     installPrefix=GetInstallPrefix(options)
73     CDMATHOptions=GetCDMATHOptions(options)
74     PETSC_DIROptions=GetPETSC_DIROptions(options)
75     PETSC_ARCHOptions=GetPETSC_ARCHOptions(options)
76     guiOptions=GetGuiOptions(options)
77     docOptions=GetDocOptions(options)
78     packagesOptions=GetPackagesOptions(options)
79     debugOptions=GetDebugOptions(options)
80     pythonOptions=GetPythonOptions(options)
81     absolutePathToConfigure = os.path.abspath(sys.argv[0])
82     absolutePathToProjectDir = os.path.dirname(absolutePathToConfigure)
83     eclipseProjectoptions=GetEclipseOptions(options)
84     cmake_options=(
85             installPrefix+" "
86             +debugOptions
87             +guiOptions+" "
88             +pythonOptions+" "
89             +CDMATHOptions+" "
90             +PETSC_DIROptions+" "
91             +PETSC_ARCHOptions+" "
92             +docOptions+" "
93             +packagesOptions+" "
94             +eclipseProjectoptions
95             )
96     cmake_executable=GetCmakeExecOption(options)
97     cmake_cmd=cmake_executable+" "+cmake_options+" "+absolutePathToProjectDir
98     return cmake_cmd
99
100 def main():
101     usage = "usage: %prog [options]"
102     p = optparse.OptionParser(usage=usage,conflict_handler="error")
103     p.add_option('--prefix',
104                  default=".",
105                  metavar="<dir>",
106                  dest="install_prefix",
107                  help="specify location for installing CoreFlows (default is $PWD)"
108                  )
109     p.add_option('--with-petsc-dir',
110                  type="string",
111                  metavar="<dir>",
112                  default=os.environ.get('PETSC_DIR'),
113                  dest="petsc_dir",
114                  help="specify the petsc install directory (default value is $PETSC_DIR environement variable )"
115                  )
116     p.add_option('--with-petsc-arch',
117                  type="string",
118                  metavar="<dir>",
119                  default=os.environ.get('PETSC_ARCH'),
120                  dest="petsc_arch",
121                  help="specify the petsc arch (default value is $PETSC_ARCH environement variable )"
122                  )
123     p.add_option('--with-cdmath-dir',
124                  type="string",
125                  metavar="<dir>",
126                  default=os.environ.get('CDMATH_DIR'),
127                  dest="cdmath_dir",
128                  help="specify the install directory or CDMATH (default is the environment variable $CDMATH_DIR)"
129                  )
130     p.add_option('--create-eclipse-project',
131                          action="store_true",
132                  default=False,
133                  dest="create_eclipse_project",
134                  help="create an eclipse project"
135                  )
136     p.add_option('--with-python',
137                          action="store_true",
138                  default=False,
139                  dest="python",
140                  help="compile python interface for CoreFlows"
141                  )
142     p.add_option('--with-packages',
143                          action="store_true",
144                  default=False,
145                  dest="packages",
146                  help="generate CoreFlows packages"
147                  )
148     p.add_option('--with-gui',
149                          action="store_true",
150                  default=False,
151                  dest="gui",
152                  help="compile CoreFlows GUI"
153                  )
154     p.add_option('--with-doc',
155                          action="store_true",
156                  default=False,
157                  dest="doc",
158                  help="generate CoreFlows documentation"
159                  )
160     p.add_option('--with-debug',
161                          action="store_true",
162                  default=False,
163                  dest="debug",
164                  help="compile CoreFlows in debug mode"
165                  )
166     p.add_option('--with-cmake-exec',
167                  type="string",
168                  metavar="<path>",
169                  default="cmake",
170                  dest="path_to_cmake_exec",
171                  help="specify a path to a specific CMake executable"
172                  )
173     options, arguments = p.parse_args()
174     CheckOptions(p)
175     cmake_cmd=ForgeCMakeCommand(options)
176     print cmake_cmd
177     print "Configuring CoreFlows"
178     returnCode=subprocess.call(cmake_cmd,shell=True)
179     returnCode=0
180     if returnCode == 0:
181         print("\n\nNow issue:\n\t$ make install\n\tfor compiling the code.")
182         print("\n\t$ make test\n\tto test the code execution.")
183         printDocumentationInstructions(options)
184     else:
185         print("error: cmake did not run correctly.")
186
187 #    if __name__ == '__main__':
188 main()