2 # -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2009-2015 EDF R&D
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 hxx2salome.py [options] <CPPCOMPO>_root_dir lib<CPPCOMPO>.hxx <CPPCOMPO>.so installDir
24 generate a SALOME component that wrapps given the C++ component
28 - <CPPCOMPO>_root_dir : install directory (absolute path) of the c++ component
29 - <CPPCOMPO>.hxx : header of the c++ component"
30 - lib<CPPCOMPO>.so : the shared library containing the c++ component
31 - installDir : directory where the generated files and the build should be installed
33 Note that <CPPCOMPO>.hxx and lib<CPPCOMPO>.so should be found in <CPPCOMPO>_root_dir)
41 from module_generator import Generator,Module,Service,HXX2SALOMEComponent
43 # ------------------------------------------------------------------------------
46 # Reproduce the main options of original hxx2salome script
47 parser = optparse.OptionParser(usage=usage)
52 help="specify the name of a environment file (bash/sh) that will" +\
59 help="to create a generic gui in your component building tree")
65 help="to compile after generation")
69 help="use this option with csh to update the environment " +\
70 "with the CSH syntax")
72 options, args = parser.parse_args()
74 assert len(args) == 4, \
75 'ERROR, four mandatory arguments are expected!\n\n%s\n' % usage
76 cppdir = args[0] # install directory of the c++ component
77 hxxfile = args[1] # header of the c++ component
78 libfile = args[2] # the shared library containing the c++ component
79 installpath = args[3] # directory where the generated files are installed
81 # Make sure given paths/files are valid
82 if not os.path.exists(cppdir):
83 print "ERROR: cppdir %s does not exist. It is mandatory" % cppdir
87 if not os.path.exists(installpath):
88 print "ERROR: installpath %s does not exist. It is mandatory" \
93 if options.environ_file != None:
94 if not os.path.exists(options.environ_file):
95 print "ERROR: environ_file %s does not exist. It is mandatory" \
96 % options.environ_file
100 hxx2salome(cppdir=cppdir,
103 installpath=installpath,
104 do_gui=options.do_gui,
105 do_compile=options.do_compile,
106 environ_file=options.environ_file,
107 shell_syntax=options.shell_syntax
111 # ------------------------------------------------------------------------------
113 def hxx2salome(cppdir,
122 # setup from environment a minimal context
123 kernel_root_dir=os.environ["KERNEL_ROOT_DIR"]
124 gui_root_dir=os.environ["GUI_ROOT_DIR"]
127 "kernel":kernel_root_dir,
131 salome_compo = HXX2SALOMEComponent(hxxfile,libfile,cppdir)
132 install_root_dir = os.path.join(installpath,salome_compo.name)
133 module_root_dir = os.path.join(install_root_dir,
134 salome_compo.name+"_INSTALL")
136 # to be able to compile the generated component
137 os.environ[salome_compo.name+"CPP_ROOT_DIR"]=cppdir
139 # if necessary creates the directory in which the component
140 # will be geberated and compiled.
142 os.mkdir(install_root_dir)
144 print "Warning : directory %s already exixts!" % install_root_dir
146 # if a graphical user interface is required,
147 # ask HXX2SALOMEComponent to generate template files
149 gui_files=salome_compo.getGUIfilesTemplate()
150 g=Generator(Module(salome_compo.name,components=[salome_compo],
151 prefix=module_root_dir,
155 g=Generator(Module(salome_compo.name,components=[salome_compo],
156 prefix=module_root_dir),
159 # go in install_root_dir, generate the component
160 os.chdir(install_root_dir)
163 # if specified : compile and install the generated component
170 # update environment file if furnished
171 if environ_file != None:
172 envfile=open(environ_file,"a")
173 if shell_syntax == "csh":
175 #------ ${compo_name}
176 setenv ${compo_name}_SRC_DIR ${install_root_dir}/${compo_name}_SRC
177 setenv ${compo_name}_ROOT_DIR ${install_root_dir}/${compo_name}_INSTALL
181 #------ ${compo_name}
182 export ${compo_name}_SRC_DIR=${install_root_dir}/${compo_name}_SRC
183 export ${compo_name}_ROOT_DIR=${install_root_dir}/${compo_name}_INSTALL
185 update_environ=string.Template(update_environ)
186 update_environ=update_environ.substitute(compo_name=salome_compo.name,
187 install_root_dir=install_root_dir)
188 envfile.write(update_environ)
192 # ------------------------------------------------------------------------------
194 if __name__ == '__main__':