Salome HOME
New version of cmake tools completely re-written
[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         kernel_list  = [
204             "DF",
205             "Launcher",
206             "OpUtil",
207             "Registry",
208             "ResourcesManager",
209             "SALOMEBasics",
210             "SalomeBatch",
211             "SalomeCatalog",
212             "SalomeCommunication",
213             "SalomeContainer",
214             "SalomeDSCContainer",
215             "SalomeDSClient",
216             "SalomeDSImpl",
217             "SalomeDS",
218             "SalomeGenericObj",
219             "SalomeHDFPersist",
220             "SalomeIDLKernel",
221             "SalomeLauncher",
222             "SalomeLifeCycleCORBA",
223             "SALOMELocalTrace",
224             "SalomeLoggerServer",
225             "SalomeNotification",
226             "SalomeNS",
227             "SalomeResourcesManager",
228             "TOOLSDS",
229             "with_loggerTraceCollector",
230             ]
231         gui_list = [
232             "caf",
233             "CAM",
234             "CASCatch",
235             "DDS",
236             "Event",
237             "GLViewer",
238             "LightApp",
239             "LogWindow",
240             "ObjBrowser",
241             "OCCViewer",
242             "Plot2d",
243             "PyConsole",
244             "PyInterp",
245             "QDS",
246             "qtx",
247             "QxScene",
248             "SalomeApp",
249             "SalomeIDLGUI",
250             "SalomeObject",
251             "SalomePrs",
252             "SalomeSession",
253             "SalomeStyle",
254             "SOCC",
255             "SPlot2d",
256             "std",
257             "SUITApp",
258             "suit",
259             "SUPERVGraph",
260             "SVTK",
261             "ToolsGUI",
262             "VTKViewer",
263             ]
264         geom_list = [
265             "BasicGUI",
266             "BlocksGUI",
267             "BooleanGUI",
268             "BREPExport",
269             "BREPImport",
270             "BuildGUI",
271             "DisplayGUI",
272             "DlgRef",
273             "EntityGUI",
274             "GenerationGUI",
275             "GEOMAlgo",
276             "GEOMArchimede",
277             "GEOMBase",
278             "GEOMbasic",
279             "GEOMClient",
280             "GEOMEngine",
281             "GEOMFiltersSelection",
282             "GEOMimpl",
283             "GEOMObject",
284             "GEOMSketcher",
285             "GEOM",
286             "GEOM_SupervEngine",
287             "GEOMToolsGUI",
288             "GroupGUI",
289             "IGESExport",
290             "IGESImport",
291             "MeasureGUI",
292             "NMTDS",
293             "NMTTools",
294             "OperationGUI",
295             "PrimitiveGUI",
296             "RepairGUI",
297             "SalomeIDLGEOM",
298             "ShHealOper",
299             "STEPExport",
300             "STEPImport",
301             "STLExport",
302             "TransformationGUI",
303             ]
304         med_list = [
305             "InterpGeometric2DAlg",
306             "interpkernelbases",
307             "interpkernel",
308             "MEDClientcmodule",
309             "medcoupling",
310             "MEDEngine",
311             "MEDMEMImpl",
312             "medmem",
313             "MED",
314             "med_V2_1",
315             "MEDWrapperBase",
316             "MEDWrapper",
317             "MEDWrapper_V2_1",
318             "MEDWrapper_V2_2",
319             "SalomeIDLMED",
320             ]
321         smesh_list = [
322             "MEFISTO2D",
323             "MeshDriverDAT",
324             "MeshDriverMED",
325             "MeshDriver",
326             "MeshDriverSTL",
327             "MeshDriverUNV",
328             "SalomeIDLSMESH",
329             "SMDS",
330             "SMESHClient",
331             "SMESHControls",
332             "SMESHDS",
333             "SMESHEngine",
334             "SMESHFiltersSelection",
335             "SMESHimpl",
336             "SMESHObject",
337             "SMESH",
338             "StdMeshersEngine",
339             "StdMeshersGUI",
340             "StdMeshers",
341             ]
342         full_list = cas_list + kernel_list + gui_list
343         full_list += geom_list + med_list + smesh_list
344         # --
345         # E.A. : sort by len before substitution ...
346         # Why ? Thing to "-lMEDWrapper" then "-lMEDWrapper_V2_1" substition
347         # And you understand ...
348         # --
349         full_list.sort(cmp = lambda x, y : cmp(len(y), len(x)))
350         # --
351         for key in full_list:
352             content = content.replace("-l%s"%(key), "${%s}"%(key))
353             pass
354         
355         # --
356         # Split content in lines to treat each one separately
357         # --
358         lines = content.split('\n')
359         
360         # --
361         # newlines contains the lines of the future CMakeLists.txt file
362         # --
363         newlines = []
364         
365         # --
366         # opened_ifs is used to deals with nested conditionnals
367         # --
368         opened_ifs = []
369         
370         # --
371         # the __thedict__ dictionnary contains key, val
372         # of the Makefile.am file
373         # --
374         self.__thedict__ = {}
375         
376         # --
377         # Initialize file ... mainly includes other cmake files
378         # --
379         self.initialize(newlines)
380         
381         # --
382         # Do the job for each line
383         # --
384         for line in lines:
385             self.treatLine(line, newlines, opened_ifs)
386             pass
387         
388         # --
389         # Finalize file ... it is in here the cmake job is done
390         # --
391         self.finalize(newlines)
392         
393         # --
394         # Concatenate newlines into content
395         # --
396         content = '\n'.join(newlines)
397         
398         # --
399         # Add a CR at end if necessary
400         # --
401         lines = content.split('\n')
402         # lines = [ l.strip() for l in lines ]
403         if len(lines[-1]) != 0:
404             lines.append('')
405             pass
406         content = '\n'.join(lines)
407         
408         # --
409         self.content = content
410         
411         # --
412         return
413     
414     def initialize(self, newlines):
415         if self.root == self.the_root:
416             # --
417             newlines.append("""
418             CMAKE_MINIMUM_REQUIRED(VERSION 2.4.7 FATAL_ERROR)
419             IF(COMMAND cmake_policy)
420             cmake_policy(SET CMP0003 NEW)
421             ENDIF(COMMAND cmake_policy)
422             """)
423             # --
424             if self.module == "kernel":
425                 newlines.append("""
426                 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindPLATFORM.cmake)
427                 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindPYTHON.cmake)
428                 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindOMNIORB.cmake)
429                 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindPTHREADS.cmake)
430                 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindHDF5.cmake)
431                 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindBOOST.cmake)
432                 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindLIBXML2.cmake)
433                 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindSWIG.cmake)
434                 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindCPPUNIT.cmake)
435                 """)
436                 pass
437             else:
438                 newlines.append("""
439                 SET(KERNEL_ROOT_DIR $ENV{KERNEL_ROOT_DIR})
440                 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindPLATFORM.cmake)
441                 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindPYTHON.cmake)
442                 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindOMNIORB.cmake)
443                 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindPTHREADS.cmake)
444                 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindHDF5.cmake)
445                 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindBOOST.cmake)
446                 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindLIBXML2.cmake)
447                 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindSWIG.cmake)
448                 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindCPPUNIT.cmake)
449                 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindKERNEL.cmake)
450                 """)
451                 if self.module == "gui":
452                     newlines.append("""
453                     INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindCAS.cmake)
454                     INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindQT4.cmake)
455                     INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindOPENGL.cmake)
456                     INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindVTK.cmake)
457                     INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindQWT.cmake)
458                     INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindSIPPYQT.cmake)
459                     """)
460                 else:
461                     newlines.append("""
462                     SET(GUI_ROOT_DIR $ENV{GUI_ROOT_DIR})
463                     INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindCAS.cmake)
464                     INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindQT4.cmake)
465                     INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindOPENGL.cmake)
466                     INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindVTK.cmake)
467                     INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindQWT.cmake)
468                     INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindSIPPYQT.cmake)
469                     INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindGUI.cmake)
470                     """)
471                     if self.module == "med":
472                         newlines.append("""
473                         INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindMEDFILE.cmake)
474                         """)
475                         pass
476                     if self.module == "smesh":
477                         newlines.append("""
478                         SET(GEOM_ROOT_DIR $ENV{GEOM_ROOT_DIR})
479                         SET(MED_ROOT_DIR $ENV{MED_ROOT_DIR})
480                         INCLUDE(${GEOM_ROOT_DIR}/adm_local/cmake_files/FindGEOM.cmake)
481                         INCLUDE(${MED_ROOT_DIR}/adm_local/cmake_files/FindMEDFILE.cmake)
482                         INCLUDE(${MED_ROOT_DIR}/adm_local/cmake_files/FindMED.cmake)
483                         """)
484                         pass
485                     if self.module == "netgenplugin":
486                         newlines.append("""
487                         SET(GEOM_ROOT_DIR $ENV{GEOM_ROOT_DIR})
488                         SET(MED_ROOT_DIR $ENV{MED_ROOT_DIR})
489                         SET(SMESH_ROOT_DIR $ENV{SMESH_ROOT_DIR})
490                         INCLUDE(${GEOM_ROOT_DIR}/adm_local/cmake_files/FindGEOM.cmake)
491                         INCLUDE(${MED_ROOT_DIR}/adm_local/cmake_files/FindMED.cmake)
492                         INCLUDE(${SMESH_ROOT_DIR}/adm_local/cmake_files/FindSMESH.cmake)
493                         INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindNETGEN.cmake)
494                         """)
495                         pass
496                     if self.module == "blsurfplugin":
497                         newlines.append("""
498                         SET(GEOM_ROOT_DIR $ENV{GEOM_ROOT_DIR})
499                         SET(MED_ROOT_DIR $ENV{MED_ROOT_DIR})
500                         SET(SMESH_ROOT_DIR $ENV{SMESH_ROOT_DIR})
501                         INCLUDE(${GEOM_ROOT_DIR}/adm_local/cmake_files/FindGEOM.cmake)
502                         INCLUDE(${MED_ROOT_DIR}/adm_local/cmake_files/FindMED.cmake)
503                         INCLUDE(${SMESH_ROOT_DIR}/adm_local/cmake_files/FindSMESH.cmake)
504                         INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindBLSURF.cmake)
505                         """)
506                         pass
507                     if self.module == "visu":
508                         newlines.append("""
509                         SET(MED_ROOT_DIR $ENV{MED_ROOT_DIR})
510                         INCLUDE(${MED_ROOT_DIR}/adm_local/cmake_files/FindMED.cmake)
511                         """)
512                         pass
513                     pass
514                 pass
515             # --
516             if self.module == "kernel":
517                 newlines.append("""
518                 SET(WITH_LOCAL 1)
519                 SET(WITH_BATCH 1)
520                 set(VERSION 5.1.1)
521                 set(XVERSION 0x050101)
522                 """)
523             elif self.module == "gui":
524                 newlines.append("""
525                 SET(GUI_ENABLE_CORBA ${CORBA_GEN})
526                 SET(ENABLE_VTKVIEWER ON)
527                 SET(ENABLE_SALOMEOBJECT ON)
528                 SET(ENABLE_OCCVIEWER ON)
529                 SET(ENABLE_GLVIEWER ON)
530                 SET(ENABLE_PLOT2DVIEWER ON)
531                 SET(ENABLE_PYCONSOLE ON)
532                 SET(ENABLE_SUPERVGRAPHVIEWER ON)
533                 # SET(ENABLE_QXGRAPHVIEWER ON)
534                 """)
535                 pass
536             elif self.module == "geom":
537                 newlines.append("""
538                 SET(GEOM_ENABLE_GUI ON)
539                 """)
540                 pass
541             elif self.module == "medfile":
542                 newlines.append("""
543                 SET(MED_NUM_MAJEUR 2)
544                 SET(MED_NUM_MINEUR 3)
545                 SET(MED_NUM_RELEASE 5)
546                 SET(LONG_OR_INT int)
547                 IF(NOT WINDOWS)
548                 SET(FLIBS -lgfortranbegin -lgfortran)
549                 ENDIF(NOT WINDOWS)
550                 """)
551                 pass
552             elif self.module == "med":
553                 newlines.append("""
554                 SET(MED_ENABLE_KERNEL ON)
555                 SET(MED_ENABLE_GUI ON)
556                 """)
557                 pass
558             elif self.module == "smesh":
559                 newlines.append("""
560                 SET(SMESH_ENABLE_GUI ON)
561                 """)
562                 pass
563             elif self.module == "netgenplugin":
564                 newlines.append("""
565                 SET(NETGENPLUGIN_ENABLE_GUI ON)
566                 """)
567                 pass
568             elif self.module == "blsurfplugin":
569                 newlines.append("""
570                 SET(BLSURFPLUGIN_ENABLE_GUI ON)
571                 """)
572                 pass
573             # --
574             pass
575         # --
576         newlines.append("""
577         SET(VERSION_INFO 0.0.0)
578         SET(SOVERSION_INFO 0)
579         SET(SUBDIRS)
580         SET(AM_CPPFLAGS)
581         SET(AM_CXXFLAGS)
582         SET(LDADD)
583         """)
584         # --
585         return
586     
587     def treatLine(self, line, newlines, opened_ifs):
588         
589         # --
590         # Print the comment above the line itself
591         # --
592         if line.find('#') >= 0:
593             fields = line.split('#')
594             line = fields[0]
595             comment = '#'.join([''] + fields[1:])
596             newlines.append(comment)
597             if len(line) == 0:
598                 return
599             pass
600         
601         # --
602         # If the line begins with 'include ', just comment it
603         # --
604         if line.find("include ") == 0:
605             newlines.append("# " + line)
606             return
607         
608         # --
609         # If the line begins with '-include', just comment it
610         # --
611         if line.find("-include") == 0:
612             newlines.append("# " + line)
613             return
614         
615         # --
616         # If the line is a definition of a make rule, just comment it
617         # --
618         if line.count(':') == 1:
619             newlines.append("# " + line)
620             return
621         
622         # --
623         # A particuliar case where there are two ":" on the same line
624         # --
625         if line.find('install-exec-local:') == 0:
626             newlines.append("# " + line)
627             return
628         
629         # --
630         # If the line begin by a tabulation, consider it's a makefile command and comment it
631         # --
632         if line.find("\t") == 0:
633             newlines.append("# " + line)
634             return
635         
636         # --
637         # --
638         key = "-version-info"
639         if line.find(key) >= 0:
640             # --
641             before = line.split(key)[0]
642             after = line[len(before)+len(key):]
643             sep = after[0]
644             after = after[1:]
645             version_info = after.split()[0]
646             line = line.replace(key+sep+version_info, "")
647             # --
648             version_info = version_info.replace(':', '.')
649             soversion_info = version_info.split('.')[0]
650             newlines.append("SET(VERSION_INFO " + version_info + ")")
651             newlines.append("SET(SOVERSION_INFO " + soversion_info + ")")
652             # --
653             pass
654         
655         # --
656         # Replace the $(TOTO) by ${TOTO}
657         # Replace the @TOTO@  by ${TOTO}
658         # --
659         line = p_dollar.sub(r"${\1}", line)
660         line = p_arobas.sub(r"${\1}", line)
661         
662         # --
663         line = line.replace(r"${top_builddir}", r"${CMAKE_BINARY_DIR}")
664         line = line.replace(r"${top_srcdir}", r"${CMAKE_SOURCE_DIR}")
665         line = line.replace(r"${srcdir}", r"${CMAKE_CURRENT_SOURCE_DIR}")
666         line = line.replace(r"${builddir}", r"${CMAKE_CURRENT_BINARY_DIR}")
667         line = line.replace(r"${datadir}", r"${CMAKE_INSTALL_PREFIX}/share")
668         
669         # --
670         # Check if the line is a 'if' condition
671         # If yes, replace it by a cmake grammar
672         # --
673         match = p_if.match(line)
674         if match:
675             theif = match.group("val")
676             if theif[0] == "!":
677                 theif = "NOT " + theif[1:]
678                 pass
679             line = p_if.sub(r"IF(%s)"%(theif), line)
680             opened_ifs.append(theif)
681             newlines.append(line)
682             return
683         
684         # --
685         # Check if the line is a 'else' condition
686         # If yes, replace it by a cmake grammar
687         # --
688         match = p_else.match(line)
689         if match:
690             line = "ELSE(%s)"%(opened_ifs[-1])
691             newlines.append(line)
692             return
693         
694         # --
695         # Check if the line is a 'endif' condition
696         # If yes, replace it by a cmake grammar
697         # --
698         match = p_endif.match(line)
699         if match:
700             line = "ENDIF(%s)"%(opened_ifs[-1])
701             opened_ifs[-1:] = []
702             newlines.append(line)
703             return
704         
705         # --
706         # Check if the line is an attribution '=' or '+='
707         # --
708         match = p_attribution.match(line)
709         if match:
710             self.treatAttribution(match, newlines)
711             return
712         
713         # --
714         newlines.append(line)
715         
716         # --
717         return
718     
719     def treatAttribution(self, match, newlines):
720         
721         spaces = match.group("spaces")
722         key = match.group("key")
723         method = match.group("method")
724         value = match.group("value")
725         # print [spaces, key, method, value]
726         
727         # --
728         # Open cmake SET command
729         # --
730         newlines.append(spaces + "SET(" + key)
731         
732         # --
733         # If method is '+=', put the previous definition as first value
734         # --
735         if method == "+=":
736             newlines.append("%s    ${%s}"%(spaces, key))
737             pass
738         
739         # --
740         fields = value.split()
741         for i in range(len(fields)):
742             newlines.append("%s    %s"%(spaces, fields[i]))
743             pass
744         
745         # --
746         if method == "+=":
747             # --
748             # The try: except KeyError is here if the +=
749             # is an error which occurs in salome ...
750             # --
751             try:
752                 self.__thedict__[key] += fields[:]
753             except KeyError:
754                 self.__thedict__[key] = fields[:]
755                 pass
756             pass
757         else:
758             self.__thedict__[key]  = fields[:]
759             pass
760         
761         # --
762         # Close cmake SET command
763         # --
764         
765         newlines.append("%s)"%(spaces))
766         
767         return
768     
769     def finalize(self, newlines):
770         
771         # --
772         # Convert the .in files in build dir
773         # --
774         for f in self.files:
775             if f[-3:] == ".in":
776                 if f == "sstream.in":
777                     continue
778                 if f in ["runContainer.in", "stopContainer.in"]:
779                     if self.module == "med":
780                         if self.root[-3:] == "csh":
781                             continue
782                         pass
783                     pass
784                 if f == "SALOMEconfig.ref.in":
785                     out = "SALOMEconfig.h"
786                 else:
787                     out = f[:-3]
788                     pass
789                 newlines.append(r'''
790                 SET(input ${CMAKE_CURRENT_SOURCE_DIR}/%s)
791                 '''%(f))
792                 newlines.append(r'''
793                 SET(output ${CMAKE_CURRENT_BINARY_DIR}/%s)
794                 '''%(out))
795                 newlines.append(r'''
796                 MESSAGE(STATUS "Creation of ${output}")
797                 CONFIGURE_FILE(${input} ${output})
798                 ''')
799                 pass
800             pass
801         
802         # --
803         # convert the SUBDIRS in cmake grammar
804         # --
805         if 1: # self.__thedict__.has_key("SUBDIRS"):
806             newlines.append(r'''
807             FOREACH(dir ${SUBDIRS})
808             IF(NOT dir STREQUAL .)
809             ADD_SUBDIRECTORY(${dir})
810             ENDIF(NOT dir STREQUAL .)
811             ENDFOREACH(dir ${SUBDIRS})
812             ''')
813             pass
814         
815         # --
816         # --
817         for key in ["lib_LTLIBRARIES", "noinst_LTLIBRARIES", "salomepyexec_LTLIBRARIES"]:
818             if self.__thedict__.has_key(key):
819                 self.addLibTarget(key, newlines)
820                 pass
821             pass
822         
823         # --
824         # --
825         for key in ["bin_PROGRAMS"]:
826             if self.__thedict__.has_key(key):
827                 self.addBinTarget(key, newlines)
828                 pass
829             pass
830         
831         # --
832         # --
833         if self.__thedict__.has_key("BASEIDL_FILES"):
834             if not self.__thedict__.has_key("IDL_FILES"):
835                 self.__thedict__["IDL_FILES"] = self.__thedict__["BASEIDL_FILES"]
836                 newlines.append('''
837                 SET(IDL_FILES ${BASEIDL_FILES})
838                 ''')
839                 pass
840             pass
841         
842         # --
843         # --
844         
845         key = "IDL_FILES"
846         if self.__thedict__.has_key(key):
847             newlines.append('''
848             FOREACH(input ${IDL_FILES})
849             STRING(REGEX REPLACE ".idl" "" base ${input})
850             SET(src ${CMAKE_CURRENT_BINARY_DIR}/${base}SK.cc)
851             SET(outputs ${src})
852             SET(dynsrc ${CMAKE_CURRENT_BINARY_DIR}/${base}DynSK.cc)
853             SET(outputs ${outputs} ${dynsrc})
854             ADD_CUSTOM_COMMAND(
855             OUTPUT ${outputs}
856             COMMAND ${OMNIORB_IDL} ${IDLCXXFLAGS} ${OMNIORB_IDLCXXFLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/${input}
857             MAIN_DEPENDENCY ${input}
858             )
859             install(FILES ${input} DESTINATION idl/salome)
860             SET(IDL_HEADER ${CMAKE_CURRENT_BINARY_DIR}/${base}.hh)
861             install(FILES ${IDL_HEADER} DESTINATION include/salome)
862             INSTALL(CODE "SET(IDL_FILE ${input})")
863             INSTALL(CODE "SET(DIR lib/python${PYTHON_VERSION}/site-packages/salome)")
864             INSTALL(CODE "SET(CMAKE_CURRENT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})")
865             INSTALL(CODE "SET(OMNIORB_IDL_PYTHON ${OMNIORB_IDL_PYTHON})")
866             # --
867             SET(flags)
868             FOREACH(f ${IDLPYFLAGS})
869             SET(flags "${flags} ${f}")
870             ENDFOREACH(f ${IDLPYFLAGS})
871             SET(IDLPYFLAGS ${flags})
872             STRING(REPLACE "\\\\" "/" IDLPYFLAGS ${IDLPYFLAGS})
873             INSTALL(CODE "SET(IDLPYFLAGS ${IDLPYFLAGS})")
874             # --
875             ''')
876             if self.module == "kernel":
877                 newlines.append('''
878                 INSTALL(SCRIPT ${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/install_python_from_idl.cmake)
879                 ''')
880             else:
881                 newlines.append('''
882                 STRING(REPLACE "\\\\" "/" KERNEL_ROOT_DIR ${KERNEL_ROOT_DIR})
883                 INSTALL(SCRIPT ${KERNEL_ROOT_DIR}/salome_adm/cmake_files/install_python_from_idl.cmake)
884                 ''')
885                 pass
886             newlines.append('''
887             ENDFOREACH(input ${IDL_FILES})
888             ''')
889             pass
890         
891         # --
892         # --
893         for key in ["SWIG_SRC", "SWIGSOURCES", "SWIG_DEF"]:
894             if self.__thedict__.has_key(key):
895                 newlines.append('''
896                 SET(SWIG_SOURCES ${%s})
897                 '''%(key))
898                 self.__thedict__["SWIG_SOURCES"] = self.__thedict__[key]
899                 pass
900             pass
901         
902         # --
903         # --
904         if self.__thedict__.has_key("SWIG_SOURCES"):
905             newlines.append('''
906             IF(SWIG_SOURCES MATCHES ";")
907             STRING(REGEX REPLACE ";.*" "" SWIG_SOURCES_FIRST "${SWIG_SOURCES}")
908             ELSE(SWIG_SOURCES MATCHES ";")
909             SET(SWIG_SOURCES_FIRST "${SWIG_SOURCES}")
910             ENDIF(SWIG_SOURCES MATCHES ";")
911             ADD_CUSTOM_COMMAND(
912             OUTPUT ${build_srcs}
913             COMMAND ${SWIG_EXECUTABLE} ${SWIG_FLAGS} ${MY_SWIG_FLAGS} -o ${build_srcs} ${CMAKE_CURRENT_SOURCE_DIR}/${SWIG_SOURCES_FIRST}
914             MAIN_DEPENDENCY ${SWIG_SOURCES}
915             )
916             ''')
917             pass
918         
919         # --
920         # --
921         key = "MOC_FILES"
922         if self.__thedict__.has_key(key):
923             newlines.append('''
924             FOREACH(output ${MOC_FILES})
925             STRING(REGEX REPLACE _moc.cxx .h input ${output})
926             SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${input})
927             SET(output ${CMAKE_CURRENT_BINARY_DIR}/${output})
928             ADD_CUSTOM_COMMAND(
929             OUTPUT ${output}
930             COMMAND ${QT_MOC_EXECUTABLE} ${MOC_FLAGS} ${input} -o ${output}
931             MAIN_DEPENDENCY ${input}
932             )
933             ENDFOREACH(output ${MOC_FILES})
934             ''')
935             pass
936         
937         # --
938         # --
939         key = "UIC_FILES"
940         if self.__thedict__.has_key(key):
941             newlines.append('''
942             FOREACH(output ${UIC_FILES})
943             STRING(REPLACE "ui_" "" input ${output})
944             STRING(REPLACE ".h" ".ui" input ${input})
945             SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${input})
946             SET(output ${CMAKE_CURRENT_BINARY_DIR}/${output})
947             ADD_CUSTOM_COMMAND(
948             OUTPUT ${output}
949             COMMAND ${QT_UIC_EXECUTABLE} -o ${output} ${input}
950             MAIN_DEPENDENCY ${input}
951             )
952             ENDFOREACH(output ${UIC_FILES})
953             ''')
954             pass
955         
956         # --
957         # --
958         key = "QRC_FILES"
959         if self.__thedict__.has_key(key):
960             newlines.append('''
961             FOREACH(output ${QRC_FILES})
962             STRING(REGEX REPLACE "qrc_" "" input ${output})
963             STRING(REGEX REPLACE ".cxx" ".qrc" input ${input})
964             STRING(REGEX REPLACE ".qrc" "" name ${input})
965             SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${input})
966             SET(output ${CMAKE_CURRENT_BINARY_DIR}/${output})
967             ADD_CUSTOM_COMMAND(
968             OUTPUT ${output}
969             COMMAND ${QT_RCC_EXECUTABLE} ${input} -o ${output} -name ${name}
970             MAIN_DEPENDENCY ${input}
971             )
972             ENDFOREACH(output ${QRC_FILES})
973             ''')
974             pass
975         
976         # --
977         # --
978         key = "SIP_FILES"
979         if self.__thedict__.has_key(key):
980             newlines.append('''
981             FOREACH(input ${SIP_FILES})
982             SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${input})
983             SET(output)
984             FOREACH(out ${SIP_SRC})
985             SET(output ${output} ${CMAKE_CURRENT_BINARY_DIR}/${out})
986             ENDFOREACH(out ${SIP_SRC})
987             ADD_CUSTOM_COMMAND(
988             OUTPUT ${output}
989             COMMAND ${SIP_EXECUTABLE} ${PYQT_SIPFLAGS} ${input}
990             MAIN_DEPENDENCY ${input}
991             )
992             ENDFOREACH(input ${SIP_FILES})
993             ''')
994             pass
995         
996         # --
997         # Treat the install targets
998         # --
999         d = {
1000             "salomeadmux_DATA"            :  "salome_adm/unix",
1001             "dist_salomeadmux_DATA"       :  "salome_adm/unix",
1002             "dist_salome_cmake_DATA"      :  "salome_adm/cmake_files",
1003             "dist_salomem4_DATA"          :  "salome_adm/unix/config_files",
1004             "dist_salome4depr_DATA"       :  "salome_adm/unix/config_files/DEPRECATED",
1005             "dist_admlocalm4_DATA"        :  "adm_local/unix/config_files",
1006             "dist_admlocal_cmake_DATA"    :  "adm_local/cmake_files",
1007             "salomeinclude_DATA"          :  "include/salome",
1008             "salomeinclude_HEADERS"       :  "include/salome",
1009             "dist_salomeres_DATA"         :  "share/salome/resources/%s"%(self.module),
1010             "nodist_salomeres_DATA"       :  "share/salome/resources/%s"%(self.module),
1011             "nodist_salomeres_SCRIPTS"    :  "share/salome/resources/%s"%(self.module),
1012             "dist_salomescript_SCRIPTS"   :  "bin/salome",
1013             "dist_salomescript_DATA"      :  "bin/salome",
1014             "dist_salomescript_PYTHON"    :  "bin/salome",
1015             "nodist_salomescript_DATA"    :  "bin/salome",
1016             "salomepython_PYTHON"         :  "lib/python${PYTHON_VERSION}/site-packages/salome",
1017             "nodist_salomepython_PYTHON"  :  "lib/python${PYTHON_VERSION}/site-packages/salome",
1018             "sharedpkgpython_PYTHON"      :  "lib/python${PYTHON_VERSION}/site-packages/salome/shared_modules",
1019             }
1020         if self.module == "medfile":
1021             d = {
1022                 "include_HEADERS"        :  "include",
1023                 "nodist_include_HEADERS" :  "include",
1024                 "bin_SCRIPTS"            :  "bin",
1025                 "doc_DATA"               :  "${docdir}",
1026                 }
1027             pass
1028         for key, value in d.items():
1029             if self.__thedict__.has_key(key):
1030                 self.addInstallTarget(key, value, newlines)
1031                 pass
1032             pass
1033         
1034         # --
1035         return
1036     
1037     def setLibAdd(self, key, newlines):
1038         # --
1039         newlines.append(r'''
1040         SET(libadd)
1041         ''')
1042         # --
1043         newlines.append(r'''
1044         IF(WINDOWS)
1045         SET(targets)
1046         SET(targets ${targets} MEFISTO2D)
1047         FOREACH(target ${targets})
1048         IF(name STREQUAL ${target})
1049         SET(dir $ENV{F2CHOME})
1050         STRING(REPLACE "\\\\" "/" dir ${dir})
1051         SET(libadd ${libadd} ${dir}/LIBF77.lib)
1052         SET(libadd ${libadd} ${dir}/LIBI77.lib)
1053         ENDIF(name STREQUAL ${target})
1054         ENDFOREACH(target ${targets})
1055         ENDIF(WINDOWS)
1056         ''')
1057         # --
1058         newlines.append(r'''
1059         SET(libs ${PLATFORM_LIBADD} ${PLATFORM_LDFLAGS} ${${amname}_LIBADD} ${${amname}_LDADD} ${${amname}_LDFLAGS})
1060         ''')
1061         if key == "bin_PROGRAMS":
1062             newlines.append(r'''
1063             SET(libs ${libs} ${LDADD})
1064             ''')
1065             pass
1066         # --
1067         newlines.append(r'''
1068         FOREACH(lib ${libs})
1069         GET_FILENAME_COMPONENT(ext ${lib} EXT)
1070         IF(ext STREQUAL .la)
1071         GET_FILENAME_COMPONENT(lib ${lib} NAME_WE)
1072         STRING(REPLACE "lib" "" lib ${lib})
1073         ENDIF(ext STREQUAL .la)
1074         SET(vars)
1075         SET(vars ${vars} -no-undefined)
1076         SET(vars ${vars} -lboost_thread)
1077         IF(WINDOWS)
1078         SET(vars ${vars} -module)
1079         SET(vars ${vars} -Wl,-E)
1080         SET(vars ${vars} -Xlinker)
1081         SET(vars ${vars} -export-dynamic)
1082         SET(vars ${vars} -lm)
1083         ENDIF(WINDOWS)
1084         FOREACH(v ${vars})
1085         IF(lib STREQUAL v)
1086         SET(lib)
1087         ENDIF(lib STREQUAL v)
1088         ENDFOREACH(v ${vars})
1089         SET(libadd ${libadd} ${lib})
1090         ENDFOREACH(lib ${libs})
1091         IF(name STREQUAL SALOMEBasics)
1092         TARGET_LINK_LIBRARIES(${name} ${PTHREAD_LIBS} ${libadd})
1093         ELSE(name STREQUAL SALOMEBasics)
1094         TARGET_LINK_LIBRARIES(${name} ${libadd})
1095         ENDIF(name STREQUAL SALOMEBasics)
1096         ''')
1097         # --
1098         return
1099     
1100     def setCompilationFlags(self, key, newlines):
1101         newlines.append(r'''
1102         SET(var)
1103         IF(WINDOWS)
1104         SET(targets)
1105         SET(targets ${targets} SalomeIDLKernel)
1106         SET(targets ${targets} SalomeDS)
1107         SET(targets ${targets} SALOMEDSTest)
1108         SET(targets ${targets} SALOMEDS_Client_exe)
1109         SET(targets ${targets} SalomeIDLGEOM)
1110         SET(targets ${targets} GEOMEngine)
1111         SET(targets ${targets} MEDEngine)
1112         SET(targets ${targets} SMESHEngine)
1113         SET(targets ${targets} SMESH)
1114         FOREACH(target ${targets})
1115         IF(name STREQUAL ${target})
1116         SET(var ${var} -DNOGDI)
1117         ENDIF(name STREQUAL ${target})
1118         ENDFOREACH(target ${targets})
1119         ENDIF(WINDOWS)
1120         ''')
1121         # --
1122         newlines.append(r'''
1123         IF(WINDOWS)
1124         SET(targets)
1125         SET(targets ${targets} MEFISTO2D)
1126         FOREACH(target ${targets})
1127         IF(name STREQUAL ${target})
1128         SET(dir $ENV{F2CHOME})
1129         STRING(REPLACE "\\\\" "/" dir ${dir})
1130         SET(var ${var} -I${dir})
1131         ENDIF(name STREQUAL ${target})
1132         ENDFOREACH(target ${targets})
1133         ENDIF(WINDOWS)
1134         ''')
1135         # --
1136         if self.module in ["geom", "med"]:
1137             newlines.append(r'''
1138             SET(var ${var} -I${CMAKE_CURRENT_SOURCE_DIR})
1139             SET(var ${var} -I${CMAKE_CURRENT_BINARY_DIR})
1140             ''')
1141             pass
1142         if key == "bin_PROGRAMS":
1143             newlines.append(r'''
1144             SET(var ${var} ${AM_CPPFLAGS})
1145             SET(var ${var} ${AM_CXXFLAGS})
1146             ''')
1147             pass
1148         newlines.append(r'''
1149         SET(var ${var} ${PLATFORM_CPPFLAGS})
1150         SET(var ${var} ${PTHREAD_CFLAGS})
1151         SET(var ${var} ${${amname}_CPPFLAGS})
1152         SET(var ${var} ${${amname}_CXXFLAGS})
1153         SET(var ${var} ${${amname}_CFLAGS})
1154         SET(vars)
1155         IF(WINDOWS)
1156         SET(vars ${vars} -include SALOMEconfig.h)
1157         ENDIF(WINDOWS)
1158         SET(flags)
1159         FOREACH(f ${var})
1160         FOREACH(v ${vars})
1161         IF(f STREQUAL v)
1162         SET(f)
1163         ENDIF(f STREQUAL v)
1164         ENDFOREACH(v ${vars})
1165         SET(flags "${flags} ${f}")
1166         ENDFOREACH(f ${var})
1167         SET_TARGET_PROPERTIES(${name} PROPERTIES COMPILE_FLAGS "${flags}")
1168         ''')
1169         return
1170     
1171     def addLibTarget(self, key, newlines):
1172         newlines.append(r'''
1173         FOREACH(amname ${%s})
1174         '''%(key))
1175         # --
1176         # Replace .la by _la ...
1177         # --
1178         newlines.append(r'''
1179         STRING(REPLACE .la _la amname ${amname})
1180         ''')
1181         # --
1182         # Remove the _la for the cmake name
1183         # --
1184         newlines.append(r'''
1185         STRING(LENGTH ${amname} len)
1186         MATH(EXPR newlen "${len}-3")
1187         STRING(SUBSTRING ${amname} 0 ${newlen} name)
1188         ''')
1189         # --
1190         # Does the target begins with lib ??
1191         # If yes, remove lib at beginning for cmake name
1192         # --
1193         newlines.append(r'''
1194         STRING(REGEX MATCH "^lib" BEGIN_WITH_lib ${name})
1195         IF(BEGIN_WITH_lib)
1196         STRING(LENGTH ${name} len)
1197         MATH(EXPR newlen "${len}-3")
1198         STRING(SUBSTRING ${name} 3 ${newlen} name)
1199         ENDIF(BEGIN_WITH_lib)
1200         ''')
1201         # --
1202         # Does the target is an idl library
1203         # --
1204         newlines.append(r'''
1205         STRING(REGEX MATCH "IDL" ISIDL ${name})
1206         ''')
1207         # --
1208         # Set the type of the library
1209         # --
1210         newlines.append(r'''
1211         IF(ISIDL)
1212         IF(WINDOWS)
1213         SET(type STATIC)
1214         ELSE(WINDOWS)
1215         SET(type SHARED)
1216         ENDIF(WINDOWS)
1217         ELSE(ISIDL)
1218         SET(type SHARED)
1219         ENDIF(ISIDL)
1220         ''')
1221         # --
1222         # Set sources for the library
1223         # --
1224         newlines.append(r'''
1225         SET(srcs)
1226         FOREACH(src ${${amname}_SOURCES} ${dist_${amname}_SOURCES})
1227         GET_FILENAME_COMPONENT(ext ${src} EXT)
1228         IF(ext STREQUAL .f)
1229         IF(src STREQUAL trte.f)
1230         SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${src})
1231         STRING(REPLACE ".f" ".c" src ${src})
1232         SET(src ${CMAKE_CURRENT_BINARY_DIR}/${src})
1233         SET(output ${src})
1234         ADD_CUSTOM_COMMAND(
1235         OUTPUT ${output}
1236         COMMAND f2c ${input}
1237         MAIN_DEPENDENCY ${input}
1238         )
1239         ELSE(src STREQUAL trte.f)
1240         SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${src})
1241         STRING(REPLACE ".f" ".o" src ${src})
1242         SET(src ${CMAKE_CURRENT_BINARY_DIR}/${src})
1243         SET(output ${src})
1244         IF(WINDOWS)
1245         SET(F77 g77)
1246         ELSE(WINDOWS)
1247         SET(F77 gfortran)
1248         ENDIF(WINDOWS)
1249         ADD_CUSTOM_COMMAND(
1250         OUTPUT ${output}
1251         COMMAND ${F77} -c -o ${output} ${input}
1252         MAIN_DEPENDENCY ${input}
1253         )
1254         ENDIF(src STREQUAL trte.f)
1255         ENDIF(ext STREQUAL .f)
1256         SET(srcs ${srcs} ${src})
1257         ENDFOREACH(src ${${amname}_SOURCES} ${dist_${amname}_SOURCES})
1258         SET(build_srcs)
1259         FOREACH(f ${nodist_${amname}_SOURCES} ${BUILT_SOURCES})
1260         GET_FILENAME_COMPONENT(ext ${f} EXT)
1261         IF(ext STREQUAL .py)
1262         ELSE(ext STREQUAL .py)
1263         SET(build_srcs ${build_srcs} ${CMAKE_CURRENT_BINARY_DIR}/${f})
1264         ENDIF(ext STREQUAL .py)
1265         ENDFOREACH(f ${nodist_${amname}_SOURCES})
1266         SET(srcs ${build_srcs} ${srcs})
1267         ''')
1268         # --
1269         # Add the library to cmake
1270         # --
1271         newlines.append(r'''
1272         ADD_LIBRARY(${name} ${type} ${srcs})
1273         ''')
1274         # --
1275         # The compilation flags
1276         # --
1277         self.setCompilationFlags(key, newlines)
1278         # --
1279         newlines.append(r'''
1280         SET_TARGET_PROPERTIES(${name} PROPERTIES VERSION ${VERSION_INFO} SOVERSION ${SOVERSION_INFO})
1281         ''')
1282         # --
1283         self.setLibAdd(key, newlines)
1284         # --
1285         if 1: # key != "noinst_LTLIBRARIES":
1286             if self.module == "medfile":
1287                 newlines.append(r'''
1288                 SET(DEST lib)
1289                 ''')
1290             else:
1291                 newlines.append(r'''
1292                 SET(DEST lib/salome)
1293                 ''')
1294                 pass
1295             newlines.append(r'''
1296             IF(BEGIN_WITH_lib)
1297             INSTALL(TARGETS ${name} DESTINATION ${DEST})
1298             ''')
1299             if self.module == "geom":
1300                 newlines.append(r'''
1301                 IF(WINDOWS)
1302                 STRING(REGEX MATCH "Export" ISExport ${name})
1303                 IF(ISExport)
1304                 INSTALL(FILES ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.dll DESTINATION ${DEST} RENAME lib${name}.dll)
1305                 ENDIF(ISExport)
1306                 STRING(REGEX MATCH "Import" ISImport ${name})
1307                 IF(ISImport)
1308                 INSTALL(FILES ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.dll DESTINATION ${DEST} RENAME lib${name}.dll)
1309                 ENDIF(ISImport)
1310                 ENDIF(WINDOWS)
1311                 ''')
1312                 pass
1313             newlines.append(r'''
1314             # IF(name STREQUAL SalomePyQt)
1315             # INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so DESTINATION ${DEST} RENAME ${name}.so)
1316             # ENDIF(name STREQUAL SalomePyQt)
1317             ''')
1318             newlines.append(r'''
1319             ELSE(BEGIN_WITH_lib)
1320             ''')
1321             newlines.append(r'''
1322             IF(WINDOWS)
1323             INSTALL(TARGETS ${name} DESTINATION lib/python${PYTHON_VERSION}/site-packages/salome)
1324             IF(CMAKE_BUILD_TYPE STREQUAL Release)
1325             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)
1326             ELSE(CMAKE_BUILD_TYPE STREQUAL Release)
1327             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)
1328             ENDIF(CMAKE_BUILD_TYPE STREQUAL Release)
1329             ELSE(WINDOWS)
1330             GET_TARGET_PROPERTY(version ${name} VERSION)
1331             GET_TARGET_PROPERTY(soversion ${name} SOVERSION)
1332             INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so.${version} DESTINATION lib/python${PYTHON_VERSION}/site-packages/salome RENAME ${name}.so.${version})
1333             INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so.${version} DESTINATION lib/python${PYTHON_VERSION}/site-packages/salome RENAME ${name}.so.${soversion})
1334             INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so.${version} DESTINATION lib/python${PYTHON_VERSION}/site-packages/salome RENAME ${name}.so)
1335             ENDIF(WINDOWS)
1336             ''')
1337             newlines.append(r'''
1338             ENDIF(BEGIN_WITH_lib)
1339             ''')
1340             pass
1341         # --
1342         newlines.append(r'''
1343         ENDFOREACH(amname ${%s})
1344         '''%(key))
1345         # --
1346         return
1347     
1348     def addBinTarget(self, key, newlines):
1349         # --
1350         newlines.append(r'''
1351         FOREACH(amname ${bin_PROGRAMS})
1352         ''')
1353         # --
1354         newlines.append(r'''
1355         SET(name "${amname}_exe")
1356         SET(srcs ${${amname}_SOURCES} ${dist_${amname}_SOURCES})
1357         LIST(LENGTH srcs nb)
1358         IF(nb)
1359         ADD_EXECUTABLE(${name} ${srcs})
1360         ''')
1361         # --
1362         self.setCompilationFlags(key, newlines)
1363         # --
1364         self.setLibAdd(key, newlines)
1365         # --
1366         if self.module == "medfile":
1367             newlines.append(r'''
1368             SET(DEST bin)
1369             ''')
1370         else:
1371             newlines.append(r'''
1372             SET(DEST bin/salome)
1373             ''')
1374             pass
1375         # --
1376         newlines.append(r'''
1377         IF(WINDOWS)
1378         INSTALL(TARGETS ${name} DESTINATION ${DEST})
1379         INSTALL(FILES ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.exe DESTINATION ${DEST} RENAME ${amname}.exe)
1380         INSTALL(CODE "FILE(REMOVE ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.exe)")
1381         ELSE(WINDOWS)
1382         SET(PERMS)
1383         SET(PERMS ${PERMS} OWNER_READ OWNER_WRITE OWNER_EXECUTE)
1384         SET(PERMS ${PERMS} GROUP_READ GROUP_EXECUTE)
1385         SET(PERMS ${PERMS} WORLD_READ WORLD_EXECUTE)
1386         INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${name} DESTINATION ${DEST} PERMISSIONS ${PERMS} RENAME ${amname})
1387         ENDIF(WINDOWS)
1388         ''')
1389         # --
1390         newlines.append(r'''
1391         ENDIF(nb)
1392         ''')
1393         # --
1394         newlines.append(r'''
1395         ENDFOREACH(amname ${bin_PROGRAMS})
1396         ''')
1397         # --
1398         return
1399     
1400     def addInstallTarget(self, key, destination, newlines):
1401         newlines.append(r"FOREACH(f ${%s})"%(key))
1402         newlines.append(r'''
1403         SET(DEST %s)
1404         '''%(destination))
1405         newlines.append(r'''
1406         STRING(COMPARE EQUAL ${f} SALOMEconfig.h.in test_SALOMEconfig.h.in)
1407         IF(test_SALOMEconfig.h.in)
1408         INSTALL(FILES SALOMEconfig.ref.in DESTINATION ${DEST} RENAME SALOMEconfig.h.in)
1409         ELSE(test_SALOMEconfig.h.in)
1410         SET(dummy dummy-NOTFOUND)
1411         MARK_AS_ADVANCED(dummy)
1412         # FILE(REMOVE ${CMAKE_INSTALL_PREFIX}/${DEST}/${f})
1413         FIND_FILE(dummy ${f} PATHS ${CMAKE_CURRENT_SOURCE_DIR} NO_DEFAULT_PATH)
1414         IF(dummy)
1415         ''')
1416         if key in ['dist_salomescript_SCRIPTS']:
1417             newlines.append(r'''
1418             SET(PERMS)
1419             SET(PERMS ${PERMS} OWNER_READ OWNER_WRITE OWNER_EXECUTE)
1420             SET(PERMS ${PERMS} GROUP_READ GROUP_EXECUTE)
1421             SET(PERMS ${PERMS} WORLD_READ WORLD_EXECUTE)
1422             INSTALL(FILES ${f} DESTINATION ${DEST} PERMISSIONS ${PERMS})
1423             ''')
1424         else:
1425             newlines.append(r'''
1426             INSTALL(FILES ${f} DESTINATION ${DEST})
1427             ''')
1428             pass
1429         newlines.append(r'''
1430         ELSE(dummy)
1431         GET_FILENAME_COMPONENT(ext ${f} EXT)
1432         IF(ext STREQUAL .qm)
1433         STRING(REGEX REPLACE .qm .ts input ${f})
1434         ''')
1435         if self.module in ["kernel", "gui"]:
1436             newlines.append(r'''
1437             SET(input ${CMAKE_CURRENT_SOURCE_DIR}/resources/${input})
1438             ''')
1439         else:
1440             newlines.append(r'''
1441             SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${input})
1442             ''')
1443             pass
1444         newlines.append(r'''
1445         SET(output ${CMAKE_CURRENT_BINARY_DIR}/${f})
1446         # ADD_CUSTOM_COMMAND(
1447         # OUTPUT ${output}
1448         # COMMAND ${QT_LRELEASE_EXECUTABLE} ${input} -qm ${output}
1449         # MAIN_DEPENDENCY ${input}
1450         # )
1451         EXECUTE_PROCESS(COMMAND ${QT_LRELEASE_EXECUTABLE} ${input} -qm ${output})
1452         ENDIF(ext STREQUAL .qm)
1453         INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${f} DESTINATION ${DEST})
1454         ENDIF(dummy)
1455         ENDIF(test_SALOMEconfig.h.in)
1456         ''')
1457         newlines.append(r'''
1458         GET_FILENAME_COMPONENT(ext ${f} EXT)
1459         IF(ext STREQUAL .py)
1460         INSTALL(CODE "SET(PYTHON_FILE ${f})")
1461         INSTALL(CODE "SET(CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})")
1462         INSTALL(CODE "SET(DEST ${DEST})")
1463         INSTALL(CODE "SET(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE})")
1464         ''')
1465         if self.module == "kernel":
1466             newlines.append('''
1467             IF(f STREQUAL SALOME_ContainerPy.py)
1468             ELSE(f STREQUAL SALOME_ContainerPy.py)
1469             IF(f STREQUAL am2cmake.py)
1470             ELSE(f STREQUAL am2cmake.py)
1471             INSTALL(SCRIPT ${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/install_and_compile_python_file.cmake)
1472             ENDIF(f STREQUAL am2cmake.py)
1473             ENDIF(f STREQUAL SALOME_ContainerPy.py)
1474             ''')
1475         else:
1476             newlines.append('''
1477             STRING(REPLACE "\\\\" "/" KERNEL_ROOT_DIR ${KERNEL_ROOT_DIR})
1478             INSTALL(SCRIPT ${KERNEL_ROOT_DIR}/salome_adm/cmake_files/install_and_compile_python_file.cmake)
1479             ''')
1480             pass
1481         newlines.append(r'''
1482         ENDIF(ext STREQUAL .py)
1483         ''') 
1484         newlines.append(r"ENDFOREACH(f ${%s})"%(key))
1485         return
1486     
1487     def writeListsFile(self):
1488         f = open(self.listsFile, "w")
1489         f.write(self.content)
1490         f.close()
1491         return
1492     
1493     pass
1494
1495 def convertAmFile(the_root, root, dirs, files, f, module):
1496     cmake = CMakeFile(the_root, root, dirs, files, f, module)
1497     cmake.writeListsFile()
1498     return
1499
1500 def usage(exit_status):
1501     from sys import exit
1502     from sys import argv
1503     print "Usage: %s --module"%(argv[0])
1504     exit(exit_status)
1505     return
1506
1507 if __name__ == "__main__":
1508     #
1509     from sys import argv
1510     if len(argv) != 2:
1511         usage(1)
1512         pass
1513     #
1514     module = argv[1]
1515     if module.find('--') != 0:
1516         usage(1)
1517         pass
1518     module = module[2:]
1519     if len(module) == 0:
1520         usage(1)
1521         pass
1522     #
1523     from os import getcwd
1524     the_root = getcwd()
1525     #
1526     from os import walk
1527     for root, dirs, files in walk(the_root):
1528         # --
1529         # E.A. : Remove 'CVS' in dirs
1530         # E.A. : It allows to not recurse in CVS dirs
1531         # E.A. : See os module python documentation
1532         # --
1533         try:
1534             dirs.remove('CVS')
1535         except ValueError:
1536             pass
1537         # --
1538         for f in files:
1539             if f == "Makefile.am":
1540                 convertAmFile(the_root, root, dirs, files, f, module)
1541                 pass
1542             pass
1543         pass
1544     #
1545     pass