Salome HOME
Compatibility release compilation on windows
[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         IF(CMAKE_BUILD_TYPE STREQUAL Release)
1094         SET_TARGET_PROPERTIES(${name} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:LIBCMT")
1095         ELSE(CMAKE_BUILD_TYPE STREQUAL Release)
1096         SET_TARGET_PROPERTIES(${name} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:LIBCMTD")
1097         ENDIF(CMAKE_BUILD_TYPE STREQUAL Release)
1098         ENDIF(name STREQUAL ${target})
1099         ENDFOREACH(target ${targets})
1100         SET(targets)
1101         SET(targets ${targets} MEFISTO2D)
1102         FOREACH(target ${targets})
1103         IF(name STREQUAL ${target})
1104         SET_TARGET_PROPERTIES(${name} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:MSVCRT")
1105         ENDIF(name STREQUAL ${target})
1106         ENDFOREACH(target ${targets})
1107         ENDIF(WINDOWS)
1108         ''')
1109         # --
1110         if self.module == "med":
1111             newlines.append(r'''
1112             IF(WINDOWS)
1113             SET_TARGET_PROPERTIES(${name} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:LIBCMTD")
1114             ENDIF(WINDOWS)
1115             ''')
1116             pass
1117         # --
1118         return
1119     
1120     def setCompilationFlags(self, key, newlines):
1121         newlines.append(r'''
1122         SET(var)
1123         IF(WINDOWS)
1124         SET(targets)
1125         SET(targets ${targets} SalomeIDLKernel)
1126         SET(targets ${targets} SalomeDS)
1127         SET(targets ${targets} SALOMEDS_Client_exe)
1128         SET(targets ${targets} SalomeIDLGEOM)
1129         SET(targets ${targets} GEOMEngine)
1130         SET(targets ${targets} MEDEngine)
1131         SET(targets ${targets} SMESHEngine)
1132         SET(targets ${targets} SMESH)
1133         FOREACH(target ${targets})
1134         IF(name STREQUAL ${target})
1135         SET(var ${var} -DNOGDI)
1136         ENDIF(name STREQUAL ${target})
1137         ENDFOREACH(target ${targets})
1138         ENDIF(WINDOWS)
1139         ''')
1140         # --
1141         newlines.append(r'''
1142         IF(WINDOWS)
1143         SET(targets)
1144         SET(targets ${targets} MEFISTO2D)
1145         FOREACH(target ${targets})
1146         IF(name STREQUAL ${target})
1147         SET(dir $ENV{F2CHOME})
1148         STRING(REPLACE "\\\\" "/" dir ${dir})
1149         SET(var ${var} -I${dir})
1150         ENDIF(name STREQUAL ${target})
1151         ENDFOREACH(target ${targets})
1152         ENDIF(WINDOWS)
1153         ''')
1154         # --
1155         newlines.append(r'''
1156         IF(WINDOWS)
1157         SET(var ${var} -D_USE_MATH_DEFINES)
1158         ENDIF(WINDOWS)
1159         ''')
1160         # --
1161         if self.module in ["geom", "med"]:
1162             newlines.append(r'''
1163             SET(var ${var} -I${CMAKE_CURRENT_SOURCE_DIR})
1164             SET(var ${var} -I${CMAKE_CURRENT_BINARY_DIR})
1165             ''')
1166             pass
1167         if key == "bin_PROGRAMS":
1168             newlines.append(r'''
1169             SET(var ${var} ${AM_CPPFLAGS})
1170             SET(var ${var} ${AM_CXXFLAGS})
1171             ''')
1172             pass
1173         newlines.append(r'''
1174         SET(var ${var} ${PLATFORM_CPPFLAGS})
1175         SET(var ${var} ${PTHREADS_INCLUDES})
1176         SET(var ${var} ${${amname}_CPPFLAGS})
1177         SET(var ${var} ${${amname}_CXXFLAGS})
1178         SET(var ${var} ${${amname}_CFLAGS})
1179         SET(flags)
1180         FOREACH(f ${var})
1181         SET(flags "${flags} ${f}")
1182         ENDFOREACH(f ${var})
1183         SET_TARGET_PROPERTIES(${name} PROPERTIES COMPILE_FLAGS "${flags}")
1184         ''')
1185         return
1186     
1187     def addLibTarget(self, key, newlines):
1188         newlines.append(r'''
1189         FOREACH(amname ${%s})
1190         '''%(key))
1191         # --
1192         # Replace .la by _la ...
1193         # --
1194         newlines.append(r'''
1195         STRING(REPLACE .la _la amname ${amname})
1196         ''')
1197         # --
1198         # Remove the _la for the cmake name
1199         # --
1200         newlines.append(r'''
1201         STRING(LENGTH ${amname} len)
1202         MATH(EXPR newlen "${len}-3")
1203         STRING(SUBSTRING ${amname} 0 ${newlen} name)
1204         ''')
1205         # --
1206         # Does the target begins with lib ??
1207         # If yes, remove lib at beginning for cmake name
1208         # --
1209         newlines.append(r'''
1210         STRING(REGEX MATCH "^lib" BEGIN_WITH_lib ${name})
1211         IF(BEGIN_WITH_lib)
1212         STRING(LENGTH ${name} len)
1213         MATH(EXPR newlen "${len}-3")
1214         STRING(SUBSTRING ${name} 3 ${newlen} name)
1215         ENDIF(BEGIN_WITH_lib)
1216         ''')
1217         # --
1218         # Does the target is an idl library
1219         # --
1220         newlines.append(r'''
1221         STRING(REGEX MATCH "IDL" ISIDL ${name})
1222         ''')
1223         # --
1224         # Set the type of the library
1225         # --
1226         newlines.append(r'''
1227         IF(ISIDL)
1228         IF(WINDOWS)
1229         SET(type STATIC)
1230         ELSE(WINDOWS)
1231         SET(type SHARED)
1232         ENDIF(WINDOWS)
1233         ELSE(ISIDL)
1234         SET(type SHARED)
1235         ENDIF(ISIDL)
1236         ''')
1237         # --
1238         # Set sources for the library
1239         # --
1240         newlines.append(r'''
1241         SET(srcs)
1242         FOREACH(src ${${amname}_SOURCES} ${dist_${amname}_SOURCES})
1243         GET_FILENAME_COMPONENT(ext ${src} EXT)
1244         IF(ext STREQUAL .f)
1245         IF(src STREQUAL trte.f)
1246         SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${src})
1247         STRING(REPLACE ".f" ".c" src ${src})
1248         SET(src ${CMAKE_CURRENT_BINARY_DIR}/${src})
1249         SET(output ${src})
1250         ADD_CUSTOM_COMMAND(
1251         OUTPUT ${output}
1252         COMMAND f2c ${input}
1253         MAIN_DEPENDENCY ${input}
1254         )
1255         ELSE(src STREQUAL trte.f)
1256         SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${src})
1257         STRING(REPLACE ".f" ".o" src ${src})
1258         SET(src ${CMAKE_CURRENT_BINARY_DIR}/${src})
1259         SET(output ${src})
1260         IF(WINDOWS)
1261         SET(F77 g77)
1262         ELSE(WINDOWS)
1263         SET(F77 gfortran)
1264         ENDIF(WINDOWS)
1265         ADD_CUSTOM_COMMAND(
1266         OUTPUT ${output}
1267         COMMAND ${F77} -c -o ${output} ${input}
1268         MAIN_DEPENDENCY ${input}
1269         )
1270         ENDIF(src STREQUAL trte.f)
1271         ENDIF(ext STREQUAL .f)
1272         SET(srcs ${srcs} ${src})
1273         ENDFOREACH(src ${${amname}_SOURCES} ${dist_${amname}_SOURCES})
1274         SET(build_srcs)
1275         FOREACH(f ${nodist_${amname}_SOURCES} ${BUILT_SOURCES})
1276         GET_FILENAME_COMPONENT(ext ${f} EXT)
1277         IF(ext STREQUAL .py)
1278         ELSE(ext STREQUAL .py)
1279         SET(build_srcs ${build_srcs} ${CMAKE_CURRENT_BINARY_DIR}/${f})
1280         ENDIF(ext STREQUAL .py)
1281         ENDFOREACH(f ${nodist_${amname}_SOURCES})
1282         SET(srcs ${build_srcs} ${srcs})
1283         ''')
1284         # --
1285         # Add the library to cmake
1286         # --
1287         newlines.append(r'''
1288         ADD_LIBRARY(${name} ${type} ${srcs})
1289         ''')
1290         # --
1291         # The compilation flags
1292         # --
1293         self.setCompilationFlags(key, newlines)
1294         # --
1295         newlines.append(r'''
1296         SET_TARGET_PROPERTIES(${name} PROPERTIES VERSION 0.0.0 SOVERSION 0)
1297         FOREACH(lib medC med)
1298         IF(lib STREQUAL ${name})
1299         SET_TARGET_PROPERTIES(${name} PROPERTIES VERSION 1.1.5 SOVERSION 1)
1300         ENDIF(lib STREQUAL ${name})
1301         ENDFOREACH(lib medC med)
1302         ''')
1303         # --
1304         from os.path import basename
1305         upper_name = basename(self.root).upper()
1306         # --
1307         if upper_name in ["2.1.X", "2.3.1"]:
1308             upper_name = "D_" + upper_name
1309             pass
1310         # --
1311         newlines.append(r'''
1312         SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL %s_EXPORTS)
1313         '''%(upper_name))
1314         # --
1315         newlines.append(r'''
1316         IF(name STREQUAL SalomeLauncher)
1317         SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL SALOME%s_EXPORTS)
1318         ENDIF(name STREQUAL SalomeLauncher)
1319         '''%(upper_name))
1320         newlines.append(r'''
1321         IF(name STREQUAL SalomeResourcesManager)
1322         SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL SALOME%s_EXPORTS)
1323         ENDIF(name STREQUAL SalomeResourcesManager)
1324         '''%(upper_name))
1325         newlines.append(r'''
1326         IF(name STREQUAL GEOMObject)
1327         SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL GEOM_%s_EXPORTS)
1328         ENDIF(name STREQUAL GEOMObject)
1329         '''%(upper_name))
1330         newlines.append(r'''
1331         IF(name STREQUAL medC)
1332         SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MEDC_DLL_EXPORTS)
1333         ENDIF(name STREQUAL medC)
1334         ''')
1335         newlines.append(r'''
1336         IF(name STREQUAL med)
1337         SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MED_DLL_EXPORTS)
1338         ENDIF(name STREQUAL med)
1339         ''')
1340         newlines.append(r'''
1341         IF(name STREQUAL medimport)
1342         SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MEDIMPORT_DLL_EXPORTS)
1343         ENDIF(name STREQUAL medimport)
1344         ''')
1345         newlines.append(r'''
1346         IF(name STREQUAL medimportcxx)
1347         SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MEDIMPORTCXX_DLL_EXPORTS)
1348         ENDIF(name STREQUAL medimportcxx)
1349         ''')
1350         # --
1351         newlines.append(r'''
1352         IF(name STREQUAL MEDWrapperBase)
1353         SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MEDWRAPPER_BASE_EXPORTS)
1354         ENDIF(name STREQUAL MEDWrapperBase)
1355         ''')
1356         newlines.append(r'''
1357         IF(name STREQUAL MEDWrapper_V2_1)
1358         SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MEDWRAPPER_V2_1_EXPORTS)
1359         ENDIF(name STREQUAL MEDWrapper_V2_1)
1360         ''')
1361         newlines.append(r'''
1362         IF(name STREQUAL med_V2_1)
1363         SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MEDWRAPPER_V2_1_CORE_EXPORTS)
1364         ENDIF(name STREQUAL med_V2_1)
1365         ''')
1366         newlines.append(r'''
1367         IF(name STREQUAL MEDWrapper_V2_2)
1368         SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MEDWRAPPER_V2_2_EXPORTS)
1369         ENDIF(name STREQUAL MEDWrapper_V2_2)
1370         ''')
1371         newlines.append(r'''
1372         IF(name STREQUAL MEDWrapper)
1373         SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MEDWRAPPER_FACTORY_EXPORTS)
1374         ENDIF(name STREQUAL MEDWrapper)
1375         ''')
1376         newlines.append(r'''
1377         IF(name STREQUAL interpkernelbases)
1378         SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL INTERPKERNELBASES_EXPORTS)
1379         ENDIF(name STREQUAL interpkernelbases)
1380         IF(name STREQUAL InterpGeometric2DAlg)
1381         SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL INTERPKERNELGEOMETRIC2D_EXPORTS)
1382         ENDIF(name STREQUAL InterpGeometric2DAlg)
1383         IF(name STREQUAL interpkernel)
1384         SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL INTERPKERNEL_EXPORTS)
1385         ENDIF(name STREQUAL interpkernel)
1386         IF(name STREQUAL MEDClientcmodule)
1387         SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MEDCLIENT_EXPORTS)
1388         ENDIF(name STREQUAL MEDClientcmodule)
1389         ''')
1390         # --
1391         newlines.append(r'''
1392         IF(name STREQUAL SMESHControls)
1393         SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL SMESHCONTROLS_EXPORTS)
1394         ENDIF(name STREQUAL SMESHControls)
1395         ''')
1396         newlines.append(r'''
1397         IF(name STREQUAL MeshDriver)
1398         SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MESHDRIVER_EXPORTS)
1399         ENDIF(name STREQUAL MeshDriver)
1400         ''')
1401         newlines.append(r'''
1402         IF(name STREQUAL MeshDriverMED)
1403         SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MESHDRIVERMED_EXPORTS)
1404         ENDIF(name STREQUAL MeshDriverMED)
1405         ''')
1406         newlines.append(r'''
1407         IF(name STREQUAL MeshDriverDAT)
1408         SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MESHDRIVERDAT_EXPORTS)
1409         ENDIF(name STREQUAL MeshDriverDAT)
1410         ''')
1411         newlines.append(r'''
1412         IF(name STREQUAL MeshDriverUNV)
1413         SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MESHDRIVERUNV_EXPORTS)
1414         ENDIF(name STREQUAL MeshDriverUNV)
1415         ''')
1416         newlines.append(r'''
1417         IF(name STREQUAL MeshDriverSTL)
1418         SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MESHDRIVERSTL_EXPORTS)
1419         ENDIF(name STREQUAL MeshDriverSTL)
1420         ''')
1421         newlines.append(r'''
1422         IF(name STREQUAL MEFISTO2D)
1423         SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MEFISTO2D_EXPORTS)
1424         ENDIF(name STREQUAL MEFISTO2D)
1425         ''')
1426         newlines.append(r'''
1427         IF(name STREQUAL SMESHObject)
1428         SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL SMESHOBJECT_EXPORTS)
1429         ENDIF(name STREQUAL SMESHObject)
1430         ''')
1431         newlines.append(r'''
1432         IF(name STREQUAL _libSMESH_Swig)
1433         SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL SMESH_SWIG_EXPORTS)
1434         ENDIF(name STREQUAL _libSMESH_Swig)
1435         ''')
1436         newlines.append(r'''
1437         IF(name STREQUAL NETGENPluginGUI)
1438         SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL NETGENPLUGIN_GUI_EXPORTS)
1439         ENDIF(name STREQUAL NETGENPluginGUI)
1440         ''')
1441         # --
1442         self.setLibAdd(key, newlines)
1443         # --
1444         if 1: # key != "noinst_LTLIBRARIES":
1445             if self.module == "medfile":
1446                 newlines.append(r'''
1447                 SET(DEST lib)
1448                 ''')
1449             else:
1450                 newlines.append(r'''
1451                 SET(DEST lib/salome)
1452                 ''')
1453                 pass
1454             newlines.append(r'''
1455             IF(BEGIN_WITH_lib)
1456             INSTALL(TARGETS ${name} DESTINATION ${DEST})
1457             ''')
1458             if self.module == "geom":
1459                 newlines.append(r'''
1460                 IF(WINDOWS)
1461                 STRING(REGEX MATCH "Export" ISExport ${name})
1462                 IF(ISExport)
1463                 INSTALL(FILES ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.dll DESTINATION ${DEST} RENAME lib${name}.dll)
1464                 ENDIF(ISExport)
1465                 STRING(REGEX MATCH "Import" ISImport ${name})
1466                 IF(ISImport)
1467                 INSTALL(FILES ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.dll DESTINATION ${DEST} RENAME lib${name}.dll)
1468                 ENDIF(ISImport)
1469                 ENDIF(WINDOWS)
1470                 ''')
1471                 pass
1472             newlines.append(r'''
1473             IF(name STREQUAL SalomePyQt)
1474             INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so DESTINATION ${DEST} RENAME ${name}.so)
1475             ENDIF(name STREQUAL SalomePyQt)
1476             ELSE(BEGIN_WITH_lib)
1477             IF(WINDOWS)
1478             INSTALL(TARGETS ${name} DESTINATION lib/python${PYTHON_VERSION}/site-packages/salome)
1479             IF(CMAKE_BUILD_TYPE STREQUAL Release)
1480             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)
1481             ELSE(CMAKE_BUILD_TYPE STREQUAL Release)
1482             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)
1483             ENDIF(CMAKE_BUILD_TYPE STREQUAL Release)
1484             ELSE(WINDOWS)
1485             GET_TARGET_PROPERTY(version ${name} VERSION)
1486             GET_TARGET_PROPERTY(soversion ${name} SOVERSION)
1487             INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so.${version} DESTINATION lib/python${PYTHON_VERSION}/site-packages/salome RENAME ${name}.so.${version})
1488             INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so.${version} DESTINATION lib/python${PYTHON_VERSION}/site-packages/salome RENAME ${name}.so.${soversion})
1489             INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so.${version} DESTINATION lib/python${PYTHON_VERSION}/site-packages/salome RENAME ${name}.so)
1490             ENDIF(WINDOWS)
1491             ENDIF(BEGIN_WITH_lib)
1492             ''')
1493             pass
1494         # --
1495         newlines.append(r'''
1496         ENDFOREACH(amname ${%s})
1497         '''%(key))
1498         # --
1499         return
1500     
1501     def addBinTarget(self, key, newlines):
1502         # --
1503         newlines.append(r'''
1504         FOREACH(amname ${bin_PROGRAMS})
1505         ''')
1506         # --
1507         newlines.append(r'''
1508         SET(name "${amname}_exe")
1509         SET(srcs ${${amname}_SOURCES} ${dist_${amname}_SOURCES})
1510         LIST(LENGTH srcs nb)
1511         IF(nb)
1512         ADD_EXECUTABLE(${name} ${srcs})
1513         ''')
1514         # --
1515         self.setCompilationFlags(key, newlines)
1516         # --
1517         self.setLibAdd(key, newlines)
1518         # --
1519         if self.module == "medfile":
1520             newlines.append(r'''
1521             SET(DEST bin)
1522             ''')
1523         else:
1524             newlines.append(r'''
1525             SET(DEST bin/salome)
1526             ''')
1527             pass
1528         # --
1529         newlines.append(r'''
1530         IF(WINDOWS)
1531         INSTALL(TARGETS ${name} DESTINATION ${DEST})
1532         INSTALL(FILES ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.exe DESTINATION ${DEST} RENAME ${amname}.exe)
1533         INSTALL(CODE "FILE(REMOVE ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.exe)")
1534         ELSE(WINDOWS)
1535         SET(PERMS)
1536         SET(PERMS ${PERMS} OWNER_READ OWNER_WRITE OWNER_EXECUTE)
1537         SET(PERMS ${PERMS} GROUP_READ GROUP_EXECUTE)
1538         SET(PERMS ${PERMS} WORLD_READ WORLD_EXECUTE)
1539         INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${name} DESTINATION ${DEST} PERMISSIONS ${PERMS} RENAME ${amname})
1540         ENDIF(WINDOWS)
1541         ''')
1542         # --
1543         newlines.append(r'''
1544         ENDIF(nb)
1545         ''')
1546         # --
1547         newlines.append(r'''
1548         ENDFOREACH(amname ${bin_PROGRAMS})
1549         ''')
1550         # --
1551         return
1552     
1553     def addInstallTarget(self, key, destination, newlines):
1554         newlines.append(r"FOREACH(f ${%s})"%(key))
1555         newlines.append(r'''
1556         SET(DEST %s)
1557         '''%(destination))
1558         newlines.append(r'''
1559         STRING(COMPARE EQUAL ${f} SALOMEconfig.h.in test_SALOMEconfig.h.in)
1560         IF(test_SALOMEconfig.h.in)
1561         INSTALL(FILES SALOMEconfig.ref.in DESTINATION ${DEST} RENAME SALOMEconfig.h.in)
1562         ELSE(test_SALOMEconfig.h.in)
1563         SET(dummy dummy-NOTFOUND)
1564         MARK_AS_ADVANCED(dummy)
1565         # FILE(REMOVE ${CMAKE_INSTALL_PREFIX}/${DEST}/${f})
1566         FIND_FILE(dummy ${f} PATHS ${CMAKE_CURRENT_SOURCE_DIR} NO_DEFAULT_PATH)
1567         IF(dummy)
1568         ''')
1569         if key in ['dist_salomescript_SCRIPTS']:
1570             newlines.append(r'''
1571             SET(PERMS)
1572             SET(PERMS ${PERMS} OWNER_READ OWNER_WRITE OWNER_EXECUTE)
1573             SET(PERMS ${PERMS} GROUP_READ GROUP_EXECUTE)
1574             SET(PERMS ${PERMS} WORLD_READ WORLD_EXECUTE)
1575             INSTALL(FILES ${f} DESTINATION ${DEST} PERMISSIONS ${PERMS})
1576             ''')
1577         else:
1578             newlines.append(r'''
1579             INSTALL(FILES ${f} DESTINATION ${DEST})
1580             ''')
1581             pass
1582         newlines.append(r'''
1583         ELSE(dummy)
1584         GET_FILENAME_COMPONENT(ext ${f} EXT)
1585         IF(ext STREQUAL .qm)
1586         STRING(REGEX REPLACE .qm .ts input ${f})
1587         ''')
1588         if self.module in ["kernel", "gui"]:
1589             newlines.append(r'''
1590             SET(input ${CMAKE_CURRENT_SOURCE_DIR}/resources/${input})
1591             ''')
1592         else:
1593             newlines.append(r'''
1594             SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${input})
1595             ''')
1596             pass
1597         newlines.append(r'''
1598         SET(output ${CMAKE_CURRENT_BINARY_DIR}/${f})
1599         # ADD_CUSTOM_COMMAND(
1600         # OUTPUT ${output}
1601         # COMMAND ${QT_LRELEASE_EXECUTABLE} ${input} -qm ${output}
1602         # MAIN_DEPENDENCY ${input}
1603         # )
1604         EXECUTE_PROCESS(COMMAND ${QT_LRELEASE_EXECUTABLE} ${input} -qm ${output})
1605         ENDIF(ext STREQUAL .qm)
1606         INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${f} DESTINATION ${DEST})
1607         ENDIF(dummy)
1608         ENDIF(test_SALOMEconfig.h.in)
1609         ''')
1610         newlines.append(r"ENDFOREACH(f ${%s})"%(key))
1611         return
1612     
1613     def writeListsFile(self):
1614         f = open(self.listsFile, "w")
1615         f.write(self.content)
1616         f.close()
1617         return
1618     
1619     pass
1620
1621 def convertAmFile(the_root, root, dirs, files, f, module):
1622     cmake = CMakeFile(the_root, root, dirs, files, f, module)
1623     cmake.writeListsFile()
1624     return
1625
1626 def usage(exit_status):
1627     from sys import exit
1628     from sys import argv
1629     print "Usage: %s --module"%(argv[0])
1630     exit(exit_status)
1631     return
1632
1633 if __name__ == "__main__":
1634     #
1635     from sys import argv
1636     if len(argv) != 2:
1637         usage(1)
1638         pass
1639     #
1640     module = argv[1]
1641     if module.find('--') != 0:
1642         usage(1)
1643         pass
1644     module = module[2:]
1645     if len(module) == 0:
1646         usage(1)
1647         pass
1648     #
1649     from os import getcwd
1650     the_root = getcwd()
1651     #
1652     from os import walk
1653     for root, dirs, files in walk(the_root):
1654         from os.path import basename
1655         if basename(root) == "CVS": continue
1656         for f in files:
1657             from os.path import basename
1658             if basename(f) == "Makefile.am":
1659                 convertAmFile(the_root, root, dirs, files, f, module)
1660                 pass
1661             pass
1662         pass
1663     #
1664     pass