1 # Copyright (C) 2012-2015 CEA/DEN, EDF R&D, OPEN CASCADE
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, or (at your option) any later version.
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.
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
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 # Author: Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
21 ####################################################################
25 # Generate C++ wrappings for *.sip files by processing them with sip.
27 # USAGE: SIP_WRAP_SIP(output_files sip_file [sip_file...] [OPTIONS options])
30 # output_files [out] variable where output file names are listed to
31 # sip_file [in] input sip file (a sequence can be provided)
32 # options [in] additional options to be specified to sip
35 # - Input files are considered relative to the current source directory.
36 # - Output files are generated in the current build directory.
39 # - Macro requires class(es) definition in the *.sip file(s) to be started
40 # on a new line without any preceeding characters.
41 # - Macro does not properly processes sip features which are wrapped
42 # with sip conditionals.
43 # - Macro works correctly only if one single sip module is processed
44 # (there's only one %Module directive within all input sip files).
47 # - Check if dependency of static sources on generated headers works properly:
48 # if header is changed, dependant sources should be recompiled.
49 # - Process sip conditionals.
50 # - Process several sip modules.
52 ####################################################################
53 MACRO(SIP_WRAP_SIP outfiles)
56 SET(_options -s ${_src_ext} -c .)
59 FOREACH(_input ${ARGN})
60 IF(${_input} STREQUAL "OPTIONS")
63 IF(${_get_options} STREQUAL "1")
64 SET(_options ${_options} ${_input})
66 SET(_sip_files ${_sip_files} ${_input})
71 FOREACH(_input ${_sip_files})
72 FILE(STRINGS ${_input} _sip_modules REGEX "%Module")
73 FILE(STRINGS ${_input} _sip_classes REGEX "^class ")
74 FOREACH(_sip_module ${_sip_modules})
75 STRING(REGEX MATCH ".*%Module *\\( *name=.*\\).*" _mod_name "${_sip_module}")
77 STRING(REGEX REPLACE ".*%Module *\\( *name=(.*).*\\).*" "\\1" _mod_name ${_sip_module})
79 STRING(REGEX REPLACE ".*%Module *(.*)" "\\1" _mod_name ${_sip_module})
81 SET(_mod_header "sipAPI${_mod_name}.h")
82 SET(_mod_source "sip${_mod_name}cmodule${_src_ext}")
83 LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/${_mod_source})
84 SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/${_mod_source})
85 SET(_module_input ${_input})
87 FOREACH(_sip_class ${_sip_classes})
88 STRING(REGEX MATCH ".*class +.* *:" _class_name "${_sip_class}")
90 STRING(REGEX REPLACE ".*class +(.*) *:.*" "\\1" _class_name ${_sip_class})
92 STRING(REGEX REPLACE ".*class *(.*)" "\\1" _class_name ${_sip_class})
94 STRING(STRIP ${_class_name} _class_name)
95 SET(_class_source "sip${_mod_name}${_class_name}${_src_ext}")
96 LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/${_class_source})
97 SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/${_class_source})
102 COMMAND ${SIP_EXECUTABLE} ${_options} ${CMAKE_CURRENT_SOURCE_DIR}/${_module_input}
103 MAIN_DEPENDENCY ${_module_input}
105 ENDMACRO(SIP_WRAP_SIP)