FindKDE3.cmake 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindKDE3
  5. --------
  6. Find the KDE3 include and library dirs, KDE preprocessors and define a some macros
  7. This module defines the following variables:
  8. ``KDE3_DEFINITIONS``
  9. compiler definitions required for compiling KDE software
  10. ``KDE3_INCLUDE_DIR``
  11. the KDE include directory
  12. ``KDE3_INCLUDE_DIRS``
  13. the KDE and the Qt include directory, for use with include_directories()
  14. ``KDE3_LIB_DIR``
  15. the directory where the KDE libraries are installed, for use with link_directories()
  16. ``QT_AND_KDECORE_LIBS``
  17. this contains both the Qt and the kdecore library
  18. ``KDE3_DCOPIDL_EXECUTABLE``
  19. the dcopidl executable
  20. ``KDE3_DCOPIDL2CPP_EXECUTABLE``
  21. the dcopidl2cpp executable
  22. ``KDE3_KCFGC_EXECUTABLE``
  23. the kconfig_compiler executable
  24. ``KDE3_FOUND``
  25. set to TRUE if all of the above has been found
  26. The following user adjustable options are provided:
  27. ``KDE3_BUILD_TESTS``
  28. enable this to build KDE testcases
  29. It also adds the following macros (from ``KDE3Macros.cmake``) ``SRCS_VAR`` is
  30. always the variable which contains the list of source files for your
  31. application or library.
  32. KDE3_AUTOMOC(file1 ... fileN)
  33. ::
  34. Call this if you want to have automatic moc file handling.
  35. This means if you include "foo.moc" in the source file foo.cpp
  36. a moc file for the header foo.h will be created automatically.
  37. You can set the property SKIP_AUTOMAKE using set_source_files_properties()
  38. to exclude some files in the list from being processed.
  39. KDE3_ADD_MOC_FILES(SRCS_VAR file1 ... fileN )
  40. ::
  41. If you don't use the KDE3_AUTOMOC() macro, for the files
  42. listed here moc files will be created (named "foo.moc.cpp")
  43. KDE3_ADD_DCOP_SKELS(SRCS_VAR header1.h ... headerN.h )
  44. ::
  45. Use this to generate DCOP skeletions from the listed headers.
  46. KDE3_ADD_DCOP_STUBS(SRCS_VAR header1.h ... headerN.h )
  47. ::
  48. Use this to generate DCOP stubs from the listed headers.
  49. KDE3_ADD_UI_FILES(SRCS_VAR file1.ui ... fileN.ui )
  50. ::
  51. Use this to add the Qt designer ui files to your application/library.
  52. KDE3_ADD_KCFG_FILES(SRCS_VAR file1.kcfgc ... fileN.kcfgc )
  53. ::
  54. Use this to add KDE kconfig compiler files to your application/library.
  55. KDE3_INSTALL_LIBTOOL_FILE(target)
  56. ::
  57. This will create and install a simple libtool file for the given target.
  58. KDE3_ADD_EXECUTABLE(name file1 ... fileN )
  59. ::
  60. Currently identical to add_executable(), may provide some advanced
  61. features in the future.
  62. KDE3_ADD_KPART(name [WITH_PREFIX] file1 ... fileN )
  63. ::
  64. Create a KDE plugin (KPart, kioslave, etc.) from the given source files.
  65. If WITH_PREFIX is given, the resulting plugin will have the prefix "lib",
  66. otherwise it won't.
  67. It creates and installs an appropriate libtool la-file.
  68. KDE3_ADD_KDEINIT_EXECUTABLE(name file1 ... fileN )
  69. ::
  70. Create a KDE application in the form of a module loadable via kdeinit.
  71. A library named kdeinit_<name> will be created and a small executable
  72. which links to it.
  73. The option KDE3_ENABLE_FINAL to enable all-in-one compilation is no
  74. longer supported.
  75. Author: Alexander Neundorf <neundorf@kde.org>
  76. #]=======================================================================]
  77. if(NOT UNIX AND KDE3_FIND_REQUIRED)
  78. message(FATAL_ERROR "Compiling KDE3 applications and libraries under Windows is not supported")
  79. endif()
  80. # If Qt4 has already been found, fail.
  81. if(QT4_FOUND)
  82. if(KDE3_FIND_REQUIRED)
  83. message( FATAL_ERROR "KDE3/Qt3 and Qt4 cannot be used together in one project.")
  84. else()
  85. if(NOT KDE3_FIND_QUIETLY)
  86. message( STATUS "KDE3/Qt3 and Qt4 cannot be used together in one project.")
  87. endif()
  88. return()
  89. endif()
  90. endif()
  91. set(QT_MT_REQUIRED TRUE)
  92. #set(QT_MIN_VERSION "3.0.0")
  93. #this line includes FindQt.cmake, which searches the Qt library and headers
  94. if(KDE3_FIND_REQUIRED)
  95. set(_REQ_STRING_KDE3 "REQUIRED")
  96. endif()
  97. find_package(Qt3 ${_REQ_STRING_KDE3})
  98. find_package(X11 ${_REQ_STRING_KDE3})
  99. #now try to find some kde stuff
  100. find_program(KDECONFIG_EXECUTABLE NAMES kde-config
  101. HINTS
  102. $ENV{KDEDIR}/bin
  103. PATHS
  104. /opt/kde3/bin
  105. /opt/kde/bin
  106. )
  107. set(KDE3PREFIX)
  108. if(KDECONFIG_EXECUTABLE)
  109. execute_process(COMMAND ${KDECONFIG_EXECUTABLE} --version
  110. OUTPUT_VARIABLE kde_config_version )
  111. string(REGEX MATCH "KDE: .\\." kde_version "${kde_config_version}")
  112. if ("${kde_version}" MATCHES "KDE: 3\\.")
  113. execute_process(COMMAND ${KDECONFIG_EXECUTABLE} --prefix
  114. OUTPUT_VARIABLE kdedir )
  115. string(REPLACE "\n" "" KDE3PREFIX "${kdedir}")
  116. endif ()
  117. endif()
  118. # at first the KDE include directory
  119. # kpassdlg.h comes from kdeui and doesn't exist in KDE4 anymore
  120. find_path(KDE3_INCLUDE_DIR kpassdlg.h
  121. HINTS
  122. $ENV{KDEDIR}/include
  123. ${KDE3PREFIX}/include
  124. PATHS
  125. /opt/kde3/include
  126. /opt/kde/include
  127. PATH_SUFFIXES include/kde
  128. )
  129. #now the KDE library directory
  130. find_library(KDE3_KDECORE_LIBRARY NAMES kdecore
  131. HINTS
  132. $ENV{KDEDIR}/lib
  133. ${KDE3PREFIX}/lib
  134. PATHS
  135. /opt/kde3/lib
  136. /opt/kde/lib
  137. )
  138. set(QT_AND_KDECORE_LIBS ${QT_LIBRARIES} ${KDE3_KDECORE_LIBRARY})
  139. get_filename_component(KDE3_LIB_DIR ${KDE3_KDECORE_LIBRARY} PATH )
  140. if(NOT KDE3_LIBTOOL_DIR)
  141. if(KDE3_KDECORE_LIBRARY MATCHES lib64)
  142. set(KDE3_LIBTOOL_DIR /lib64/kde3)
  143. elseif(KDE3_KDECORE_LIBRARY MATCHES libx32)
  144. set(KDE3_LIBTOOL_DIR /libx32/kde3)
  145. else()
  146. set(KDE3_LIBTOOL_DIR /lib/kde3)
  147. endif()
  148. endif()
  149. #now search for the dcop utilities
  150. find_program(KDE3_DCOPIDL_EXECUTABLE NAMES dcopidl
  151. HINTS
  152. $ENV{KDEDIR}/bin
  153. ${KDE3PREFIX}/bin
  154. PATHS
  155. /opt/kde3/bin
  156. /opt/kde/bin
  157. )
  158. find_program(KDE3_DCOPIDL2CPP_EXECUTABLE NAMES dcopidl2cpp
  159. HINTS
  160. $ENV{KDEDIR}/bin
  161. ${KDE3PREFIX}/bin
  162. PATHS
  163. /opt/kde3/bin
  164. /opt/kde/bin
  165. )
  166. find_program(KDE3_KCFGC_EXECUTABLE NAMES kconfig_compiler
  167. HINTS
  168. $ENV{KDEDIR}/bin
  169. ${KDE3PREFIX}/bin
  170. PATHS
  171. /opt/kde3/bin
  172. /opt/kde/bin
  173. )
  174. #SET KDE3_FOUND
  175. if (KDE3_INCLUDE_DIR AND KDE3_LIB_DIR AND KDE3_DCOPIDL_EXECUTABLE AND KDE3_DCOPIDL2CPP_EXECUTABLE AND KDE3_KCFGC_EXECUTABLE)
  176. set(KDE3_FOUND TRUE)
  177. else ()
  178. set(KDE3_FOUND FALSE)
  179. endif ()
  180. # add some KDE specific stuff
  181. set(KDE3_DEFINITIONS -DQT_CLEAN_NAMESPACE -D_GNU_SOURCE)
  182. # set compiler flags only if KDE3 has actually been found
  183. if(KDE3_FOUND)
  184. set(_KDE3_USE_FLAGS FALSE)
  185. if(CMAKE_COMPILER_IS_GNUCXX)
  186. set(_KDE3_USE_FLAGS TRUE) # use flags for gnu compiler
  187. execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version
  188. OUTPUT_VARIABLE out)
  189. # gnu gcc 2.96 does not work with flags
  190. # I guess 2.95 also doesn't then
  191. if("${out}" MATCHES "2.9[56]")
  192. set(_KDE3_USE_FLAGS FALSE)
  193. endif()
  194. endif()
  195. #only on linux, but NOT e.g. on FreeBSD:
  196. if(CMAKE_SYSTEM_NAME MATCHES "Linux" AND _KDE3_USE_FLAGS)
  197. set (KDE3_DEFINITIONS ${KDE3_DEFINITIONS} -D_XOPEN_SOURCE=500 -D_BSD_SOURCE)
  198. set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-long-long -ansi -Wundef -Wcast-align -Wconversion -Wchar-subscripts -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security -Wmissing-format-attribute -fno-common")
  199. set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-virtual-dtor -Wno-long-long -ansi -Wundef -Wcast-align -Wconversion -Wchar-subscripts -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security -fno-exceptions -fno-check-new -fno-common")
  200. endif()
  201. # works on FreeBSD, NOT tested on NetBSD and OpenBSD
  202. if (CMAKE_SYSTEM_NAME MATCHES BSD AND _KDE3_USE_FLAGS)
  203. set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-long-long -ansi -Wundef -Wcast-align -Wconversion -Wchar-subscripts -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security -Wmissing-format-attribute -fno-common")
  204. set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-virtual-dtor -Wno-long-long -Wundef -Wcast-align -Wconversion -Wchar-subscripts -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security -Wmissing-format-attribute -fno-exceptions -fno-check-new -fno-common")
  205. endif ()
  206. # if no special buildtype is selected, add -O2 as default optimization
  207. if (NOT CMAKE_BUILD_TYPE AND _KDE3_USE_FLAGS)
  208. set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2")
  209. set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
  210. endif ()
  211. #set(CMAKE_SHARED_LINKER_FLAGS "-avoid-version -module -Wl,--no-undefined -Wl,--allow-shlib-undefined")
  212. #set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--fatal-warnings -avoid-version -Wl,--no-undefined -lc")
  213. #set(CMAKE_MODULE_LINKER_FLAGS "-Wl,--fatal-warnings -avoid-version -Wl,--no-undefined -lc")
  214. endif()
  215. # KDE3Macros.cmake contains all the KDE specific macros
  216. include(${CMAKE_CURRENT_LIST_DIR}/KDE3Macros.cmake)
  217. macro (KDE3_PRINT_RESULTS)
  218. if(KDE3_INCLUDE_DIR)
  219. message(STATUS "Found KDE3 include dir: ${KDE3_INCLUDE_DIR}")
  220. else()
  221. message(STATUS "Didn't find KDE3 headers")
  222. endif()
  223. if(KDE3_LIB_DIR)
  224. message(STATUS "Found KDE3 library dir: ${KDE3_LIB_DIR}")
  225. else()
  226. message(STATUS "Didn't find KDE3 core library")
  227. endif()
  228. if(KDE3_DCOPIDL_EXECUTABLE)
  229. message(STATUS "Found KDE3 dcopidl preprocessor: ${KDE3_DCOPIDL_EXECUTABLE}")
  230. else()
  231. message(STATUS "Didn't find the KDE3 dcopidl preprocessor")
  232. endif()
  233. if(KDE3_DCOPIDL2CPP_EXECUTABLE)
  234. message(STATUS "Found KDE3 dcopidl2cpp preprocessor: ${KDE3_DCOPIDL2CPP_EXECUTABLE}")
  235. else()
  236. message(STATUS "Didn't find the KDE3 dcopidl2cpp preprocessor")
  237. endif()
  238. if(KDE3_KCFGC_EXECUTABLE)
  239. message(STATUS "Found KDE3 kconfig_compiler preprocessor: ${KDE3_KCFGC_EXECUTABLE}")
  240. else()
  241. message(STATUS "Didn't find the KDE3 kconfig_compiler preprocessor")
  242. endif()
  243. endmacro ()
  244. if (KDE3_FIND_REQUIRED AND NOT KDE3_FOUND)
  245. #bail out if something wasn't found
  246. KDE3_PRINT_RESULTS()
  247. message(FATAL_ERROR "Could NOT find everything required for compiling KDE 3 programs")
  248. endif ()
  249. if (NOT KDE3_FIND_QUIETLY)
  250. KDE3_PRINT_RESULTS()
  251. endif ()
  252. #add the found Qt and KDE include directories to the current include path
  253. set(KDE3_INCLUDE_DIRS ${QT_INCLUDE_DIR} ${KDE3_INCLUDE_DIR})