FindKDE3.cmake 10 KB

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