Salome HOME
Merge branch 'V9_2_2_BR'
[tools/yacsgen.git] / module_generator / gener.py
index 5b5a32bb2f674dfa9b6a4f30eda816602ac60660..6b6dc1c47217c4aac4fe5bb5e664a4dabdbb927a 100644 (file)
@@ -1,9 +1,9 @@
-# Copyright (C) 2009-2013  EDF R&D
+# Copyright (C) 2009-2019  EDF R&D
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
 # License as published by the Free Software Foundation; either
-# version 2.1 of the License.
+# version 2.1 of the License, or (at your option) any later version.
 #
 # This library is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -24,31 +24,30 @@ import warnings
 try:
   from string import Template
 except:
-  from compat import Template, set
+  from module_generator.compat import Template, set
 
 class Invalid(Exception):
   pass
 
 debug=0
 
-from mod_tmpl import resMakefile, makecommon, configure, paco_configure
-from mod_tmpl import mainMakefile, autogen, application
-from mod_tmpl import check_sphinx
-from cata_tmpl import catalog, interface, idl, idlMakefile, parallel_interface
-from cata_tmpl import xml, xml_interface, xml_service
-from cata_tmpl import idlMakefilePaCO_BUILT_SOURCES, idlMakefilePaCO_nodist_salomeinclude_HEADERS
-from cata_tmpl import idlMakefilePACO_salomepython_DATA, idlMakefilePACO_salomeidl_DATA
-from cata_tmpl import idlMakefilePACO_INCLUDES
-from cata_tmpl import cataOutStream, cataInStream, cataOutparam, cataInparam
-from cata_tmpl import cataOutParallelStream, cataInParallelStream
-from cata_tmpl import cataService, cataCompo
-from aster_tmpl import check_aster
-from salomemodules import salome_modules
-from yacstypes import corbaTypes, corbaOutTypes, moduleTypes, idlTypes, corba_in_type, corba_out_type
-from yacstypes import ValidTypes, PyValidTypes, calciumTypes, DatastreamParallelTypes
-from yacstypes import ValidImpl, ValidImplTypes, ValidStreamTypes, ValidParallelStreamTypes, ValidDependencies
-from gui_tmpl import pyguimakefile, pysalomeapp, cppguimakefile, cppsalomeapp
-from doc_tmpl import docmakefile, docconf, docsalomeapp
+from module_generator.mod_tmpl import *
+from module_generator.cata_tmpl import catalog, interface, idl
+from module_generator.cata_tmpl import xml, xml_interface, xml_service
+from module_generator.cata_tmpl import idlMakefilePaCO_BUILT_SOURCES, idlMakefilePaCO_nodist_salomeinclude_HEADERS
+from module_generator.cata_tmpl import idlMakefilePACO_salomepython_DATA, idlMakefilePACO_salomeidl_DATA
+from module_generator.cata_tmpl import idlMakefilePACO_INCLUDES
+from module_generator.cata_tmpl import cataOutStream, cataInStream, cataOutparam, cataInparam
+from module_generator.cata_tmpl import cataOutParallelStream, cataInParallelStream
+from module_generator.cata_tmpl import cataService, cataCompo
+#from aster_tmpl import check_aster
+from module_generator.salomemodules import salome_modules
+from module_generator.yacstypes import corbaTypes, corbaOutTypes, moduleTypes, idlTypes, corba_in_type, corba_out_type
+from module_generator.yacstypes import ValidTypes, PyValidTypes, calciumTypes, DatastreamParallelTypes
+from module_generator.yacstypes import ValidImpl, ValidImplTypes, ValidStreamTypes, ValidParallelStreamTypes, ValidDependencies
+from module_generator.gui_tmpl import cmake_py_gui, pysalomeapp, cmake_cpp_gui, cppsalomeapp
+from module_generator.doc_tmpl import docmakefile, docconf, docsalomeapp
+from module_generator import yacsgen_version
 
 def makedirs(namedir):
   """Create a new directory named namedir. If a directory already exists copy it to namedir.bak"""
@@ -71,15 +70,12 @@ class Module(object):
    :type name: str
    :param components: gives the list of components of the module.
    :param prefix: is the path of the installation directory.
-   :param layout: If given and has the value "monodir", all components
-      will be generated in a single directory. The default is to generate each component in its
-      own directory.
    :param doc: can be used to add an online documentation to the module. It must be a list of file names (sources, images, ...) that will be
       used to build a sphinx documentation (see http://sphinx.pocoo.org, for more information). If not given, the Makefile.am
       and the conf.py (sphinx configuration) files are generated. In this case, the file name extension of source files must be .rst.
       See small examples in Examples/pygui1 and Examples/cppgui1.
    :param gui: can be used to add a GUI to the module. It must be a list of file names (sources, images, qt designer files, ...).
-      If not given, the Makefile.am and SalomeApp.xml are generated. All image files are put in the resources directory of the module.
+      If not given, the CMakeLists.txt and SalomeApp.xml are generated. All image files are put in the resources directory of the module.
       The GUI can be implemented in C++ (file name extension '.cxx') or in Python (file name extension '.py').
       See small examples in Examples/pygui1 and Examples/cppgui1.
 
@@ -90,19 +86,18 @@ class Module(object):
                                                   prefix="./install")
 
   """
-  def __init__(self, name, components=None, prefix="",layout="multidir", doc=None, gui=None):
+  def __init__(self, name, components=None, prefix="", doc=None, gui=None):
     self.name = name
     self.components = components or []
     self.prefix = prefix or "%s_INSTALL" % name
-    self.layout=layout
     self.doc = doc
     self.gui = gui
     try:
       self.validate()
-    except Invalid,e:
+    except Invalid as e:
       if debug:
         traceback.print_exc()
-      print "Error in module %s: %s" % (name,e)
+      print("Error in module %s: %s" % (name,e))
       raise SystemExit
 
   def validate(self):
@@ -115,11 +110,34 @@ class Module(object):
         raise Invalid("%s is already defined as a component of the module" % compo.name)
       lcompo.add(compo.name)
       compo.validate()
-    if self.gui and self.layout != "multidir":
-      raise Invalid("A module with GUI can not be generated if layout is not multidir")
+
+class Library(object):
+  """
+     A :class:'Library' instance contains the informations of a user library.
+     
+     :param name: name of the library (exemple: "cppunit", "calcul")
+     :param path: path where to find the library (exemple: "/home/user/libs")
+  """
+  
+  def __init__(self, name, path):
+    self.name=name
+    self.path=path
+
+  def findLibrary(self):
+    """
+    return : text for the FIND_LIBRARY command for cmake.
+    Feel free to overload this function for your own needs.
+    """
+    return "FIND_LIBRARY( "+self.cmakeVarName()+" "+self.name+" PATH "+self.path + ")\n"
+    
+  def cmakeVarName(self):
+    """
+    return : name of the cmake variable used by FIND_LIBRARY
+    """
+    return "_userlib_" + self.name.split()[0]
 
 class Component(object):
-  def __init__(self, name, services=None, impl="PY", libs="", rlibs="",
+  def __init__(self, name, services=None, impl="PY", libs=[], rlibs="",
                      includes="", kind="lib", sources=None,
                      inheritedclass="",compodefs="",
                      idls=None,interfacedefs="",inheritedinterface="",addedmethods=""):
@@ -138,6 +156,31 @@ class Component(object):
     self.inheritedinterface=inheritedinterface
     self.addedmethods=addedmethods
 
+  def additionalLibraries(self):
+    """ generate the cmake code for finding the additional libraries
+    return
+      string containing a list of "find_library"
+      string containing a list of cmake variables defined
+    """
+    cmake_text=""
+    cmake_vars=""
+    
+    for lib in self.libs:
+      cmake_text = cmake_text + lib.findLibrary()
+      cmake_vars = cmake_vars + "${" + lib.cmakeVarName() + "}\n  "
+    
+    var_template = Template("$${${name}_SalomeIDL${name}}")
+    for mod in self.getDependentModules():
+      if salome_modules[mod]["linklibs"]:
+        cmake_vars = cmake_vars + salome_modules[mod]["linklibs"]
+      else:
+        default_lib = var_template.substitute(name=mod)
+        print("Unknown libraries for module " + mod)
+        print("Using default library name " + default_lib)
+        cmake_vars = cmake_vars + default_lib + "\n  "
+    
+    return cmake_text, cmake_vars
+
   def validate(self):
     if self.impl not in ValidImpl:
       raise Invalid("%s is not a valid implementation. It should be one of %s" % (self.impl, ValidImpl))
@@ -163,6 +206,65 @@ class Component(object):
   def setPrerequisites(self, prerequisites_file):
     self.prerequisites = prerequisites_file
 
+  def getIdlInterfaces(self):
+    services = self.getIdlServices()
+    inheritedinterface=""
+    if self.inheritedinterface:
+      inheritedinterface=self.inheritedinterface+","
+    return interface.substitute(component=self.name,
+                                services="\n".join(services),
+                                inheritedinterface=inheritedinterface)
+
+  def getIdlServices(self):
+    services = []
+    for serv in self.services:
+      params = []
+      for name, typ in serv.inport:
+        if typ == "file":continue #files are not passed through IDL interface
+        if self.impl in ("PY", "ASTER") and typ == "pyobj":
+          typ = "Engines::fileBlock"
+        else:
+          typ=idlTypes[typ]
+        params.append("in %s %s" % (typ, name))
+      for name, typ in serv.outport:
+        if typ == "file":continue #files are not passed through IDL interface
+        if self.impl in ("PY", "ASTER") and typ == "pyobj":
+          typ = "Engines::fileBlock"
+        else:
+          typ=idlTypes[typ]
+        params.append("out %s %s" % (typ, name))
+      service = "    %s %s(" % (idlTypes[serv.ret],serv.name)
+      service = service+",".join(params)+") raises (SALOME::SALOME_Exception);"
+      services.append(service)
+    return services
+
+  def getIdlDefs(self):
+    idldefs = """
+#include "DSC_Engines.idl"
+#include "SALOME_Parametric.idl"
+"""
+    if self.interfacedefs:
+      idldefs = idldefs + self.interfacedefs
+    return idldefs
+
+  def getDependentModules(self):
+    """get the list of SALOME modules used by the component
+    """
+    def get_dependent_modules(mod,modules):
+      modules.add(mod)
+      if "depends" in salome_modules[mod]:
+        for m in salome_modules[mod]["depends"]:
+          if m not in modules:
+            get_dependent_modules(m,modules)
+
+    depend_modules = set()
+    for serv in self.services:
+      for name, typ in serv.inport + serv.outport + [ ("return",serv.ret) ] :
+        mod = moduleTypes[typ]
+        if mod:
+          get_dependent_modules(mod,depend_modules)
+    return depend_modules
+
 class Service(object):
   """
    A :class:`Service` instance represents a component service with dataflow and datastream ports.
@@ -192,7 +294,7 @@ class Service(object):
 
       >>> s1 = module_generator.Service('myservice', inport=[("a","double"),],
                                         instream=[("aa","CALCIUM_double","I")],
-                                        body="print a")
+                                        body="print( a)")
 
 
   """
@@ -317,10 +419,14 @@ class Generator(object):
     for component in self.module.components:
       component.setPrerequisites(self.context.get("prerequisites"))
 
+  def sourceDir(self):
+    """ get the name of the source directory"""
+    return self.module.name+"_SRC"
+
   def generate(self):
     """Generate a SALOME source module"""
     module = self.module
-    namedir = module.name+"_SRC"
+    namedir = self.sourceDir()
     force = self.context.get("force")
     update = self.context.get("update")
     paco = self.context.get("paco")
@@ -335,212 +441,122 @@ class Generator(object):
       os.makedirs(namedir)
 
     srcs = {}
-    makefile = "SUBDIRS="
-    makefileItems={"header":"""
-include $(top_srcdir)/adm_local/make_common_starter.am
-AM_CFLAGS=$(SALOME_INCLUDES) -fexceptions
-""",
-                   "salomepython_PYTHON":[],
-                   "dist_salomescript_SCRIPTS":[],
-                   "salomeres_DATA":[],
-                   "lib_LTLIBRARIES":[],
-                   "salomeinclude_HEADERS":[],
-                   "body":"",
-                  }
 
     #get the list of SALOME modules used and put it in used_modules attribute
-    def get_dependent_modules(mod,modules):
-      modules[mod]=1
-      if not salome_modules[mod].has_key("depends"):return
-      for m in salome_modules[mod]["depends"]:
-        if modules.has_key(m):continue
-        get_dependent_modules(m,modules)
-
-    modules = {}
+    modules = set()
     for compo in module.components:
-      for serv in compo.services:
-        for name, typ in serv.inport + serv.outport + [ ("return",serv.ret) ] :
-          mod = moduleTypes[typ]
-          if mod:
-            get_dependent_modules(mod,modules)
-
-    self.used_modules = modules.keys()
+      modules |= compo.getDependentModules()
+      
+    self.used_modules = modules
 
     for compo in module.components:
       #for components files
       fdict=compo.makeCompo(self)
-      if self.module.layout=="multidir":
-        srcs[compo.name] = fdict
-        #for src/Makefile.am
-        makefile = makefile + " " + compo.name
-      else:
-        srcs.update(fdict)
-        #for src/Makefile.am
-        mdict=compo.getMakefileItems(self)
-        makefileItems["salomepython_PYTHON"]=makefileItems["salomepython_PYTHON"]+mdict.get("salomepython_PYTHON",[])
-        makefileItems["dist_salomescript_SCRIPTS"]=makefileItems["dist_salomescript_SCRIPTS"]+mdict.get("dist_salomescript_SCRIPTS",[])
-        makefileItems["salomeres_DATA"]=makefileItems["salomeres_DATA"]+mdict.get("salomeres_DATA",[])
-        makefileItems["lib_LTLIBRARIES"]=makefileItems["lib_LTLIBRARIES"]+mdict.get("lib_LTLIBRARIES",[])
-        makefileItems["salomeinclude_HEADERS"]=makefileItems["salomeinclude_HEADERS"]+mdict.get("salomeinclude_HEADERS",[])
-        makefileItems["body"]=makefileItems["body"]+mdict.get("body","")+'\n'
+      srcs[compo.name] = fdict
 
-    if module.gui:
+    cmakecontent = ""
+    components_string = "".join([x.name+" " for x in module.components])
+
+    if self.module.gui:
       GUIname=module.name+"GUI"
       fdict=self.makeGui(namedir)
       srcs[GUIname] = fdict
-      #for src/Makefile.am
-      makefile = makefile + " " + GUIname
-
-    if self.module.layout == "multidir":
-      srcs["Makefile.am"] = makefile+'\n'
-    else:
-      srcs["Makefile.am"] = self.makeMakefile(makefileItems)
+      components_string = components_string + "\n  " + GUIname
+      
+    cmakecontent = cmake_src.substitute(components=components_string)
+    srcs["CMakeLists.txt"] = cmakecontent
 
     docsubdir=""
     if module.doc:
       docsubdir="doc"
+      cmake_doc="ON"
+    else:
+      cmake_doc="OFF"
 
     #for catalog files
     catalogfile = "%sCatalog.xml" % module.name
 
-    need_boost=0
     if module.gui:
-        need_boost=1
-    for compo in module.components:
-      if hasattr(compo,"calciumextendedinterface") and compo.calciumextendedinterface:
-        need_boost=1
-        break
-
-    #add makefile definitions to make_common_starter.am
-    other_includes=""
-    common_starter = makecommon.substitute(other_includes=other_includes)
-    for mod in self.used_modules:
-      common_starter = common_starter + salome_modules[mod]["makefiledefs"] + '\n'
-
-    adm_local={"make_common_starter.am": common_starter, "check_aster.m4":check_aster}
-    if module.doc:
-      adm_local["check_sphinx.m4"]=check_sphinx
+      cmake_gui="ON"
+    else:
+      cmake_gui="OFF"
+      
+    prefix = os.path.abspath(self.module.prefix)
+    component_libs = "".join([x.libraryName()+" " for x in module.components])
+    add_modules = ""
+    for x in self.used_modules:
+      cmake_text = cmake_find_module.substitute(module=x)
+      if x == "MED":
+        cmake_text = cmake_text + """
+#####################################
+# FIND MEDCOUPLING
+#####################################
+SET(MEDCOUPLING_ROOT_DIR $ENV{MEDCOUPLING_ROOT_DIR} CACHE PATH "Path to MEDCOUPLING module")
+IF(EXISTS ${MEDCOUPLING_ROOT_DIR})
+  LIST(APPEND CMAKE_MODULE_PATH "${MEDCOUPLING_ROOT_DIR}/cmake_files")
+  FIND_PACKAGE(SalomeMEDCoupling REQUIRED)
+  ADD_DEFINITIONS(${MEDCOUPLING_DEFINITIONS})
+  INCLUDE_DIRECTORIES(${MEDCOUPLING_INCLUDE_DIRS})
+ELSE(EXISTS ${MEDCOUPLING_ROOT_DIR})
+  MESSAGE(FATAL_ERROR "We absolutely need MEDCOUPLING module, please define MEDCOUPLING_ROOT_DIR")
+ENDIF(EXISTS ${MEDCOUPLING_ROOT_DIR})
+#####################################
 
-    self.makeFiles({"autogen.sh":autogen,
-                    "Makefile.am":mainMakefile.substitute(docsubdir=docsubdir),
+"""
+      add_modules = add_modules + cmake_text
+      pass
+    
+    self.makeFiles({"CMakeLists.txt":cmake_root_cpp.substitute(
+                                                 module=self.module.name,
+                                                 module_min=self.module.name.lower(),
+                                                 compolibs=component_libs,
+                                                 with_doc=cmake_doc,
+                                                 with_gui=cmake_gui,
+                                                 add_modules=add_modules,
+                                                 major_version=yacsgen_version.major_version,
+                                                 minor_version=yacsgen_version.minor_version,
+                                                 patch_version=yacsgen_version.patch_version),
                     "README":"", "NEWS":"", "AUTHORS":"", "ChangeLog":"",
                     "src":srcs,
-                    "resources":{"Makefile.am":resMakefile.substitute(module=module.name), catalogfile:self.makeCatalog()},
-                    "adm_local":adm_local,
+                    "resources":{"CMakeLists.txt":cmake_ressources.substitute(
+                                                        module=self.module.name),
+                                 catalogfile:self.makeCatalog()},
                     }, namedir)
 
-    #add checks for modules in configure.ac
-    configure_modules=""
-    for mod in self.used_modules:
-      configure_modules = configure_modules + salome_modules[mod]["configdefs"] + '\n'
-
-    #for configure.ac
-    configure_makefiles = []
-    if self.module.layout=="multidir":
-      for compo in module.components:
-        configure_makefiles.append("     src/"+compo.name+"/Makefile")
-
-    if module.gui:
-      configure_makefiles.append("     src/%sGUI/Makefile" % module.name)
-    if module.doc:
-      configure_makefiles.append("     doc/Makefile")
-
-    other_check=""
-    other_summary=""
-    other_require=""
-
-    if need_boost:
-      other_check=other_check+"""CHECK_BOOST
-"""
-      other_summary=other_summary+"""echo "  Boost  ................. : $boost_ok"
-"""
-
-    if module.gui:
-      other_check=other_check + """CHECK_SALOME_GUI
-CHECK_QT
-"""
-      other_summary=other_summary+'''echo "  SALOME GUI ............. : $SalomeGUI_ok"
-echo "  Qt ..................... : $qt_ok"
-'''
-      other_require=other_require + """
-      if test "x$SalomeGUI_ok" = "xno"; then
-        AC_MSG_ERROR([SALOME GUI is required],1)
-      fi
-      if test "x$qt_ok" = "xno"; then
-        AC_MSG_ERROR([Qt library is required],1)
-      fi
-"""
-    if module.doc:
-      other_check=other_check+"CHECK_SPHINX\n"
-      other_summary=other_summary+'''echo "  Sphinx ................. : $sphinx_ok"\n'''
-      other_require=other_require + """
-      if test "x$sphinx_ok" = "xno"; then
-        AC_MSG_ERROR([Sphinx documentation generator is required],1)
-      fi
-"""
-
     files={}
     #for idl files
     idlfile = "%s.idl" % module.name
-    paco_config=""
-    PACO_BUILT_SOURCES=""
-    PACO_SALOMEINCLUDE_HEADERS=""
-    PACO_INCLUDES=""
-    PACO_salomepython_DATA=""
-    PACO_salomeidl_DATA=""
-
-    if paco:
-      PACO_BUILT_SOURCES = idlMakefilePaCO_BUILT_SOURCES.substitute(module=module.name)
-      PACO_SALOMEINCLUDE_HEADERS = idlMakefilePaCO_nodist_salomeinclude_HEADERS.substitute(module=module.name)
-      PACO_salomepython_DATA = idlMakefilePACO_salomepython_DATA.substitute(module=module.name)
-      PACO_salomeidl_DATA = idlMakefilePACO_salomeidl_DATA.substitute(module=module.name)
-      PACO_INCLUDES = idlMakefilePACO_INCLUDES
-      paco_config=paco_configure
-
-    files["configure.ac"]=configure.substitute(module=module.name.lower(),
-                                               makefiles='\n'.join(configure_makefiles),
-                                               paco_configure=paco_config,
-                                               modules=configure_modules,
-                                               other_check=other_check,
-                                               other_summary=other_summary,
-                                               other_require=other_require,
-                                              )
 
     #if components have other idls
     other_idls=""
-    other_sks=""
+#    other_sks=""
     for compo in module.components:
       if compo.idls:
         for idl in compo.idls:
           for fidl in glob.glob(idl):
             other_idls=other_idls+os.path.basename(fidl) +" "
-            other_sks=other_sks+os.path.splitext(os.path.basename(fidl))[0]+"SK.cc "
-
-    idlfiles={"Makefile.am":    idlMakefile.substitute(module=module.name,
-                                                       PACO_BUILT_SOURCES=PACO_BUILT_SOURCES,
-                                                       PACO_SALOMEINCLUDE_HEADERS=PACO_SALOMEINCLUDE_HEADERS,
-                                                       PACO_INCLUDES=PACO_INCLUDES,
-                                                       PACO_salomepython_DATA=PACO_salomepython_DATA,
-                                                       PACO_salomeidl_DATA=PACO_salomeidl_DATA,
-                                                       other_idls=other_idls,other_sks=other_sks,
-                                                       ),
-              idlfile : self.makeidl(),
+#            other_sks=other_sks+os.path.splitext(os.path.basename(fidl))[0]+"SK.cc "
+
+    include_template=Template("$${${module}_ROOT_DIR}/idl/salome")
+    opt_inc="".join([include_template.substitute(module=x)+"\n  " for x in self.used_modules])
+    link_template=Template("$${${module}_SalomeIDL${module}}")
+    opt_link="".join([link_template.substitute(module=x)+"\n  " for x in self.used_modules])
+    
+    idlfiles={"CMakeLists.txt":cmake_idl.substitute(module=module.name,
+                                                    extra_idl=other_idls,
+                                                    extra_include=opt_inc,
+                                                    extra_link=opt_link),
+              idlfile         :self.makeidl(),
              }
-    if paco:
-      idlfiles["%s.xml" % module.name]=self.makexml()
 
     files["idl"]=idlfiles
 
     self.makeFiles(files,namedir)
 
-    os.chmod(os.path.join(namedir, "autogen.sh"), 0777)
     #copy source files if any in created tree
     for compo in module.components:
       for src in compo.sources:
-        if self.module.layout=="multidir":
-          shutil.copyfile(src, os.path.join(namedir, "src", compo.name, os.path.basename(src)))
-        else:
-          shutil.copyfile(src, os.path.join(namedir, "src", os.path.basename(src)))
+        shutil.copyfile(src, os.path.join(namedir, "src", compo.name, os.path.basename(src)))
 
       if compo.idls:
         #copy provided idl files in idl directory
@@ -548,20 +564,6 @@ echo "  Qt ..................... : $qt_ok"
           for fidl in glob.glob(idl):
             shutil.copyfile(fidl, os.path.join(namedir, "idl", os.path.basename(fidl)))
 
-    checks= ("check_Kernel.m4", "check_omniorb.m4", "ac_linker_options.m4", "ac_cxx_option.m4",
-             "python.m4", "enable_pthreads.m4", "check_f77.m4", "acx_pthread.m4", "check_paco++.m4",
-             "check_mpi.m4", "check_lam.m4", "check_openmpi.m4", "check_mpich.m4")
-    if need_boost:
-      checks=checks+("check_boost.m4",)
-    for m4file in checks:
-      shutil.copyfile(os.path.join(self.kernel, "salome_adm", "unix", "config_files", m4file),
-                      os.path.join(namedir, "adm_local", m4file))
-
-    if self.module.gui:
-      for m4file in ("check_GUI.m4", "check_qt.m4", "check_opengl.m4"):
-        shutil.copyfile(os.path.join(self.gui, "adm_local", "unix", "config_files", m4file),
-                        os.path.join(namedir, "adm_local", m4file))
-
     self.makeDoc(namedir)
     return
 
@@ -570,25 +572,36 @@ echo "  Qt ..................... : $qt_ok"
       return
     rep=os.path.join(namedir,"doc")
     os.makedirs(rep)
+    doc_files=""
     for docs in self.module.doc:
       for doc in glob.glob(docs):
         name = os.path.basename(doc)
+        doc_files = doc_files + name + "\n  "
         shutil.copyfile(doc, os.path.join(rep, name))
 
     d={}
 
-    others=""
     if not self.module.gui:
        #without gui but with doc: create a small SalomeApp.xml in doc directory
        if not os.path.exists(os.path.join(namedir, "doc", "SalomeApp.xml")):
          #create a minimal SalomeApp.xml
-         salomeapp=docsalomeapp.substitute(module=self.module.name,lmodule=self.module.name.lower())
+         salomeapp=docsalomeapp.substitute(module=self.module.name,
+                                           lmodule=self.module.name.lower(),
+                                           version=yacsgen_version.complete_version)
          d["SalomeApp.xml"]=salomeapp
-       others="SalomeApp.xml"
 
-    if not os.path.exists(os.path.join(namedir, "doc", "Makefile.am")):
-      #create a minimal makefile.am
-      d["Makefile.am"]=docmakefile.substitute(others=others)
+    if not os.path.exists(os.path.join(namedir, "doc", "CMakeLists.txt")):
+      #create a minimal CMakeLists.txt
+      makefile_txt=docmakefile.substitute(module=self.module.name,
+                                          files=doc_files)
+      if not self.module.gui:
+        txt = 'INSTALL(FILES SalomeApp.xml DESTINATION \
+"${SALOME_%s_INSTALL_RES_DATA}")\n' % self.module.name
+        makefile_txt = makefile_txt + txt
+        pass
+      
+      d["CMakeLists.txt"]=makefile_txt
+      pass
 
     if not os.path.exists(os.path.join(namedir, "doc", "conf.py")):
       #create a minimal conf.py
@@ -619,72 +632,94 @@ echo "  Qt ..................... : $qt_ok"
 
   def makePyGUI(self,namedir):
     d={}
-    if not os.path.exists(os.path.join(namedir, "src", self.module.name+"GUI", "Makefile.am")):
-      #create a minimal makefile.am
-      sources=[]
-      other=[]
+    if not os.path.exists(os.path.join(namedir, "src", self.module.name+"GUI", "CMakeLists.txt")):
+      #create a minimal CMakeLists.txt
+      sources=""
+      other=""
+      ui_files=""
+      ts_files=""
       for srcs in self.module.gui:
         for src in glob.glob(srcs):
           if src[-3:]==".py":
-            sources.append(os.path.basename(src))
+            sources=sources+os.path.basename(src)+"\n  "
+          elif src[-3:]==".ts":
+            ts_files=ts_files+os.path.basename(src)+"\n  "
           else:
-            other.append(os.path.basename(src))
-      makefile=pyguimakefile.substitute(sources=" ".join(sources),other_sources=" ".join(other))
-      d["Makefile.am"]=makefile
+            other=other+os.path.basename(src)+"\n  "
+      makefile=cmake_py_gui.substitute(module=self.module.name,
+                                       scripts=sources,
+                                       ts_resources=ts_files,
+                                       resources=other)
+      d["CMakeLists.txt"]=makefile
 
     if not os.path.exists(os.path.join(namedir, "src", self.module.name+"GUI", "SalomeApp.xml")):
       #create a minimal SalomeApp.xml
-      salomeapp=pysalomeapp.substitute(module=self.module.name,lmodule=self.module.name.lower())
+      salomeapp=pysalomeapp.substitute(module=self.module.name,
+                                       lmodule=self.module.name.lower(),
+                                       version=yacsgen_version.complete_version)
       d["SalomeApp.xml"]=salomeapp
 
     return d
 
   def makeCPPGUI(self,namedir):
     d={}
-    if not os.path.exists(os.path.join(namedir, "src", self.module.name+"GUI", "Makefile.am")):
-      #create a minimal makefile.am
-      sources=[]
-      other=[]
-      ui_files=[]
+    if not os.path.exists(os.path.join(namedir, "src", self.module.name+"GUI", "CMakeLists.txt")):
+      #create a minimal CMakeLists.txt
+      sources=""
+      headers=""
+      other=""
+      ui_files=""
+      ts_files=""
       for srcs in self.module.gui:
         for src in glob.glob(srcs):
-          if src[-4:]==".cxx":
-            sources.append(os.path.basename(src))
-          elif src[-2:]==".h":
-            sources.append(os.path.basename(src)[:-2]+"_moc.cxx")
+          if src[-4:]==".cxx" or src[-4:]==".cpp":
+            sources=sources+os.path.basename(src)+"\n  "
+          elif src[-2:]==".h" or src[-4:]==".hxx":
+            headers=headers+os.path.basename(src)+"\n  "
           elif src[-3:]==".ui":
-            ui_files.append("ui_"+os.path.basename(src)[:-3]+".h")
+            ui_files=ui_files+os.path.basename(src)+"\n  "
           elif src[-3:]==".ts":
-            other.append(os.path.basename(src)[:-3]+".qm")
+            ts_files = ts_files + os.path.basename(src) + "\n  "
           else:
-            other.append(os.path.basename(src))
-
-      makefile=cppguimakefile.substitute(sources=" ".join(sources),other_sources=" ".join(other),
-                                         module=self.module.name, uisources= " ".join(ui_files))
-      d["Makefile.am"]=makefile
+            other=other+os.path.basename(src)+"\n  "
+
+      compo_dirs = "".join(["${PROJECT_SOURCE_DIR}/src/"+x.name+"\n  " for x in self.module.components])
+      compo_dirs = compo_dirs + "${PROJECT_BINARY_DIR}/src/" + self.module.name + "GUI\n"
+      component_libs = "".join([x.libraryName()+" " for x in self.module.components])
+      makefile=cmake_cpp_gui.substitute(module=self.module.name,
+                                    include_dirs=compo_dirs,
+                                    libs=component_libs,
+                                    uic_files=ui_files,
+                                    moc_headers=headers,
+                                    sources=sources,
+                                    resources=other,
+                                    ts_resources=ts_files)
+      d["CMakeLists.txt"]=makefile
 
     if not os.path.exists(os.path.join(namedir, "src", self.module.name+"GUI", "SalomeApp.xml")):
       #create a minimal SalomeApp.xml
-      salomeapp=cppsalomeapp.substitute(module=self.module.name,lmodule=self.module.name.lower())
+      salomeapp=cppsalomeapp.substitute(module=self.module.name,
+                                        lmodule=self.module.name.lower(),
+                                        version=yacsgen_version.complete_version)
       d["SalomeApp.xml"]=salomeapp
 
     return d
 
   def makeMakefile(self,makefileItems):
     makefile=""
-    if makefileItems.has_key("header"):
+    if "header" in makefileItems:
       makefile=makefile + makefileItems["header"]+'\n'
-    if makefileItems.has_key("lib_LTLIBRARIES"):
+    if "lib_LTLIBRARIES" in makefileItems:
       makefile=makefile+"lib_LTLIBRARIES= "+" ".join(makefileItems["lib_LTLIBRARIES"])+'\n'
-    if makefileItems.has_key("salomepython_PYTHON"):
+    if "salomepython_PYTHON" in makefileItems:
       makefile=makefile+"salomepython_PYTHON= "+" ".join(makefileItems["salomepython_PYTHON"])+'\n'
-    if makefileItems.has_key("dist_salomescript_SCRIPTS"):
+    if "dist_salomescript_SCRIPTS" in makefileItems:
       makefile=makefile+"dist_salomescript_SCRIPTS= "+" ".join(makefileItems["dist_salomescript_SCRIPTS"])+'\n'
-    if makefileItems.has_key("salomeres_DATA"):
+    if "salomeres_DATA" in makefileItems:
       makefile=makefile+"salomeres_DATA= "+" ".join(makefileItems["salomeres_DATA"])+'\n'
-    if makefileItems.has_key("salomeinclude_HEADERS"):
+    if "salomeinclude_HEADERS" in makefileItems:
       makefile=makefile+"salomeinclude_HEADERS= "+" ".join(makefileItems["salomeinclude_HEADERS"])+'\n'
-    if makefileItems.has_key("body"):
+    if "body" in makefileItems:
       makefile=makefile+makefileItems["body"]+'\n'
     return makefile
 
@@ -734,81 +769,30 @@ echo "  Qt ..................... : $qt_ok"
 
   def makeidl(self):
     """generate module IDL file source (CORBA interface)"""
-    from pacocompo import PACOComponent
     interfaces = []
     idldefs=""
     for compo in self.module.components:
-      if isinstance(compo, PACOComponent):
-        services = []
-        for serv in compo.services:
-          params = []
-          for name, typ in serv.inport:
-            if typ == "file":continue #files are not passed through IDL interface
-            params.append("in %s %s" % (idlTypes[typ], name))
-          for name, typ in serv.outport:
-            if typ == "file":continue #files are not passed through IDL interface
-            params.append("out %s %s" % (idlTypes[typ], name))
-          service = "    void %s(" % serv.name
-          service = service+",".join(params)+");"
-          services.append(service)
-
-        interfaces.append(parallel_interface.substitute(component=compo.name, services="\n".join(services)))
-
-      else:
-        services = []
-        for serv in compo.services:
-          params = []
-          for name, typ in serv.inport:
-            if typ == "file":continue #files are not passed through IDL interface
-            if compo.impl in ("PY", "ASTER") and typ == "pyobj":
-              typ = "Engines::fileBlock"
-            else:
-              typ=idlTypes[typ]
-            params.append("in %s %s" % (typ, name))
-          for name, typ in serv.outport:
-            if typ == "file":continue #files are not passed through IDL interface
-            if compo.impl in ("PY", "ASTER") and typ == "pyobj":
-              typ = "Engines::fileBlock"
-            else:
-              typ=idlTypes[typ]
-            params.append("out %s %s" % (typ, name))
-          service = "    %s %s(" % (idlTypes[serv.ret],serv.name)
-          service = service+",".join(params)+") raises (SALOME::SALOME_Exception);"
-          services.append(service)
-
-        from hxxcompo import HXX2SALOMEComponent
-        from hxxparacompo import HXX2SALOMEParaComponent
-        if isinstance(compo,HXX2SALOMEComponent) or isinstance(compo,HXX2SALOMEParaComponent):
-          from hxx_tmpl import interfaceidlhxx
-          Inherited=""
-          if isinstance(compo,HXX2SALOMEParaComponent):
-              Inherited="SALOME_MED::ParaMEDMEMComponent"
-              idldefs="""#include "ParaMEDMEMComponent.idl"\n"""
-          else:
-              if compo.use_medmem==True:
-                  Inherited="Engines::EngineComponent,SALOME::MultiCommClass,SALOME_MED::MED_Gen_Driver"
-              else:
-                  Inherited="Engines::EngineComponent"
-          interfaces.append(interfaceidlhxx.substitute(component=compo.name,inherited=Inherited, services="\n".join(services)))
-        else:
-          inheritedinterface=""
-          if compo.inheritedinterface:
-            inheritedinterface=compo.inheritedinterface+","
-          interfaces.append(interface.substitute(component=compo.name, services="\n".join(services),inheritedinterface=inheritedinterface))
+      interfaces.append(compo.getIdlInterfaces())
 
     #build idl includes for SALOME modules
     for mod in self.used_modules:
       idldefs = idldefs + salome_modules[mod]["idldefs"]
 
     for compo in self.module.components:
-      if compo.interfacedefs:
-        idldefs = idldefs + compo.interfacedefs
+      idldefs = idldefs + compo.getIdlDefs()
+    
+    filteredDefs = []
+    for defLine in idldefs.split('\n'):
+      if defLine not in filteredDefs:
+        filteredDefs.append(defLine)
 
-    return idl.substitute(module=self.module.name, interfaces='\n'.join(interfaces),idldefs=idldefs)
+    return idl.substitute(module=self.module.name,
+                          interfaces='\n'.join(interfaces),
+                          idldefs='\n'.join(filteredDefs) )
 
   # For PaCO++
   def makexml(self):
-    from pacocompo import PACOComponent
+    from .pacocompo import PACOComponent
     interfaces = []
     for compo in self.module.components:
       if isinstance(compo, PACOComponent):
@@ -825,57 +809,42 @@ echo "  Qt ..................... : $qt_ok"
        dic key = file name to create
        dic value = file content or dictionary defining the content of a sub directory
     """
-    for name, content in dic.items():
+    for name, content in list(dic.items()):
       filename = os.path.join(basedir, name)
       if isinstance(content, str):
-        fil =  open(filename, 'w')
-        fil.write(content)
-        fil.close()
+        # encodage to utf-8 if unicode string / on python3 str are unicode
+        with open(filename, 'w') as fil:
+          fil.write(content)
       else:
         if not os.path.exists(filename):
           os.makedirs(filename)
         self.makeFiles(content, filename)
 
-  def bootstrap(self):
-    """Execute the first build step (bootstrap autotools with autogen.sh script) : execution of libtool, autoconf, automake"""
-    ier = os.system("cd %s_SRC;sh autogen.sh" % self.module.name)
-    if ier != 0:
-      raise Invalid("bootstrap has ended in error")
-
   def configure(self):
     """Execute the second build step (configure) with installation prefix as given by the prefix attribute of module"""
-    prefix = self.module.prefix
-    paco = self.context.get("paco")
-    mpi = self.context.get("mpi")
-    args = (self.module.name, self.kernel, self.aster)
-    cmd = "cd %s_SRC;./configure --with-kernel=%s --with-aster=%s" % args
-    if self.gui:
-      cmd = cmd + " --with-gui=%s" % self.gui
-    if prefix:
-      prefix = os.path.abspath(prefix)
-      cmd = cmd + " --prefix=%s" % prefix
-    if paco:
-      cmd += " --with-paco=%s" % paco
-    if mpi:
-      cmd += " --with-mpi=%s" % mpi
-
-    ier = os.system(cmd)
+    prefix = os.path.abspath(self.module.prefix)
+
+    self.build_dir = "%s_build" % self.module.name
+    makedirs(self.build_dir)
+    
+    build_sh = "cd %s; cmake ../%s -DCMAKE_INSTALL_PREFIX:PATH=%s"%(self.build_dir, self.sourceDir(), prefix) 
+    ier = os.system(build_sh)
     if ier != 0:
       raise Invalid("configure has ended in error")
 
   def make(self):
     """Execute the third build step (compile and link) : make"""
-    make_command = "make "
+    make_command = "cd %s; make " % self.build_dir
     if self.makeflags:
       make_command += self.makeflags
-    ier = os.system("cd %s_SRC;%s" % (self.module.name, make_command))
+    ier = os.system(make_command)
     if ier != 0:
       raise Invalid("make has ended in error")
 
   def install(self):
     """Execute the installation step : make install """
-    makedirs(self.module.prefix)
-    ier = os.system("cd %s_SRC;make install" % self.module.name)
+    make_command = "cd %s; make install" % self.build_dir
+    ier = os.system(make_command)
     if ier != 0:
       raise Invalid("install has ended in error")
 
@@ -898,7 +867,6 @@ echo "  Qt ..................... : $qt_ok"
 
      >>> g=Generator(m,context)
      >>> g.generate()
-     >>> g.bootstrap()
      >>> g.configure()
      >>> g.make()
      >>> g.install()
@@ -938,28 +906,35 @@ echo "  Qt ..................... : $qt_ok"
     modules = []
     if restrict:
       for mod in restrict:
-        if modules_dict.has_key(mod):
+        if mod in modules_dict:
           modules.append(modules_dict[mod])
     else:
-      modules = modules_dict.values()
+      modules = list(modules_dict.values())
 
     #add the alternate modules if given
     if altmodules:
-      for module, path in altmodules.items():
+      for module, path in list(altmodules.items()):
         modules.append('  <module name="%s" path="%s"/>' % (module, path))
 
     #add the generated module
     modules.append('  <module name="%s" path="%s"/>' % (self.module.name, os.path.abspath(self.module.prefix)))
 
-
+    ROOT_SALOME=os.getenv("ROOT_SALOME")
     #try to find a prerequisites file
     prerequisites = self.context.get("prerequisites")
     if not prerequisites:
       #try to find one in rootdir
-      prerequisites = os.path.join(rootdir, "profile%s.sh" % suffix)
+      prerequisites = os.path.join(ROOT_SALOME, "salome_prerequisites.sh")
     if not os.path.exists(prerequisites):
       raise Invalid("Can not create an application : prerequisites file not defined or does not exist")
 
+    salome_context = self.context.get("salome_context")
+    if not salome_context:
+      #try to find one in rootdir
+      salome_context = os.path.join(ROOT_SALOME, "salome_context.cfg")
+    if not os.path.exists(salome_context):
+      raise Invalid("Can not create an application : salome_context file not defined or does not exist")
+
     #add resources catalog if it exists
     resources_spec=""
     if os.path.isfile(resources):
@@ -967,6 +942,7 @@ echo "  Qt ..................... : $qt_ok"
 
     #create config_appli.xml file
     appli = application.substitute(prerequisites=prerequisites,
+                                   context=salome_context,
                                    modules="\n".join(modules),
                                    resources=resources_spec)
     fil = open(os.path.join(appliname, "config_appli.xml"), 'w')
@@ -991,4 +967,3 @@ echo "  Qt ..................... : $qt_ok"
       host = socket.gethostname().split('.')[0]
       fil.write(command % host)
       fil.close()
-