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