1 # Copyright (C) 2012-2013 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.
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 ####################################################################
23 # _PYQT4_WRAP_GET_UNIQUE_TARGET_NAME: internal function
25 # Used to generate unique custom target name for usage in
26 # PYQT4_WRAP_UIC macro.
28 # USAGE: _PYQT4_WRAP_GET_UNIQUE_TARGET_NAME(prefix unique_name)
31 # prefix [in] prefix for the name
32 # unique_name [out] unique name generated by function
34 ####################################################################
35 FUNCTION(_PYQT4_WRAP_GET_UNIQUE_TARGET_NAME name unique_name)
36 SET(_propertyName "_PYQT4_WRAP_UNIQUE_COUNTER_${name}")
37 GET_PROPERTY(_currentCounter GLOBAL PROPERTY "${_propertyName}")
38 IF(NOT _currentCounter)
39 SET(_currentCounter 1)
41 SET(${unique_name} "${name}_${_currentCounter}" PARENT_SCOPE)
42 MATH(EXPR _currentCounter "${_currentCounter} + 1")
43 SET_PROPERTY(GLOBAL PROPERTY ${_propertyName} ${_currentCounter} )
46 ####################################################################
48 # PYQT4_WRAP_UIC macro
50 # Create Python modules by processing input *.ui (Qt designer) files with
53 # USAGE: PYQT4_WRAP_UIC(output_files pyuic_files)
56 # output_files [out] variable where output file names are listed to
57 # pyuic_files [in] list of *.ui files
60 # - Input files are considered relative to the current source directory.
61 # - Output files are generated in the current build directory.
62 # - Macro automatically adds custom build target to generate output files
64 ####################################################################
65 MACRO(PYQT4_WRAP_UIC outfiles)
66 FOREACH(_input ${ARGN})
67 GET_FILENAME_COMPONENT(_input_name ${_input} NAME)
68 STRING(REPLACE ".ui" "_ui.py" _input_name ${_input_name})
69 SET(_output ${CMAKE_CURRENT_BINARY_DIR}/${_input_name})
72 COMMAND ${PYQT_PYUIC_EXECUTABLE} -o ${_output} ${CMAKE_CURRENT_SOURCE_DIR}/${_input}
73 MAIN_DEPENDENCY ${_input}
75 SET(${outfiles} ${${outfiles}} ${_output})
77 _PYQT4_WRAP_GET_UNIQUE_TARGET_NAME(BUILD_UI_PY_FILES _uniqueTargetName)
78 ADD_CUSTOM_TARGET(${_uniqueTargetName} ALL DEPENDS ${${outfiles}})
79 ENDMACRO(PYQT4_WRAP_UIC)
81 ####################################################################
83 # PYQT4_WRAP_SIP macro
85 # Generate C++ wrappings for *.sip files by processing them with sip.
87 # USAGE: PYQT4_WRAP_SIP(output_files sip_files)
90 # output_files [out] variable where output file names are listed to
91 # sip_files [in] list of *.sip files
94 # - Input files are considered relative to the current source directory.
95 # - Output files are generated in the current build directory.
96 # - This version of macro requires class(es) definition in the
97 # *.sip file to be started on a new line without any preceeding characters.
100 # - Check if dependency of static sources on generated headers works properly:
101 # if header is changed, dependant sources should be recompiled.
103 ####################################################################
104 MACRO(PYQT4_WRAP_SIP outfiles)
105 FOREACH(_input ${ARGN})
106 FILE(STRINGS ${_input} _sip_modules REGEX "%Module")
107 FILE(STRINGS ${_input} _sip_classes REGEX "^class ")
109 FOREACH(_sip_module ${_sip_modules})
110 STRING(REGEX MATCH ".*%Module *\\( *name=.*\\).*" _mod_name "${_sip_module}")
112 STRING(REGEX REPLACE ".*%Module *\\( *name=(.*).*\\).*" "\\1" _mod_name ${_sip_module})
114 STRING(REGEX REPLACE ".*%Module *(.*)" "\\1" _mod_name ${_sip_module})
116 SET(_mod_header "sipAPI${_mod_name}.h")
117 SET(_mod_source "sip${_mod_name}cmodule${PYQT_CXX_EXT}")
118 LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/${_mod_source})
119 SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/${_mod_source})
121 FOREACH(_sip_class ${_sip_classes})
122 STRING(REGEX MATCH ".*class +.* *:" _class_name "${_sip_class}")
124 STRING(REGEX REPLACE ".*class +(.*) *:.*" "\\1" _class_name ${_sip_class})
126 STRING(REGEX REPLACE ".*class *(.*)" "\\1" _class_name ${_sip_class})
128 STRING(STRIP ${_class_name} _class_name)
129 SET(_class_source "sip${_mod_name}${_class_name}${PYQT_CXX_EXT}")
130 LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/${_class_source})
131 SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/${_class_source})
135 COMMAND ${SIP_EXECUTABLE} ${PYQT_SIPFLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/${_input}
136 MAIN_DEPENDENCY ${_input}
139 ENDMACRO(PYQT4_WRAP_SIP)