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