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