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 ####################################################################
23 # _PYQT_WRAP_GET_UNIQUE_TARGET_NAME: internal function
25 # Used to generate unique custom target name for usage in
26 # PYQT_WRAP_UIC macro.
28 # USAGE: _PYQT_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(_PYQT_WRAP_GET_UNIQUE_TARGET_NAME name unique_name)
36 SET(_propertyName "_PYQT_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 ####################################################################
50 # Create Python modules by processing input *.ui (Qt designer) files with
53 # USAGE: PYQT_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(PYQT_WRAP_UIC outfiles)
69 FOREACH(_input ${ARGN})
70 GET_FILENAME_COMPONENT(_input_name ${_input} NAME)
71 STRING(REPLACE ".ui" "_ui.py" _input_name ${_input_name})
72 SET(_output ${CMAKE_CURRENT_BINARY_DIR}/${_input_name})
75 COMMAND ${PYQT_PYUIC_PATH} -o ${_output} ${CMAKE_CURRENT_SOURCE_DIR}/${_input}
76 MAIN_DEPENDENCY ${_input}
78 SET(${outfiles} ${${outfiles}} ${_output})
80 _PYQT_WRAP_GET_UNIQUE_TARGET_NAME(BUILD_UI_PY_FILES _uniqueTargetName)
81 ADD_CUSTOM_TARGET(${_uniqueTargetName} ALL DEPENDS ${${outfiles}})
85 # ANA: Workaround for the Microsoft Visual Studio 2010. Seems there is a bug in
86 # the Microsoft Visual Studio 2010 or CMake 2.8.10.2: custom target doesn't work
87 # for the list of the dependencies. It works only for the first dependency in the
88 # list. So generate separate target for the each input file. This problem will be
89 #investigated in the future.
92 SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)
93 _PYQT_WRAP_GET_UNIQUE_TARGET_NAME(BUILD_UI_PY_FILES _uniqueTargetName)
94 ADD_CUSTOM_TARGET(${_uniqueTargetName} ALL)
95 FOREACH(_input ${ARGN})
96 GET_FILENAME_COMPONENT(_input_name ${_input} NAME)
97 STRING(REPLACE ".ui" "_ui.py" _input_name ${_input_name})
98 SET(_output ${CMAKE_CURRENT_BINARY_DIR}/${_input_name})
99 _PYQT_WRAP_GET_UNIQUE_TARGET_NAME(BUILD_UI_PY_FILES _TgName)
100 ADD_CUSTOM_TARGET(${_TgName} ${PYQT_PYUIC_PATH} -o ${_output} ${CMAKE_CURRENT_SOURCE_DIR}/${_input}
103 SET_TARGET_PROPERTIES(${_TgName} PROPERTIES FOLDER PYQT_WRAP_UIC_TARGETS)
104 ADD_DEPENDENCIES(${_uniqueTargetName} DEPEND ${_TgName})
105 SET(${outfiles} ${${outfiles}} ${_output})
108 ENDMACRO(PYQT_WRAP_UIC)
110 ####################################################################
112 # PYQT_WRAP_SIP macro
114 # Generate C++ wrappings for *.sip files by processing them with sip.
116 # USAGE: PYQT_WRAP_SIP(output_files sip_files)
119 # output_files [out] variable where output file names are listed to
120 # sip_files [in] list of *.sip files
123 # - Input files are considered relative to the current source directory.
124 # - Output files are generated in the current build directory.
125 # - This version of macro requires class(es) definition in the
126 # *.sip file to be started on a new line without any preceeding characters.
129 # - The macro does not properly processes sip features which are wrapped
130 # with sip conditionals.
131 # - The macro works only if one single sip module is processed
132 # (there's only one %Module directive within all input sip files).
135 # - Check if dependency of static sources on generated headers works properly:
136 # if header is changed, dependant sources should be recompiled.
137 # - Think how to properly process sip conditionals.
138 # - Process several sip modules.
140 ####################################################################
141 MACRO(PYQT_WRAP_SIP outfiles)
144 FOREACH(_input ${ARGN})
145 FILE(STRINGS ${_input} _sip_modules REGEX "%Module")
146 FILE(STRINGS ${_input} _sip_classes REGEX "^class ")
147 FOREACH(_sip_module ${_sip_modules})
148 STRING(REGEX MATCH ".*%Module *\\( *name=.*\\).*" _mod_name "${_sip_module}")
150 STRING(REGEX REPLACE ".*%Module *\\( *name=(.*).*\\).*" "\\1" _mod_name ${_sip_module})
152 STRING(REGEX REPLACE ".*%Module *(.*)" "\\1" _mod_name ${_sip_module})
154 SET(_mod_header "sipAPI${_mod_name}.h")
155 SET(_mod_source "sip${_mod_name}cmodule${PYQT_CXX_EXT}")
156 LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/${_mod_source})
157 SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/${_mod_source})
158 SET(_module_input ${_input})
160 FOREACH(_sip_class ${_sip_classes})
161 STRING(REGEX MATCH ".*class +.* *:" _class_name "${_sip_class}")
163 STRING(REGEX REPLACE ".*class +(.*) *:.*" "\\1" _class_name ${_sip_class})
165 STRING(REGEX REPLACE ".*class *(.*)" "\\1" _class_name ${_sip_class})
167 STRING(STRIP ${_class_name} _class_name)
168 SET(_class_source "sip${_mod_name}${_class_name}${PYQT_CXX_EXT}")
169 LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/${_class_source})
170 SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/${_class_source})
175 COMMAND ${SIP_EXECUTABLE} ${PYQT_SIPFLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/${_module_input}
176 MAIN_DEPENDENCY ${_module_input}
178 ENDMACRO(PYQT_WRAP_SIP)
181 ####################################################################
183 # PYQT_WRAP_QRC macro
185 # Generate Python wrappings for *.qrc files by processing them with pyrcc5.
187 # USAGE: PYQT_WRAP_QRC(output_files qrc_files)
190 # output_files [out] variable where output file names are listed to
191 # qrc_files [in] list of *.qrc files
194 # - Input files are considered relative to the current source directory.
195 # - Output files are generated in the current build directory.
196 # - Macro automatically adds custom build target to generate output files
198 ####################################################################
200 MACRO(PYQT_WRAP_QRC outfiles)
201 FOREACH(_input ${ARGN})
202 GET_FILENAME_COMPONENT(_input_name ${_input} NAME)
203 STRING(REPLACE ".qrc" "_qrc.py" _input_name ${_input_name})
204 SET(_output ${CMAKE_CURRENT_BINARY_DIR}/${_input_name})
207 COMMAND ${PYQT_PYRCC_PATH} -o ${_output} ${CMAKE_CURRENT_SOURCE_DIR}/${_input}
208 MAIN_DEPENDENCY ${_input}
210 SET(${outfiles} ${${outfiles}} ${_output})
212 _PYQT_WRAP_GET_UNIQUE_TARGET_NAME(BUILD_QRC_PY_FILES _uniqueTargetName)
213 ADD_CUSTOM_TARGET(${_uniqueTargetName} ALL DEPENDS ${${outfiles}})
214 ENDMACRO(PYQT_WRAP_QRC)