Salome HOME
Merging with V7_main branch.
[modules/hydro.git] / CMake / UsePyQt4EXT.cmake
1 # Copyright (C) 2012-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19 # Author: Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
20
21 ####################################################################
22 #
23 # PYQT4_WRAP_SIP_EXT macro
24 #
25 # Generate C++ wrappings for *.sip files by processing them with sip.
26 #
27 # USAGE: PYQT4_WRAP_SIP_EXT(output_files sip_files)
28 #
29 # ARGUMENTS:
30 #   output_files [out] variable where output file names are listed to
31 #   sip_files    [in]  list of *.sip files
32
33 # NOTES:
34 #   - Input files are considered relative to the current source directory.
35 #   - Output files are generated in the current build directory.
36 #   - This version of macro requires class(es) definition in the 
37 #     *.sip file to be started on a new line without any preceeding characters.
38 #
39 # TODO:
40 #   - Check if dependency of static sources on generated headers works properly:
41 #     if header is changed, dependant sources should be recompiled.
42
43 ####################################################################
44 MACRO(PYQT4_WRAP_SIP_EXT outfiles)
45   FOREACH(_input ${ARGN})
46     FILE(STRINGS ${_input} _sip_modules REGEX "%Module")
47     FILE(STRINGS ${_input} _sip_includes REGEX "%Include")
48     FILE(STRINGS ${_input} _sip_classes REGEX "^class ")
49     SET(_output)
50    
51     FOREACH(_sip_module ${_sip_modules})
52       STRING(REGEX MATCH ".*%Module *\\( *name=.*\\).*" _mod_name "${_sip_module}")
53       IF (_mod_name)
54         STRING(REGEX REPLACE ".*%Module *\\( *name=(.*).*\\).*" "\\1" _mod_name ${_sip_module})
55       ELSE()
56         STRING(REGEX REPLACE ".*%Module *(.*)" "\\1" _mod_name ${_sip_module})
57       ENDIF()
58       SET(_mod_header "sipAPI${_mod_name}.h")
59       SET(_mod_source "sip${_mod_name}cmodule${PYQT_CXX_EXT}")
60       LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/${_mod_source})
61       SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/${_mod_source})
62     ENDFOREACH()
63
64     FOREACH(_sip_include ${_sip_includes})
65       STRING(REGEX REPLACE ".*%Include +(.*)\\.sip *" "\\1" _include_name ${_sip_include})
66       SET(_include_source "sip${_mod_name}${_include_name}${PYQT_CXX_EXT}")
67       LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/${_include_source})
68       SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/${_include_source})
69     ENDFOREACH()
70
71     FOREACH(_sip_class ${_sip_classes})
72       STRING(REGEX MATCH ".*class +.* *:" _class_name "${_sip_class}")
73       IF (_class_name)
74         STRING(REGEX REPLACE ".*class +(.*) *:.*" "\\1" _class_name ${_sip_class})
75       ELSE()
76         STRING(REGEX REPLACE ".*class *(.*)" "\\1" _class_name ${_sip_class})
77       ENDIF()
78       STRING(STRIP ${_class_name} _class_name)
79       SET(_class_source "sip${_mod_name}${_class_name}${PYQT_CXX_EXT}")
80       LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/${_class_source})
81       SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/${_class_source})
82     ENDFOREACH()
83     
84     ADD_CUSTOM_COMMAND(
85       OUTPUT ${_output}
86       COMMAND ${SIP_EXECUTABLE} ${PYQT_SIPFLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/${_input}
87       MAIN_DEPENDENCY ${_input}
88       )
89       
90   ENDFOREACH()
91 ENDMACRO(PYQT4_WRAP_SIP_EXT)
92
93