KDE3Macros.cmake 12 KB

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