Salome HOME
Update according new version of
[modules/kernel.git] / salome_adm / cmake_files / am2cmake.py
1 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 #
6 #  This library is free software; you can redistribute it and/or
7 #  modify it under the terms of the GNU Lesser General Public
8 #  License as published by the Free Software Foundation; either
9 #  version 2.1 of the License.
10 #
11 #  This library is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 #  Lesser General Public License for more details.
15 #
16 #  You should have received a copy of the GNU Lesser General Public
17 #  License along with this library; if not, write to the Free Software
18 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 #
20 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22 import re
23
24 # ----
25 # A set of regular expressions used ...
26 # ----
27
28 p_multiline = re.compile(r"""
29 \\           # One backslash
30 \s*          # 0 or more space
31 \n           # One CR
32 """, re.VERBOSE)
33
34 p_dollar = re.compile(r"""
35 \$\(           # a $ then a (
36 (?P<val>       # open the group val
37 [^)]*          # the group contain 0 or more non ) characters
38 )              # close the group
39 \)             # a ) at the end
40 """, re.VERBOSE)
41
42 p_arobas = re.compile(r"""
43 @              # a @
44 (?P<val>       # open the group val
45 [^@]*            # the group contain 0 or more non @ characters
46 )              # close the group
47 @              # a @ at the end
48 """, re.VERBOSE)
49
50 p_if = re.compile(r"""
51 ^          # beginning of the string
52 \s*        # 0 or more space
53 if         # an if
54 \s+        # 1 or more space
55 (?P<val>   # open the group val
56 [^\s]+     # the group contain 1 or more non space characters
57 )          # close the group
58 """, re.VERBOSE)
59
60 p_else = re.compile(r"""
61 ^          # beginning of the line
62 \s*        # 0 or more space
63 else       #
64 \s*        # 0 or more space
65 """, re.VERBOSE)
66
67 p_endif = re.compile(r"""
68 ^          # beginning of the line
69 \s*        # 0 or more space
70 endif      # a endif
71 \s*        # 0 or more space
72 """, re.VERBOSE)
73
74 p_attribution = re.compile(r"""
75 ^              # beginning of the line
76 (?P<spaces>    # open the group spaces
77 \s*            # 0 or more space
78 )              # close the group
79 (?P<key>       # open the group key
80 \w+            # the group contain 1 or more alphanumeric characters
81 )              # close the group
82 \s*            # 0 or more space
83 (?P<method>    # open the group method
84 \+?            # 0 or 1 +
85 =              # One =
86 )              # close the group
87 (?P<value>     # open the group value
88 .*             # 0 or more any characters 
89 )              # close the group
90 """, re.VERBOSE)
91
92 # -----
93
94 class CMakeFile(object):
95     
96     def __init__(self, the_root, root, dirs, files, f, module):
97         #
98         self.the_root = the_root
99         self.root = root
100         self.dirs = dirs
101         self.files = files
102         self.module = module
103         #
104         from os.path import join
105         self.amFile = join(root, f)
106         self.listsFile = join(root, "CMakeLists.txt")
107         #
108         self.parseFile()
109         #
110         return
111     
112     def parseFile(self):
113         
114         # --
115         # Read the Makefile.am file
116         # --
117         amFile = self.amFile
118         stream = open(amFile)
119         content = stream.read()
120         stream.close()
121         
122         # --
123         # Replace the composed lines separated by "\\n" by an unique line
124         # --
125         content = p_multiline.sub(r' ', content)
126         
127         # --
128         # Compatibility netgen plugin
129         # --
130         content = content.replace("../NETGEN/libNETGEN.la", "${NETGEN_LIBS}")
131         
132         # --
133         cas_list = [
134             "BinLPlugin",
135             "BinPlugin",
136             "BinTObjPlugin",
137             "BinXCAFPlugin",
138             "FWOSPlugin",
139             "PTKernel",
140             "StdLPlugin",
141             "StdPlugin",
142             "TKAdvTools",
143             "TKBin",
144             "TKBinL",
145             "TKBinTObj",
146             "TKBinXCAF",
147             "TKBO",
148             "TKBool",
149             "TKBRep",
150             "TKCAF",
151             "TKCDF",
152             "TKernel",
153             "TKFeat",
154             "TKFillet",
155             "TKG2d",
156             "TKG3d",
157             "TKGeomAlgo",
158             "TKGeomBase",
159             "TKHLR",
160             "TKIGES",
161             "TKLCAF",
162             "TKMath",
163             "TKMesh",
164             "TKMeshVS",
165             "TKNIS",
166             "TKOffset",
167             "TKOpenGl",
168             "TKPCAF",
169             "TKPLCAF",
170             "TKPrim",
171             "TKPShape",
172             "TKService",
173             "TKShapeSchema",
174             "TKShHealing",
175             "TKStdLSchema",
176             "TKStdSchema",
177             "TKSTEP",
178             "TKSTEP209",
179             "TKSTEPAttr",
180             "TKSTEPBase",
181             "TKSTL",
182             "TKTObj",
183             "TKTopAlgo",
184             "TKV2d",
185             "TKV3d",
186             "TKVRML",
187             "TKXCAF",
188             "TKXCAFSchema",
189             "TKXDEIGES",
190             "TKXDESTEP",
191             "TKXMesh",
192             "TKXml",
193             "TKXmlL",
194             "TKXmlTObj",
195             "TKXmlXCAF",
196             "TKXSBase",
197             "XCAFPlugin",
198             "XmlLPlugin",
199             "XmlPlugin",
200             "XmlTObjPlugin",
201             "XmlXCAFPlugin",
202             ]
203         vtk_list = [
204             "vtkCommonPythonD",
205             "vtkGraphicsPythonD",
206             "vtkImagingPythonD",
207             ]
208         kernel_list  = [
209             "DF",
210             "Launcher",
211             "OpUtil",
212             "Registry",
213             "ResourcesManager",
214             "SALOMEBasics",
215             "SalomeBatch",
216             "SalomeCatalog",
217             "SalomeCommunication",
218             "SalomeContainer",
219             "SalomeDSCContainer",
220             "SalomeDSClient",
221             "SalomeDSImpl",
222             "SalomeDS",
223             "SalomeGenericObj",
224             "SalomeHDFPersist",
225             "SalomeIDLKernel",
226             "SalomeLauncher",
227             "SalomeLifeCycleCORBA",
228             "SALOMELocalTrace",
229             "SalomeLoggerServer",
230             "SalomeNotification",
231             "SalomeNS",
232             "SalomeResourcesManager",
233             "TOOLSDS",
234             "with_loggerTraceCollector",
235             ]
236         gui_list = [
237             "caf",
238             "CAM",
239             "CASCatch",
240             "DDS",
241             "Event",
242             "GLViewer",
243             "LightApp",
244             "LogWindow",
245             "ObjBrowser",
246             "OCCViewer",
247             "Plot2d",
248             "PyConsole",
249             "PyInterp",
250             "QDS",
251             "qtx",
252             "QxScene",
253             "SalomeApp",
254             "SalomeIDLGUI",
255             "SalomeObject",
256             "SalomePrs",
257             "SalomeSession",
258             "SalomeStyle",
259             "SOCC",
260             "SPlot2d",
261             "std",
262             "SUITApp",
263             "suit",
264             "SUPERVGraph",
265             "SVTK",
266             "ToolsGUI",
267             "VTKViewer",
268             ]
269         geom_list = [
270             "BasicGUI",
271             "BlocksGUI",
272             "BooleanGUI",
273             "BREPExport",
274             "BREPImport",
275             "BuildGUI",
276             "DisplayGUI",
277             "DlgRef",
278             "EntityGUI",
279             "GenerationGUI",
280             "GEOMAlgo",
281             "GEOMArchimede",
282             "GEOMBase",
283             "GEOMbasic",
284             "GEOMClient",
285             "GEOMEngine",
286             "GEOMFiltersSelection",
287             "GEOMimpl",
288             "GEOMObject",
289             "GEOMSketcher",
290             "GEOM",
291             "GEOM_SupervEngine",
292             "GEOMToolsGUI",
293             "GroupGUI",
294             "IGESExport",
295             "IGESImport",
296             "MeasureGUI",
297             "NMTDS",
298             "NMTTools",
299             "OperationGUI",
300             "PrimitiveGUI",
301             "RepairGUI",
302             "SalomeIDLGEOM",
303             "ShHealOper",
304             "STEPExport",
305             "STEPImport",
306             "STLExport",
307             "TransformationGUI",
308             ]
309         med_list = [
310             "InterpGeometric2DAlg",
311             "interpkernelbases",
312             "interpkernel",
313             "MEDClientcmodule",
314             "medcoupling",
315             "MEDEngine",
316             "MEDMEMImpl",
317             "medmem",
318             "MED",
319             "med_V2_1",
320             "MEDWrapperBase",
321             "MEDWrapper",
322             "MEDWrapper_V2_1",
323             "MEDWrapper_V2_2",
324             "SalomeIDLMED",
325             ]
326         smesh_list = [
327             "MEFISTO2D",
328             "MeshDriverDAT",
329             "MeshDriverMED",
330             "MeshDriver",
331             "MeshDriverSTL",
332             "MeshDriverUNV",
333             "SalomeIDLSMESH",
334             "SMDS",
335             "SMESHClient",
336             "SMESHControls",
337             "SMESHDS",
338             "SMESHEngine",
339             "SMESHFiltersSelection",
340             "SMESHimpl",
341             "SMESHObject",
342             "SMESH",
343             "StdMeshersEngine",
344             "StdMeshersGUI",
345             "StdMeshers",
346             ]
347         full_list  = cas_list + vtk_list
348         full_list += kernel_list + gui_list
349         full_list += geom_list + med_list + smesh_list
350         # --
351         # E.A. : sort by len before substitution ...
352         # Why ? Thing to "-lMEDWrapper" then "-lMEDWrapper_V2_1" substition
353         # And you understand ...
354         # --
355         full_list.sort(cmp = lambda x, y : cmp(len(y), len(x)))
356         # --
357         for key in full_list:
358             content = content.replace("-l%s"%(key), "${%s}"%(key))
359             pass
360         
361         # --
362         # Split content in lines to treat each one separately
363         # --
364         lines = content.split('\n')
365         
366         # --
367         # newlines contains the lines of the future CMakeLists.txt file
368         # --
369         newlines = []
370         
371         # --
372         # opened_ifs is used to deals with nested conditionnals
373         # --
374         opened_ifs = []
375         
376         # --
377         # the __thedict__ dictionnary contains key, val
378         # of the Makefile.am file
379         # --
380         self.__thedict__ = {}
381         
382         # --
383         # Initialize file ... mainly includes other cmake files
384         # --
385         self.initialize(newlines)
386         
387         # --
388         # Do the job for each line
389         # --
390         for line in lines:
391             self.treatLine(line, newlines, opened_ifs)
392             pass
393         
394         # --
395         # Finalize file ... it is in here the cmake job is done
396         # --
397         self.finalize(newlines)
398         
399         # --
400         # Concatenate newlines into content
401         # --
402         content = '\n'.join(newlines)
403         
404         # --
405         # Add a CR at end if necessary
406         # --
407         lines = content.split('\n')
408         # lines = [ l.strip() for l in lines ]
409         if len(lines[-1]) != 0:
410             lines.append('')
411             pass
412         content = '\n'.join(lines)
413         
414         # --
415         self.content = content
416         
417         # --
418         return
419     
420     def initialize(self, newlines):
421         if self.root == self.the_root:
422             # --
423             newlines.append("""
424             CMAKE_MINIMUM_REQUIRED(VERSION 2.4.7 FATAL_ERROR)
425             IF(COMMAND cmake_policy)
426             cmake_policy(SET CMP0003 NEW)
427             ENDIF(COMMAND cmake_policy)
428             """)
429             # --
430             if self.module == "kernel":
431                 newlines.append("""
432                 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindPLATFORM.cmake)
433                 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindPYTHON.cmake)
434                 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindOMNIORB.cmake)
435                 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindPTHREADS.cmake)
436                 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindHDF5.cmake)
437                 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindBOOST.cmake)
438                 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindLIBXML2.cmake)
439                 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindSWIG.cmake)
440                 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindCPPUNIT.cmake)
441                 """)
442                 pass
443             else:
444                 newlines.append("""
445                 SET(KERNEL_ROOT_DIR $ENV{KERNEL_ROOT_DIR})
446                 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindPLATFORM.cmake)
447                 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindPYTHON.cmake)
448                 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindOMNIORB.cmake)
449                 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindPTHREADS.cmake)
450                 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindHDF5.cmake)
451                 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindBOOST.cmake)
452                 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindLIBXML2.cmake)
453                 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindSWIG.cmake)
454                 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindCPPUNIT.cmake)
455                 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindKERNEL.cmake)
456                 """)
457                 if self.module == "gui":
458                     newlines.append("""
459                     INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindCAS.cmake)
460                     INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindQT4.cmake)
461                     INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindOPENGL.cmake)
462                     INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindVTK.cmake)
463                     INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindQWT.cmake)
464                     INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindSIPPYQT.cmake)
465                     """)
466                 else:
467                     newlines.append("""
468                     SET(GUI_ROOT_DIR $ENV{GUI_ROOT_DIR})
469                     INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindCAS.cmake)
470                     INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindQT4.cmake)
471                     INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindOPENGL.cmake)
472                     INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindVTK.cmake)
473                     INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindQWT.cmake)
474                     INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindSIPPYQT.cmake)
475                     INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindGUI.cmake)
476                     """)
477                     if self.module == "med":
478                         newlines.append("""
479                         INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindMEDFILE.cmake)
480                         """)
481                         pass
482                     if self.module == "smesh":
483                         newlines.append("""
484                         SET(GEOM_ROOT_DIR $ENV{GEOM_ROOT_DIR})
485                         SET(MED_ROOT_DIR $ENV{MED_ROOT_DIR})
486                         INCLUDE(${GEOM_ROOT_DIR}/adm_local/cmake_files/FindGEOM.cmake)
487                         INCLUDE(${MED_ROOT_DIR}/adm_local/cmake_files/FindMEDFILE.cmake)
488                         INCLUDE(${MED_ROOT_DIR}/adm_local/cmake_files/FindMED.cmake)
489                         """)
490                         pass
491                     if self.module == "netgenplugin":
492                         newlines.append("""
493                         SET(GEOM_ROOT_DIR $ENV{GEOM_ROOT_DIR})
494                         SET(MED_ROOT_DIR $ENV{MED_ROOT_DIR})
495                         SET(SMESH_ROOT_DIR $ENV{SMESH_ROOT_DIR})
496                         INCLUDE(${GEOM_ROOT_DIR}/adm_local/cmake_files/FindGEOM.cmake)
497                         INCLUDE(${MED_ROOT_DIR}/adm_local/cmake_files/FindMED.cmake)
498                         INCLUDE(${SMESH_ROOT_DIR}/adm_local/cmake_files/FindSMESH.cmake)
499                         INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindNETGEN.cmake)
500                         """)
501                         pass
502                     if self.module == "blsurfplugin":
503                         newlines.append("""
504                         SET(GEOM_ROOT_DIR $ENV{GEOM_ROOT_DIR})
505                         SET(MED_ROOT_DIR $ENV{MED_ROOT_DIR})
506                         SET(SMESH_ROOT_DIR $ENV{SMESH_ROOT_DIR})
507                         INCLUDE(${GEOM_ROOT_DIR}/adm_local/cmake_files/FindGEOM.cmake)
508                         INCLUDE(${MED_ROOT_DIR}/adm_local/cmake_files/FindMED.cmake)
509                         INCLUDE(${SMESH_ROOT_DIR}/adm_local/cmake_files/FindSMESH.cmake)
510                         INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindBLSURF.cmake)
511                         """)
512                         pass
513                     if self.module == "hexoticplugin":
514                         newlines.append("""
515                         SET(GEOM_ROOT_DIR $ENV{GEOM_ROOT_DIR})
516                         SET(MED_ROOT_DIR $ENV{MED_ROOT_DIR})
517                         SET(SMESH_ROOT_DIR $ENV{SMESH_ROOT_DIR})
518                         INCLUDE(${GEOM_ROOT_DIR}/adm_local/cmake_files/FindGEOM.cmake)
519                         INCLUDE(${MED_ROOT_DIR}/adm_local/cmake_files/FindMED.cmake)
520                         INCLUDE(${SMESH_ROOT_DIR}/adm_local/cmake_files/FindSMESH.cmake)
521                         """)
522                         pass
523                     if self.module == "ghs3dplugin":
524                         newlines.append("""
525                         SET(GEOM_ROOT_DIR $ENV{GEOM_ROOT_DIR})
526                         SET(MED_ROOT_DIR $ENV{MED_ROOT_DIR})
527                         SET(SMESH_ROOT_DIR $ENV{SMESH_ROOT_DIR})
528                         INCLUDE(${GEOM_ROOT_DIR}/adm_local/cmake_files/FindGEOM.cmake)
529                         INCLUDE(${MED_ROOT_DIR}/adm_local/cmake_files/FindMED.cmake)
530                         INCLUDE(${SMESH_ROOT_DIR}/adm_local/cmake_files/FindSMESH.cmake)
531                         """)
532                         pass
533                     if self.module == "visu":
534                         newlines.append("""
535                         SET(MED_ROOT_DIR $ENV{MED_ROOT_DIR})
536                         INCLUDE(${MED_ROOT_DIR}/adm_local/cmake_files/FindMED.cmake)
537                         """)
538                         pass
539                     pass
540                 pass
541             # --
542             if self.module == "kernel":
543                 newlines.append("""
544                 SET(WITH_LOCAL 1)
545                 SET(WITH_BATCH 1)
546                 set(VERSION 5.1.2)
547                 set(XVERSION 0x050102)
548                 SET(CALCIUM_IDL_INT_F77 long)
549                 SET(CALCIUM_CORBA_INT_F77 CORBA::Long)
550                 SET(LONG_OR_INT int)
551                 """)
552             elif self.module == "gui":
553                 newlines.append("""
554                 SET(GUI_ENABLE_CORBA ${CORBA_GEN})
555                 SET(ENABLE_VTKVIEWER ON)
556                 SET(ENABLE_SALOMEOBJECT ON)
557                 SET(ENABLE_OCCVIEWER ON)
558                 SET(ENABLE_GLVIEWER ON)
559                 SET(ENABLE_PLOT2DVIEWER ON)
560                 SET(ENABLE_PYCONSOLE ON)
561                 SET(ENABLE_SUPERVGRAPHVIEWER ON)
562                 # SET(ENABLE_QXGRAPHVIEWER ON)
563                 set(VERSION 5.1.2)
564                 set(XVERSION 0x050102)
565                 """)
566                 pass
567             elif self.module == "geom":
568                 newlines.append("""
569                 SET(GEOM_ENABLE_GUI ON)
570                 """)
571                 pass
572             elif self.module == "medfile":
573                 newlines.append("""
574                 SET(MED_NUM_MAJEUR 2)
575                 SET(MED_NUM_MINEUR 3)
576                 SET(MED_NUM_RELEASE 5)
577                 SET(LONG_OR_INT int)
578                 IF(NOT WINDOWS)
579                 SET(FLIBS -lgfortranbegin -lgfortran)
580                 ENDIF(NOT WINDOWS)
581                 """)
582                 pass
583             elif self.module == "med":
584                 newlines.append("""
585                 SET(MED_ENABLE_KERNEL ON)
586                 SET(MED_ENABLE_GUI ON)
587                 """)
588                 pass
589             elif self.module == "smesh":
590                 newlines.append("""
591                 SET(SMESH_ENABLE_GUI ON)
592                 """)
593                 pass
594             elif self.module == "netgenplugin":
595                 newlines.append("""
596                 SET(NETGENPLUGIN_ENABLE_GUI ON)
597                 """)
598                 pass
599             elif self.module == "blsurfplugin":
600                 newlines.append("""
601                 SET(BLSURFPLUGIN_ENABLE_GUI ON)
602                 """)
603                 pass
604             # --
605             pass
606         # --
607         newlines.append("""
608         SET(VERSION_INFO 0.0.0)
609         SET(SOVERSION_INFO 0)
610         SET(SUBDIRS)
611         SET(AM_CPPFLAGS)
612         SET(AM_CXXFLAGS)
613         SET(LDADD)
614         """)
615         newlines.append(r'''
616         SET(AM_CPPFLAGS ${AM_CPPFLAGS} -DHAVE_SALOME_CONFIG -I${CMAKE_BINARY_DIR}/salome_adm/unix -include SALOMEconfig.h)
617         SET(AM_CXXFLAGS ${AM_CXXFLAGS} -DHAVE_SALOME_CONFIG -I${CMAKE_BINARY_DIR}/salome_adm/unix -include SALOMEconfig.h)
618         ''')
619         # --
620         return
621     
622     def treatLine(self, line, newlines, opened_ifs):
623         
624         # --
625         # Print the comment above the line itself
626         # --
627         if line.find('#') >= 0:
628             fields = line.split('#')
629             line = fields[0]
630             comment = '#'.join([''] + fields[1:])
631             newlines.append(comment)
632             if len(line) == 0:
633                 return
634             pass
635         
636         # --
637         # If the line begins with 'include ', just comment it
638         # --
639         if line.find("include ") == 0:
640             newlines.append("# " + line)
641             return
642         
643         # --
644         # If the line begins with '-include', just comment it
645         # --
646         if line.find("-include") == 0:
647             newlines.append("# " + line)
648             return
649         
650         # --
651         # If the line is a definition of a make rule, just comment it
652         # --
653         if line.count(':') == 1:
654             newlines.append("# " + line)
655             return
656         
657         # --
658         # A particuliar case where there are two ":" on the same line
659         # --
660         if line.find('install-exec-local:') == 0:
661             newlines.append("# " + line)
662             return
663         
664         # --
665         # If the line begin by a tabulation, consider it's a makefile command and comment it
666         # --
667         if line.find("\t") == 0:
668             newlines.append("# " + line)
669             return
670         
671         # --
672         # --
673         key = "-version-info"
674         if line.find(key) >= 0:
675             # --
676             before = line.split(key)[0]
677             after = line[len(before)+len(key):]
678             sep = after[0]
679             after = after[1:]
680             version_info = after.split()[0]
681             line = line.replace(key+sep+version_info, "")
682             # --
683             version_info = version_info.replace(':', '.')
684             soversion_info = version_info.split('.')[0]
685             newlines.append("SET(VERSION_INFO " + version_info + ")")
686             newlines.append("SET(SOVERSION_INFO " + soversion_info + ")")
687             # --
688             pass
689         
690         # --
691         # Replace the $(TOTO) by ${TOTO}
692         # Replace the @TOTO@  by ${TOTO}
693         # --
694         line = p_dollar.sub(r"${\1}", line)
695         line = p_arobas.sub(r"${\1}", line)
696         
697         # --
698         line = line.replace(r"${top_builddir}", r"${CMAKE_BINARY_DIR}")
699         line = line.replace(r"${top_srcdir}", r"${CMAKE_SOURCE_DIR}")
700         line = line.replace(r"${srcdir}", r"${CMAKE_CURRENT_SOURCE_DIR}")
701         line = line.replace(r"${builddir}", r"${CMAKE_CURRENT_BINARY_DIR}")
702         line = line.replace(r"${datadir}", r"${CMAKE_INSTALL_PREFIX}/share")
703         
704         # --
705         # Check if the line is a 'if' condition
706         # If yes, replace it by a cmake grammar
707         # --
708         match = p_if.match(line)
709         if match:
710             theif = match.group("val")
711             if theif[0] == "!":
712                 theif = "NOT " + theif[1:]
713                 pass
714             line = p_if.sub(r"IF(%s)"%(theif), line)
715             opened_ifs.append(theif)
716             newlines.append(line)
717             return
718         
719         # --
720         # Check if the line is a 'else' condition
721         # If yes, replace it by a cmake grammar
722         # --
723         match = p_else.match(line)
724         if match:
725             line = "ELSE(%s)"%(opened_ifs[-1])
726             newlines.append(line)
727             return
728         
729         # --
730         # Check if the line is a 'endif' condition
731         # If yes, replace it by a cmake grammar
732         # --
733         match = p_endif.match(line)
734         if match:
735             line = "ENDIF(%s)"%(opened_ifs[-1])
736             opened_ifs[-1:] = []
737             newlines.append(line)
738             return
739         
740         # --
741         # Check if the line is an attribution '=' or '+='
742         # --
743         match = p_attribution.match(line)
744         if match:
745             self.treatAttribution(match, newlines)
746             return
747         
748         # --
749         newlines.append(line)
750         
751         # --
752         return
753     
754     def treatAttribution(self, match, newlines):
755         
756         spaces = match.group("spaces")
757         key = match.group("key")
758         method = match.group("method")
759         value = match.group("value")
760         # print [spaces, key, method, value]
761         
762         # --
763         # Open cmake SET command
764         # --
765         newlines.append(spaces + "SET(" + key)
766         
767         # --
768         # If method is '+=', put the previous definition as first value
769         # --
770         if method == "+=":
771             newlines.append("%s    ${%s}"%(spaces, key))
772             pass
773         
774         # --
775         fields = value.split()
776         for i in range(len(fields)):
777             newlines.append("%s    %s"%(spaces, fields[i]))
778             pass
779         
780         # --
781         if method == "+=":
782             # --
783             # The try: except KeyError is here if the +=
784             # is an error which occurs in salome ...
785             # --
786             try:
787                 self.__thedict__[key] += fields[:]
788             except KeyError:
789                 self.__thedict__[key] = fields[:]
790                 pass
791             pass
792         else:
793             self.__thedict__[key]  = fields[:]
794             pass
795         
796         # --
797         # Close cmake SET command
798         # --
799         
800         newlines.append("%s)"%(spaces))
801         
802         return
803     
804     def finalize(self, newlines):
805         
806         # --
807         # Convert the .in files in build dir
808         # --
809         for f in self.files:
810             if f[-3:] == ".in":
811                 if f == "sstream.in":
812                     continue
813                 if f in ["runContainer.in", "stopContainer.in"]:
814                     if self.module == "med":
815                         if self.root[-3:] == "csh":
816                             continue
817                         pass
818                     pass
819                 if f == "SALOMEconfig.ref.in":
820                     out = "SALOMEconfig.h"
821                 else:
822                     out = f[:-3]
823                     pass
824                 newlines.append(r'''
825                 SET(input ${CMAKE_CURRENT_SOURCE_DIR}/%s)
826                 '''%(f))
827                 newlines.append(r'''
828                 SET(output ${CMAKE_CURRENT_BINARY_DIR}/%s)
829                 '''%(out))
830                 newlines.append(r'''
831                 MESSAGE(STATUS "Creation of ${output}")
832                 CONFIGURE_FILE(${input} ${output})
833                 ''')
834                 pass
835             pass
836         
837         # --
838         # convert the SUBDIRS in cmake grammar
839         # --
840         if 1: # self.__thedict__.has_key("SUBDIRS"):
841             newlines.append(r'''
842             FOREACH(dir ${SUBDIRS})
843             IF(NOT dir STREQUAL .)
844             ADD_SUBDIRECTORY(${dir})
845             ENDIF(NOT dir STREQUAL .)
846             ENDFOREACH(dir ${SUBDIRS})
847             ''')
848             pass
849         
850         # --
851         # --
852         for key in ["lib_LTLIBRARIES", "noinst_LTLIBRARIES", "salomepyexec_LTLIBRARIES"]:
853             if self.__thedict__.has_key(key):
854                 self.addLibTarget(key, newlines)
855                 pass
856             pass
857         
858         # --
859         # --
860         for key in ["bin_PROGRAMS"]:
861             if self.__thedict__.has_key(key):
862                 self.addBinTarget(key, newlines)
863                 pass
864             pass
865         
866         # --
867         # --
868         if self.__thedict__.has_key("BASEIDL_FILES"):
869             if not self.__thedict__.has_key("IDL_FILES"):
870                 self.__thedict__["IDL_FILES"] = self.__thedict__["BASEIDL_FILES"]
871                 newlines.append('''
872                 SET(IDL_FILES ${BASEIDL_FILES})
873                 ''')
874                 pass
875             pass
876         
877         # --
878         # --
879         
880         key = "IDL_FILES"
881         if self.__thedict__.has_key(key):
882             if self.module == "kernel":
883                 newlines.append('''
884                 SET(IDL_FILES ${IDL_FILES} Calcium_Ports.idl)
885                 ''')
886                 pass
887             newlines.append('''
888             FOREACH(input ${IDL_FILES})
889             STRING(REGEX REPLACE ".idl" "" base ${input})
890             SET(src ${CMAKE_CURRENT_BINARY_DIR}/${base}SK.cc)
891             SET(outputs ${src})
892             SET(dynsrc ${CMAKE_CURRENT_BINARY_DIR}/${base}DynSK.cc)
893             SET(outputs ${outputs} ${dynsrc})
894             IF(input STREQUAL Calcium_Ports.idl)
895             SET(input ${CMAKE_CURRENT_BINARY_DIR}/${input})
896             ELSE(input STREQUAL Calcium_Ports.idl)
897             SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${input})
898             ENDIF(input STREQUAL Calcium_Ports.idl)
899             ADD_CUSTOM_COMMAND(
900             OUTPUT ${outputs}
901             COMMAND ${OMNIORB_IDL} ${IDLCXXFLAGS} ${OMNIORB_IDLCXXFLAGS} ${input}
902             MAIN_DEPENDENCY ${input}
903             )
904             install(FILES ${input} DESTINATION idl/salome)
905             SET(IDL_HEADER ${CMAKE_CURRENT_BINARY_DIR}/${base}.hh)
906             install(FILES ${IDL_HEADER} DESTINATION include/salome)
907             INSTALL(CODE "SET(IDL_FILE ${input})")
908             INSTALL(CODE "SET(DIR lib/python${PYTHON_VERSION}/site-packages/salome)")
909             INSTALL(CODE "SET(CMAKE_CURRENT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})")
910             INSTALL(CODE "SET(OMNIORB_IDL_PYTHON ${OMNIORB_IDL_PYTHON})")
911             # --
912             SET(flags)
913             FOREACH(f ${IDLPYFLAGS})
914             SET(flags "${flags} ${f}")
915             ENDFOREACH(f ${IDLPYFLAGS})
916             SET(IDLPYFLAGS ${flags})
917             STRING(REPLACE "\\\\" "/" IDLPYFLAGS ${IDLPYFLAGS})
918             INSTALL(CODE "SET(IDLPYFLAGS ${IDLPYFLAGS})")
919             # --
920             ''')
921             if self.module == "kernel":
922                 newlines.append('''
923                 INSTALL(SCRIPT ${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/install_python_from_idl.cmake)
924                 ''')
925             else:
926                 newlines.append('''
927                 STRING(REPLACE "\\\\" "/" KERNEL_ROOT_DIR ${KERNEL_ROOT_DIR})
928                 INSTALL(SCRIPT ${KERNEL_ROOT_DIR}/salome_adm/cmake_files/install_python_from_idl.cmake)
929                 ''')
930                 pass
931             newlines.append('''
932             ENDFOREACH(input ${IDL_FILES})
933             ''')
934             pass
935         
936         # --
937         # --
938         for key in ["SWIG_SRC", "SWIGSOURCES", "SWIG_DEF"]:
939             if self.__thedict__.has_key(key):
940                 newlines.append('''
941                 SET(SWIG_SOURCES ${%s})
942                 '''%(key))
943                 self.__thedict__["SWIG_SOURCES"] = self.__thedict__[key]
944                 pass
945             pass
946         
947         # --
948         # --
949         if self.__thedict__.has_key("SWIG_SOURCES"):
950             newlines.append('''
951             IF(SWIG_SOURCES MATCHES ";")
952             STRING(REGEX REPLACE ";.*" "" SWIG_SOURCES_FIRST "${SWIG_SOURCES}")
953             ELSE(SWIG_SOURCES MATCHES ";")
954             SET(SWIG_SOURCES_FIRST "${SWIG_SOURCES}")
955             ENDIF(SWIG_SOURCES MATCHES ";")
956             ADD_CUSTOM_COMMAND(
957             OUTPUT ${build_srcs}
958             COMMAND ${SWIG_EXECUTABLE} ${SWIG_FLAGS} ${MY_SWIG_FLAGS} -o ${build_srcs} ${CMAKE_CURRENT_SOURCE_DIR}/${SWIG_SOURCES_FIRST}
959             MAIN_DEPENDENCY ${SWIG_SOURCES}
960             )
961             ''')
962             pass
963         
964         # --
965         # --
966         key = "MOC_FILES"
967         if self.__thedict__.has_key(key):
968             newlines.append('''
969             FOREACH(output ${MOC_FILES})
970             STRING(REGEX REPLACE _moc.cxx .h input ${output})
971             SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${input})
972             SET(output ${CMAKE_CURRENT_BINARY_DIR}/${output})
973             ADD_CUSTOM_COMMAND(
974             OUTPUT ${output}
975             COMMAND ${QT_MOC_EXECUTABLE} ${MOC_FLAGS} ${input} -o ${output}
976             MAIN_DEPENDENCY ${input}
977             )
978             ENDFOREACH(output ${MOC_FILES})
979             ''')
980             pass
981         
982         # --
983         # --
984         key = "UIC_FILES"
985         if self.__thedict__.has_key(key):
986             newlines.append('''
987             FOREACH(output ${UIC_FILES})
988             STRING(REPLACE "ui_" "" input ${output})
989             STRING(REPLACE ".h" ".ui" input ${input})
990             SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${input})
991             SET(output ${CMAKE_CURRENT_BINARY_DIR}/${output})
992             ADD_CUSTOM_COMMAND(
993             OUTPUT ${output}
994             COMMAND ${QT_UIC_EXECUTABLE} -o ${output} ${input}
995             MAIN_DEPENDENCY ${input}
996             )
997             ENDFOREACH(output ${UIC_FILES})
998             ''')
999             pass
1000         
1001         # --
1002         # --
1003         key = "QRC_FILES"
1004         if self.__thedict__.has_key(key):
1005             newlines.append('''
1006             FOREACH(output ${QRC_FILES})
1007             STRING(REGEX REPLACE "qrc_" "" input ${output})
1008             STRING(REGEX REPLACE ".cxx" ".qrc" input ${input})
1009             STRING(REGEX REPLACE ".qrc" "" name ${input})
1010             SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${input})
1011             SET(output ${CMAKE_CURRENT_BINARY_DIR}/${output})
1012             ADD_CUSTOM_COMMAND(
1013             OUTPUT ${output}
1014             COMMAND ${QT_RCC_EXECUTABLE} ${input} -o ${output} -name ${name}
1015             MAIN_DEPENDENCY ${input}
1016             )
1017             ENDFOREACH(output ${QRC_FILES})
1018             ''')
1019             pass
1020         
1021         # --
1022         # --
1023         key = "SIP_FILES"
1024         if self.__thedict__.has_key(key):
1025             newlines.append('''
1026             FOREACH(input ${SIP_FILES})
1027             SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${input})
1028             SET(output)
1029             FOREACH(out ${SIP_SRC})
1030             SET(output ${output} ${CMAKE_CURRENT_BINARY_DIR}/${out})
1031             ENDFOREACH(out ${SIP_SRC})
1032             ADD_CUSTOM_COMMAND(
1033             OUTPUT ${output}
1034             COMMAND ${SIP_EXECUTABLE} ${PYQT_SIPFLAGS} ${input}
1035             MAIN_DEPENDENCY ${input}
1036             )
1037             ENDFOREACH(input ${SIP_FILES})
1038             ''')
1039             pass
1040         
1041         # --
1042         # Treat the install targets
1043         # --
1044         d = {
1045             "salomeadmux_DATA"            :  "salome_adm/unix",
1046             "dist_salomeadmux_DATA"       :  "salome_adm/unix",
1047             "dist_salome_cmake_DATA"      :  "salome_adm/cmake_files",
1048             "dist_salomem4_DATA"          :  "salome_adm/unix/config_files",
1049             "dist_salome4depr_DATA"       :  "salome_adm/unix/config_files/DEPRECATED",
1050             "dist_admlocalm4_DATA"        :  "adm_local/unix/config_files",
1051             "dist_admlocal_cmake_DATA"    :  "adm_local/cmake_files",
1052             "salomeinclude_DATA"          :  "include/salome",
1053             "salomeinclude_HEADERS"       :  "include/salome",
1054             "dist_salomeres_DATA"         :  "share/salome/resources/%s"%(self.module),
1055             "nodist_salomeres_DATA"       :  "share/salome/resources/%s"%(self.module),
1056             "nodist_salomeres_SCRIPTS"    :  "share/salome/resources/%s"%(self.module),
1057             "dist_salomescript_SCRIPTS"   :  "bin/salome",
1058             "dist_salomescript_DATA"      :  "bin/salome",
1059             "dist_salomescript_PYTHON"    :  "bin/salome",
1060             "nodist_salomescript_DATA"    :  "bin/salome",
1061             "salomepython_PYTHON"         :  "lib/python${PYTHON_VERSION}/site-packages/salome",
1062             "nodist_salomepython_PYTHON"  :  "lib/python${PYTHON_VERSION}/site-packages/salome",
1063             "sharedpkgpython_PYTHON"      :  "lib/python${PYTHON_VERSION}/site-packages/salome/shared_modules",
1064             }
1065         if self.module == "medfile":
1066             d = {
1067                 "include_HEADERS"        :  "include",
1068                 "nodist_include_HEADERS" :  "include",
1069                 "bin_SCRIPTS"            :  "bin",
1070                 "doc_DATA"               :  "${docdir}",
1071                 }
1072             pass
1073         for key, value in d.items():
1074             if self.__thedict__.has_key(key):
1075                 self.addInstallTarget(key, value, newlines)
1076                 pass
1077             pass
1078         
1079         # --
1080         return
1081     
1082     def setLibAdd(self, key, newlines):
1083         # --
1084         newlines.append(r'''
1085         SET(libadd)
1086         ''')
1087         # --
1088         newlines.append(r'''
1089         IF(WINDOWS)
1090         SET(targets)
1091         SET(targets ${targets} MEFISTO2D)
1092         FOREACH(target ${targets})
1093         IF(name STREQUAL ${target})
1094         SET(dir $ENV{F2CHOME})
1095         STRING(REPLACE "\\\\" "/" dir ${dir})
1096         SET(libadd ${libadd} ${dir}/LIBF77.lib)
1097         SET(libadd ${libadd} ${dir}/LIBI77.lib)
1098         ENDIF(name STREQUAL ${target})
1099         ENDFOREACH(target ${targets})
1100         ENDIF(WINDOWS)
1101         ''')
1102         # --
1103         newlines.append(r'''
1104         SET(libs ${PLATFORM_LIBADD} ${PLATFORM_LDFLAGS} ${${amname}_LIBADD} ${${amname}_LDADD} ${${amname}_LDFLAGS})
1105         FOREACH(lib SALOMEBasics SalomeBatch)
1106         IF(name STREQUAL lib)
1107         SET(libs ${libs} ${PTHREAD_LIBS})
1108         ENDIF(name STREQUAL lib)
1109         ENDFOREACH(lib SALOMEBasics SalomeBatch)
1110         ''')
1111         if key == "bin_PROGRAMS":
1112             newlines.append(r'''
1113             SET(libs ${libs} ${LDADD})
1114             ''')
1115             pass
1116         # --
1117         newlines.append(r'''
1118         FOREACH(lib ${libs})
1119         GET_FILENAME_COMPONENT(ext ${lib} EXT)
1120         IF(ext STREQUAL .la)
1121         GET_FILENAME_COMPONENT(lib ${lib} NAME_WE)
1122         STRING(REPLACE "lib" "" lib ${lib})
1123         ENDIF(ext STREQUAL .la)
1124         SET(vars)
1125         SET(vars ${vars} -no-undefined)
1126         SET(vars ${vars} -lvtkWidgets)
1127         IF(WINDOWS)
1128         SET(vars ${vars} -module)
1129         SET(vars ${vars} -Wl,-E)
1130         SET(vars ${vars} -Xlinker)
1131         SET(vars ${vars} -export-dynamic)
1132         SET(vars ${vars} -lm)
1133         SET(vars ${vars} -lboost_thread)
1134         SET(vars ${vars} -lboost_signals)
1135         ENDIF(WINDOWS)
1136         FOREACH(v ${vars})
1137         IF(lib STREQUAL v)
1138         SET(lib)
1139         ENDIF(lib STREQUAL v)
1140         ENDFOREACH(v ${vars})
1141         SET(libadd ${libadd} ${lib})
1142         ENDFOREACH(lib ${libs})
1143         TARGET_LINK_LIBRARIES(${name} ${libadd})
1144         ''')
1145         # --
1146         newlines.append(r'''
1147         IF(WINDOWS)
1148         SET(targets)
1149         SET(targets ${targets} MEFISTO2D)
1150         FOREACH(target ${targets})
1151         IF(name STREQUAL ${target})
1152         IF(CMAKE_BUILD_TYPE STREQUAL Debug)
1153         SET_TARGET_PROPERTIES(${name} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:MSVCRT")
1154         ENDIF(CMAKE_BUILD_TYPE STREQUAL Debug)
1155         ENDIF(name STREQUAL ${target})
1156         ENDFOREACH(target ${targets})
1157         ENDIF(WINDOWS)
1158         ''')
1159         # --
1160         return
1161     
1162     def setCompilationFlags(self, key, newlines):
1163         newlines.append(r'''
1164         SET(var)
1165         IF(WINDOWS)
1166         SET(targets)
1167         SET(targets ${targets} SalomeIDLKernel)
1168         SET(targets ${targets} SalomeDS)
1169         SET(targets ${targets} SALOMEDSTest)
1170         SET(targets ${targets} SALOMEDS_Client_exe)
1171         SET(targets ${targets} SalomeIDLGEOM)
1172         SET(targets ${targets} GEOMEngine)
1173         SET(targets ${targets} MEDEngine)
1174         SET(targets ${targets} SMESHEngine)
1175         SET(targets ${targets} SMESH)
1176         FOREACH(target ${targets})
1177         IF(name STREQUAL ${target})
1178         SET(var ${var} -DNOGDI)
1179         ENDIF(name STREQUAL ${target})
1180         ENDFOREACH(target ${targets})
1181         ENDIF(WINDOWS)
1182         ''')
1183         # --
1184         newlines.append(r'''
1185         IF(WINDOWS)
1186         SET(targets)
1187         SET(targets ${targets} MEFISTO2D)
1188         FOREACH(target ${targets})
1189         IF(name STREQUAL ${target})
1190         SET(dir $ENV{F2CHOME})
1191         STRING(REPLACE "\\\\" "/" dir ${dir})
1192         SET(var ${var} -I${dir})
1193         ENDIF(name STREQUAL ${target})
1194         ENDFOREACH(target ${targets})
1195         ENDIF(WINDOWS)
1196         ''')
1197         # --
1198         if self.module in ["geom", "med"]:
1199             newlines.append(r'''
1200             SET(var ${var} -I${CMAKE_CURRENT_SOURCE_DIR})
1201             SET(var ${var} -I${CMAKE_CURRENT_BINARY_DIR})
1202             ''')
1203             pass
1204         newlines.append(r'''
1205         SET(var ${var} ${AM_CPPFLAGS})
1206         SET(var ${var} ${AM_CXXFLAGS})
1207         ''')
1208         newlines.append(r'''
1209         SET(var ${var} ${PLATFORM_CPPFLAGS})
1210         SET(var ${var} ${PTHREAD_CFLAGS})
1211         SET(var ${var} ${${amname}_CPPFLAGS})
1212         SET(var ${var} ${${amname}_CXXFLAGS})
1213         SET(var ${var} ${${amname}_CFLAGS})
1214         SET(vars)
1215         IF(WINDOWS)
1216         SET(vars ${vars} -include SALOMEconfig.h)
1217         SET(vars ${vars} -ftemplate-depth-32)
1218         ENDIF(WINDOWS)
1219         SET(flags)
1220         FOREACH(f ${var})
1221         FOREACH(v ${vars})
1222         IF(f STREQUAL v)
1223         SET(f)
1224         ENDIF(f STREQUAL v)
1225         ENDFOREACH(v ${vars})
1226         SET(flags "${flags} ${f}")
1227         ENDFOREACH(f ${var})
1228         SET_TARGET_PROPERTIES(${name} PROPERTIES COMPILE_FLAGS "${flags}")
1229         ''')
1230         return
1231     
1232     def addLibTarget(self, key, newlines):
1233         newlines.append(r'''
1234         FOREACH(amname ${%s})
1235         '''%(key))
1236         # --
1237         # Replace .la by _la ...
1238         # --
1239         newlines.append(r'''
1240         STRING(REPLACE .la _la amname ${amname})
1241         ''')
1242         # --
1243         # Remove the _la for the cmake name
1244         # --
1245         newlines.append(r'''
1246         STRING(LENGTH ${amname} len)
1247         MATH(EXPR newlen "${len}-3")
1248         STRING(SUBSTRING ${amname} 0 ${newlen} name)
1249         ''')
1250         # --
1251         # Does the target begins with lib ??
1252         # If yes, remove lib at beginning for cmake name
1253         # --
1254         newlines.append(r'''
1255         STRING(REGEX MATCH "^lib" BEGIN_WITH_lib ${name})
1256         IF(BEGIN_WITH_lib)
1257         STRING(LENGTH ${name} len)
1258         MATH(EXPR newlen "${len}-3")
1259         STRING(SUBSTRING ${name} 3 ${newlen} name)
1260         ENDIF(BEGIN_WITH_lib)
1261         ''')
1262         # --
1263         # Does the target is an idl library
1264         # --
1265         newlines.append(r'''
1266         STRING(REGEX MATCH "IDL" ISIDL ${name})
1267         ''')
1268         # --
1269         # Set the type of the library
1270         # --
1271         newlines.append(r'''
1272         IF(ISIDL)
1273         IF(WINDOWS)
1274         SET(type STATIC)
1275         ELSE(WINDOWS)
1276         SET(type SHARED)
1277         ENDIF(WINDOWS)
1278         ELSE(ISIDL)
1279         SET(type SHARED)
1280         ENDIF(ISIDL)
1281         ''')
1282         # --
1283         # Set sources for the library
1284         # --
1285         newlines.append(r'''
1286         SET(srcs)
1287         FOREACH(src ${${amname}_SOURCES} ${dist_${amname}_SOURCES})
1288         GET_FILENAME_COMPONENT(ext ${src} EXT)
1289         IF(ext STREQUAL .f)
1290         IF(src STREQUAL trte.f)
1291         SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${src})
1292         STRING(REPLACE ".f" ".c" src ${src})
1293         SET(src ${CMAKE_CURRENT_BINARY_DIR}/${src})
1294         SET(output ${src})
1295         ADD_CUSTOM_COMMAND(
1296         OUTPUT ${output}
1297         COMMAND f2c ${input}
1298         MAIN_DEPENDENCY ${input}
1299         )
1300         ELSE(src STREQUAL trte.f)
1301         SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${src})
1302         STRING(REPLACE ".f" ".o" src ${src})
1303         SET(src ${CMAKE_CURRENT_BINARY_DIR}/${src})
1304         SET(output ${src})
1305         IF(WINDOWS)
1306         SET(F77 g77)
1307         ELSE(WINDOWS)
1308         SET(F77 gfortran)
1309         ENDIF(WINDOWS)
1310         ADD_CUSTOM_COMMAND(
1311         OUTPUT ${output}
1312         COMMAND ${F77} -c -o ${output} ${input}
1313         MAIN_DEPENDENCY ${input}
1314         )
1315         ENDIF(src STREQUAL trte.f)
1316         ENDIF(ext STREQUAL .f)
1317         SET(srcs ${srcs} ${src})
1318         ENDFOREACH(src ${${amname}_SOURCES} ${dist_${amname}_SOURCES})
1319         ''')
1320         newlines.append(r'''
1321         SET(build_srcs)
1322         ''')
1323         newlines.append(r'''
1324         SET(l ${nodist_${amname}_SOURCES} ${BUILT_SOURCES})
1325         ''')
1326         newlines.append(r'''
1327         FOREACH(f ${l})
1328         GET_FILENAME_COMPONENT(ext ${f} EXT)
1329         IF(ext STREQUAL .py)
1330         ELSE(ext STREQUAL .py)
1331         SET(build_srcs ${build_srcs} ${CMAKE_CURRENT_BINARY_DIR}/${f})
1332         ENDIF(ext STREQUAL .py)
1333         ENDFOREACH(f ${l})
1334         SET(srcs ${build_srcs} ${srcs})
1335         ''')
1336         # --
1337         # Add the library to cmake
1338         # --
1339         newlines.append(r'''
1340         ADD_LIBRARY(${name} ${type} ${srcs})
1341         ''')
1342         # --
1343         # The compilation flags
1344         # --
1345         self.setCompilationFlags(key, newlines)
1346         # --
1347         newlines.append(r'''
1348         SET_TARGET_PROPERTIES(${name} PROPERTIES VERSION ${VERSION_INFO} SOVERSION ${SOVERSION_INFO})
1349         ''')
1350         # --
1351         self.setLibAdd(key, newlines)
1352         # --
1353         if 1: # key != "noinst_LTLIBRARIES":
1354             if self.module == "medfile":
1355                 newlines.append(r'''
1356                 SET(DEST lib)
1357                 ''')
1358             else:
1359                 newlines.append(r'''
1360                 SET(DEST lib/salome)
1361                 ''')
1362                 pass
1363             newlines.append(r'''
1364             IF(BEGIN_WITH_lib)
1365             INSTALL(TARGETS ${name} DESTINATION ${DEST})
1366             ''')
1367             if self.module == "gui":
1368                 newlines.append(r'''
1369                 FOREACH(lib SalomePyQt)
1370                 IF(name STREQUAL lib)
1371                 IF(WINDOWS)
1372                 IF(CMAKE_BUILD_TYPE STREQUAL Release)
1373                 INSTALL(FILES ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.dll DESTINATION ${DEST} RENAME ${name}.pyd)
1374                 ELSE(CMAKE_BUILD_TYPE STREQUAL Release)
1375                 INSTALL(FILES ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.dll DESTINATION ${DEST} RENAME ${name}_d.pyd)
1376                 ENDIF(CMAKE_BUILD_TYPE STREQUAL Release)
1377                 ELSE(WINDOWS)
1378                 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so DESTINATION ${DEST} RENAME ${name}.so)
1379                 ENDIF(WINDOWS)
1380                 ENDIF(name STREQUAL lib)
1381                 ENDFOREACH(lib SalomePyQt)
1382                 FOREACH(lib SalomePy)
1383                 IF(name STREQUAL lib)
1384                 IF(WINDOWS)
1385                 IF(CMAKE_BUILD_TYPE STREQUAL Release)
1386                 INSTALL(FILES ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.dll DESTINATION ${DEST} RENAME lib${name}.pyd)
1387                 ELSE(CMAKE_BUILD_TYPE STREQUAL Release)
1388                 INSTALL(FILES ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.dll DESTINATION ${DEST} RENAME lib${name}_d.pyd)
1389                 ENDIF(CMAKE_BUILD_TYPE STREQUAL Release)
1390                 ENDIF(WINDOWS)
1391                 ENDIF(name STREQUAL lib)
1392                 ENDFOREACH(lib SalomePy)
1393                 ''')
1394                 pass
1395             if self.module == "geom":
1396                 newlines.append(r'''
1397                 IF(WINDOWS)
1398                 STRING(REGEX MATCH "Export" ISExport ${name})
1399                 IF(ISExport)
1400                 INSTALL(FILES ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.dll DESTINATION ${DEST} RENAME lib${name}.dll)
1401                 ENDIF(ISExport)
1402                 STRING(REGEX MATCH "Import" ISImport ${name})
1403                 IF(ISImport)
1404                 INSTALL(FILES ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.dll DESTINATION ${DEST} RENAME lib${name}.dll)
1405                 ENDIF(ISImport)
1406                 ENDIF(WINDOWS)
1407                 ''')
1408                 pass
1409             newlines.append(r'''
1410             ELSE(BEGIN_WITH_lib)
1411             ''')
1412             newlines.append(r'''
1413             IF(WINDOWS)
1414             INSTALL(TARGETS ${name} DESTINATION lib/python${PYTHON_VERSION}/site-packages/salome)
1415             IF(CMAKE_BUILD_TYPE STREQUAL Release)
1416             INSTALL(FILES ${CMAKE_INSTALL_PREFIX}/lib/python${PYTHON_VERSION}/site-packages/salome/${name}.dll DESTINATION lib/python${PYTHON_VERSION}/site-packages/salome RENAME ${name}.pyd)
1417             ELSE(CMAKE_BUILD_TYPE STREQUAL Release)
1418             INSTALL(FILES ${CMAKE_INSTALL_PREFIX}/lib/python${PYTHON_VERSION}/site-packages/salome/${name}.dll DESTINATION lib/python${PYTHON_VERSION}/site-packages/salome RENAME ${name}_d.pyd)
1419             ENDIF(CMAKE_BUILD_TYPE STREQUAL Release)
1420             ELSE(WINDOWS)
1421             GET_TARGET_PROPERTY(version ${name} VERSION)
1422             GET_TARGET_PROPERTY(soversion ${name} SOVERSION)
1423             INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so.${version} DESTINATION lib/python${PYTHON_VERSION}/site-packages/salome RENAME ${name}.so.${version})
1424             INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so.${version} DESTINATION lib/python${PYTHON_VERSION}/site-packages/salome RENAME ${name}.so.${soversion})
1425             INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so.${version} DESTINATION lib/python${PYTHON_VERSION}/site-packages/salome RENAME ${name}.so)
1426             ENDIF(WINDOWS)
1427             ''')
1428             newlines.append(r'''
1429             ENDIF(BEGIN_WITH_lib)
1430             ''')
1431             pass
1432         # --
1433         newlines.append(r'''
1434         ENDFOREACH(amname ${%s})
1435         '''%(key))
1436         # --
1437         return
1438     
1439     def addBinTarget(self, key, newlines):
1440         # --
1441         newlines.append(r'''
1442         FOREACH(amname ${bin_PROGRAMS})
1443         ''')
1444         # --
1445         newlines.append(r'''
1446         SET(name "${amname}_exe")
1447         SET(srcs ${${amname}_SOURCES} ${dist_${amname}_SOURCES})
1448         LIST(LENGTH srcs nb)
1449         IF(nb)
1450         ADD_EXECUTABLE(${name} ${srcs})
1451         ''')
1452         # --
1453         self.setCompilationFlags(key, newlines)
1454         # --
1455         self.setLibAdd(key, newlines)
1456         # --
1457         if self.module == "medfile":
1458             newlines.append(r'''
1459             SET(DEST bin)
1460             ''')
1461         else:
1462             newlines.append(r'''
1463             SET(DEST bin/salome)
1464             ''')
1465             pass
1466         # --
1467         newlines.append(r'''
1468         IF(WINDOWS)
1469         INSTALL(TARGETS ${name} DESTINATION ${DEST})
1470         INSTALL(FILES ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.exe DESTINATION ${DEST} RENAME ${amname}.exe)
1471         INSTALL(CODE "FILE(REMOVE ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.exe)")
1472         ELSE(WINDOWS)
1473         SET(PERMS)
1474         SET(PERMS ${PERMS} OWNER_READ OWNER_WRITE OWNER_EXECUTE)
1475         SET(PERMS ${PERMS} GROUP_READ GROUP_EXECUTE)
1476         SET(PERMS ${PERMS} WORLD_READ WORLD_EXECUTE)
1477         INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${name} DESTINATION ${DEST} PERMISSIONS ${PERMS} RENAME ${amname})
1478         ENDIF(WINDOWS)
1479         ''')
1480         # --
1481         newlines.append(r'''
1482         ENDIF(nb)
1483         ''')
1484         # --
1485         newlines.append(r'''
1486         ENDFOREACH(amname ${bin_PROGRAMS})
1487         ''')
1488         # --
1489         return
1490     
1491     def addInstallTarget(self, key, destination, newlines):
1492         newlines.append(r"FOREACH(f ${%s})"%(key))
1493         newlines.append(r'''
1494         SET(DEST %s)
1495         '''%(destination))
1496         newlines.append(r'''
1497         STRING(COMPARE EQUAL ${f} SALOMEconfig.h.in test_SALOMEconfig.h.in)
1498         IF(test_SALOMEconfig.h.in)
1499         INSTALL(FILES SALOMEconfig.ref.in DESTINATION ${DEST} RENAME SALOMEconfig.h.in)
1500         ELSE(test_SALOMEconfig.h.in)
1501         SET(dummy dummy-NOTFOUND)
1502         MARK_AS_ADVANCED(dummy)
1503         # FILE(REMOVE ${CMAKE_INSTALL_PREFIX}/${DEST}/${f})
1504         FIND_FILE(dummy ${f} PATHS ${CMAKE_CURRENT_SOURCE_DIR} NO_DEFAULT_PATH)
1505         IF(dummy)
1506         ''')
1507         if key in ['dist_salomescript_SCRIPTS']:
1508             newlines.append(r'''
1509             SET(PERMS)
1510             SET(PERMS ${PERMS} OWNER_READ OWNER_WRITE OWNER_EXECUTE)
1511             SET(PERMS ${PERMS} GROUP_READ GROUP_EXECUTE)
1512             SET(PERMS ${PERMS} WORLD_READ WORLD_EXECUTE)
1513             INSTALL(FILES ${f} DESTINATION ${DEST} PERMISSIONS ${PERMS})
1514             ''')
1515         else:
1516             newlines.append(r'''
1517             GET_FILENAME_COMPONENT(ext ${f} EXT)
1518             IF(ext STREQUAL .py)
1519             IF(DEST STREQUAL bin/salome)
1520             SET(PERMS)
1521             SET(PERMS ${PERMS} OWNER_READ OWNER_WRITE OWNER_EXECUTE)
1522             SET(PERMS ${PERMS} GROUP_READ GROUP_EXECUTE)
1523             SET(PERMS ${PERMS} WORLD_READ WORLD_EXECUTE)
1524             INSTALL(FILES ${f} DESTINATION ${DEST} PERMISSIONS ${PERMS})
1525             ELSE(DEST STREQUAL bin/salome)
1526             INSTALL(FILES ${f} DESTINATION ${DEST})
1527             ENDIF(DEST STREQUAL bin/salome)
1528             ELSE(ext STREQUAL .py)
1529             INSTALL(FILES ${f} DESTINATION ${DEST})
1530             ENDIF(ext STREQUAL .py)
1531             ''')
1532             pass
1533         newlines.append(r'''
1534         ELSE(dummy)
1535         GET_FILENAME_COMPONENT(ext ${f} EXT)
1536         IF(ext STREQUAL .qm)
1537         STRING(REGEX REPLACE .qm .ts input ${f})
1538         ''')
1539         if self.module in ["kernel", "gui"]:
1540             newlines.append(r'''
1541             SET(input ${CMAKE_CURRENT_SOURCE_DIR}/resources/${input})
1542             ''')
1543         else:
1544             newlines.append(r'''
1545             SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${input})
1546             ''')
1547             pass
1548         newlines.append(r'''
1549         SET(output ${CMAKE_CURRENT_BINARY_DIR}/${f})
1550         # ADD_CUSTOM_COMMAND(
1551         # OUTPUT ${output}
1552         # COMMAND ${QT_LRELEASE_EXECUTABLE} ${input} -qm ${output}
1553         # MAIN_DEPENDENCY ${input}
1554         # )
1555         EXECUTE_PROCESS(COMMAND ${QT_LRELEASE_EXECUTABLE} ${input} -qm ${output})
1556         ENDIF(ext STREQUAL .qm)
1557         INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${f} DESTINATION ${DEST})
1558         ENDIF(dummy)
1559         ENDIF(test_SALOMEconfig.h.in)
1560         ''')
1561         newlines.append(r'''
1562         GET_FILENAME_COMPONENT(ext ${f} EXT)
1563         IF(ext STREQUAL .py)
1564         INSTALL(CODE "SET(PYTHON_FILE ${f})")
1565         INSTALL(CODE "SET(CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})")
1566         INSTALL(CODE "SET(DEST ${DEST})")
1567         INSTALL(CODE "SET(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE})")
1568         ''')
1569         if self.module == "kernel":
1570             newlines.append('''
1571             IF(f STREQUAL SALOME_ContainerPy.py)
1572             ELSE(f STREQUAL SALOME_ContainerPy.py)
1573             IF(f STREQUAL am2cmake.py)
1574             ELSE(f STREQUAL am2cmake.py)
1575             INSTALL(SCRIPT ${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/install_and_compile_python_file.cmake)
1576             ENDIF(f STREQUAL am2cmake.py)
1577             ENDIF(f STREQUAL SALOME_ContainerPy.py)
1578             ''')
1579         else:
1580             newlines.append('''
1581             STRING(REPLACE "\\\\" "/" KERNEL_ROOT_DIR ${KERNEL_ROOT_DIR})
1582             INSTALL(SCRIPT ${KERNEL_ROOT_DIR}/salome_adm/cmake_files/install_and_compile_python_file.cmake)
1583             ''')
1584             pass
1585         newlines.append(r'''
1586         ENDIF(ext STREQUAL .py)
1587         ''') 
1588         newlines.append(r"ENDFOREACH(f ${%s})"%(key))
1589         return
1590     
1591     def writeListsFile(self):
1592         f = open(self.listsFile, "w")
1593         f.write(self.content)
1594         f.close()
1595         return
1596     
1597     pass
1598
1599 def convertAmFile(the_root, root, dirs, files, f, module):
1600     cmake = CMakeFile(the_root, root, dirs, files, f, module)
1601     cmake.writeListsFile()
1602     return
1603
1604 def usage(exit_status):
1605     from sys import exit
1606     from sys import argv
1607     print "Usage: %s --module"%(argv[0])
1608     exit(exit_status)
1609     return
1610
1611 if __name__ == "__main__":
1612     #
1613     from sys import argv
1614     if len(argv) != 2:
1615         usage(1)
1616         pass
1617     #
1618     module = argv[1]
1619     if module.find('--') != 0:
1620         usage(1)
1621         pass
1622     module = module[2:]
1623     if len(module) == 0:
1624         usage(1)
1625         pass
1626     #
1627     from os import getcwd
1628     the_root = getcwd()
1629     #
1630     from os import walk
1631     for root, dirs, files in walk(the_root):
1632         # --
1633         # E.A. : Remove 'CVS' in dirs
1634         # E.A. : It allows to not recurse in CVS dirs
1635         # E.A. : See os module python documentation
1636         # --
1637         try:
1638             dirs.remove('CVS')
1639         except ValueError:
1640             pass
1641         # --
1642         for f in files:
1643             if f == "Makefile.am":
1644                 convertAmFile(the_root, root, dirs, files, f, module)
1645                 pass
1646             pass
1647         pass
1648     #
1649     pass