]> SALOME platform Git repositories - modules/kernel.git/blob - salome_adm/cmake_files/am2cmake.py
Salome HOME
*** empty log message ***
[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         # --
616         return
617     
618     def treatLine(self, line, newlines, opened_ifs):
619         
620         # --
621         # Print the comment above the line itself
622         # --
623         if line.find('#') >= 0:
624             fields = line.split('#')
625             line = fields[0]
626             comment = '#'.join([''] + fields[1:])
627             newlines.append(comment)
628             if len(line) == 0:
629                 return
630             pass
631         
632         # --
633         # If the line begins with 'include ', just comment it
634         # --
635         if line.find("include ") == 0:
636             newlines.append("# " + line)
637             return
638         
639         # --
640         # If the line begins with '-include', just comment it
641         # --
642         if line.find("-include") == 0:
643             newlines.append("# " + line)
644             return
645         
646         # --
647         # If the line is a definition of a make rule, just comment it
648         # --
649         if line.count(':') == 1:
650             newlines.append("# " + line)
651             return
652         
653         # --
654         # A particuliar case where there are two ":" on the same line
655         # --
656         if line.find('install-exec-local:') == 0:
657             newlines.append("# " + line)
658             return
659         
660         # --
661         # If the line begin by a tabulation, consider it's a makefile command and comment it
662         # --
663         if line.find("\t") == 0:
664             newlines.append("# " + line)
665             return
666         
667         # --
668         # --
669         key = "-version-info"
670         if line.find(key) >= 0:
671             # --
672             before = line.split(key)[0]
673             after = line[len(before)+len(key):]
674             sep = after[0]
675             after = after[1:]
676             version_info = after.split()[0]
677             line = line.replace(key+sep+version_info, "")
678             # --
679             version_info = version_info.replace(':', '.')
680             soversion_info = version_info.split('.')[0]
681             newlines.append("SET(VERSION_INFO " + version_info + ")")
682             newlines.append("SET(SOVERSION_INFO " + soversion_info + ")")
683             # --
684             pass
685         
686         # --
687         # Replace the $(TOTO) by ${TOTO}
688         # Replace the @TOTO@  by ${TOTO}
689         # --
690         line = p_dollar.sub(r"${\1}", line)
691         line = p_arobas.sub(r"${\1}", line)
692         
693         # --
694         line = line.replace(r"${top_builddir}", r"${CMAKE_BINARY_DIR}")
695         line = line.replace(r"${top_srcdir}", r"${CMAKE_SOURCE_DIR}")
696         line = line.replace(r"${srcdir}", r"${CMAKE_CURRENT_SOURCE_DIR}")
697         line = line.replace(r"${builddir}", r"${CMAKE_CURRENT_BINARY_DIR}")
698         line = line.replace(r"${datadir}", r"${CMAKE_INSTALL_PREFIX}/share")
699         
700         # --
701         # Check if the line is a 'if' condition
702         # If yes, replace it by a cmake grammar
703         # --
704         match = p_if.match(line)
705         if match:
706             theif = match.group("val")
707             if theif[0] == "!":
708                 theif = "NOT " + theif[1:]
709                 pass
710             line = p_if.sub(r"IF(%s)"%(theif), line)
711             opened_ifs.append(theif)
712             newlines.append(line)
713             return
714         
715         # --
716         # Check if the line is a 'else' condition
717         # If yes, replace it by a cmake grammar
718         # --
719         match = p_else.match(line)
720         if match:
721             line = "ELSE(%s)"%(opened_ifs[-1])
722             newlines.append(line)
723             return
724         
725         # --
726         # Check if the line is a 'endif' condition
727         # If yes, replace it by a cmake grammar
728         # --
729         match = p_endif.match(line)
730         if match:
731             line = "ENDIF(%s)"%(opened_ifs[-1])
732             opened_ifs[-1:] = []
733             newlines.append(line)
734             return
735         
736         # --
737         # Check if the line is an attribution '=' or '+='
738         # --
739         match = p_attribution.match(line)
740         if match:
741             self.treatAttribution(match, newlines)
742             return
743         
744         # --
745         newlines.append(line)
746         
747         # --
748         return
749     
750     def treatAttribution(self, match, newlines):
751         
752         spaces = match.group("spaces")
753         key = match.group("key")
754         method = match.group("method")
755         value = match.group("value")
756         # print [spaces, key, method, value]
757         
758         # --
759         # Open cmake SET command
760         # --
761         newlines.append(spaces + "SET(" + key)
762         
763         # --
764         # If method is '+=', put the previous definition as first value
765         # --
766         if method == "+=":
767             newlines.append("%s    ${%s}"%(spaces, key))
768             pass
769         
770         # --
771         fields = value.split()
772         for i in range(len(fields)):
773             newlines.append("%s    %s"%(spaces, fields[i]))
774             pass
775         
776         # --
777         if method == "+=":
778             # --
779             # The try: except KeyError is here if the +=
780             # is an error which occurs in salome ...
781             # --
782             try:
783                 self.__thedict__[key] += fields[:]
784             except KeyError:
785                 self.__thedict__[key] = fields[:]
786                 pass
787             pass
788         else:
789             self.__thedict__[key]  = fields[:]
790             pass
791         
792         # --
793         # Close cmake SET command
794         # --
795         
796         newlines.append("%s)"%(spaces))
797         
798         return
799     
800     def finalize(self, newlines):
801         
802         # --
803         # Convert the .in files in build dir
804         # --
805         for f in self.files:
806             if f[-3:] == ".in":
807                 if f == "sstream.in":
808                     continue
809                 if f in ["runContainer.in", "stopContainer.in"]:
810                     if self.module == "med":
811                         if self.root[-3:] == "csh":
812                             continue
813                         pass
814                     pass
815                 if f == "SALOMEconfig.ref.in":
816                     out = "SALOMEconfig.h"
817                 else:
818                     out = f[:-3]
819                     pass
820                 newlines.append(r'''
821                 SET(input ${CMAKE_CURRENT_SOURCE_DIR}/%s)
822                 '''%(f))
823                 newlines.append(r'''
824                 SET(output ${CMAKE_CURRENT_BINARY_DIR}/%s)
825                 '''%(out))
826                 newlines.append(r'''
827                 MESSAGE(STATUS "Creation of ${output}")
828                 CONFIGURE_FILE(${input} ${output})
829                 ''')
830                 pass
831             pass
832         
833         # --
834         # convert the SUBDIRS in cmake grammar
835         # --
836         if 1: # self.__thedict__.has_key("SUBDIRS"):
837             newlines.append(r'''
838             FOREACH(dir ${SUBDIRS})
839             IF(NOT dir STREQUAL .)
840             ADD_SUBDIRECTORY(${dir})
841             ENDIF(NOT dir STREQUAL .)
842             ENDFOREACH(dir ${SUBDIRS})
843             ''')
844             pass
845         
846         # --
847         # --
848         for key in ["lib_LTLIBRARIES", "noinst_LTLIBRARIES", "salomepyexec_LTLIBRARIES"]:
849             if self.__thedict__.has_key(key):
850                 self.addLibTarget(key, newlines)
851                 pass
852             pass
853         
854         # --
855         # --
856         for key in ["bin_PROGRAMS"]:
857             if self.__thedict__.has_key(key):
858                 self.addBinTarget(key, newlines)
859                 pass
860             pass
861         
862         # --
863         # --
864         if self.__thedict__.has_key("BASEIDL_FILES"):
865             if not self.__thedict__.has_key("IDL_FILES"):
866                 self.__thedict__["IDL_FILES"] = self.__thedict__["BASEIDL_FILES"]
867                 newlines.append('''
868                 SET(IDL_FILES ${BASEIDL_FILES})
869                 ''')
870                 pass
871             pass
872         
873         # --
874         # --
875         
876         key = "IDL_FILES"
877         if self.__thedict__.has_key(key):
878             if self.module == "kernel":
879                 newlines.append('''
880                 SET(IDL_FILES ${IDL_FILES} Calcium_Ports.idl)
881                 ''')
882                 pass
883             newlines.append('''
884             FOREACH(input ${IDL_FILES})
885             STRING(REGEX REPLACE ".idl" "" base ${input})
886             SET(src ${CMAKE_CURRENT_BINARY_DIR}/${base}SK.cc)
887             SET(outputs ${src})
888             SET(dynsrc ${CMAKE_CURRENT_BINARY_DIR}/${base}DynSK.cc)
889             SET(outputs ${outputs} ${dynsrc})
890             IF(input STREQUAL Calcium_Ports.idl)
891             SET(input ${CMAKE_CURRENT_BINARY_DIR}/${input})
892             ELSE(input STREQUAL Calcium_Ports.idl)
893             SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${input})
894             ENDIF(input STREQUAL Calcium_Ports.idl)
895             ADD_CUSTOM_COMMAND(
896             OUTPUT ${outputs}
897             COMMAND ${OMNIORB_IDL} ${IDLCXXFLAGS} ${OMNIORB_IDLCXXFLAGS} ${input}
898             MAIN_DEPENDENCY ${input}
899             )
900             install(FILES ${input} DESTINATION idl/salome)
901             SET(IDL_HEADER ${CMAKE_CURRENT_BINARY_DIR}/${base}.hh)
902             install(FILES ${IDL_HEADER} DESTINATION include/salome)
903             INSTALL(CODE "SET(IDL_FILE ${input})")
904             INSTALL(CODE "SET(DIR lib/python${PYTHON_VERSION}/site-packages/salome)")
905             INSTALL(CODE "SET(CMAKE_CURRENT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})")
906             INSTALL(CODE "SET(OMNIORB_IDL_PYTHON ${OMNIORB_IDL_PYTHON})")
907             # --
908             SET(flags)
909             FOREACH(f ${IDLPYFLAGS})
910             SET(flags "${flags} ${f}")
911             ENDFOREACH(f ${IDLPYFLAGS})
912             SET(IDLPYFLAGS ${flags})
913             STRING(REPLACE "\\\\" "/" IDLPYFLAGS ${IDLPYFLAGS})
914             INSTALL(CODE "SET(IDLPYFLAGS ${IDLPYFLAGS})")
915             # --
916             ''')
917             if self.module == "kernel":
918                 newlines.append('''
919                 INSTALL(SCRIPT ${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/install_python_from_idl.cmake)
920                 ''')
921             else:
922                 newlines.append('''
923                 STRING(REPLACE "\\\\" "/" KERNEL_ROOT_DIR ${KERNEL_ROOT_DIR})
924                 INSTALL(SCRIPT ${KERNEL_ROOT_DIR}/salome_adm/cmake_files/install_python_from_idl.cmake)
925                 ''')
926                 pass
927             newlines.append('''
928             ENDFOREACH(input ${IDL_FILES})
929             ''')
930             pass
931         
932         # --
933         # --
934         for key in ["SWIG_SRC", "SWIGSOURCES", "SWIG_DEF"]:
935             if self.__thedict__.has_key(key):
936                 newlines.append('''
937                 SET(SWIG_SOURCES ${%s})
938                 '''%(key))
939                 self.__thedict__["SWIG_SOURCES"] = self.__thedict__[key]
940                 pass
941             pass
942         
943         # --
944         # --
945         if self.__thedict__.has_key("SWIG_SOURCES"):
946             newlines.append('''
947             IF(SWIG_SOURCES MATCHES ";")
948             STRING(REGEX REPLACE ";.*" "" SWIG_SOURCES_FIRST "${SWIG_SOURCES}")
949             ELSE(SWIG_SOURCES MATCHES ";")
950             SET(SWIG_SOURCES_FIRST "${SWIG_SOURCES}")
951             ENDIF(SWIG_SOURCES MATCHES ";")
952             ADD_CUSTOM_COMMAND(
953             OUTPUT ${build_srcs}
954             COMMAND ${SWIG_EXECUTABLE} ${SWIG_FLAGS} ${MY_SWIG_FLAGS} -o ${build_srcs} ${CMAKE_CURRENT_SOURCE_DIR}/${SWIG_SOURCES_FIRST}
955             MAIN_DEPENDENCY ${SWIG_SOURCES}
956             )
957             ''')
958             pass
959         
960         # --
961         # --
962         key = "MOC_FILES"
963         if self.__thedict__.has_key(key):
964             newlines.append('''
965             FOREACH(output ${MOC_FILES})
966             STRING(REGEX REPLACE _moc.cxx .h input ${output})
967             SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${input})
968             SET(output ${CMAKE_CURRENT_BINARY_DIR}/${output})
969             ADD_CUSTOM_COMMAND(
970             OUTPUT ${output}
971             COMMAND ${QT_MOC_EXECUTABLE} ${MOC_FLAGS} ${input} -o ${output}
972             MAIN_DEPENDENCY ${input}
973             )
974             ENDFOREACH(output ${MOC_FILES})
975             ''')
976             pass
977         
978         # --
979         # --
980         key = "UIC_FILES"
981         if self.__thedict__.has_key(key):
982             newlines.append('''
983             FOREACH(output ${UIC_FILES})
984             STRING(REPLACE "ui_" "" input ${output})
985             STRING(REPLACE ".h" ".ui" input ${input})
986             SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${input})
987             SET(output ${CMAKE_CURRENT_BINARY_DIR}/${output})
988             ADD_CUSTOM_COMMAND(
989             OUTPUT ${output}
990             COMMAND ${QT_UIC_EXECUTABLE} -o ${output} ${input}
991             MAIN_DEPENDENCY ${input}
992             )
993             ENDFOREACH(output ${UIC_FILES})
994             ''')
995             pass
996         
997         # --
998         # --
999         key = "QRC_FILES"
1000         if self.__thedict__.has_key(key):
1001             newlines.append('''
1002             FOREACH(output ${QRC_FILES})
1003             STRING(REGEX REPLACE "qrc_" "" input ${output})
1004             STRING(REGEX REPLACE ".cxx" ".qrc" input ${input})
1005             STRING(REGEX REPLACE ".qrc" "" name ${input})
1006             SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${input})
1007             SET(output ${CMAKE_CURRENT_BINARY_DIR}/${output})
1008             ADD_CUSTOM_COMMAND(
1009             OUTPUT ${output}
1010             COMMAND ${QT_RCC_EXECUTABLE} ${input} -o ${output} -name ${name}
1011             MAIN_DEPENDENCY ${input}
1012             )
1013             ENDFOREACH(output ${QRC_FILES})
1014             ''')
1015             pass
1016         
1017         # --
1018         # --
1019         key = "SIP_FILES"
1020         if self.__thedict__.has_key(key):
1021             newlines.append('''
1022             FOREACH(input ${SIP_FILES})
1023             SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${input})
1024             SET(output)
1025             FOREACH(out ${SIP_SRC})
1026             SET(output ${output} ${CMAKE_CURRENT_BINARY_DIR}/${out})
1027             ENDFOREACH(out ${SIP_SRC})
1028             ADD_CUSTOM_COMMAND(
1029             OUTPUT ${output}
1030             COMMAND ${SIP_EXECUTABLE} ${PYQT_SIPFLAGS} ${input}
1031             MAIN_DEPENDENCY ${input}
1032             )
1033             ENDFOREACH(input ${SIP_FILES})
1034             ''')
1035             pass
1036         
1037         # --
1038         # Treat the install targets
1039         # --
1040         d = {
1041             "salomeadmux_DATA"            :  "salome_adm/unix",
1042             "dist_salomeadmux_DATA"       :  "salome_adm/unix",
1043             "dist_salome_cmake_DATA"      :  "salome_adm/cmake_files",
1044             "dist_salomem4_DATA"          :  "salome_adm/unix/config_files",
1045             "dist_salome4depr_DATA"       :  "salome_adm/unix/config_files/DEPRECATED",
1046             "dist_admlocalm4_DATA"        :  "adm_local/unix/config_files",
1047             "dist_admlocal_cmake_DATA"    :  "adm_local/cmake_files",
1048             "salomeinclude_DATA"          :  "include/salome",
1049             "salomeinclude_HEADERS"       :  "include/salome",
1050             "dist_salomeres_DATA"         :  "share/salome/resources/%s"%(self.module),
1051             "nodist_salomeres_DATA"       :  "share/salome/resources/%s"%(self.module),
1052             "nodist_salomeres_SCRIPTS"    :  "share/salome/resources/%s"%(self.module),
1053             "dist_salomescript_SCRIPTS"   :  "bin/salome",
1054             "dist_salomescript_DATA"      :  "bin/salome",
1055             "dist_salomescript_PYTHON"    :  "bin/salome",
1056             "nodist_salomescript_DATA"    :  "bin/salome",
1057             "salomepython_PYTHON"         :  "lib/python${PYTHON_VERSION}/site-packages/salome",
1058             "nodist_salomepython_PYTHON"  :  "lib/python${PYTHON_VERSION}/site-packages/salome",
1059             "sharedpkgpython_PYTHON"      :  "lib/python${PYTHON_VERSION}/site-packages/salome/shared_modules",
1060             }
1061         if self.module == "medfile":
1062             d = {
1063                 "include_HEADERS"        :  "include",
1064                 "nodist_include_HEADERS" :  "include",
1065                 "bin_SCRIPTS"            :  "bin",
1066                 "doc_DATA"               :  "${docdir}",
1067                 }
1068             pass
1069         for key, value in d.items():
1070             if self.__thedict__.has_key(key):
1071                 self.addInstallTarget(key, value, newlines)
1072                 pass
1073             pass
1074         
1075         # --
1076         return
1077     
1078     def setLibAdd(self, key, newlines):
1079         # --
1080         newlines.append(r'''
1081         SET(libadd)
1082         ''')
1083         # --
1084         newlines.append(r'''
1085         IF(WINDOWS)
1086         SET(targets)
1087         SET(targets ${targets} MEFISTO2D)
1088         FOREACH(target ${targets})
1089         IF(name STREQUAL ${target})
1090         SET(dir $ENV{F2CHOME})
1091         STRING(REPLACE "\\\\" "/" dir ${dir})
1092         SET(libadd ${libadd} ${dir}/LIBF77.lib)
1093         SET(libadd ${libadd} ${dir}/LIBI77.lib)
1094         ENDIF(name STREQUAL ${target})
1095         ENDFOREACH(target ${targets})
1096         ENDIF(WINDOWS)
1097         ''')
1098         # --
1099         newlines.append(r'''
1100         SET(libs ${PLATFORM_LIBADD} ${PLATFORM_LDFLAGS} ${${amname}_LIBADD} ${${amname}_LDADD} ${${amname}_LDFLAGS})
1101         FOREACH(lib SALOMEBasics SalomeBatch)
1102         IF(name STREQUAL lib)
1103         SET(libs ${libs} ${PTHREAD_LIBS})
1104         ENDIF(name STREQUAL lib)
1105         ENDFOREACH(lib SALOMEBasics SalomeBatch)
1106         ''')
1107         if key == "bin_PROGRAMS":
1108             newlines.append(r'''
1109             SET(libs ${libs} ${LDADD})
1110             ''')
1111             pass
1112         # --
1113         newlines.append(r'''
1114         FOREACH(lib ${libs})
1115         GET_FILENAME_COMPONENT(ext ${lib} EXT)
1116         IF(ext STREQUAL .la)
1117         GET_FILENAME_COMPONENT(lib ${lib} NAME_WE)
1118         STRING(REPLACE "lib" "" lib ${lib})
1119         ENDIF(ext STREQUAL .la)
1120         SET(vars)
1121         SET(vars ${vars} -no-undefined)
1122         SET(vars ${vars} -lvtkWidgets)
1123         IF(WINDOWS)
1124         SET(vars ${vars} -module)
1125         SET(vars ${vars} -Wl,-E)
1126         SET(vars ${vars} -Xlinker)
1127         SET(vars ${vars} -export-dynamic)
1128         SET(vars ${vars} -lm)
1129         SET(vars ${vars} -lboost_thread)
1130         SET(vars ${vars} -lboost_signals)
1131         ENDIF(WINDOWS)
1132         FOREACH(v ${vars})
1133         IF(lib STREQUAL v)
1134         SET(lib)
1135         ENDIF(lib STREQUAL v)
1136         ENDFOREACH(v ${vars})
1137         SET(libadd ${libadd} ${lib})
1138         ENDFOREACH(lib ${libs})
1139         TARGET_LINK_LIBRARIES(${name} ${libadd})
1140         ''')
1141         # --
1142         newlines.append(r'''
1143         IF(WINDOWS)
1144         SET(targets)
1145         SET(targets ${targets} MEFISTO2D)
1146         FOREACH(target ${targets})
1147         IF(name STREQUAL ${target})
1148         IF(CMAKE_BUILD_TYPE STREQUAL Debug)
1149         SET_TARGET_PROPERTIES(${name} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:MSVCRT")
1150         ENDIF(CMAKE_BUILD_TYPE STREQUAL Debug)
1151         ENDIF(name STREQUAL ${target})
1152         ENDFOREACH(target ${targets})
1153         ENDIF(WINDOWS)
1154         ''')
1155         # --
1156         return
1157     
1158     def setCompilationFlags(self, key, newlines):
1159         newlines.append(r'''
1160         SET(var)
1161         IF(WINDOWS)
1162         SET(targets)
1163         SET(targets ${targets} SalomeIDLKernel)
1164         SET(targets ${targets} SalomeDS)
1165         SET(targets ${targets} SALOMEDSTest)
1166         SET(targets ${targets} SALOMEDS_Client_exe)
1167         SET(targets ${targets} SalomeIDLGEOM)
1168         SET(targets ${targets} GEOMEngine)
1169         SET(targets ${targets} MEDEngine)
1170         SET(targets ${targets} SMESHEngine)
1171         SET(targets ${targets} SMESH)
1172         FOREACH(target ${targets})
1173         IF(name STREQUAL ${target})
1174         SET(var ${var} -DNOGDI)
1175         ENDIF(name STREQUAL ${target})
1176         ENDFOREACH(target ${targets})
1177         ENDIF(WINDOWS)
1178         ''')
1179         # --
1180         newlines.append(r'''
1181         IF(WINDOWS)
1182         SET(targets)
1183         SET(targets ${targets} MEFISTO2D)
1184         FOREACH(target ${targets})
1185         IF(name STREQUAL ${target})
1186         SET(dir $ENV{F2CHOME})
1187         STRING(REPLACE "\\\\" "/" dir ${dir})
1188         SET(var ${var} -I${dir})
1189         ENDIF(name STREQUAL ${target})
1190         ENDFOREACH(target ${targets})
1191         ENDIF(WINDOWS)
1192         ''')
1193         # --
1194         if self.module in ["geom", "med"]:
1195             newlines.append(r'''
1196             SET(var ${var} -I${CMAKE_CURRENT_SOURCE_DIR})
1197             SET(var ${var} -I${CMAKE_CURRENT_BINARY_DIR})
1198             ''')
1199             pass
1200         if key == "bin_PROGRAMS":
1201             newlines.append(r'''
1202             SET(var ${var} ${AM_CPPFLAGS})
1203             SET(var ${var} ${AM_CXXFLAGS})
1204             ''')
1205             pass
1206         newlines.append(r'''
1207         SET(var ${var} ${PLATFORM_CPPFLAGS})
1208         SET(var ${var} ${PTHREAD_CFLAGS})
1209         SET(var ${var} ${${amname}_CPPFLAGS})
1210         SET(var ${var} ${${amname}_CXXFLAGS})
1211         SET(var ${var} ${${amname}_CFLAGS})
1212         SET(vars)
1213         IF(WINDOWS)
1214         SET(vars ${vars} -include SALOMEconfig.h)
1215         SET(vars ${vars} -ftemplate-depth-32)
1216         ENDIF(WINDOWS)
1217         SET(flags)
1218         FOREACH(f ${var})
1219         FOREACH(v ${vars})
1220         IF(f STREQUAL v)
1221         SET(f)
1222         ENDIF(f STREQUAL v)
1223         ENDFOREACH(v ${vars})
1224         SET(flags "${flags} ${f}")
1225         ENDFOREACH(f ${var})
1226         SET_TARGET_PROPERTIES(${name} PROPERTIES COMPILE_FLAGS "${flags}")
1227         ''')
1228         return
1229     
1230     def addLibTarget(self, key, newlines):
1231         newlines.append(r'''
1232         FOREACH(amname ${%s})
1233         '''%(key))
1234         # --
1235         # Replace .la by _la ...
1236         # --
1237         newlines.append(r'''
1238         STRING(REPLACE .la _la amname ${amname})
1239         ''')
1240         # --
1241         # Remove the _la for the cmake name
1242         # --
1243         newlines.append(r'''
1244         STRING(LENGTH ${amname} len)
1245         MATH(EXPR newlen "${len}-3")
1246         STRING(SUBSTRING ${amname} 0 ${newlen} name)
1247         ''')
1248         # --
1249         # Does the target begins with lib ??
1250         # If yes, remove lib at beginning for cmake name
1251         # --
1252         newlines.append(r'''
1253         STRING(REGEX MATCH "^lib" BEGIN_WITH_lib ${name})
1254         IF(BEGIN_WITH_lib)
1255         STRING(LENGTH ${name} len)
1256         MATH(EXPR newlen "${len}-3")
1257         STRING(SUBSTRING ${name} 3 ${newlen} name)
1258         ENDIF(BEGIN_WITH_lib)
1259         ''')
1260         # --
1261         # Does the target is an idl library
1262         # --
1263         newlines.append(r'''
1264         STRING(REGEX MATCH "IDL" ISIDL ${name})
1265         ''')
1266         # --
1267         # Set the type of the library
1268         # --
1269         newlines.append(r'''
1270         IF(ISIDL)
1271         IF(WINDOWS)
1272         SET(type STATIC)
1273         ELSE(WINDOWS)
1274         SET(type SHARED)
1275         ENDIF(WINDOWS)
1276         ELSE(ISIDL)
1277         SET(type SHARED)
1278         ENDIF(ISIDL)
1279         ''')
1280         # --
1281         # Set sources for the library
1282         # --
1283         newlines.append(r'''
1284         SET(srcs)
1285         FOREACH(src ${${amname}_SOURCES} ${dist_${amname}_SOURCES})
1286         GET_FILENAME_COMPONENT(ext ${src} EXT)
1287         IF(ext STREQUAL .f)
1288         IF(src STREQUAL trte.f)
1289         SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${src})
1290         STRING(REPLACE ".f" ".c" src ${src})
1291         SET(src ${CMAKE_CURRENT_BINARY_DIR}/${src})
1292         SET(output ${src})
1293         ADD_CUSTOM_COMMAND(
1294         OUTPUT ${output}
1295         COMMAND f2c ${input}
1296         MAIN_DEPENDENCY ${input}
1297         )
1298         ELSE(src STREQUAL trte.f)
1299         SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${src})
1300         STRING(REPLACE ".f" ".o" src ${src})
1301         SET(src ${CMAKE_CURRENT_BINARY_DIR}/${src})
1302         SET(output ${src})
1303         IF(WINDOWS)
1304         SET(F77 g77)
1305         ELSE(WINDOWS)
1306         SET(F77 gfortran)
1307         ENDIF(WINDOWS)
1308         ADD_CUSTOM_COMMAND(
1309         OUTPUT ${output}
1310         COMMAND ${F77} -c -o ${output} ${input}
1311         MAIN_DEPENDENCY ${input}
1312         )
1313         ENDIF(src STREQUAL trte.f)
1314         ENDIF(ext STREQUAL .f)
1315         SET(srcs ${srcs} ${src})
1316         ENDFOREACH(src ${${amname}_SOURCES} ${dist_${amname}_SOURCES})
1317         ''')
1318         newlines.append(r'''
1319         SET(build_srcs)
1320         ''')
1321         newlines.append(r'''
1322         SET(l ${nodist_${amname}_SOURCES} ${BUILT_SOURCES})
1323         ''')
1324         newlines.append(r'''
1325         FOREACH(f ${l})
1326         GET_FILENAME_COMPONENT(ext ${f} EXT)
1327         IF(ext STREQUAL .py)
1328         ELSE(ext STREQUAL .py)
1329         SET(build_srcs ${build_srcs} ${CMAKE_CURRENT_BINARY_DIR}/${f})
1330         ENDIF(ext STREQUAL .py)
1331         ENDFOREACH(f ${l})
1332         SET(srcs ${build_srcs} ${srcs})
1333         ''')
1334         # --
1335         # Add the library to cmake
1336         # --
1337         newlines.append(r'''
1338         ADD_LIBRARY(${name} ${type} ${srcs})
1339         ''')
1340         # --
1341         # The compilation flags
1342         # --
1343         self.setCompilationFlags(key, newlines)
1344         # --
1345         newlines.append(r'''
1346         SET_TARGET_PROPERTIES(${name} PROPERTIES VERSION ${VERSION_INFO} SOVERSION ${SOVERSION_INFO})
1347         ''')
1348         # --
1349         self.setLibAdd(key, newlines)
1350         # --
1351         if 1: # key != "noinst_LTLIBRARIES":
1352             if self.module == "medfile":
1353                 newlines.append(r'''
1354                 SET(DEST lib)
1355                 ''')
1356             else:
1357                 newlines.append(r'''
1358                 SET(DEST lib/salome)
1359                 ''')
1360                 pass
1361             newlines.append(r'''
1362             IF(BEGIN_WITH_lib)
1363             INSTALL(TARGETS ${name} DESTINATION ${DEST})
1364             ''')
1365             if self.module == "gui":
1366                 newlines.append(r'''
1367                 FOREACH(lib SalomePyQt)
1368                 IF(name STREQUAL lib)
1369                 IF(WINDOWS)
1370                 IF(CMAKE_BUILD_TYPE STREQUAL Release)
1371                 INSTALL(FILES ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.dll DESTINATION ${DEST} RENAME ${name}.pyd)
1372                 ELSE(CMAKE_BUILD_TYPE STREQUAL Release)
1373                 INSTALL(FILES ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.dll DESTINATION ${DEST} RENAME ${name}_d.pyd)
1374                 ENDIF(CMAKE_BUILD_TYPE STREQUAL Release)
1375                 ELSE(WINDOWS)
1376                 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so DESTINATION ${DEST} RENAME ${name}.so)
1377                 ENDIF(WINDOWS)
1378                 ENDIF(name STREQUAL lib)
1379                 ENDFOREACH(lib SalomePyQt)
1380                 FOREACH(lib SalomePy)
1381                 IF(name STREQUAL lib)
1382                 IF(WINDOWS)
1383                 IF(CMAKE_BUILD_TYPE STREQUAL Release)
1384                 INSTALL(FILES ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.dll DESTINATION ${DEST} RENAME lib${name}.pyd)
1385                 ELSE(CMAKE_BUILD_TYPE STREQUAL Release)
1386                 INSTALL(FILES ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.dll DESTINATION ${DEST} RENAME lib${name}_d.pyd)
1387                 ENDIF(CMAKE_BUILD_TYPE STREQUAL Release)
1388                 ENDIF(WINDOWS)
1389                 ENDIF(name STREQUAL lib)
1390                 ENDFOREACH(lib SalomePy)
1391                 ''')
1392                 pass
1393             if self.module == "geom":
1394                 newlines.append(r'''
1395                 IF(WINDOWS)
1396                 STRING(REGEX MATCH "Export" ISExport ${name})
1397                 IF(ISExport)
1398                 INSTALL(FILES ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.dll DESTINATION ${DEST} RENAME lib${name}.dll)
1399                 ENDIF(ISExport)
1400                 STRING(REGEX MATCH "Import" ISImport ${name})
1401                 IF(ISImport)
1402                 INSTALL(FILES ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.dll DESTINATION ${DEST} RENAME lib${name}.dll)
1403                 ENDIF(ISImport)
1404                 ENDIF(WINDOWS)
1405                 ''')
1406                 pass
1407             newlines.append(r'''
1408             ELSE(BEGIN_WITH_lib)
1409             ''')
1410             newlines.append(r'''
1411             IF(WINDOWS)
1412             INSTALL(TARGETS ${name} DESTINATION lib/python${PYTHON_VERSION}/site-packages/salome)
1413             IF(CMAKE_BUILD_TYPE STREQUAL Release)
1414             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)
1415             ELSE(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}_d.pyd)
1417             ENDIF(CMAKE_BUILD_TYPE STREQUAL Release)
1418             ELSE(WINDOWS)
1419             GET_TARGET_PROPERTY(version ${name} VERSION)
1420             GET_TARGET_PROPERTY(soversion ${name} SOVERSION)
1421             INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so.${version} DESTINATION lib/python${PYTHON_VERSION}/site-packages/salome RENAME ${name}.so.${version})
1422             INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so.${version} DESTINATION lib/python${PYTHON_VERSION}/site-packages/salome RENAME ${name}.so.${soversion})
1423             INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so.${version} DESTINATION lib/python${PYTHON_VERSION}/site-packages/salome RENAME ${name}.so)
1424             ENDIF(WINDOWS)
1425             ''')
1426             newlines.append(r'''
1427             ENDIF(BEGIN_WITH_lib)
1428             ''')
1429             pass
1430         # --
1431         newlines.append(r'''
1432         ENDFOREACH(amname ${%s})
1433         '''%(key))
1434         # --
1435         return
1436     
1437     def addBinTarget(self, key, newlines):
1438         # --
1439         newlines.append(r'''
1440         FOREACH(amname ${bin_PROGRAMS})
1441         ''')
1442         # --
1443         newlines.append(r'''
1444         SET(name "${amname}_exe")
1445         SET(srcs ${${amname}_SOURCES} ${dist_${amname}_SOURCES})
1446         LIST(LENGTH srcs nb)
1447         IF(nb)
1448         ADD_EXECUTABLE(${name} ${srcs})
1449         ''')
1450         # --
1451         self.setCompilationFlags(key, newlines)
1452         # --
1453         self.setLibAdd(key, newlines)
1454         # --
1455         if self.module == "medfile":
1456             newlines.append(r'''
1457             SET(DEST bin)
1458             ''')
1459         else:
1460             newlines.append(r'''
1461             SET(DEST bin/salome)
1462             ''')
1463             pass
1464         # --
1465         newlines.append(r'''
1466         IF(WINDOWS)
1467         INSTALL(TARGETS ${name} DESTINATION ${DEST})
1468         INSTALL(FILES ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.exe DESTINATION ${DEST} RENAME ${amname}.exe)
1469         INSTALL(CODE "FILE(REMOVE ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.exe)")
1470         ELSE(WINDOWS)
1471         SET(PERMS)
1472         SET(PERMS ${PERMS} OWNER_READ OWNER_WRITE OWNER_EXECUTE)
1473         SET(PERMS ${PERMS} GROUP_READ GROUP_EXECUTE)
1474         SET(PERMS ${PERMS} WORLD_READ WORLD_EXECUTE)
1475         INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${name} DESTINATION ${DEST} PERMISSIONS ${PERMS} RENAME ${amname})
1476         ENDIF(WINDOWS)
1477         ''')
1478         # --
1479         newlines.append(r'''
1480         ENDIF(nb)
1481         ''')
1482         # --
1483         newlines.append(r'''
1484         ENDFOREACH(amname ${bin_PROGRAMS})
1485         ''')
1486         # --
1487         return
1488     
1489     def addInstallTarget(self, key, destination, newlines):
1490         newlines.append(r"FOREACH(f ${%s})"%(key))
1491         newlines.append(r'''
1492         SET(DEST %s)
1493         '''%(destination))
1494         newlines.append(r'''
1495         STRING(COMPARE EQUAL ${f} SALOMEconfig.h.in test_SALOMEconfig.h.in)
1496         IF(test_SALOMEconfig.h.in)
1497         INSTALL(FILES SALOMEconfig.ref.in DESTINATION ${DEST} RENAME SALOMEconfig.h.in)
1498         ELSE(test_SALOMEconfig.h.in)
1499         SET(dummy dummy-NOTFOUND)
1500         MARK_AS_ADVANCED(dummy)
1501         # FILE(REMOVE ${CMAKE_INSTALL_PREFIX}/${DEST}/${f})
1502         FIND_FILE(dummy ${f} PATHS ${CMAKE_CURRENT_SOURCE_DIR} NO_DEFAULT_PATH)
1503         IF(dummy)
1504         ''')
1505         if key in ['dist_salomescript_SCRIPTS']:
1506             newlines.append(r'''
1507             SET(PERMS)
1508             SET(PERMS ${PERMS} OWNER_READ OWNER_WRITE OWNER_EXECUTE)
1509             SET(PERMS ${PERMS} GROUP_READ GROUP_EXECUTE)
1510             SET(PERMS ${PERMS} WORLD_READ WORLD_EXECUTE)
1511             INSTALL(FILES ${f} DESTINATION ${DEST} PERMISSIONS ${PERMS})
1512             ''')
1513         else:
1514             newlines.append(r'''
1515             GET_FILENAME_COMPONENT(ext ${f} EXT)
1516             IF(ext STREQUAL .py)
1517             IF(DEST STREQUAL bin/salome)
1518             SET(PERMS)
1519             SET(PERMS ${PERMS} OWNER_READ OWNER_WRITE OWNER_EXECUTE)
1520             SET(PERMS ${PERMS} GROUP_READ GROUP_EXECUTE)
1521             SET(PERMS ${PERMS} WORLD_READ WORLD_EXECUTE)
1522             INSTALL(FILES ${f} DESTINATION ${DEST} PERMISSIONS ${PERMS})
1523             ELSE(DEST STREQUAL bin/salome)
1524             INSTALL(FILES ${f} DESTINATION ${DEST})
1525             ENDIF(DEST STREQUAL bin/salome)
1526             ELSE(ext STREQUAL .py)
1527             INSTALL(FILES ${f} DESTINATION ${DEST})
1528             ENDIF(ext STREQUAL .py)
1529             ''')
1530             pass
1531         newlines.append(r'''
1532         ELSE(dummy)
1533         GET_FILENAME_COMPONENT(ext ${f} EXT)
1534         IF(ext STREQUAL .qm)
1535         STRING(REGEX REPLACE .qm .ts input ${f})
1536         ''')
1537         if self.module in ["kernel", "gui"]:
1538             newlines.append(r'''
1539             SET(input ${CMAKE_CURRENT_SOURCE_DIR}/resources/${input})
1540             ''')
1541         else:
1542             newlines.append(r'''
1543             SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${input})
1544             ''')
1545             pass
1546         newlines.append(r'''
1547         SET(output ${CMAKE_CURRENT_BINARY_DIR}/${f})
1548         # ADD_CUSTOM_COMMAND(
1549         # OUTPUT ${output}
1550         # COMMAND ${QT_LRELEASE_EXECUTABLE} ${input} -qm ${output}
1551         # MAIN_DEPENDENCY ${input}
1552         # )
1553         EXECUTE_PROCESS(COMMAND ${QT_LRELEASE_EXECUTABLE} ${input} -qm ${output})
1554         ENDIF(ext STREQUAL .qm)
1555         INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${f} DESTINATION ${DEST})
1556         ENDIF(dummy)
1557         ENDIF(test_SALOMEconfig.h.in)
1558         ''')
1559         newlines.append(r'''
1560         GET_FILENAME_COMPONENT(ext ${f} EXT)
1561         IF(ext STREQUAL .py)
1562         INSTALL(CODE "SET(PYTHON_FILE ${f})")
1563         INSTALL(CODE "SET(CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})")
1564         INSTALL(CODE "SET(DEST ${DEST})")
1565         INSTALL(CODE "SET(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE})")
1566         ''')
1567         if self.module == "kernel":
1568             newlines.append('''
1569             IF(f STREQUAL SALOME_ContainerPy.py)
1570             ELSE(f STREQUAL SALOME_ContainerPy.py)
1571             IF(f STREQUAL am2cmake.py)
1572             ELSE(f STREQUAL am2cmake.py)
1573             INSTALL(SCRIPT ${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/install_and_compile_python_file.cmake)
1574             ENDIF(f STREQUAL am2cmake.py)
1575             ENDIF(f STREQUAL SALOME_ContainerPy.py)
1576             ''')
1577         else:
1578             newlines.append('''
1579             STRING(REPLACE "\\\\" "/" KERNEL_ROOT_DIR ${KERNEL_ROOT_DIR})
1580             INSTALL(SCRIPT ${KERNEL_ROOT_DIR}/salome_adm/cmake_files/install_and_compile_python_file.cmake)
1581             ''')
1582             pass
1583         newlines.append(r'''
1584         ENDIF(ext STREQUAL .py)
1585         ''') 
1586         newlines.append(r"ENDFOREACH(f ${%s})"%(key))
1587         return
1588     
1589     def writeListsFile(self):
1590         f = open(self.listsFile, "w")
1591         f.write(self.content)
1592         f.close()
1593         return
1594     
1595     pass
1596
1597 def convertAmFile(the_root, root, dirs, files, f, module):
1598     cmake = CMakeFile(the_root, root, dirs, files, f, module)
1599     cmake.writeListsFile()
1600     return
1601
1602 def usage(exit_status):
1603     from sys import exit
1604     from sys import argv
1605     print "Usage: %s --module"%(argv[0])
1606     exit(exit_status)
1607     return
1608
1609 if __name__ == "__main__":
1610     #
1611     from sys import argv
1612     if len(argv) != 2:
1613         usage(1)
1614         pass
1615     #
1616     module = argv[1]
1617     if module.find('--') != 0:
1618         usage(1)
1619         pass
1620     module = module[2:]
1621     if len(module) == 0:
1622         usage(1)
1623         pass
1624     #
1625     from os import getcwd
1626     the_root = getcwd()
1627     #
1628     from os import walk
1629     for root, dirs, files in walk(the_root):
1630         # --
1631         # E.A. : Remove 'CVS' in dirs
1632         # E.A. : It allows to not recurse in CVS dirs
1633         # E.A. : See os module python documentation
1634         # --
1635         try:
1636             dirs.remove('CVS')
1637         except ValueError:
1638             pass
1639         # --
1640         for f in files:
1641             if f == "Makefile.am":
1642                 convertAmFile(the_root, root, dirs, files, f, module)
1643                 pass
1644             pass
1645         pass
1646     #
1647     pass