|
| 1 | +#============================================================================= |
| 2 | +# Copyright 2005-2011 Kitware, Inc. |
| 3 | +# All rights reserved. |
| 4 | +# |
| 5 | +# Redistribution and use in source and binary forms, with or without |
| 6 | +# modification, are permitted provided that the following conditions |
| 7 | +# are met: |
| 8 | +# |
| 9 | +# * Redistributions of source code must retain the above copyright |
| 10 | +# notice, this list of conditions and the following disclaimer. |
| 11 | +# |
| 12 | +# * Redistributions in binary form must reproduce the above copyright |
| 13 | +# notice, this list of conditions and the following disclaimer in the |
| 14 | +# documentation and/or other materials provided with the distribution. |
| 15 | +# |
| 16 | +# * Neither the name of Kitware, Inc. nor the names of its |
| 17 | +# contributors may be used to endorse or promote products derived |
| 18 | +# from this software without specific prior written permission. |
| 19 | +# |
| 20 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | +# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | +#============================================================================= |
| 32 | + |
| 33 | +# The automoc_qt4 macro is superceded by CMAKE_AUTOMOC from CMake 2.8.6 |
| 34 | +# A Qt 5 version is not provided by CMake or Qt. |
| 35 | + |
| 36 | +include(MacroAddFileDependencies) |
| 37 | + |
| 38 | +MACRO (QT4_GET_MOC_FLAGS _moc_flags) |
| 39 | + SET(${_moc_flags}) |
| 40 | + GET_DIRECTORY_PROPERTY(_inc_DIRS INCLUDE_DIRECTORIES) |
| 41 | + |
| 42 | + FOREACH(_current ${_inc_DIRS}) |
| 43 | + IF("${_current}" MATCHES "\\.framework/?$") |
| 44 | + STRING(REGEX REPLACE "/[^/]+\\.framework" "" framework_path "${_current}") |
| 45 | + SET(${_moc_flags} ${${_moc_flags}} "-F${framework_path}") |
| 46 | + ELSE("${_current}" MATCHES "\\.framework/?$") |
| 47 | + SET(${_moc_flags} ${${_moc_flags}} "-I${_current}") |
| 48 | + ENDIF("${_current}" MATCHES "\\.framework/?$") |
| 49 | + ENDFOREACH(_current ${_inc_DIRS}) |
| 50 | + |
| 51 | + GET_DIRECTORY_PROPERTY(_defines COMPILE_DEFINITIONS) |
| 52 | + FOREACH(_current ${_defines}) |
| 53 | + SET(${_moc_flags} ${${_moc_flags}} "-D${_current}") |
| 54 | + ENDFOREACH(_current ${_defines}) |
| 55 | + |
| 56 | + IF(Q_OS_WIN) |
| 57 | + SET(${_moc_flags} ${${_moc_flags}} -DWIN32) |
| 58 | + ENDIF(Q_OS_WIN) |
| 59 | + |
| 60 | +ENDMACRO(QT4_GET_MOC_FLAGS) |
| 61 | + |
| 62 | +# helper macro to set up a moc rule |
| 63 | +MACRO (QT4_CREATE_MOC_COMMAND infile outfile moc_flags moc_options) |
| 64 | + # For Windows, create a parameters file to work around command line length limit |
| 65 | + IF (WIN32) |
| 66 | + # Pass the parameters in a file. Set the working directory to |
| 67 | + # be that containing the parameters file and reference it by |
| 68 | + # just the file name. This is necessary because the moc tool on |
| 69 | + # MinGW builds does not seem to handle spaces in the path to the |
| 70 | + # file given with the @ syntax. |
| 71 | + GET_FILENAME_COMPONENT(_moc_outfile_name "${outfile}" NAME) |
| 72 | + GET_FILENAME_COMPONENT(_moc_outfile_dir "${outfile}" PATH) |
| 73 | + IF(_moc_outfile_dir) |
| 74 | + SET(_moc_working_dir WORKING_DIRECTORY ${_moc_outfile_dir}) |
| 75 | + ENDIF(_moc_outfile_dir) |
| 76 | + SET (_moc_parameters_file ${outfile}_parameters) |
| 77 | + SET (_moc_parameters ${moc_flags} ${moc_options} -o "${outfile}" "${infile}") |
| 78 | + STRING (REPLACE ";" "\n" _moc_parameters "${_moc_parameters}") |
| 79 | + FILE (WRITE ${_moc_parameters_file} "${_moc_parameters}") |
| 80 | + ADD_CUSTOM_COMMAND(OUTPUT ${outfile} |
| 81 | + COMMAND ${QT_MOC_EXECUTABLE} @${_moc_outfile_name}_parameters |
| 82 | + DEPENDS ${infile} |
| 83 | + ${_moc_working_dir} |
| 84 | + VERBATIM) |
| 85 | + ELSE (WIN32) |
| 86 | + ADD_CUSTOM_COMMAND(OUTPUT ${outfile} |
| 87 | + COMMAND ${QT_MOC_EXECUTABLE} |
| 88 | + ARGS ${moc_flags} ${moc_options} -o ${outfile} ${infile} |
| 89 | + DEPENDS ${infile} VERBATIM) |
| 90 | + ENDIF (WIN32) |
| 91 | +ENDMACRO (QT4_CREATE_MOC_COMMAND) |
| 92 | + |
| 93 | + |
| 94 | +MACRO(QT4_AUTOMOC) |
| 95 | + QT4_GET_MOC_FLAGS(_moc_INCS) |
| 96 | + |
| 97 | + SET(_matching_FILES ) |
| 98 | + FOREACH (_current_FILE ${ARGN}) |
| 99 | + |
| 100 | + GET_FILENAME_COMPONENT(_abs_FILE ${_current_FILE} ABSOLUTE) |
| 101 | + # if "SKIP_AUTOMOC" is set to true, we will not handle this file here. |
| 102 | + # This is required to make uic work correctly: |
| 103 | + # we need to add generated .cpp files to the sources (to compile them), |
| 104 | + # but we cannot let automoc handle them, as the .cpp files don't exist yet when |
| 105 | + # cmake is run for the very first time on them -> however the .cpp files might |
| 106 | + # exist at a later run. at that time we need to skip them, so that we don't add two |
| 107 | + # different rules for the same moc file |
| 108 | + GET_SOURCE_FILE_PROPERTY(_skip ${_abs_FILE} SKIP_AUTOMOC) |
| 109 | + |
| 110 | + IF ( NOT _skip AND EXISTS ${_abs_FILE} ) |
| 111 | + |
| 112 | + FILE(READ ${_abs_FILE} _contents) |
| 113 | + |
| 114 | + GET_FILENAME_COMPONENT(_abs_PATH ${_abs_FILE} PATH) |
| 115 | + |
| 116 | + STRING(REGEX MATCHALL "# *include +[^ ]+\\.moc[\">]" _match "${_contents}") |
| 117 | + IF(_match) |
| 118 | + FOREACH (_current_MOC_INC ${_match}) |
| 119 | + STRING(REGEX MATCH "[^ <\"]+\\.moc" _current_MOC "${_current_MOC_INC}") |
| 120 | + |
| 121 | + GET_FILENAME_COMPONENT(_basename ${_current_MOC} NAME_WE) |
| 122 | + IF(EXISTS ${_abs_PATH}/${_basename}.hpp) |
| 123 | + SET(_header ${_abs_PATH}/${_basename}.hpp) |
| 124 | + ELSE(EXISTS ${_abs_PATH}/${_basename}.hpp) |
| 125 | + SET(_header ${_abs_PATH}/${_basename}.h) |
| 126 | + ENDIF(EXISTS ${_abs_PATH}/${_basename}.hpp) |
| 127 | + SET(_moc ${CMAKE_CURRENT_BINARY_DIR}/${_current_MOC}) |
| 128 | + QT4_CREATE_MOC_COMMAND(${_header} ${_moc} "${_moc_INCS}" "") |
| 129 | + MACRO_ADD_FILE_DEPENDENCIES(${_abs_FILE} ${_moc}) |
| 130 | + ENDFOREACH (_current_MOC_INC) |
| 131 | + ENDIF(_match) |
| 132 | + ENDIF ( NOT _skip AND EXISTS ${_abs_FILE} ) |
| 133 | + ENDFOREACH (_current_FILE) |
| 134 | +ENDMACRO(QT4_AUTOMOC) |
| 135 | + |
| 136 | + |
| 137 | +# Portability helpers. |
| 138 | + |
| 139 | +set(QT_QTGUI_LIBRARIES |
| 140 | + ${Qt5Gui_LIBRARIES} |
| 141 | + ${Qt5Widgets_LIBRARIES} |
| 142 | + ${Qt5PrintSupport_LIBRARIES} |
| 143 | + ${Qt5Svg_LIBRARIES} |
| 144 | +) |
| 145 | + |
| 146 | +set(QT_INCLUDES |
| 147 | + ${Qt5Gui_INCLUDE_DIRS} |
| 148 | + ${Qt5Widgets_INCLUDE_DIRS} |
| 149 | + ${Qt5PrintSupport_INCLUDE_DIRS} |
| 150 | + ${Qt5Svg_INCLUDE_DIRS} |
| 151 | +) |
| 152 | +set(QT_QTGUI_LIBRARY ${QT_QTGUI_LIBRARIES}) |
| 153 | + |
| 154 | +set(_qt_modules |
| 155 | + Core |
| 156 | + Declarative |
| 157 | + Widgets |
| 158 | + Script |
| 159 | + ScriptTools |
| 160 | + Network |
| 161 | + Test |
| 162 | + Designer |
| 163 | + Concurrent |
| 164 | + Xml |
| 165 | + XmlPatterns |
| 166 | + UiTools |
| 167 | + Qml |
| 168 | + Quick1 |
| 169 | + WebKit |
| 170 | + WebKitWidgets |
| 171 | + Sql |
| 172 | + OpenGL |
| 173 | +) |
| 174 | + |
| 175 | +foreach(_module ${_qt_modules}) |
| 176 | + string(TOUPPER ${_module} _module_upper) |
| 177 | + set(QT_QT${_module_upper}_LIBRARIES ${Qt5${_module}_LIBRARIES}) |
| 178 | + set(QT_QT${_module_upper}_LIBRARY ${QT_QT${_module_upper}_LIBRARIES}) |
| 179 | + list(APPEND QT_INCLUDES ${Qt5${_module}_INCLUDE_DIRS}) |
| 180 | + set(QT_QT${_module_upper}_FOUND ${Qt5${_module}_FOUND}) |
| 181 | +endforeach() |
| 182 | + |
| 183 | +list(APPEND QT_QTCORE_LIBRARIES ${Qt5Concurrent_LIBRARIES}) |
| 184 | +list(APPEND QT_QTCORE_LIBRARY ${Qt5Concurrent_LIBRARIES}) |
| 185 | + |
| 186 | +list(APPEND QT_QTWEBKIT_LIBRARIES ${Qt5WebKitWidgets_LIBRARIES}) |
| 187 | +list(APPEND QT_QTWEBKIT_LIBRARY ${Qt5WebKitWidgets_LIBRARIES}) |
| 188 | + |
| 189 | +set(QT_QTDECLARATIVE_LIBRARIES ${Qt5Quick1_LIBRARIES}) |
| 190 | +set(QT_QTDECLARATIVE_LIBRARY ${Qt5Quick1_LIBRARIES}) |
| 191 | + |
| 192 | +set(QT_LRELEASE_EXECUTABLE lrelease-qt5) |
| 193 | +set(QT_LUPDATE_EXECUTABLE lupdate-qt5) |
| 194 | + |
| 195 | +set(QT_INSTALL_PREFIX ${_qt5Core_install_prefix}) |
| 196 | + |
| 197 | +get_target_property(QT_QMAKE_EXECUTABLE Qt5::qmake LOCATION) |
| 198 | +set(QT_RCC_EXECUTABLE Qt5::rcc LOCATION) |
| 199 | +if (TARGET Qt5::uic) |
| 200 | + get_target_property(QT_UIC_EXECUTABLE Qt5::uic LOCATION) |
| 201 | +endif() |
| 202 | + |
| 203 | + |
| 204 | +if (TARGET Qt5::qdbuscpp2xml) |
| 205 | + get_target_property(QT_QDBUSCPP2XML_EXECUTABLE Qt5::qdbuscpp2xml LOCATION) |
| 206 | +endif() |
| 207 | + |
| 208 | +if (TARGET Qt5::qdbusxml2cpp) |
| 209 | + get_target_property(QT_QDBUSXML2CPP_EXECUTABLE Qt5::qdbusxml2cpp LOCATION) |
| 210 | +endif() |
| 211 | + |
| 212 | +add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0) |
| 213 | + |
| 214 | +macro(qt4_wrap_ui) |
| 215 | + qt5_wrap_ui(${ARGN}) |
| 216 | +endmacro() |
| 217 | + |
| 218 | +macro(qt4_wrap_cpp) |
| 219 | + qt5_wrap_cpp(${ARGN}) |
| 220 | +endmacro() |
| 221 | + |
| 222 | +macro(qt4_generate_moc) |
| 223 | + qt5_generate_moc(${ARGN}) |
| 224 | +endmacro() |
| 225 | + |
| 226 | +macro(qt4_add_dbus_adaptor) |
| 227 | + qt5_add_dbus_adaptor(${ARGN}) |
| 228 | +endmacro() |
| 229 | + |
| 230 | +macro(qt4_add_dbus_interfaces) |
| 231 | + qt5_add_dbus_interfaces(${ARGN}) |
| 232 | +endmacro() |
| 233 | + |
| 234 | +macro(qt4_add_dbus_interface) |
| 235 | + qt5_add_dbus_interface(${ARGN}) |
| 236 | +endmacro() |
| 237 | + |
| 238 | +macro(qt4_generate_dbus_interface) |
| 239 | + qt5_generate_dbus_interface(${ARGN}) |
| 240 | +endmacro() |
| 241 | + |
| 242 | +macro(qt4_add_resources) |
| 243 | + qt5_add_resources(${ARGN}) |
| 244 | +endmacro() |
| 245 | + |
0 commit comments