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 content = content.replace("-no-undefined -version-info=0:0:0", "")
129 content = content.replace("-include SALOMEconfig.h", "")
132 # Compatibility medfile
134 content = content.replace("-no-undefined -version-info 0:0:0", "")
135 content = content.replace("-no-undefined -version-info 2:5:1", "")
138 # Compatibility netgen plugin
140 content = content.replace("../NETGEN/libNETGEN.la", "${NETGEN_LIBS}")
222 "SalomeCommunication",
224 "SalomeDSCContainer",
232 "SalomeLifeCycleCORBA",
234 "SalomeLoggerServer",
235 "SalomeNotification",
237 "SalomeResourcesManager",
239 "with_loggerTraceCollector",
291 "GEOMFiltersSelection",
315 "InterpGeometric2DAlg",
344 "SMESHFiltersSelection",
352 full_list = cas_list + kernel_list + gui_list
353 full_list += geom_list + med_list + smesh_list
359 # E.A. : sort by len before substitution ...
360 # Why ? Thing to "-lMEDWrapper" then "-lMEDWrapper_V2_1" substition
361 # And you understand ...
363 full_list.sort(cmp = lambda x, y : cmp(len(y), len(x)))
365 for key in full_list:
366 content = content.replace("-l%s"%(key), "${%s}"%(key))
370 # Split content in lines to treat each one separately
372 lines = content.split('\n')
375 # newlines contains the lines of the future CMakeLists.txt file
380 # opened_ifs is used to deals with nested conditionnals
385 # the __thedict__ dictionnary contains key, val
386 # of the Makefile.am file
388 self.__thedict__ = {}
391 # Initialize file ... mainly includes other cmake files
393 self.initialize(newlines)
396 # Do the job for each line
399 self.treatLine(line, newlines, opened_ifs)
403 # Finalize file ... it is in here the cmake job is done
405 self.finalize(newlines)
408 # Add a last CR at the end of the file
410 newlines.append('\n')
413 # Concatenate newlines into content
415 content = '\n'.join(newlines)
418 self.content = content
423 def initialize(self, newlines):
424 if self.root == self.the_root:
427 CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
428 IF(COMMAND cmake_policy)
429 cmake_policy(SET CMP0003 NEW)
430 ENDIF(COMMAND cmake_policy)
433 if self.module == "kernel":
435 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindPLATFORM.cmake)
436 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindPYTHON.cmake)
437 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindOMNIORB.cmake)
438 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindPTHREADS.cmake)
439 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindHDF5.cmake)
440 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindBOOST.cmake)
441 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindLIBXML2.cmake)
442 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindSWIG.cmake)
443 INCLUDE(${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/FindCPPUNIT.cmake)
448 SET(KERNEL_ROOT_DIR $ENV{KERNEL_ROOT_DIR})
449 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindPLATFORM.cmake)
450 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindPYTHON.cmake)
451 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindOMNIORB.cmake)
452 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindPTHREADS.cmake)
453 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindHDF5.cmake)
454 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindBOOST.cmake)
455 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindLIBXML2.cmake)
456 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindSWIG.cmake)
457 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindCPPUNIT.cmake)
458 INCLUDE(${KERNEL_ROOT_DIR}/salome_adm/cmake_files/FindKERNEL.cmake)
460 if self.module == "gui":
462 INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindCAS.cmake)
463 INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindQT4.cmake)
464 INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindOPENGL.cmake)
465 INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindVTK.cmake)
466 INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindQWT.cmake)
467 INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindSIPPYQT.cmake)
471 SET(GUI_ROOT_DIR $ENV{GUI_ROOT_DIR})
472 INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindCAS.cmake)
473 INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindQT4.cmake)
474 INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindOPENGL.cmake)
475 INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindVTK.cmake)
476 INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindQWT.cmake)
477 INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindSIPPYQT.cmake)
478 INCLUDE(${GUI_ROOT_DIR}/adm_local/cmake_files/FindGUI.cmake)
480 if self.module == "med":
482 INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindMEDFILE.cmake)
485 if self.module == "smesh":
487 SET(GEOM_ROOT_DIR $ENV{GEOM_ROOT_DIR})
488 SET(MED_ROOT_DIR $ENV{MED_ROOT_DIR})
489 INCLUDE(${GEOM_ROOT_DIR}/adm_local/cmake_files/FindGEOM.cmake)
490 INCLUDE(${MED_ROOT_DIR}/adm_local/cmake_files/FindMEDFILE.cmake)
491 INCLUDE(${MED_ROOT_DIR}/adm_local/cmake_files/FindMED.cmake)
494 if self.module == "netgenplugin":
496 SET(GEOM_ROOT_DIR $ENV{GEOM_ROOT_DIR})
497 SET(MED_ROOT_DIR $ENV{MED_ROOT_DIR})
498 SET(SMESH_ROOT_DIR $ENV{SMESH_ROOT_DIR})
499 INCLUDE(${GEOM_ROOT_DIR}/adm_local/cmake_files/FindGEOM.cmake)
500 INCLUDE(${MED_ROOT_DIR}/adm_local/cmake_files/FindMED.cmake)
501 INCLUDE(${SMESH_ROOT_DIR}/adm_local/cmake_files/FindSMESH.cmake)
502 INCLUDE(${CMAKE_SOURCE_DIR}/adm_local/cmake_files/FindNETGEN.cmake)
508 if self.module == "kernel":
513 set(XVERSION 0x040103)
515 elif self.module == "gui":
517 SET(GUI_ENABLE_CORBA ${CORBA_GEN})
518 SET(ENABLE_VTKVIEWER ON)
519 SET(ENABLE_SALOMEOBJECT ON)
520 SET(ENABLE_OCCVIEWER ON)
521 SET(ENABLE_GLVIEWER ON)
522 SET(ENABLE_PLOT2DVIEWER ON)
523 SET(ENABLE_PYCONSOLE ON)
524 SET(ENABLE_SUPERVGRAPHVIEWER ON)
525 # SET(ENABLE_QXGRAPHVIEWER ON)
528 elif self.module == "geom":
530 SET(GEOM_ENABLE_GUI ON)
533 elif self.module == "medfile":
535 SET(MED_NUM_MAJEUR 2)
536 SET(MED_NUM_MINEUR 3)
537 SET(MED_NUM_RELEASE 5)
540 SET(FLIBS -lgfortranbegin -lgfortran)
544 elif self.module == "med":
546 SET(MED_ENABLE_KERNEL ON)
547 SET(MED_ENABLE_GUI ON)
550 elif self.module == "smesh":
552 SET(SMESH_ENABLE_GUI ON)
555 elif self.module == "netgenplugin":
557 SET(NETGENPLUGIN_ENABLE_GUI ON)
572 def treatLine(self, line, newlines, opened_ifs):
575 # Print the comment above the line itself
577 if line.find('#') >= 0:
578 fields = line.split('#')
580 comment = '#'.join([''] + fields[1:])
581 newlines.append(comment)
587 # If the line begins with 'include ', just comment it
589 if line.find("include ") == 0:
590 newlines.append("# " + line)
594 # If the line begins with '-include', just comment it
596 if line.find("-include") == 0:
597 newlines.append("# " + line)
601 # If the line is a definition of a make rule, just comment it
603 if line.count(':') == 1:
604 newlines.append("# " + line)
610 if line.find('install-exec-local:') == 0:
611 newlines.append("# " + line)
615 # If the line begin by a tabulation, consider it's a makefile command and comment it
617 if line.find("\t") == 0:
618 newlines.append("# " + line)
622 # Replace the $(TOTO) by ${TOTO}
623 # Replace the @TOTO@ by ${TOTO}
625 line = p_dollar.sub(r"${\1}", line)
626 line = p_arobas.sub(r"${\1}", line)
629 line = line.replace(r"${top_builddir}", r"${CMAKE_BINARY_DIR}")
630 line = line.replace(r"${top_srcdir}", r"${CMAKE_SOURCE_DIR}")
631 line = line.replace(r"${srcdir}", r"${CMAKE_CURRENT_SOURCE_DIR}")
632 line = line.replace(r"${builddir}", r"${CMAKE_CURRENT_BINARY_DIR}")
633 line = line.replace(r"${datadir}", r"${CMAKE_INSTALL_PREFIX}/share")
636 # Check if the line is a 'if' condition
637 # If yes, replace it by a cmake grammar
639 match = p_if.match(line)
641 theif = match.group("val")
643 theif = "NOT " + theif[1:]
645 line = p_if.sub(r"IF(%s)"%(theif), line)
646 opened_ifs.append(theif)
647 newlines.append(line)
651 # Check if the line is a 'else' condition
652 # If yes, replace it by a cmake grammar
654 match = p_else.match(line)
656 line = "ELSE(%s)"%(opened_ifs[-1])
657 newlines.append(line)
661 # Check if the line is a 'endif' condition
662 # If yes, replace it by a cmake grammar
664 match = p_endif.match(line)
666 line = "ENDIF(%s)"%(opened_ifs[-1])
668 newlines.append(line)
672 # Check if the line is an attribution '=' or '+='
674 match = p_attribution.match(line)
676 self.treatAttribution(match, newlines)
680 newlines.append(line)
685 def treatAttribution(self, match, newlines):
687 spaces = match.group("spaces")
688 key = match.group("key")
689 method = match.group("method")
690 value = match.group("value")
691 # print [spaces, key, method, value]
694 # Open cmake SET command
696 newlines.append(spaces + "SET(" + key)
699 # If method is '+=', put the previous definition as first value
702 newlines.append("%s ${%s}"%(spaces, key))
706 fields = value.split()
707 for i in range(len(fields)):
708 newlines.append("%s %s"%(spaces, fields[i]))
714 # The try: except KeyError is here if the +=
715 # is an error which occurs in salome ...
718 self.__thedict__[key] += fields[:]
720 self.__thedict__[key] = fields[:]
724 self.__thedict__[key] = fields[:]
728 # Close cmake SET command
731 newlines.append("%s)"%(spaces))
735 def finalize(self, newlines):
738 # Convert the .in files in build dir
742 if f == "sstream.in":
744 if f in ["runContainer.in", "stopContainer.in"]:
745 if self.module == "med":
746 if self.root[-3:] == "csh":
750 if f == "SALOMEconfig.ref.in":
751 out = "SALOMEconfig.h"
756 SET(input ${CMAKE_CURRENT_SOURCE_DIR}/%s)
759 SET(output ${CMAKE_CURRENT_BINARY_DIR}/%s)
762 MESSAGE(STATUS "Creation of ${output}")
763 CONFIGURE_FILE(${input} ${output})
769 # convert the SUBDIRS in cmake grammar
771 if 1: # self.__thedict__.has_key("SUBDIRS"):
773 FOREACH(dir ${SUBDIRS})
774 IF(NOT dir STREQUAL .)
775 ADD_SUBDIRECTORY(${dir})
776 ENDIF(NOT dir STREQUAL .)
777 ENDFOREACH(dir ${SUBDIRS})
783 for key in ["lib_LTLIBRARIES", "noinst_LTLIBRARIES", "salomepyexec_LTLIBRARIES"]:
784 if self.__thedict__.has_key(key):
785 self.addLibTarget(key, newlines)
791 for key in ["bin_PROGRAMS"]:
792 if self.__thedict__.has_key(key):
793 self.addBinTarget(key, newlines)
799 if self.__thedict__.has_key("BASEIDL_FILES"):
800 if not self.__thedict__.has_key("IDL_FILES"):
801 self.__thedict__["IDL_FILES"] = self.__thedict__["BASEIDL_FILES"]
803 SET(IDL_FILES ${BASEIDL_FILES})
812 if self.__thedict__.has_key(key):
814 FOREACH(input ${IDL_FILES})
815 STRING(REGEX REPLACE ".idl" "" base ${input})
816 SET(src ${CMAKE_CURRENT_BINARY_DIR}/${base}SK.cc)
818 SET(dynsrc ${CMAKE_CURRENT_BINARY_DIR}/${base}DynSK.cc)
819 SET(outputs ${outputs} ${dynsrc})
822 COMMAND ${OMNIORB_IDL} ${IDLCXXFLAGS} ${OMNIORB_IDLCXXFLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/${input}
823 MAIN_DEPENDENCY ${input}
825 install(FILES ${input} DESTINATION idl/salome)
826 SET(IDL_HEADER ${CMAKE_CURRENT_BINARY_DIR}/${base}.hh)
827 install(FILES ${IDL_HEADER} DESTINATION include/salome)
828 INSTALL(CODE "SET(IDL_FILE ${input})")
829 INSTALL(CODE "SET(DIR lib/python${PYTHON_VERSION}/site-packages/salome)")
830 INSTALL(CODE "SET(CMAKE_CURRENT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})")
831 INSTALL(CODE "SET(OMNIORB_IDL_PYTHON ${OMNIORB_IDL_PYTHON})")
834 FOREACH(f ${IDLPYFLAGS})
835 SET(flags "${flags} ${f}")
836 ENDFOREACH(f ${IDLPYFLAGS})
837 SET(IDLPYFLAGS ${flags})
838 STRING(REPLACE "\\\\" "/" IDLPYFLAGS ${IDLPYFLAGS})
839 INSTALL(CODE "SET(IDLPYFLAGS ${IDLPYFLAGS})")
842 if self.module == "kernel":
844 INSTALL(SCRIPT ${CMAKE_SOURCE_DIR}/salome_adm/cmake_files/install_python_from_idl.cmake)
848 STRING(REPLACE "\\\\" "/" KERNEL_ROOT_DIR ${KERNEL_ROOT_DIR})
849 INSTALL(SCRIPT ${KERNEL_ROOT_DIR}/salome_adm/cmake_files/install_python_from_idl.cmake)
853 ENDFOREACH(input ${IDL_FILES})
859 for key in ["SWIG_SRC", "SWIGSOURCES", "SWIG_DEF"]:
860 if self.__thedict__.has_key(key):
862 SET(SWIG_SOURCES ${%s})
864 self.__thedict__["SWIG_SOURCES"] = self.__thedict__[key]
870 if self.__thedict__.has_key("SWIG_SOURCES"):
872 IF(SWIG_SOURCES MATCHES ";")
873 STRING(REGEX REPLACE ";.*" "" SWIG_SOURCES_FIRST "${SWIG_SOURCES}")
874 ELSE(SWIG_SOURCES MATCHES ";")
875 SET(SWIG_SOURCES_FIRST "${SWIG_SOURCES}")
876 ENDIF(SWIG_SOURCES MATCHES ";")
879 COMMAND ${SWIG_EXECUTABLE} ${SWIG_FLAGS} ${MY_SWIG_FLAGS} -o ${build_srcs} ${CMAKE_CURRENT_SOURCE_DIR}/${SWIG_SOURCES_FIRST}
880 MAIN_DEPENDENCY ${SWIG_SOURCES}
888 if self.__thedict__.has_key(key):
890 FOREACH(output ${MOC_FILES})
891 STRING(REGEX REPLACE _moc.cxx .h input ${output})
892 SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${input})
893 SET(output ${CMAKE_CURRENT_BINARY_DIR}/${output})
896 COMMAND ${QT_MOC_EXECUTABLE} ${MOC_FLAGS} ${input} -o ${output}
897 MAIN_DEPENDENCY ${input}
899 ENDFOREACH(output ${MOC_FILES})
906 if self.__thedict__.has_key(key):
908 FOREACH(output ${UIC_FILES})
909 STRING(REPLACE "ui_" "" input ${output})
910 STRING(REPLACE ".h" ".ui" input ${input})
911 SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${input})
912 SET(output ${CMAKE_CURRENT_BINARY_DIR}/${output})
915 COMMAND ${QT_UIC_EXECUTABLE} -o ${output} ${input}
916 MAIN_DEPENDENCY ${input}
918 ENDFOREACH(output ${UIC_FILES})
925 if self.__thedict__.has_key(key):
927 FOREACH(output ${QRC_FILES})
928 STRING(REGEX REPLACE "qrc_" "" input ${output})
929 STRING(REGEX REPLACE ".cxx" ".qrc" input ${input})
930 STRING(REGEX REPLACE ".qrc" "" name ${input})
931 SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${input})
932 SET(output ${CMAKE_CURRENT_BINARY_DIR}/${output})
935 COMMAND ${QT_RCC_EXECUTABLE} ${input} -o ${output} -name ${name}
936 MAIN_DEPENDENCY ${input}
938 ENDFOREACH(output ${QRC_FILES})
945 if self.__thedict__.has_key(key):
947 FOREACH(input ${SIP_FILES})
948 SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${input})
950 FOREACH(out ${SIP_SRC})
951 SET(output ${output} ${CMAKE_CURRENT_BINARY_DIR}/${out})
952 ENDFOREACH(out ${SIP_SRC})
955 COMMAND ${SIP_EXECUTABLE} ${PYQT_SIPFLAGS} ${input}
956 MAIN_DEPENDENCY ${input}
958 ENDFOREACH(input ${SIP_FILES})
963 # Treat the install targets
966 "salomeadmux_DATA" : "salome_adm/unix",
967 "dist_salomeadmux_DATA" : "salome_adm/unix",
968 "dist_salome_cmake_DATA" : "salome_adm/cmake_files",
969 "dist_salomem4_DATA" : "salome_adm/unix/config_files",
970 "dist_salome4depr_DATA" : "salome_adm/unix/config_files/DEPRECATED",
971 "dist_admlocalm4_DATA" : "adm_local/unix/config_files",
972 "dist_admlocal_cmake_DATA" : "adm_local/cmake_files",
973 "salomeinclude_DATA" : "include/salome",
974 "salomeinclude_HEADERS" : "include/salome",
975 "dist_salomeres_DATA" : "share/salome/resources/%s"%(self.module),
976 "nodist_salomeres_DATA" : "share/salome/resources/%s"%(self.module),
977 "nodist_salomeres_SCRIPTS" : "share/salome/resources/%s"%(self.module),
978 "dist_salomescript_SCRIPTS" : "bin/salome",
979 "dist_salomescript_DATA" : "bin/salome",
980 "dist_salomescript_PYTHON" : "bin/salome",
981 "nodist_salomescript_DATA" : "bin/salome",
982 "salomepython_PYTHON" : "lib/python${PYTHON_VERSION}/site-packages/salome",
983 "nodist_salomepython_PYTHON" : "lib/python${PYTHON_VERSION}/site-packages/salome",
984 "sharedpkgpython_PYTHON" : "lib/python${PYTHON_VERSION}/site-packages/salome/shared_modules",
986 if self.module == "medfile":
988 "include_HEADERS" : "include",
989 "nodist_include_HEADERS" : "include",
990 "bin_SCRIPTS" : "bin",
991 "doc_DATA" : "${docdir}",
994 for key, value in d.items():
995 if self.__thedict__.has_key(key):
996 self.addInstallTarget(key, value, newlines)
1003 def setLibAdd(self, key, newlines):
1005 newlines.append(r'''
1009 newlines.append(r'''
1011 SET(libadd ${libadd} Userenv.lib Ws2_32.lib)
1013 SET(libadd ${libadd} -ldl -lpthread)
1017 newlines.append(r'''
1020 SET(targets ${targets} MEFISTO2D)
1021 FOREACH(target ${targets})
1022 IF(name STREQUAL ${target})
1023 SET(dir $ENV{F2CHOME})
1024 STRING(REPLACE "\\\\" "/" dir ${dir})
1025 SET(libadd ${libadd} ${dir}/LIBF77.lib)
1026 SET(libadd ${libadd} ${dir}/LIBI77.lib)
1027 ENDIF(name STREQUAL ${target})
1028 ENDFOREACH(target ${targets})
1032 newlines.append(r'''
1033 SET(libs ${${amname}_LIBADD} ${${amname}_LDADD} ${${amname}_LDFLAGS})
1035 if key == "bin_PROGRAMS":
1036 newlines.append(r'''
1037 SET(libs ${libs} ${LDADD})
1041 newlines.append(r'''
1042 FOREACH(lib ${libs})
1043 GET_FILENAME_COMPONENT(ext ${lib} EXT)
1044 IF(ext STREQUAL .la)
1045 GET_FILENAME_COMPONENT(lib ${lib} NAME_WE)
1046 STRING(REPLACE "lib" "" lib ${lib})
1047 ENDIF(ext STREQUAL .la)
1049 SET(vars -Xlinker -export-dynamic -module -Wl,-E)
1050 SET(vars ${vars} -lutil -lm)
1054 ENDIF(lib STREQUAL v)
1055 ENDFOREACH(v ${vars})
1057 SET(libadd ${libadd} ${lib})
1058 ENDFOREACH(lib ${libs})
1059 TARGET_LINK_LIBRARIES(${name} ${PTHREADS_LIBRARY} ${libadd})
1062 newlines.append(r'''
1065 SET(targets ${targets} SalomeHDFPersist)
1066 SET(targets ${targets} medC)
1067 SET(targets ${targets} medimport)
1068 SET(targets ${targets} medimportcxx)
1069 FOREACH(target ${targets})
1070 IF(name STREQUAL ${target})
1071 SET_TARGET_PROPERTIES(${name} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:LIBCMTD")
1072 ENDIF(name STREQUAL ${target})
1073 ENDFOREACH(target ${targets})
1075 SET(targets ${targets} MEFISTO2D)
1076 FOREACH(target ${targets})
1077 IF(name STREQUAL ${target})
1078 SET_TARGET_PROPERTIES(${name} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:MSVCRT")
1079 ENDIF(name STREQUAL ${target})
1080 ENDFOREACH(target ${targets})
1084 if self.module == "med":
1085 newlines.append(r'''
1087 SET_TARGET_PROPERTIES(${name} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:LIBCMTD")
1094 def setCompilationFlags(self, key, newlines):
1095 newlines.append(r'''
1099 SET(targets ${targets} SalomeIDLKernel)
1100 SET(targets ${targets} SalomeDS)
1101 SET(targets ${targets} SALOMEDS_Client_exe)
1102 SET(targets ${targets} SalomeIDLGEOM)
1103 SET(targets ${targets} GEOMEngine)
1104 SET(targets ${targets} MEDEngine)
1105 SET(targets ${targets} SMESHEngine)
1106 SET(targets ${targets} SMESH)
1107 FOREACH(target ${targets})
1108 IF(name STREQUAL ${target})
1109 SET(var ${var} -DNOGDI)
1110 ENDIF(name STREQUAL ${target})
1111 ENDFOREACH(target ${targets})
1115 newlines.append(r'''
1118 SET(targets ${targets} MEFISTO2D)
1119 FOREACH(target ${targets})
1120 IF(name STREQUAL ${target})
1121 SET(dir $ENV{F2CHOME})
1122 STRING(REPLACE "\\\\" "/" dir ${dir})
1123 SET(var ${var} -I${dir})
1124 ENDIF(name STREQUAL ${target})
1125 ENDFOREACH(target ${targets})
1129 newlines.append(r'''
1131 SET(var ${var} -D_USE_MATH_DEFINES)
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} ${PTHREADS_INCLUDES})
1150 SET(var ${var} ${${amname}_CPPFLAGS})
1151 SET(var ${var} ${${amname}_CXXFLAGS})
1152 SET(var ${var} ${${amname}_CFLAGS})
1155 SET(flags "${flags} ${f}")
1156 ENDFOREACH(f ${var})
1157 SET_TARGET_PROPERTIES(${name} PROPERTIES COMPILE_FLAGS "${flags}")
1161 def addLibTarget(self, key, newlines):
1162 newlines.append(r'''
1163 FOREACH(amname ${%s})
1166 # Replace .la by _la ...
1168 newlines.append(r'''
1169 STRING(REPLACE .la _la amname ${amname})
1172 # Remove the _la for the cmake name
1174 newlines.append(r'''
1175 STRING(LENGTH ${amname} len)
1176 MATH(EXPR newlen "${len}-3")
1177 STRING(SUBSTRING ${amname} 0 ${newlen} name)
1180 # Does the target begins with lib ??
1181 # If yes, remove lib at beginning for cmake name
1183 newlines.append(r'''
1184 STRING(REGEX MATCH "^lib" BEGIN_WITH_lib ${name})
1186 STRING(LENGTH ${name} len)
1187 MATH(EXPR newlen "${len}-3")
1188 STRING(SUBSTRING ${name} 3 ${newlen} name)
1189 ENDIF(BEGIN_WITH_lib)
1192 # Does the target is an idl library
1194 newlines.append(r'''
1195 STRING(REGEX MATCH "IDL" ISIDL ${name})
1198 # Set the type of the library
1200 newlines.append(r'''
1212 # Set sources for the library
1214 newlines.append(r'''
1216 FOREACH(src ${${amname}_SOURCES} ${dist_${amname}_SOURCES})
1217 GET_FILENAME_COMPONENT(ext ${src} EXT)
1219 IF(src STREQUAL trte.f)
1220 SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${src})
1221 STRING(REPLACE ".f" ".c" src ${src})
1222 SET(src ${CMAKE_CURRENT_BINARY_DIR}/${src})
1226 COMMAND f2c ${input}
1227 MAIN_DEPENDENCY ${input}
1229 ELSE(src STREQUAL trte.f)
1230 SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${src})
1231 STRING(REPLACE ".f" ".o" src ${src})
1232 SET(src ${CMAKE_CURRENT_BINARY_DIR}/${src})
1241 COMMAND ${F77} -c -o ${output} ${input}
1242 MAIN_DEPENDENCY ${input}
1244 ENDIF(src STREQUAL trte.f)
1245 ENDIF(ext STREQUAL .f)
1246 SET(srcs ${srcs} ${src})
1247 ENDFOREACH(src ${${amname}_SOURCES} ${dist_${amname}_SOURCES})
1249 FOREACH(f ${nodist_${amname}_SOURCES} ${BUILT_SOURCES})
1250 GET_FILENAME_COMPONENT(ext ${f} EXT)
1251 IF(ext STREQUAL .py)
1252 ELSE(ext STREQUAL .py)
1253 SET(build_srcs ${build_srcs} ${CMAKE_CURRENT_BINARY_DIR}/${f})
1254 ENDIF(ext STREQUAL .py)
1255 ENDFOREACH(f ${nodist_${amname}_SOURCES})
1256 SET(srcs ${build_srcs} ${srcs})
1259 # Add the library to cmake
1261 newlines.append(r'''
1262 ADD_LIBRARY(${name} ${type} ${srcs})
1265 # The compilation flags
1267 self.setCompilationFlags(key, newlines)
1269 newlines.append(r'''
1270 SET_TARGET_PROPERTIES(${name} PROPERTIES VERSION 0.0.0 SOVERSION 0)
1271 FOREACH(lib medC med)
1272 IF(lib STREQUAL ${name})
1273 SET_TARGET_PROPERTIES(${name} PROPERTIES VERSION 1.1.5 SOVERSION 1)
1274 ENDIF(lib STREQUAL ${name})
1275 ENDFOREACH(lib medC med)
1278 from os.path import basename
1279 upper_name = basename(self.root).upper()
1281 if upper_name in ["2.1.X", "2.3.1"]:
1282 upper_name = "D_" + upper_name
1285 newlines.append(r'''
1286 SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL %s_EXPORTS)
1289 newlines.append(r'''
1290 IF(name STREQUAL SalomeLauncher)
1291 SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL SALOME%s_EXPORTS)
1292 ENDIF(name STREQUAL SalomeLauncher)
1294 newlines.append(r'''
1295 IF(name STREQUAL SalomeResourcesManager)
1296 SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL SALOME%s_EXPORTS)
1297 ENDIF(name STREQUAL SalomeResourcesManager)
1299 newlines.append(r'''
1300 IF(name STREQUAL GEOMObject)
1301 SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL GEOM_%s_EXPORTS)
1302 ENDIF(name STREQUAL GEOMObject)
1304 newlines.append(r'''
1305 IF(name STREQUAL medC)
1306 SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MEDC_DLL_EXPORTS)
1307 ENDIF(name STREQUAL medC)
1309 newlines.append(r'''
1310 IF(name STREQUAL med)
1311 SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MED_DLL_EXPORTS)
1312 ENDIF(name STREQUAL med)
1314 newlines.append(r'''
1315 IF(name STREQUAL medimport)
1316 SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MEDIMPORT_DLL_EXPORTS)
1317 ENDIF(name STREQUAL medimport)
1319 newlines.append(r'''
1320 IF(name STREQUAL medimportcxx)
1321 SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MEDIMPORTCXX_DLL_EXPORTS)
1322 ENDIF(name STREQUAL medimportcxx)
1325 newlines.append(r'''
1326 IF(name STREQUAL MEDWrapperBase)
1327 SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MEDWRAPPER_BASE_EXPORTS)
1328 ENDIF(name STREQUAL MEDWrapperBase)
1330 newlines.append(r'''
1331 IF(name STREQUAL MEDWrapper_V2_1)
1332 SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MEDWRAPPER_V2_1_EXPORTS)
1333 ENDIF(name STREQUAL MEDWrapper_V2_1)
1335 newlines.append(r'''
1336 IF(name STREQUAL med_V2_1)
1337 SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MEDWRAPPER_V2_1_CORE_EXPORTS)
1338 ENDIF(name STREQUAL med_V2_1)
1340 newlines.append(r'''
1341 IF(name STREQUAL MEDWrapper_V2_2)
1342 SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MEDWRAPPER_V2_2_EXPORTS)
1343 ENDIF(name STREQUAL MEDWrapper_V2_2)
1345 newlines.append(r'''
1346 IF(name STREQUAL MEDWrapper)
1347 SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MEDWRAPPER_FACTORY_EXPORTS)
1348 ENDIF(name STREQUAL MEDWrapper)
1350 newlines.append(r'''
1351 IF(name STREQUAL interpkernelbases)
1352 SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL INTERPKERNELBASES_EXPORTS)
1353 ENDIF(name STREQUAL interpkernelbases)
1354 IF(name STREQUAL InterpGeometric2DAlg)
1355 SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL INTERPKERNELGEOMETRIC2D_EXPORTS)
1356 ENDIF(name STREQUAL InterpGeometric2DAlg)
1357 IF(name STREQUAL interpkernel)
1358 SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL INTERPKERNEL_EXPORTS)
1359 ENDIF(name STREQUAL interpkernel)
1360 IF(name STREQUAL MEDClientcmodule)
1361 SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MEDCLIENT_EXPORTS)
1362 ENDIF(name STREQUAL MEDClientcmodule)
1365 newlines.append(r'''
1366 IF(name STREQUAL SMESHControls)
1367 SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL SMESHCONTROLS_EXPORTS)
1368 ENDIF(name STREQUAL SMESHControls)
1370 newlines.append(r'''
1371 IF(name STREQUAL MeshDriver)
1372 SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MESHDRIVER_EXPORTS)
1373 ENDIF(name STREQUAL MeshDriver)
1375 newlines.append(r'''
1376 IF(name STREQUAL MeshDriverMED)
1377 SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MESHDRIVERMED_EXPORTS)
1378 ENDIF(name STREQUAL MeshDriverMED)
1380 newlines.append(r'''
1381 IF(name STREQUAL MeshDriverDAT)
1382 SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MESHDRIVERDAT_EXPORTS)
1383 ENDIF(name STREQUAL MeshDriverDAT)
1385 newlines.append(r'''
1386 IF(name STREQUAL MeshDriverUNV)
1387 SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MESHDRIVERUNV_EXPORTS)
1388 ENDIF(name STREQUAL MeshDriverUNV)
1390 newlines.append(r'''
1391 IF(name STREQUAL MeshDriverSTL)
1392 SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MESHDRIVERSTL_EXPORTS)
1393 ENDIF(name STREQUAL MeshDriverSTL)
1395 newlines.append(r'''
1396 IF(name STREQUAL MEFISTO2D)
1397 SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL MEFISTO2D_EXPORTS)
1398 ENDIF(name STREQUAL MEFISTO2D)
1400 newlines.append(r'''
1401 IF(name STREQUAL SMESHObject)
1402 SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL SMESHOBJECT_EXPORTS)
1403 ENDIF(name STREQUAL SMESHObject)
1405 newlines.append(r'''
1406 IF(name STREQUAL _libSMESH_Swig)
1407 SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL SMESH_SWIG_EXPORTS)
1408 ENDIF(name STREQUAL _libSMESH_Swig)
1410 newlines.append(r'''
1411 IF(name STREQUAL NETGENPluginGUI)
1412 SET_TARGET_PROPERTIES(${name} PROPERTIES DEFINE_SYMBOL NETGENPLUGIN_GUI_EXPORTS)
1413 ENDIF(name STREQUAL NETGENPluginGUI)
1416 self.setLibAdd(key, newlines)
1418 if 1: # key != "noinst_LTLIBRARIES":
1419 if self.module == "medfile":
1420 newlines.append(r'''
1424 newlines.append(r'''
1425 SET(DEST lib/salome)
1428 newlines.append(r'''
1430 INSTALL(TARGETS ${name} DESTINATION ${DEST})
1432 if self.module == "geom":
1433 newlines.append(r'''
1435 STRING(REGEX MATCH "Export" ISExport ${name})
1437 INSTALL(FILES ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.dll DESTINATION ${DEST} RENAME lib${name}.dll)
1439 STRING(REGEX MATCH "Import" ISImport ${name})
1441 INSTALL(FILES ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.dll DESTINATION ${DEST} RENAME lib${name}.dll)
1446 newlines.append(r'''
1447 IF(name STREQUAL SalomePyQt)
1448 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so DESTINATION ${DEST} RENAME ${name}.so)
1449 ENDIF(name STREQUAL SalomePyQt)
1450 ELSE(BEGIN_WITH_lib)
1452 INSTALL(TARGETS ${name} DESTINATION lib/python${PYTHON_VERSION}/site-packages/salome)
1453 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)
1455 GET_TARGET_PROPERTY(version ${name} VERSION)
1456 GET_TARGET_PROPERTY(soversion ${name} SOVERSION)
1457 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so.${version} DESTINATION lib/python${PYTHON_VERSION}/site-packages/salome RENAME ${name}.so.${version})
1458 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so.${version} DESTINATION lib/python${PYTHON_VERSION}/site-packages/salome RENAME ${name}.so.${soversion})
1459 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so.${version} DESTINATION lib/python${PYTHON_VERSION}/site-packages/salome RENAME ${name}.so)
1461 ENDIF(BEGIN_WITH_lib)
1465 newlines.append(r'''
1466 ENDFOREACH(amname ${%s})
1471 def addBinTarget(self, key, newlines):
1473 newlines.append(r'''
1474 FOREACH(amname ${bin_PROGRAMS})
1477 newlines.append(r'''
1478 SET(name "${amname}_exe")
1479 SET(srcs ${${amname}_SOURCES} ${dist_${amname}_SOURCES})
1480 LIST(LENGTH srcs nb)
1482 ADD_EXECUTABLE(${name} ${srcs})
1485 self.setCompilationFlags(key, newlines)
1487 self.setLibAdd(key, newlines)
1489 if self.module == "medfile":
1490 newlines.append(r'''
1494 newlines.append(r'''
1495 SET(DEST bin/salome)
1499 newlines.append(r'''
1501 INSTALL(TARGETS ${name} DESTINATION ${DEST})
1502 INSTALL(FILES ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.exe DESTINATION ${DEST} RENAME ${amname}.exe)
1503 INSTALL(CODE "FILE(REMOVE ${CMAKE_INSTALL_PREFIX}/${DEST}/${name}.exe)")
1506 SET(PERMS ${PERMS} OWNER_READ OWNER_WRITE OWNER_EXECUTE)
1507 SET(PERMS ${PERMS} GROUP_READ GROUP_EXECUTE)
1508 SET(PERMS ${PERMS} WORLD_READ WORLD_EXECUTE)
1509 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${name} DESTINATION ${DEST} PERMISSIONS ${PERMS} RENAME ${amname})
1513 newlines.append(r'''
1517 newlines.append(r'''
1518 ENDFOREACH(amname ${bin_PROGRAMS})
1523 def addInstallTarget(self, key, destination, newlines):
1524 newlines.append(r"FOREACH(f ${%s})"%(key))
1525 newlines.append(r'''
1528 newlines.append(r'''
1529 STRING(COMPARE EQUAL ${f} SALOMEconfig.h.in test_SALOMEconfig.h.in)
1530 IF(test_SALOMEconfig.h.in)
1531 INSTALL(FILES SALOMEconfig.ref.in DESTINATION ${DEST} RENAME SALOMEconfig.h.in)
1532 ELSE(test_SALOMEconfig.h.in)
1533 SET(dummy dummy-NOTFOUND)
1534 MARK_AS_ADVANCED(dummy)
1535 # FILE(REMOVE ${CMAKE_INSTALL_PREFIX}/${DEST}/${f})
1536 FIND_FILE(dummy ${f} PATHS ${CMAKE_CURRENT_SOURCE_DIR} NO_DEFAULT_PATH)
1539 if key in ['dist_salomescript_SCRIPTS']:
1540 newlines.append(r'''
1542 SET(PERMS ${PERMS} OWNER_READ OWNER_WRITE OWNER_EXECUTE)
1543 SET(PERMS ${PERMS} GROUP_READ GROUP_EXECUTE)
1544 SET(PERMS ${PERMS} WORLD_READ WORLD_EXECUTE)
1545 INSTALL(FILES ${f} DESTINATION ${DEST} PERMISSIONS ${PERMS})
1548 newlines.append(r'''
1549 INSTALL(FILES ${f} DESTINATION ${DEST})
1552 newlines.append(r'''
1554 GET_FILENAME_COMPONENT(ext ${f} EXT)
1555 IF(ext STREQUAL .qm)
1556 STRING(REGEX REPLACE .qm .ts input ${f})
1558 if self.module in ["kernel", "gui"]:
1559 newlines.append(r'''
1560 SET(input ${CMAKE_CURRENT_SOURCE_DIR}/resources/${input})
1563 newlines.append(r'''
1564 SET(input ${CMAKE_CURRENT_SOURCE_DIR}/${input})
1567 newlines.append(r'''
1568 SET(output ${CMAKE_CURRENT_BINARY_DIR}/${f})
1569 # ADD_CUSTOM_COMMAND(
1571 # COMMAND ${QT_LRELEASE_EXECUTABLE} ${input} -qm ${output}
1572 # MAIN_DEPENDENCY ${input}
1574 EXECUTE_PROCESS(COMMAND ${QT_LRELEASE_EXECUTABLE} ${input} -qm ${output})
1575 ENDIF(ext STREQUAL .qm)
1576 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${f} DESTINATION ${DEST})
1578 ENDIF(test_SALOMEconfig.h.in)
1580 newlines.append(r"ENDFOREACH(f ${%s})"%(key))
1583 def writeListsFile(self):
1584 f = open(self.listsFile, "w")
1585 f.write(self.content)
1591 def convertAmFile(the_root, root, dirs, files, f, module):
1592 cmake = CMakeFile(the_root, root, dirs, files, f, module)
1593 cmake.writeListsFile()
1596 def usage(exit_status):
1597 from sys import exit
1598 from sys import argv
1599 print "Usage: %s --module"%(argv[0])
1603 if __name__ == "__main__":
1605 from sys import argv
1611 if module.find('--') != 0:
1615 if len(module) == 0:
1619 from os import getcwd
1623 for root, dirs, files in walk(the_root):
1624 from os.path import basename
1625 if basename(root) == "CVS": continue
1627 from os.path import basename
1628 if basename(f) == "Makefile.am":
1629 convertAmFile(the_root, root, dirs, files, f, module)