Haibo Huang | 241d398 | 2020-02-28 16:39:50 -0800 | [diff] [blame] | 1 | # Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
| 2 | # file Copyright.txt or https://cmake.org/licensing for details. |
| 3 | |
| 4 | # |
| 5 | |
| 6 | # See FindKDE3.cmake for documentation. |
| 7 | # |
| 8 | # this file contains the following macros: |
| 9 | # KDE3_ADD_DCOP_SKELS |
| 10 | # KDE3_ADD_DCOP_STUBS |
| 11 | # KDE3_ADD_MOC_FILES |
| 12 | # KDE3_ADD_UI_FILES |
| 13 | # KDE3_ADD_KCFG_FILES |
| 14 | # KDE3_AUTOMOC |
| 15 | # KDE3_INSTALL_LIBTOOL_FILE |
| 16 | # KDE3_CREATE_FINAL_FILE |
| 17 | # KDE3_ADD_KPART |
| 18 | # KDE3_ADD_KDEINIT_EXECUTABLE |
| 19 | # KDE3_ADD_EXECUTABLE |
| 20 | |
| 21 | |
| 22 | #neundorf@kde.org |
| 23 | |
| 24 | include(AddFileDependencies) |
| 25 | |
| 26 | #create the kidl and skeletion file for dcop stuff |
| 27 | #usage: KDE_ADD_COP_SKELS(foo_SRCS ${dcop_headers}) |
| 28 | macro(KDE3_ADD_DCOP_SKELS _sources) |
| 29 | foreach (_current_FILE ${ARGN}) |
| 30 | |
| 31 | get_filename_component(_tmp_FILE ${_current_FILE} ABSOLUTE) |
| 32 | get_filename_component(_basename ${_tmp_FILE} NAME_WE) |
| 33 | |
| 34 | set(_skel ${CMAKE_CURRENT_BINARY_DIR}/${_basename}_skel.cpp) |
| 35 | set(_kidl ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.kidl) |
| 36 | |
| 37 | if (NOT HAVE_${_basename}_KIDL_RULE) |
| 38 | set(HAVE_${_basename}_KIDL_RULE ON) |
| 39 | |
| 40 | add_custom_command(OUTPUT ${_kidl} |
| 41 | COMMAND ${KDE3_DCOPIDL_EXECUTABLE} |
| 42 | ARGS ${_tmp_FILE} > ${_kidl} |
| 43 | DEPENDS ${_tmp_FILE} |
| 44 | ) |
| 45 | |
| 46 | endif () |
| 47 | |
| 48 | if (NOT HAVE_${_basename}_SKEL_RULE) |
| 49 | set(HAVE_${_basename}_SKEL_RULE ON) |
| 50 | |
| 51 | add_custom_command(OUTPUT ${_skel} |
| 52 | COMMAND ${KDE3_DCOPIDL2CPP_EXECUTABLE} |
| 53 | ARGS --c++-suffix cpp --no-signals --no-stub ${_kidl} |
| 54 | DEPENDS ${_kidl} |
| 55 | ) |
| 56 | |
| 57 | endif () |
| 58 | |
| 59 | set(${_sources} ${${_sources}} ${_skel}) |
| 60 | |
| 61 | endforeach () |
| 62 | |
| 63 | endmacro() |
| 64 | |
| 65 | |
| 66 | macro(KDE3_ADD_DCOP_STUBS _sources) |
| 67 | foreach (_current_FILE ${ARGN}) |
| 68 | |
| 69 | get_filename_component(_tmp_FILE ${_current_FILE} ABSOLUTE) |
| 70 | |
| 71 | get_filename_component(_basename ${_tmp_FILE} NAME_WE) |
| 72 | |
| 73 | set(_stub_CPP ${CMAKE_CURRENT_BINARY_DIR}/${_basename}_stub.cpp) |
| 74 | set(_kidl ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.kidl) |
| 75 | |
| 76 | if (NOT HAVE_${_basename}_KIDL_RULE) |
| 77 | set(HAVE_${_basename}_KIDL_RULE ON) |
| 78 | |
| 79 | |
| 80 | add_custom_command(OUTPUT ${_kidl} |
| 81 | COMMAND ${KDE3_DCOPIDL_EXECUTABLE} |
| 82 | ARGS ${_tmp_FILE} > ${_kidl} |
| 83 | DEPENDS ${_tmp_FILE} |
| 84 | ) |
| 85 | |
| 86 | endif () |
| 87 | |
| 88 | |
| 89 | if (NOT HAVE_${_basename}_STUB_RULE) |
| 90 | set(HAVE_${_basename}_STUB_RULE ON) |
| 91 | |
| 92 | add_custom_command(OUTPUT ${_stub_CPP} |
| 93 | COMMAND ${KDE3_DCOPIDL2CPP_EXECUTABLE} |
| 94 | ARGS --c++-suffix cpp --no-signals --no-skel ${_kidl} |
| 95 | DEPENDS ${_kidl} |
| 96 | ) |
| 97 | |
| 98 | endif () |
| 99 | |
| 100 | set(${_sources} ${${_sources}} ${_stub_CPP}) |
| 101 | |
| 102 | endforeach () |
| 103 | |
| 104 | endmacro() |
| 105 | |
| 106 | |
| 107 | macro(KDE3_ADD_KCFG_FILES _sources) |
| 108 | foreach (_current_FILE ${ARGN}) |
| 109 | |
| 110 | get_filename_component(_tmp_FILE ${_current_FILE} ABSOLUTE) |
| 111 | |
| 112 | get_filename_component(_basename ${_tmp_FILE} NAME_WE) |
| 113 | |
| 114 | file(READ ${_tmp_FILE} _contents) |
| 115 | string(REGEX REPLACE "^(.*\n)?File=([^\n]+)\n.*$" "\\2" _kcfg_FILE "${_contents}") |
| 116 | |
| 117 | set(_src_FILE ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.cpp) |
| 118 | set(_header_FILE ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.h) |
| 119 | |
| 120 | add_custom_command(OUTPUT ${_src_FILE} |
| 121 | COMMAND ${KDE3_KCFGC_EXECUTABLE} |
| 122 | ARGS ${CMAKE_CURRENT_SOURCE_DIR}/${_kcfg_FILE} ${_tmp_FILE} |
| 123 | DEPENDS ${_tmp_FILE} ${CMAKE_CURRENT_SOURCE_DIR}/${_kcfg_FILE} |
| 124 | ) |
| 125 | |
| 126 | set(${_sources} ${${_sources}} ${_src_FILE}) |
| 127 | |
| 128 | endforeach () |
| 129 | |
| 130 | endmacro() |
| 131 | |
| 132 | |
| 133 | #create the moc files and add them to the list of sources |
| 134 | #usage: KDE_ADD_MOC_FILES(foo_SRCS ${moc_headers}) |
| 135 | macro(KDE3_ADD_MOC_FILES _sources) |
| 136 | foreach (_current_FILE ${ARGN}) |
| 137 | |
| 138 | get_filename_component(_tmp_FILE ${_current_FILE} ABSOLUTE) |
| 139 | |
| 140 | get_filename_component(_basename ${_tmp_FILE} NAME_WE) |
| 141 | set(_moc ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.moc.cpp) |
| 142 | |
| 143 | add_custom_command(OUTPUT ${_moc} |
| 144 | COMMAND ${QT_MOC_EXECUTABLE} |
| 145 | ARGS ${_tmp_FILE} -o ${_moc} |
| 146 | DEPENDS ${_tmp_FILE} |
| 147 | ) |
| 148 | |
| 149 | set(${_sources} ${${_sources}} ${_moc}) |
| 150 | |
| 151 | endforeach () |
| 152 | endmacro() |
| 153 | |
| 154 | |
| 155 | get_filename_component( KDE3_MODULE_DIR ${CMAKE_CURRENT_LIST_FILE} PATH) |
| 156 | |
| 157 | #create the implementation files from the ui files and add them to the list of sources |
| 158 | #usage: KDE_ADD_UI_FILES(foo_SRCS ${ui_files}) |
| 159 | macro(KDE3_ADD_UI_FILES _sources ) |
| 160 | foreach (_current_FILE ${ARGN}) |
| 161 | |
| 162 | get_filename_component(_tmp_FILE ${_current_FILE} ABSOLUTE) |
| 163 | |
| 164 | get_filename_component(_basename ${_tmp_FILE} NAME_WE) |
| 165 | set(_header ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.h) |
| 166 | set(_src ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.cpp) |
| 167 | set(_moc ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.moc.cpp) |
| 168 | |
| 169 | add_custom_command(OUTPUT ${_header} |
| 170 | COMMAND ${QT_UIC_EXECUTABLE} |
| 171 | ARGS -L ${KDE3_LIB_DIR}/kde3/plugins/designer -nounload -o ${_header} ${CMAKE_CURRENT_SOURCE_DIR}/${_current_FILE} |
| 172 | DEPENDS ${_tmp_FILE} |
| 173 | ) |
| 174 | |
| 175 | add_custom_command(OUTPUT ${_src} |
| 176 | COMMAND ${CMAKE_COMMAND} |
| 177 | ARGS |
| 178 | -DKDE_UIC_PLUGIN_DIR:FILEPATH=${KDE3_LIB_DIR}/kde3/plugins/designer |
| 179 | -DKDE_UIC_EXECUTABLE:FILEPATH=${QT_UIC_EXECUTABLE} |
| 180 | -DKDE_UIC_FILE:FILEPATH=${_tmp_FILE} |
| 181 | -DKDE_UIC_CPP_FILE:FILEPATH=${_src} |
| 182 | -DKDE_UIC_H_FILE:FILEPATH=${_header} |
| 183 | -P ${KDE3_MODULE_DIR}/kde3uic.cmake |
| 184 | DEPENDS ${_header} |
| 185 | ) |
| 186 | |
| 187 | add_custom_command(OUTPUT ${_moc} |
| 188 | COMMAND ${QT_MOC_EXECUTABLE} |
| 189 | ARGS ${_header} -o ${_moc} |
| 190 | DEPENDS ${_header} |
| 191 | ) |
| 192 | |
| 193 | set(${_sources} ${${_sources}} ${_src} ${_moc} ) |
| 194 | |
| 195 | endforeach () |
| 196 | endmacro() |
| 197 | |
| 198 | |
| 199 | macro(KDE3_AUTOMOC) |
| 200 | set(_matching_FILES ) |
| 201 | foreach (_current_FILE ${ARGN}) |
| 202 | |
| 203 | get_filename_component(_abs_FILE ${_current_FILE} ABSOLUTE) |
| 204 | |
| 205 | # if "SKIP_AUTOMOC" is set to true, we will not handle this file here. |
| 206 | # here. this is required to make bouic work correctly: |
| 207 | # we need to add generated .cpp files to the sources (to compile them), |
| 208 | # but we cannot let automoc handle them, as the .cpp files don't exist yet when |
| 209 | # cmake is run for the very first time on them -> however the .cpp files might |
| 210 | # exist at a later run. at that time we need to skip them, so that we don't add two |
| 211 | # different rules for the same moc file |
| 212 | get_source_file_property(_skip ${_abs_FILE} SKIP_AUTOMOC) |
| 213 | |
| 214 | if (EXISTS ${_abs_FILE} AND NOT _skip) |
| 215 | |
| 216 | file(STRINGS ${_abs_FILE} _match REGEX "#include +[^ ]+\\.moc[\">]") |
| 217 | |
| 218 | get_filename_component(_abs_PATH ${_abs_FILE} PATH) |
| 219 | |
| 220 | foreach (_current_MOC_INC IN LISTS _match) |
| 221 | string(REGEX MATCH "[^ <\"]+\\.moc" _current_MOC "${_current_MOC_INC}") |
| 222 | |
| 223 | get_filename_component(_basename ${_current_MOC} NAME_WE) |
| 224 | # set(_header ${CMAKE_CURRENT_SOURCE_DIR}/${_basename}.h) |
| 225 | set(_header ${_abs_PATH}/${_basename}.h) |
| 226 | set(_moc ${CMAKE_CURRENT_BINARY_DIR}/${_current_MOC}) |
| 227 | |
| 228 | add_custom_command(OUTPUT ${_moc} |
| 229 | COMMAND ${QT_MOC_EXECUTABLE} |
| 230 | ARGS ${_header} -o ${_moc} |
| 231 | DEPENDS ${_header} |
| 232 | ) |
| 233 | |
| 234 | ADD_FILE_DEPENDENCIES(${_abs_FILE} ${_moc}) |
| 235 | |
| 236 | endforeach () |
| 237 | unset(_match) |
| 238 | unset(_header) |
| 239 | unset(_moc) |
| 240 | endif () |
| 241 | endforeach () |
| 242 | endmacro() |
| 243 | |
| 244 | # only used internally by KDE3_INSTALL_ICONS |
| 245 | macro (_KDE3_ADD_ICON_INSTALL_RULE _install_SCRIPT _install_PATH _group _orig_NAME _install_NAME) |
| 246 | |
| 247 | # if the string doesn't match the pattern, the result is the full string, so all three have the same content |
| 248 | if (NOT ${_group} STREQUAL ${_install_NAME} ) |
| 249 | set(_icon_GROUP "actions") |
| 250 | |
| 251 | if (${_group} STREQUAL "mime") |
| 252 | set(_icon_GROUP "mimetypes") |
| 253 | endif () |
| 254 | |
| 255 | if (${_group} STREQUAL "filesys") |
| 256 | set(_icon_GROUP "filesystems") |
| 257 | endif () |
| 258 | |
| 259 | if (${_group} STREQUAL "device") |
| 260 | set(_icon_GROUP "devices") |
| 261 | endif () |
| 262 | |
| 263 | if (${_group} STREQUAL "app") |
| 264 | set(_icon_GROUP "apps") |
| 265 | endif () |
| 266 | |
| 267 | if (${_group} STREQUAL "action") |
| 268 | set(_icon_GROUP "actions") |
| 269 | endif () |
| 270 | |
| 271 | # message(STATUS "icon: ${_current_ICON} size: ${_size} group: ${_group} name: ${_name}" ) |
| 272 | install(FILES ${_orig_NAME} DESTINATION ${_install_PATH}/${_icon_GROUP}/ RENAME ${_install_NAME} ) |
| 273 | endif () |
| 274 | |
| 275 | endmacro () |
| 276 | |
| 277 | |
| 278 | macro (KDE3_INSTALL_ICONS _theme ) |
| 279 | set(_defaultpath "${CMAKE_INSTALL_PREFIX}/share/icons") |
| 280 | # first the png icons |
| 281 | file(GLOB _icons *.png) |
| 282 | foreach (_current_ICON ${_icons} ) |
| 283 | string(REGEX REPLACE "^.*/[a-zA-Z]+([0-9]+)\\-([a-z]+)\\-(.+\\.png)$" "\\1" _size "${_current_ICON}") |
| 284 | string(REGEX REPLACE "^.*/[a-zA-Z]+([0-9]+)\\-([a-z]+)\\-(.+\\.png)$" "\\2" _group "${_current_ICON}") |
| 285 | string(REGEX REPLACE "^.*/[a-zA-Z]+([0-9]+)\\-([a-z]+)\\-(.+\\.png)$" "\\3" _name "${_current_ICON}") |
| 286 | _KDE3_ADD_ICON_INSTALL_RULE(${CMAKE_CURRENT_BINARY_DIR}/install_icons.cmake |
| 287 | ${_defaultpath}/${_theme}/${_size}x${_size} |
| 288 | ${_group} ${_current_ICON} ${_name}) |
| 289 | endforeach () |
| 290 | |
| 291 | # and now the svg icons |
| 292 | file(GLOB _icons *.svgz) |
| 293 | foreach (_current_ICON ${_icons} ) |
| 294 | string(REGEX REPLACE "^.*/crsc\\-([a-z]+)\\-(.+\\.svgz)$" "\\1" _group "${_current_ICON}") |
| 295 | string(REGEX REPLACE "^.*/crsc\\-([a-z]+)\\-(.+\\.svgz)$" "\\2" _name "${_current_ICON}") |
| 296 | _KDE3_ADD_ICON_INSTALL_RULE(${CMAKE_CURRENT_BINARY_DIR}/install_icons.cmake |
| 297 | ${_defaultpath}/${_theme}/scalable |
| 298 | ${_group} ${_current_ICON} ${_name}) |
| 299 | endforeach () |
| 300 | |
| 301 | endmacro () |
| 302 | |
| 303 | macro(KDE3_INSTALL_LIBTOOL_FILE _target) |
| 304 | get_target_property(_target_location ${_target} LOCATION) |
| 305 | |
| 306 | get_filename_component(_laname ${_target_location} NAME_WE) |
| 307 | get_filename_component(_soname ${_target_location} NAME) |
| 308 | set(_laname ${CMAKE_CURRENT_BINARY_DIR}/${_laname}.la) |
| 309 | |
| 310 | file(WRITE ${_laname} "# ${_laname} - a libtool library file, generated by cmake \n") |
| 311 | file(APPEND ${_laname} "# The name that we can dlopen(3).\n") |
| 312 | file(APPEND ${_laname} "dlname='${_soname}'\n") |
| 313 | file(APPEND ${_laname} "# Names of this library\n") |
| 314 | if(CYGWIN) |
| 315 | file(APPEND ${_laname} "library_names='${_soname}'\n") |
| 316 | else() |
| 317 | file(APPEND ${_laname} "library_names='${_soname} ${_soname} ${_soname}'\n") |
| 318 | endif() |
| 319 | file(APPEND ${_laname} "# The name of the static archive\n") |
| 320 | file(APPEND ${_laname} "old_library=''\n") |
| 321 | file(APPEND ${_laname} "# Libraries that this one depends upon.\n") |
| 322 | file(APPEND ${_laname} "dependency_libs=''\n") |
| 323 | # file(APPEND ${_laname} "dependency_libs='${${_target}_LIB_DEPENDS}'\n") |
| 324 | file(APPEND ${_laname} "# Version information.\ncurrent=0\nage=0\nrevision=0\n") |
| 325 | file(APPEND ${_laname} "# Is this an already installed library?\ninstalled=yes\n") |
| 326 | file(APPEND ${_laname} "# Should we warn about portability when linking against -modules?\nshouldnotlink=yes\n") |
| 327 | file(APPEND ${_laname} "# Files to dlopen/dlpreopen\ndlopen=''\ndlpreopen=''\n") |
| 328 | file(APPEND ${_laname} "# Directory that this library needs to be installed in:\n") |
| 329 | file(APPEND ${_laname} "libdir='${CMAKE_INSTALL_PREFIX}/lib/kde3'\n") |
| 330 | |
| 331 | install_files(${KDE3_LIBTOOL_DIR} FILES ${_laname}) |
| 332 | endmacro() |
| 333 | |
| 334 | |
| 335 | macro(KDE3_CREATE_FINAL_FILE _filename) |
| 336 | file(WRITE ${_filename} "//autogenerated file\n") |
| 337 | foreach (_current_FILE ${ARGN}) |
| 338 | file(APPEND ${_filename} "#include \"${_current_FILE}\"\n") |
| 339 | endforeach () |
| 340 | |
| 341 | endmacro() |
| 342 | |
| 343 | |
| 344 | # option(KDE3_ENABLE_FINAL "Enable final all-in-one compilation") |
| 345 | option(KDE3_BUILD_TESTS "Build the tests") |
| 346 | |
| 347 | |
| 348 | macro(KDE3_ADD_KPART _target_NAME _with_PREFIX) |
| 349 | #is the first argument is "WITH_PREFIX" then keep the standard "lib" prefix, otherwise SET the prefix empty |
| 350 | if (${_with_PREFIX} STREQUAL "WITH_PREFIX") |
| 351 | set(_first_SRC) |
| 352 | else () |
| 353 | set(_first_SRC ${_with_PREFIX}) |
| 354 | endif () |
| 355 | |
| 356 | # if (KDE3_ENABLE_FINAL) |
| 357 | # KDE3_CREATE_FINAL_FILE(${_target_NAME}_final.cpp ${_first_SRC} ${ARGN}) |
| 358 | # add_library(${_target_NAME} MODULE ${_target_NAME}_final.cpp) |
| 359 | # else () |
| 360 | add_library(${_target_NAME} MODULE ${_first_SRC} ${ARGN}) |
| 361 | # endif () |
| 362 | |
| 363 | if(_first_SRC) |
| 364 | set_target_properties(${_target_NAME} PROPERTIES PREFIX "") |
| 365 | endif() |
| 366 | |
| 367 | KDE3_INSTALL_LIBTOOL_FILE(${_target_NAME}) |
| 368 | |
| 369 | endmacro() |
| 370 | |
| 371 | |
| 372 | macro(KDE3_ADD_KDEINIT_EXECUTABLE _target_NAME ) |
| 373 | |
| 374 | # if (KDE3_ENABLE_FINAL) |
| 375 | # KDE3_CREATE_FINAL_FILE(${_target_NAME}_final.cpp ${ARGN}) |
| 376 | # add_library(kdeinit_${_target_NAME} SHARED ${_target_NAME}_final.cpp) |
| 377 | # else () |
| 378 | add_library(kdeinit_${_target_NAME} SHARED ${ARGN} ) |
| 379 | # endif () |
| 380 | |
| 381 | configure_file(${KDE3_MODULE_DIR}/kde3init_dummy.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/${_target_NAME}_dummy.cpp) |
| 382 | |
| 383 | add_executable( ${_target_NAME} ${CMAKE_CURRENT_BINARY_DIR}/${_target_NAME}_dummy.cpp ) |
| 384 | target_link_libraries( ${_target_NAME} kdeinit_${_target_NAME} ) |
| 385 | |
| 386 | endmacro() |
| 387 | |
| 388 | |
| 389 | macro(KDE3_ADD_EXECUTABLE _target_NAME ) |
| 390 | |
| 391 | # if (KDE3_ENABLE_FINAL) |
| 392 | # KDE3_CREATE_FINAL_FILE(${_target_NAME}_final.cpp ${ARGN}) |
| 393 | # add_executable(${_target_NAME} ${_target_NAME}_final.cpp) |
| 394 | # else () |
| 395 | add_executable(${_target_NAME} ${ARGN} ) |
| 396 | # endif () |
| 397 | |
| 398 | endmacro() |
| 399 | |
| 400 | |