1 # Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
25 # A set of regular expressions used ...
28 p_multiline = re.compile(r"""
34 p_dollar = re.compile(r"""
36 (?P<val> # open the group val
37 [^)]* # the group contain 0 or more non ) characters
42 p_arobas = re.compile(r"""
44 (?P<val> # open the group val
45 [^@]* # the group contain 0 or more non @ characters
50 p_if = re.compile(r"""
51 ^ # beginning of the string
55 (?P<val> # open the group val
56 [^\s]+ # the group contain 1 or more non space characters
60 p_else = re.compile(r"""
61 ^ # beginning of the line
67 p_endif = re.compile(r"""
68 ^ # beginning of the line
74 p_attribution = re.compile(r"""
75 ^ # beginning of the line
76 (?P<spaces> # open the group spaces
79 (?P<key> # open the group key
80 \w+ # the group contain 1 or more alphanumeric characters
83 (?P<method> # open the group method
87 (?P<value> # open the group value
88 .* # 0 or more any characters
94 class CMakeFile(object):
96 def __init__(self, the_root, root, dirs, files, f, module):
98 self.the_root = the_root
104 from os.path import join
105 self.amFile = join(root, f)
106 self.listsFile = join(root, "CMakeLists.txt")
115 # Read the Makefile.am file
118 stream = open(amFile)
119 content = stream.read()
123 # Replace the composed lines separated by "\\n" by an unique line
125 content = p_multiline.sub(r' ', content)
128 # Compatibility netgen plugin
130 content = content.replace("../NETGEN/libNETGEN.la", "${NETGEN_LIBS}")
212 "SalomeCommunication",
214 "SalomeDSCContainer",
222 "SalomeLifeCycleCORBA",
224 "SalomeLoggerServer",
225 "SalomeNotification",
227 "SalomeResourcesManager",
229 "with_loggerTraceCollector",
281 "GEOMFiltersSelection",
305 "InterpGeometric2DAlg",
334 "SMESHFiltersSelection",
342 full_list = cas_list + kernel_list + gui_list
343 full_list += geom_list + med_list + smesh_list
345 # E.A. : sort by len before substitution ...
346 # Why ? Thing to "-lMEDWrapper" then "-lMEDWrapper_V2_1" substition
347 # And you understand ...
349 full_list.sort(cmp = lambda x, y : cmp(len(y), len(x)))
351 for key in full_list:
352 content = content.replace("-l%s"%(key), "${%s}"%(key))
356 # Split content in lines to treat each one separately
358 lines = content.split('\n')
361 # newlines contains the lines of the future CMakeLists.txt file
366 # opened_ifs is used to deals with nested conditionnals
371 # the __thedict__ dictionnary contains key, val
372 # of the Makefile.am file
374 self.__thedict__ = {}
377 # Initialize file ... mainly includes other cmake files
379 self.initialize(newlines)
382 # Do the job for each line
385 self.treatLine(line, newlines, opened_ifs)
389 # Finalize file ... it is in here the cmake job is done
391 self.finalize(newlines)
394 # Concatenate newlines into content
396 content = '\n'.join(newlines)
399 # Add a CR at end if necessary
401 lines = content.split('\n')
402 # lines = [ l.strip() for l in lines ]
403 if len(lines[-1]) != 0:
406 content = '\n'.join(lines)
409 self.content = content
414 def initialize(self, newlines):
415 if self.root == self.the_root:
418 CMAKE_MINIMUM_REQUIRED(VERSION 2.4.7 FATAL_ERROR)
419 IF(COMMAND cmake_policy)
420 cmake_policy(SET CMP0003 NEW)
421 ENDIF(COMMAND cmake_policy)
424 if self.module == "kernel":
426 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindPLATFORM.cmake)
427 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindPYTHON.cmake)
428 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindOMNIORB.cmake)
429 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindPTHREADS.cmake)
430 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindHDF5.cmake)
431 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindBOOST.cmake)
432 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindLIBXML2.cmake)
433 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindSWIG.cmake)
434 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindCPPUNIT.cmake)
439 SET(KERNEL_ROOT_DIR $ENV{KERNEL_ROOT_DIR})
440 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindPLATFORM.cmake)
441 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindPYTHON.cmake)
442 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindOMNIORB.cmake)
443 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindPTHREADS.cmake)
444 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindHDF5.cmake)
445 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindBOOST.cmake)
446 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindLIBXML2.cmake)
447 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindSWIG.cmake)
448 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindCPPUNIT.cmake)
449 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindKERNEL.cmake)
451 if self.module == "gui":
453 INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindCAS.cmake)
454 INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindQT4.cmake)
455 INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindOPENGL.cmake)
456 INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindVTK.cmake)
457 INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindQWT.cmake)
458 INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindSIPPYQT.cmake)
462 SET(GUI_ROOT_DIR $ENV{GUI_ROOT_DIR})
463 INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindCAS.cmake)
464 INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindQT4.cmake)
465 INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindOPENGL.cmake)
466 INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindVTK.cmake)
467 INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindQWT.cmake)
468 INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindSIPPYQT.cmake)
469 INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindGUI.cmake)
471 if self.module == "med":
473 INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindMEDFILE.cmake)
476 if self.module == "smesh":
478 SET(GEOM_ROOT_DIR $ENV{GEOM_ROOT_DIR})
479 SET(MED_ROOT_DIR $ENV{MED_ROOT_DIR})
480 INCLUDE(${GEOM_ROOT_DIR}/adm_local/cmake_files/FindGEOM.cmake)
481 INCLUDE(${MED_ROOT_DIR}/adm_local/cmake_files/FindMEDFILE.cmake)
482 INCLUDE(${MED_ROOT_DIR}/adm_local/cmake_files/FindMED.cmake)
485 if self.module == "netgenplugin":
487 SET(GEOM_ROOT_DIR $ENV{GEOM_ROOT_DIR})
488 SET(MED_ROOT_DIR $ENV{MED_ROOT_DIR})
489 SET(SMESH_ROOT_DIR $ENV{SMESH_ROOT_DIR})
490 INCLUDE(${GEOM_ROOT_DIR}/adm_local/cmake_files/FindGEOM.cmake)
491 INCLUDE(${MED_ROOT_DIR}/adm_local/cmake_files/FindMED.cmake)
492 INCLUDE(${SMESH_ROOT_DIR}/adm_local/cmake_files/FindSMESH.cmake)
493 INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindNETGEN.cmake)
496 if self.module == "blsurfplugin":
498 SET(GEOM_ROOT_DIR $ENV{GEOM_ROOT_DIR})
499 SET(MED_ROOT_DIR $ENV{MED_ROOT_DIR})
500 SET(SMESH_ROOT_DIR $ENV{SMESH_ROOT_DIR})
501 INCLUDE(${GEOM_ROOT_DIR}/adm_local/cmake_files/FindGEOM.cmake)
502 INCLUDE(${MED_ROOT_DIR}/adm_local/cmake_files/FindMED.cmake)
503 INCLUDE(${SMESH_ROOT_DIR}/adm_local/cmake_files/FindSMESH.cmake)
504 INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindBLSURF.cmake)
507 if self.module == "visu":
509 SET(MED_ROOT_DIR $ENV{MED_ROOT_DIR})
510 INCLUDE(${MED_ROOT_DIR}/adm_local/cmake_files/FindMED.cmake)
516 if self.module == "kernel":
521 set(XVERSION 0x050101)
523 elif self.module == "gui":
525 SET(GUI_ENABLE_CORBA ${CORBA_GEN})
526 SET(ENABLE_VTKVIEWER ON)
527 SET(ENABLE_SALOMEOBJECT ON)
528 SET(ENABLE_OCCVIEWER ON)
529 SET(ENABLE_GLVIEWER ON)
530 SET(ENABLE_PLOT2DVIEWER ON)
531 SET(ENABLE_PYCONSOLE ON)
532 SET(ENABLE_SUPERVGRAPHVIEWER ON)
533 # SET(ENABLE_QXGRAPHVIEWER ON)
536 elif self.module == "geom":
538 SET(GEOM_ENABLE_GUI ON)
541 elif self.module == "medfile":
543 SET(MED_NUM_MAJEUR 2)
544 SET(MED_NUM_MINEUR 3)
545 SET(MED_NUM_RELEASE 5)
548 SET(FLIBS -lgfortranbegin -lgfortran)
552 elif self.module == "med":
554 SET(MED_ENABLE_KERNEL ON)
555 SET(MED_ENABLE_GUI ON)
558 elif self.module == "smesh":
560 SET(SMESH_ENABLE_GUI ON)
563 elif self.module == "netgenplugin":
565 SET(NETGENPLUGIN_ENABLE_GUI ON)
568 elif self.module == "blsurfplugin":
570 SET(BLSURFPLUGIN_ENABLE_GUI ON)
577 SET(VERSION_INFO 0.0.0)
578 SET(SOVERSION_INFO 0)
587 def treatLine(self, line, newlines, opened_ifs):
590 # Print the comment above the line itself
592 if line.find('#') >= 0:
593 fields = line.split('#')
595 comment = '#'.join([''] + fields[1:])
596 newlines.append(comment)
602 # If the line begins with 'include ', just comment it
604 if line.find("include ") == 0:
605 newlines.append("# " + line)
609 # If the line begins with '-include', just comment it
611 if line.find("-include") == 0:
612 newlines.append("# " + line)
616 # If the line is a definition of a make rule, just comment it
618 if line.count(':') == 1:
619 newlines.append("# " + line)
623 # A particuliar case where there are two ":" on the same line
625 if line.find('install-exec-local:') == 0:
626 newlines.append("# " + line)
630 # If the line begin by a tabulation, consider it's a makefile command and comment it
632 if line.find("\t") == 0:
633 newlines.append("# " + line)
638 key = "-version-info"
639 if line.find(key) >= 0:
641 before = line.split(key)[0]
642 after = line[len(before)+len(key):]
645 version_info = after.split()[0]
646 line = line.replace(key+sep+version_info, "")
648 version_info = version_info.replace(':', '.')
649 soversion_info = version_info.split('.')[0]
650 newlines.append("SET(VERSION_INFO " + version_info + ")")
651 newlines.append("SET(SOVERSION_INFO " + soversion_info + ")")
656 # Replace the $(TOTO) by ${TOTO}
657 # Replace the @TOTO@ by ${TOTO}
659 line = p_dollar.sub(r"${\1}", line)
660 line = p_arobas.sub(r"${\1}", line)
663 line = line.replace(r"${top_builddir}", r"${CMAKE_BINARY_DIR}")
664 line = line.replace(r"${top_srcdir}", r"${CMAKE_SOURCE_DIR}")
665 line = line.replace(r"${srcdir}", r"${CMAKE_CURRENT_SOURCE_DIR}")
666 line = line.replace(r"${builddir}", r"${CMAKE_CURRENT_BINARY_DIR}")
667 line = line.replace(r"${datadir}", r"${CMAKE_INSTALL_PREFIX}/share")
670 # Check if the line is a 'if' condition
671 # If yes, replace it by a cmake grammar
673 match = p_if.match(line)
675 theif = match.group("val")
677 theif = "NOT " + theif[1:]
679 line = p_if.sub(r"IF(%s)"%(theif), line)
680 opened_ifs.append(theif)
681 newlines.append(line)
685 # Check if the line is a 'else' condition
686 # If yes, replace it by a cmake grammar
688 match = p_else.match(line)
690 line = "ELSE(%s)"%(opened_ifs[-1])
691 newlines.append(line)
695 # Check if the line is a 'endif' condition
696 # If yes, replace it by a cmake grammar
698 match = p_endif.match(line)
700 line = "ENDIF(%s)"%(opened_ifs[-1])
702 newlines.append(line)
706 # Check if the line is an attribution '=' or '+='
708 match = p_attribution.match(line)
710 self.treatAttribution(match, newlines)
714 newlines.append(line)
719 def treatAttribution(self, match, newlines):
721 spaces = match.group("spaces")
722 key = match.group("key")
723 method = match.group("method")
724 value = match.group("value")
725 # print [spaces, key, method, value]
728 # Open cmake SET command
730 newlines.append(spaces + "SET(" + key)
733 # If method is '+=', put the previous definition as first value
736 newlines.append("%s ${%s}"%(spaces, key))
740 fields = value.split()
741 for i in range(len(fields)):
742 newlines.append("%s %s"%(spaces, fields[i]))
748 # The try: except KeyError is here if the +=
749 # is an error which occurs in salome ...
752 self.__thedict__[key] += fields[:]
754 self.__thedict__[key] = fields[:]
758 self.__thedict__[key] = fields[:]
762 # Close cmake SET command
765 newlines.append("%s)"%(spaces))
769 def finalize(self, newlines):
772 # Convert the .in files in build dir
776 if f == "sstream.in":
778 if f in ["runContainer.in", "stopContainer.in"]:
779 if self.module == "med":
780 if self.root[-3:] == "csh":
784 if f == "SALOMEconfig.ref.in":
785 out = "SALOMEconfig.h"
790 SET(input ${CMAKE_CURRENT_SOURCE_DIR}/%s)
793 SET(output ${CMAKE_CURRENT_BINARY_DIR}/%s)
796 MESSAGE(STATUS "Creation of ${output}")
797 CONFIGURE_FILE(${input} ${output})
803 # convert the SUBDIRS in cmake grammar
805 if 1: # self.__thedict__.has_key("SUBDIRS"):
807 FOREACH(dir ${SUBDIRS})
808 IF(NOT dir STREQUAL .)
809 ADD_SUBDIRECTORY(${dir})
810 ENDIF(NOT dir STREQUAL .)
811 ENDFOREACH(dir ${SUBDIRS})
817 for key in ["lib_LTLIBRARIES", "noinst_LTLIBRARIES", "salomepyexec_LTLIBRARIES"]:
818 if self.__thedict__.has_key(key):
819 self.addLibTarget(key, newlines)
825 for key in ["bin_PROGRAMS"]:
826 if self.__thedict__.has_key(key):
827 self.addBinTarget(key, newlines)
833 if self.__thedict__.has_key("BASEIDL_FILES"):
834 if not self.__thedict__.has_key("IDL_FILES"):
835 self.__thedict__["IDL_FILES"] = self.__thedict__["BASEIDL_FILES"]
837 SET(IDL_FILES ${BASEIDL_FILES})
846 if self.__thedict__.has_key(key):
848 FOREACH(input ${IDL_FILES})
849 STRING(REGEX REPLACE ".idl" "" base ${input})
850 SET(src ${CMAKE_CURRENT_BINARY_DIR}/${base}SK.cc)
852 SET(dynsrc ${CMAKE_CURRENT_BINARY_DIR}/${base}DynSK.cc)
853 SET(outputs ${outputs} ${dynsrc})
856 COMMAND ${OMNIORB_IDL} ${IDLCXXFLAGS} ${OMNIORB_IDLCXXFLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/${input}
857 MAIN_DEPENDENCY ${input}
859 install(FILES ${input} DESTINATION idl/salome)
860 SET(IDL_HEADER ${CMAKE_CURRENT_BINARY_DIR}/${base}.hh)
861 install(FILES ${IDL_HEADER} DESTINATION include/salome)
862 INSTALL(CODE "SET(IDL_FILE ${input})")
863 INSTALL(CODE "SET(DIR lib/python${PYTHON_VERSION}/site-packages/salome)")
864 INSTALL(CODE "SET(CMAKE_CURRENT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})")
865 INSTALL(CODE "SET(OMNIORB_IDL_PYTHON ${OMNIORB_IDL_PYTHON})")
868 FOREACH(f ${IDLPYFLAGS})
869 SET(flags "${flags} ${f}")
870 ENDFOREACH(f ${IDLPYFLAGS})
871 SET(IDLPYFLAGS ${flags})
872 STRING(REPLACE "\\\\" "/" IDLPYFLAGS ${IDLPYFLAGS})
873 INSTALL(CODE "SET(IDLPYFLAGS ${IDLPYFLAGS})")
876 if self.module == "kernel":
878 INSTALL(SCRIPT ${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/install_python_from_idl.cmake)
882 STRING(REPLACE "\\\\" "/" KERNEL_ROOT_DIR ${KERNEL_ROOT_DIR})
883 INSTALL(SCRIPT ${KERNEL_ROOT_DIR}/salome_adm/cmake_files/install_python_from_idl.cmake)
887 ENDFOREACH(input ${IDL_FILES})
893 for key in ["SWIG_SRC", "SWIGSOURCES", "SWIG_DEF"]:
894 if self.__thedict__.has_key(key):
896 SET(SWIG_SOURCES ${%s})
898 self.__thedict__["SWIG_SOURCES"] = self.__thedict__[key]
904 if self.__thedict__.has_key("SWIG_SOURCES"):
906 IF(SWIG_SOURCES MATCHES ";")
907 STRING(REGEX REPLACE ";.*" "" SWIG_SOURCES_FIRST "${SWIG_SOURCES}")
908 ELSE(SWIG_SOURCES MATCHES ";")
909 SET(SWIG_SOURCES_FIRST "${SWIG_SOURCES}")
910 ENDIF(SWIG_SOURCES MATCHES ";")
913 COMMAND ${SWIG_EXECUTABLE} ${SWIG_FLAGS} ${MY_SWIG_FLAGS} -o ${build_srcs} ${CMAKE_CURRENT_SOURCE_DIR}/${SWIG_SOURCES_FIRST}
914 MAIN_DEPENDENCY ${SWIG_SOURCES}
922 if self.__thedict__.has_key(key):
924 FOREACH(output ${MOC_FILES})
925 STRING(REGEX REPLACE _moc.cxx .h input ${output})
926 SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${input})
927 SET(output ${CMAKE_CURRENT_BINARY_DIR}/${output})
930 COMMAND ${QT_MOC_EXECUTABLE} ${MOC_FLAGS} ${input} -o ${output}
931 MAIN_DEPENDENCY ${input}
933 ENDFOREACH(output ${MOC_FILES})
940 if self.__thedict__.has_key(key):
942 FOREACH(output ${UIC_FILES})
943 STRING(REPLACE "ui_" "" input ${output})
944 STRING(REPLACE ".h" ".ui" input ${input})
945 SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${input})
946 SET(output ${CMAKE_CURRENT_BINARY_DIR}/${output})
949 COMMAND ${QT_UIC_EXECUTABLE} -o ${output} ${input}
950 MAIN_DEPENDENCY ${input}
952 ENDFOREACH(output ${UIC_FILES})
959 if self.__thedict__.has_key(key):
961 FOREACH(output ${QRC_FILES})
962 STRING(REGEX REPLACE "qrc_" "" input ${output})
963 STRING(REGEX REPLACE ".cxx" ".qrc" input ${input})
964 STRING(REGEX REPLACE ".qrc" "" name ${input})
965 SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${input})
966 SET(output ${CMAKE_CURRENT_BINARY_DIR}/${output})
969 COMMAND ${QT_RCC_EXECUTABLE} ${input} -o ${output} -name ${name}
970 MAIN_DEPENDENCY ${input}
972 ENDFOREACH(output ${QRC_FILES})
979 if self.__thedict__.has_key(key):
981 FOREACH(input ${SIP_FILES})
982 SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${input})
984 FOREACH(out ${SIP_SRC})
985 SET(output ${output} ${CMAKE_CURRENT_BINARY_DIR}/${out})
986 ENDFOREACH(out ${SIP_SRC})
989 COMMAND ${SIP_EXECUTABLE} ${PYQT_SIPFLAGS} ${input}
990 MAIN_DEPENDENCY ${input}
992 ENDFOREACH(input ${SIP_FILES})
997 # Treat the install targets
1000 "salomeadmux_DATA" : "salome_adm/unix",
1001 "dist_salomeadmux_DATA" : "salome_adm/unix",
1002 "dist_salome_cmake_DATA" : "salome_adm/cmake_files",
1003 "dist_salomem4_DATA" : "salome_adm/unix/config_files",
1004 "dist_salome4depr_DATA" : "salome_adm/unix/config_files/DEPRECATED",
1005 "dist_admlocalm4_DATA" : "adm_local/unix/config_files",
1006 "dist_admlocal_cmake_DATA" : "adm_local/cmake_files",
1007 "salomeinclude_DATA" : "include/salome",
1008 "salomeinclude_HEADERS" : "include/salome",
1009 "dist_salomeres_DATA" : "share/salome/resources/%s"%(self.module),
1010 "nodist_salomeres_DATA" : "share/salome/resources/%s"%(self.module),
1011 "nodist_salomeres_SCRIPTS" : "share/salome/resources/%s"%(self.module),
1012 "dist_salomescript_SCRIPTS" : "bin/salome",
1013 "dist_salomescript_DATA" : "bin/salome",
1014 "dist_salomescript_PYTHON" : "bin/salome",
1015 "nodist_salomescript_DATA" : "bin/salome",
1016 "salomepython_PYTHON" : "lib/python${PYTHON_VERSION}/site-packages/salome",
1017 "nodist_salomepython_PYTHON" : "lib/python${PYTHON_VERSION}/site-packages/salome",
1018 "sharedpkgpython_PYTHON" : "lib/python${PYTHON_VERSION}/site-packages/salome/shared_modules",
1020 if self.module == "medfile":
1022 "include_HEADERS" : "include",
1023 "nodist_include_HEADERS" : "include",
1024 "bin_SCRIPTS" : "bin",
1025 "doc_DATA" : "${docdir}",
1028 for key, value in d.items():
1029 if self.__thedict__.has_key(key):
1030 self.addInstallTarget(key, value, newlines)
1037 def setLibAdd(self, key, newlines):
1039 newlines.append(r'''
1043 newlines.append(r'''
1046 SET(targets ${targets} MEFISTO2D)
1047 FOREACH(target ${targets})
1048 IF(name STREQUAL ${target})
1049 SET(dir $ENV{F2CHOME})
1050 STRING(REPLACE "\\\\" "/" dir ${dir})
1051 SET(libadd ${libadd} ${dir}/LIBF77.lib)
1052 SET(libadd ${libadd} ${dir}/LIBI77.lib)
1053 ENDIF(name STREQUAL ${target})
1054 ENDFOREACH(target ${targets})
1058 newlines.append(r'''
1059 SET(libs ${PLATFORM_LIBADD} ${PLATFORM_LDFLAGS} ${${amname}_LIBADD} ${${amname}_LDADD} ${${amname}_LDFLAGS})
1060 IF(name STREQUAL SALOMEBasics)
1061 SET(libs ${libs} ${PTHREAD_LIBS})
1062 ENDIF(name STREQUAL SALOMEBasics)
1064 if key == "bin_PROGRAMS":
1065 newlines.append(r'''
1066 SET(libs ${libs} ${LDADD})
1070 newlines.append(r'''
1071 FOREACH(lib ${libs})
1072 GET_FILENAME_COMPONENT(ext ${lib} EXT)
1073 IF(ext STREQUAL .la)
1074 GET_FILENAME_COMPONENT(lib ${lib} NAME_WE)
1075 STRING(REPLACE "lib" "" lib ${lib})
1076 ENDIF(ext STREQUAL .la)
1078 SET(vars ${vars} -no-undefined)
1079 SET(vars ${vars} -lboost_thread)
1081 SET(vars ${vars} -module)
1082 SET(vars ${vars} -Wl,-E)
1083 SET(vars ${vars} -Xlinker)
1084 SET(vars ${vars} -export-dynamic)
1085 SET(vars ${vars} -lm)
1090 ENDIF(lib STREQUAL v)
1091 ENDFOREACH(v ${vars})
1092 SET(libadd ${libadd} ${lib})
1093 ENDFOREACH(lib ${libs})
1094 TARGET_LINK_LIBRARIES(${name} ${libadd})
1099 def setCompilationFlags(self, key, newlines):
1100 newlines.append(r'''
1104 SET(targets ${targets} SalomeIDLKernel)
1105 SET(targets ${targets} SalomeDS)
1106 SET(targets ${targets} SALOMEDSTest)
1107 SET(targets ${targets} SALOMEDS_Client_exe)
1108 SET(targets ${targets} SalomeIDLGEOM)
1109 SET(targets ${targets} GEOMEngine)
1110 SET(targets ${targets} MEDEngine)
1111 SET(targets ${targets} SMESHEngine)
1112 SET(targets ${targets} SMESH)
1113 FOREACH(target ${targets})
1114 IF(name STREQUAL ${target})
1115 SET(var ${var} -DNOGDI)
1116 ENDIF(name STREQUAL ${target})
1117 ENDFOREACH(target ${targets})
1121 newlines.append(r'''
1124 SET(targets ${targets} MEFISTO2D)
1125 FOREACH(target ${targets})
1126 IF(name STREQUAL ${target})
1127 SET(dir $ENV{F2CHOME})
1128 STRING(REPLACE "\\\\" "/" dir ${dir})
1129 SET(var ${var} -I${dir})
1130 ENDIF(name STREQUAL ${target})
1131 ENDFOREACH(target ${targets})
1135 if self.module in ["geom", "med"]:
1136 newlines.append(r'''
1137 SET(var ${var} -I${CMAKE_CURRENT_SOURCE_DIR})
1138 SET(var ${var} -I${CMAKE_CURRENT_BINARY_DIR})
1141 if key == "bin_PROGRAMS":
1142 newlines.append(r'''
1143 SET(var ${var} ${AM_CPPFLAGS})
1144 SET(var ${var} ${AM_CXXFLAGS})
1147 newlines.append(r'''
1148 SET(var ${var} ${PLATFORM_CPPFLAGS})
1149 SET(var ${var} ${PTHREAD_CFLAGS})
1150 SET(var ${var} ${${amname}_CPPFLAGS})
1151 SET(var ${var} ${${amname}_CXXFLAGS})
1152 SET(var ${var} ${${amname}_CFLAGS})
1155 SET(vars ${vars} -include SALOMEconfig.h)
1156 SET(vars ${vars} -ftemplate-depth-32)
1164 ENDFOREACH(v ${vars})
1165 SET(flags "${flags} ${f}")
1166 ENDFOREACH(f ${var})
1167 SET_TARGET_PROPERTIES(${name} PROPERTIES COMPILE_FLAGS "${flags}")
1171 def addLibTarget(self, key, newlines):
1172 newlines.append(r'''
1173 FOREACH(amname ${%s})
1176 # Replace .la by _la ...
1178 newlines.append(r'''
1179 STRING(REPLACE .la _la amname ${amname})
1182 # Remove the _la for the cmake name
1184 newlines.append(r'''
1185 STRING(LENGTH ${amname} len)
1186 MATH(EXPR newlen "${len}-3")
1187 STRING(SUBSTRING ${amname} 0 ${newlen} name)
1190 # Does the target begins with lib ??
1191 # If yes, remove lib at beginning for cmake name
1193 newlines.append(r'''
1194 STRING(REGEX MATCH "^lib" BEGIN_WITH_lib ${name})
1196 STRING(LENGTH ${name} len)
1197 MATH(EXPR newlen "${len}-3")
1198 STRING(SUBSTRING ${name} 3 ${newlen} name)
1199 ENDIF(BEGIN_WITH_lib)
1202 # Does the target is an idl library
1204 newlines.append(r'''
1205 STRING(REGEX MATCH "IDL" ISIDL ${name})
1208 # Set the type of the library
1210 newlines.append(r'''
1222 # Set sources for the library
1224 newlines.append(r'''
1226 FOREACH(src ${${amname}_SOURCES} ${dist_${amname}_SOURCES})
1227 GET_FILENAME_COMPONENT(ext ${src} EXT)
1229 IF(src STREQUAL trte.f)
1230 SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${src})
1231 STRING(REPLACE ".f" ".c" src ${src})
1232 SET(src ${CMAKE_CURRENT_BINARY_DIR}/${src})
1236 COMMAND f2c ${input}
1237 MAIN_DEPENDENCY ${input}
1239 ELSE(src STREQUAL trte.f)
1240 SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${src})
1241 STRING(REPLACE ".f" ".o" src ${src})
1242 SET(src ${CMAKE_CURRENT_BINARY_DIR}/${src})
1251 COMMAND ${F77} -c -o ${output} ${input}
1252 MAIN_DEPENDENCY ${input}
1254 ENDIF(src STREQUAL trte.f)
1255 ENDIF(ext STREQUAL .f)
1256 SET(srcs ${srcs} ${src})
1257 ENDFOREACH(src ${${amname}_SOURCES} ${dist_${amname}_SOURCES})
1259 FOREACH(f ${nodist_${amname}_SOURCES} ${BUILT_SOURCES})
1260 GET_FILENAME_COMPONENT(ext ${f} EXT)
1261 IF(ext STREQUAL .py)
1262 ELSE(ext STREQUAL .py)
1263 SET(build_srcs ${build_srcs} ${CMAKE_CURRENT_BINARY_DIR}/${f})
1264 ENDIF(ext STREQUAL .py)
1265 ENDFOREACH(f ${nodist_${amname}_SOURCES})
1266 SET(srcs ${build_srcs} ${srcs})
1269 # Add the library to cmake
1271 newlines.append(r'''
1272 ADD_LIBRARY(${name} ${type} ${srcs})
1275 # The compilation flags
1277 self.setCompilationFlags(key, newlines)
1279 newlines.append(r'''
1280 SET_TARGET_PROPERTIES(${name} PROPERTIES VERSION ${VERSION_INFO} SOVERSION ${SOVERSION_INFO})
1283 self.setLibAdd(key, newlines)
1285 if 1: # key != "noinst_LTLIBRARIES":
1286 if self.module == "medfile":
1287 newlines.append(r'''
1291 newlines.append(r'''
1292 SET(DEST lib/salome)
1295 newlines.append(r'''
1297 INSTALL(TARGETS ${name} DESTINATION ${DEST})
1299 if self.module == "geom":
1300 newlines.append(r'''
1302 STRING(REGEX MATCH "Export" ISExport ${name})
1304 INSTALL(FILES ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.dll DESTINATION ${DEST} RENAME lib${name}.dll)
1306 STRING(REGEX MATCH "Import" ISImport ${name})
1308 INSTALL(FILES ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.dll DESTINATION ${DEST} RENAME lib${name}.dll)
1313 newlines.append(r'''
1314 # IF(name STREQUAL SalomePyQt)
1315 # INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so DESTINATION ${DEST} RENAME ${name}.so)
1316 # ENDIF(name STREQUAL SalomePyQt)
1318 newlines.append(r'''
1319 ELSE(BEGIN_WITH_lib)
1321 newlines.append(r'''
1323 INSTALL(TARGETS ${name} DESTINATION lib/python${PYTHON_VERSION}/site-packages/salome)
1324 IF(CMAKE_BUILD_TYPE STREQUAL Release)
1325 INSTALL(FILES ${CMAKE_INSTALL_PREFIX}/lib/python${PYTHON_VERSION}/site-packages/salome/${name}.dll DESTINATION lib/python${PYTHON_VERSION}/site-packages/salome RENAME ${name}.pyd)
1326 ELSE(CMAKE_BUILD_TYPE STREQUAL Release)
1327 INSTALL(FILES ${CMAKE_INSTALL_PREFIX}/lib/python${PYTHON_VERSION}/site-packages/salome/${name}.dll DESTINATION lib/python${PYTHON_VERSION}/site-packages/salome RENAME ${name}_d.pyd)
1328 ENDIF(CMAKE_BUILD_TYPE STREQUAL Release)
1330 GET_TARGET_PROPERTY(version ${name} VERSION)
1331 GET_TARGET_PROPERTY(soversion ${name} SOVERSION)
1332 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so.${version} DESTINATION lib/python${PYTHON_VERSION}/site-packages/salome RENAME ${name}.so.${version})
1333 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so.${version} DESTINATION lib/python${PYTHON_VERSION}/site-packages/salome RENAME ${name}.so.${soversion})
1334 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so.${version} DESTINATION lib/python${PYTHON_VERSION}/site-packages/salome RENAME ${name}.so)
1337 newlines.append(r'''
1338 ENDIF(BEGIN_WITH_lib)
1342 newlines.append(r'''
1343 ENDFOREACH(amname ${%s})
1348 def addBinTarget(self, key, newlines):
1350 newlines.append(r'''
1351 FOREACH(amname ${bin_PROGRAMS})
1354 newlines.append(r'''
1355 SET(name "${amname}_exe")
1356 SET(srcs ${${amname}_SOURCES} ${dist_${amname}_SOURCES})
1357 LIST(LENGTH srcs nb)
1359 ADD_EXECUTABLE(${name} ${srcs})
1362 self.setCompilationFlags(key, newlines)
1364 self.setLibAdd(key, newlines)
1366 if self.module == "medfile":
1367 newlines.append(r'''
1371 newlines.append(r'''
1372 SET(DEST bin/salome)
1376 newlines.append(r'''
1378 INSTALL(TARGETS ${name} DESTINATION ${DEST})
1379 INSTALL(FILES ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.exe DESTINATION ${DEST} RENAME ${amname}.exe)
1380 INSTALL(CODE "FILE(REMOVE ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.exe)")
1383 SET(PERMS ${PERMS} OWNER_READ OWNER_WRITE OWNER_EXECUTE)
1384 SET(PERMS ${PERMS} GROUP_READ GROUP_EXECUTE)
1385 SET(PERMS ${PERMS} WORLD_READ WORLD_EXECUTE)
1386 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${name} DESTINATION ${DEST} PERMISSIONS ${PERMS} RENAME ${amname})
1390 newlines.append(r'''
1394 newlines.append(r'''
1395 ENDFOREACH(amname ${bin_PROGRAMS})
1400 def addInstallTarget(self, key, destination, newlines):
1401 newlines.append(r"FOREACH(f ${%s})"%(key))
1402 newlines.append(r'''
1405 newlines.append(r'''
1406 STRING(COMPARE EQUAL ${f} SALOMEconfig.h.in test_SALOMEconfig.h.in)
1407 IF(test_SALOMEconfig.h.in)
1408 INSTALL(FILES SALOMEconfig.ref.in DESTINATION ${DEST} RENAME SALOMEconfig.h.in)
1409 ELSE(test_SALOMEconfig.h.in)
1410 SET(dummy dummy-NOTFOUND)
1411 MARK_AS_ADVANCED(dummy)
1412 # FILE(REMOVE ${CMAKE_INSTALL_PREFIX}/${DEST}/${f})
1413 FIND_FILE(dummy ${f} PATHS ${CMAKE_CURRENT_SOURCE_DIR} NO_DEFAULT_PATH)
1416 if key in ['dist_salomescript_SCRIPTS']:
1417 newlines.append(r'''
1419 SET(PERMS ${PERMS} OWNER_READ OWNER_WRITE OWNER_EXECUTE)
1420 SET(PERMS ${PERMS} GROUP_READ GROUP_EXECUTE)
1421 SET(PERMS ${PERMS} WORLD_READ WORLD_EXECUTE)
1422 INSTALL(FILES ${f} DESTINATION ${DEST} PERMISSIONS ${PERMS})
1425 newlines.append(r'''
1426 INSTALL(FILES ${f} DESTINATION ${DEST})
1429 newlines.append(r'''
1431 GET_FILENAME_COMPONENT(ext ${f} EXT)
1432 IF(ext STREQUAL .qm)
1433 STRING(REGEX REPLACE .qm .ts input ${f})
1435 if self.module in ["kernel", "gui"]:
1436 newlines.append(r'''
1437 SET(input ${CMAKE_CURRENT_SOURCE_DIR}/resources/${input})
1440 newlines.append(r'''
1441 SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${input})
1444 newlines.append(r'''
1445 SET(output ${CMAKE_CURRENT_BINARY_DIR}/${f})
1446 # ADD_CUSTOM_COMMAND(
1448 # COMMAND ${QT_LRELEASE_EXECUTABLE} ${input} -qm ${output}
1449 # MAIN_DEPENDENCY ${input}
1451 EXECUTE_PROCESS(COMMAND ${QT_LRELEASE_EXECUTABLE} ${input} -qm ${output})
1452 ENDIF(ext STREQUAL .qm)
1453 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${f} DESTINATION ${DEST})
1455 ENDIF(test_SALOMEconfig.h.in)
1457 newlines.append(r'''
1458 GET_FILENAME_COMPONENT(ext ${f} EXT)
1459 IF(ext STREQUAL .py)
1460 INSTALL(CODE "SET(PYTHON_FILE ${f})")
1461 INSTALL(CODE "SET(CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})")
1462 INSTALL(CODE "SET(DEST ${DEST})")
1463 INSTALL(CODE "SET(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE})")
1465 if self.module == "kernel":
1467 IF(f STREQUAL SALOME_ContainerPy.py)
1468 ELSE(f STREQUAL SALOME_ContainerPy.py)
1469 IF(f STREQUAL am2cmake.py)
1470 ELSE(f STREQUAL am2cmake.py)
1471 INSTALL(SCRIPT ${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/install_and_compile_python_file.cmake)
1472 ENDIF(f STREQUAL am2cmake.py)
1473 ENDIF(f STREQUAL SALOME_ContainerPy.py)
1477 STRING(REPLACE "\\\\" "/" KERNEL_ROOT_DIR ${KERNEL_ROOT_DIR})
1478 INSTALL(SCRIPT ${KERNEL_ROOT_DIR}/salome_adm/cmake_files/install_and_compile_python_file.cmake)
1481 newlines.append(r'''
1482 ENDIF(ext STREQUAL .py)
1484 newlines.append(r"ENDFOREACH(f ${%s})"%(key))
1487 def writeListsFile(self):
1488 f = open(self.listsFile, "w")
1489 f.write(self.content)
1495 def convertAmFile(the_root, root, dirs, files, f, module):
1496 cmake = CMakeFile(the_root, root, dirs, files, f, module)
1497 cmake.writeListsFile()
1500 def usage(exit_status):
1501 from sys import exit
1502 from sys import argv
1503 print "Usage: %s --module"%(argv[0])
1507 if __name__ == "__main__":
1509 from sys import argv
1515 if module.find('--') != 0:
1519 if len(module) == 0:
1523 from os import getcwd
1527 for root, dirs, files in walk(the_root):
1529 # E.A. : Remove 'CVS' in dirs
1530 # E.A. : It allows to not recurse in CVS dirs
1531 # E.A. : See os module python documentation
1539 if f == "Makefile.am":
1540 convertAmFile(the_root, root, dirs, files, f, module)