KDE3Macros.cmake 13 KB

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