Salome HOME
60281289bfac9cb914393f8f1d369992ae9794c1
[tools/configuration.git] / cmake / UseQtExt.cmake
1 # Copyright (C) 2007-2020  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, or (at your option) any later version.
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
20 IF (QT_VERSION VERSION_LESS "5.0")
21   INCLUDE(${QT_USE_FILE})
22 ENDIF()
23
24 # This MACRO uses the following vars
25 # - QT_LRELEASE_EXECUTABLE : (given by default by FindQT.cmake)
26 #
27 # tsfiles containing all ts files to be compiled.
28 # installdir contains directory (relative to install_prefix) where to install files after compilation of ts files too qm.
29 MACRO(QT_INSTALL_TS_RESOURCES tsfiles installdir)
30   FOREACH(_input ${tsfiles})
31     GET_FILENAME_COMPONENT(_name ${_input} NAME_WE)
32     SET(_output ${CMAKE_CURRENT_BINARY_DIR}/${_name}.qm)
33     SET(_cmd_${_name} ${QT_LRELEASE_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${_input} -qm ${_output})
34     ADD_CUSTOM_TARGET(QT_INSTALL_TS_RESOURCES_${_name} ALL COMMAND ${_cmd_${_name}} DEPENDS ${_input})
35     INSTALL(FILES ${_output} DESTINATION ${installdir})
36   ENDFOREACH()
37 ENDMACRO(QT_INSTALL_TS_RESOURCES)
38
39 MACRO(QT_WRAP_MOC)
40 IF (QT_VERSION VERSION_LESS "5.0")
41   QT4_WRAP_CPP(${ARGN})
42 ELSE()
43   QT5_WRAP_CPP(${ARGN})  
44   # Workaround to avoid problem with bug in moc preprocessor:
45   # The problem is reproduced on Linux in case if native system Qt is installed
46   # and "-I/usr/include" parameter is presented in the moc command line before
47   # custom Qt includes. This bug takes place in Qt-5.6.0 and newer. To avoid this
48   # bug move "-I/usr/include" parameter in the "moc parameters" file to the end
49   # of the "include section".
50   IF (NOT WIN32)
51     FOREACH(IT ${ARGN})
52       GET_FILENAME_COMPONENT(IT ${IT} ABSOLUTE)
53       GET_FILENAME_COMPONENT(PFILE ${IT} NAME_WE)
54       SET(OUTFILE ${CMAKE_CURRENT_BINARY_DIR}/moc_${PFILE}.cpp_parameters)
55       IF(EXISTS ${OUTFILE})      
56         SET(NEW_CONTENT)
57         SET(IS_INCLUDE_SECTION TRUE)
58         SET(HAS_SYSTEM_INC FALSE)
59         FILE(READ ${OUTFILE} CONTENT)
60         STRING(REGEX REPLACE "\n" ";" CONTENT "${CONTENT}")
61         list(REMOVE_DUPLICATES CONTENT)
62         FOREACH(S ${CONTENT})
63           IF("${S}" MATCHES "^-I")
64             IF("${S}" STREQUAL "-I/usr/include")
65               SET(HAS_SYSTEM_INC TRUE)
66             ELSE()
67               SET(NEW_CONTENT ${NEW_CONTENT} "${S}\n")
68             ENDIF()
69           ELSE()
70             SET(IS_INCLUDE_SECTION FALSE)
71           ENDIF()
72           IF(NOT IS_INCLUDE_SECTION)
73             IF(HAS_SYSTEM_INC)
74               SET(NEW_CONTENT ${NEW_CONTENT} "-I/usr/include\n")
75               SET(HAS_SYSTEM_INC FALSE)
76             ENDIF()
77             SET(NEW_CONTENT ${NEW_CONTENT} "${S}\n")
78           ENDIF()
79         ENDFOREACH()
80         FILE(WRITE ${OUTFILE} ${NEW_CONTENT})   
81       ENDIF()
82     ENDFOREACH()
83   ENDIF()
84 ENDIF()
85 ENDMACRO(QT_WRAP_MOC)
86
87 MACRO(QT_WRAP_UIC)
88 IF (QT_VERSION VERSION_LESS "5.0")
89   QT4_WRAP_UI(${ARGN})
90 ELSE()
91   QT5_WRAP_UI(${ARGN})
92 ENDIF()
93 ENDMACRO(QT_WRAP_UIC)
94
95 MACRO(QT_ADD_RESOURCES)
96 IF (QT_VERSION VERSION_LESS "5.0")
97   QT4_ADD_RESOURCES(${ARGN})
98 ELSE()
99   QT5_ADD_RESOURCES(${ARGN})
100 ENDIF()
101 ENDMACRO(QT_ADD_RESOURCES)