1
0

FindKDE3.cmake 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. # - Find the KDE3 include and library dirs, KDE preprocessors and define a some macros
  2. #
  3. # This module defines the following variables:
  4. # KDE3_DEFINITIONS - compiler definitions required for compiling KDE software
  5. # KDE3_INCLUDE_DIR - the KDE include directory
  6. # KDE3_INCLUDE_DIRS - the KDE and the Qt include directory, for use with include_directories()
  7. # KDE3_LIB_DIR - the directory where the KDE libraries are installed, for use with link_directories()
  8. # QT_AND_KDECORE_LIBS - this contains both the Qt and the kdecore library
  9. # KDE3_DCOPIDL_EXECUTABLE - the dcopidl executable
  10. # KDE3_DCOPIDL2CPP_EXECUTABLE - the dcopidl2cpp executable
  11. # KDE3_KCFGC_EXECUTABLE - the kconfig_compiler executable
  12. # KDE3_FOUND - set to TRUE if all of the above has been found
  13. #
  14. # The following user adjustable options are provided:
  15. #
  16. # KDE3_BUILD_TESTS - enable this to build KDE testcases
  17. #
  18. #
  19. # It also adds the following macros (from KDE3Macros.cmake)
  20. # SRCS_VAR is always the variable which contains the list of source files for your application or library.
  21. #
  22. # KDE3_AUTOMOC(file1 ... fileN)
  23. # Call this if you want to have automatic moc file handling.
  24. # This means if you include "foo.moc" in the source file foo.cpp
  25. # a moc file for the header foo.h will be created automatically.
  26. # You can set the property SKIP_AUTOMAKE using set_source_files_properties()
  27. # to exclude some files in the list from being processed.
  28. #
  29. # KDE3_ADD_MOC_FILES(SRCS_VAR file1 ... fileN )
  30. # If you don't use the KDE3_AUTOMOC() macro, for the files
  31. # listed here moc files will be created (named "foo.moc.cpp")
  32. #
  33. # KDE3_ADD_DCOP_SKELS(SRCS_VAR header1.h ... headerN.h )
  34. # Use this to generate DCOP skeletions from the listed headers.
  35. #
  36. # KDE3_ADD_DCOP_STUBS(SRCS_VAR header1.h ... headerN.h )
  37. # Use this to generate DCOP stubs from the listed headers.
  38. #
  39. # KDE3_ADD_UI_FILES(SRCS_VAR file1.ui ... fileN.ui )
  40. # Use this to add the Qt designer ui files to your application/library.
  41. #
  42. # KDE3_ADD_KCFG_FILES(SRCS_VAR file1.kcfgc ... fileN.kcfgc )
  43. # Use this to add KDE kconfig compiler files to your application/library.
  44. #
  45. # KDE3_INSTALL_LIBTOOL_FILE(target)
  46. # This will create and install a simple libtool file for the given target.
  47. #
  48. # KDE3_ADD_EXECUTABLE(name file1 ... fileN )
  49. # Currently identical to add_executable(), may provide some advanced features in the future.
  50. #
  51. # KDE3_ADD_KPART(name [WITH_PREFIX] file1 ... fileN )
  52. # Create a KDE plugin (KPart, kioslave, etc.) from the given source files.
  53. # If WITH_PREFIX is given, the resulting plugin will have the prefix "lib", otherwise it won't.
  54. # It creates and installs an appropriate libtool la-file.
  55. #
  56. # KDE3_ADD_KDEINIT_EXECUTABLE(name file1 ... fileN )
  57. # Create a KDE application in the form of a module loadable via kdeinit.
  58. # A library named kdeinit_<name> will be created and a small executable which links to it.
  59. #
  60. # The option KDE3_ENABLE_FINAL to enable all-in-one compilation is
  61. # no longer supported.
  62. #
  63. #
  64. # Author: Alexander Neundorf <[email protected]>
  65. #=============================================================================
  66. # Copyright 2006-2009 Kitware, Inc.
  67. # Copyright 2006 Alexander Neundorf <[email protected]>
  68. #
  69. # Distributed under the OSI-approved BSD License (the "License");
  70. # see accompanying file Copyright.txt for details.
  71. #
  72. # This software is distributed WITHOUT ANY WARRANTY; without even the
  73. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  74. # See the License for more information.
  75. #=============================================================================
  76. # (To distribute this file outside of CMake, substitute the full
  77. # License text for the above reference.)
  78. if(NOT UNIX AND KDE3_FIND_REQUIRED)
  79. message(FATAL_ERROR "Compiling KDE3 applications and libraries under Windows is not supported")
  80. endif()
  81. # If Qt4 has already been found, fail.
  82. if(QT4_FOUND)
  83. if(KDE3_FIND_REQUIRED)
  84. message( FATAL_ERROR "KDE3/Qt3 and Qt4 cannot be used together in one project.")
  85. else()
  86. if(NOT KDE3_FIND_QUIETLY)
  87. message( STATUS "KDE3/Qt3 and Qt4 cannot be used together in one project.")
  88. endif()
  89. return()
  90. endif()
  91. endif()
  92. set(QT_MT_REQUIRED TRUE)
  93. #set(QT_MIN_VERSION "3.0.0")
  94. #this line includes FindQt.cmake, which searches the Qt library and headers
  95. if(KDE3_FIND_REQUIRED)
  96. set(_REQ_STRING_KDE3 "REQUIRED")
  97. endif()
  98. find_package(Qt3 ${_REQ_STRING_KDE3})
  99. find_package(X11 ${_REQ_STRING_KDE3})
  100. #now try to find some kde stuff
  101. find_program(KDECONFIG_EXECUTABLE NAMES kde-config
  102. HINTS
  103. $ENV{KDEDIR}/bin
  104. PATHS
  105. /opt/kde3/bin
  106. /opt/kde/bin
  107. )
  108. set(KDE3PREFIX)
  109. if(KDECONFIG_EXECUTABLE)
  110. execute_process(COMMAND ${KDECONFIG_EXECUTABLE} --version
  111. OUTPUT_VARIABLE kde_config_version )
  112. string(REGEX MATCH "KDE: .\\." kde_version "${kde_config_version}")
  113. if ("${kde_version}" MATCHES "KDE: 3\\.")
  114. execute_process(COMMAND ${KDECONFIG_EXECUTABLE} --prefix
  115. OUTPUT_VARIABLE kdedir )
  116. string(REGEX REPLACE "\n" "" KDE3PREFIX "${kdedir}")
  117. endif ()
  118. endif()
  119. # at first the KDE include directory
  120. # kpassdlg.h comes from kdeui and doesn't exist in KDE4 anymore
  121. find_path(KDE3_INCLUDE_DIR kpassdlg.h
  122. HINTS
  123. $ENV{KDEDIR}/include
  124. ${KDE3PREFIX}/include
  125. PATHS
  126. /opt/kde3/include
  127. /opt/kde/include
  128. /usr/include/kde
  129. /usr/local/include/kde
  130. )
  131. #now the KDE library directory
  132. find_library(KDE3_KDECORE_LIBRARY NAMES kdecore
  133. HINTS
  134. $ENV{KDEDIR}/lib
  135. ${KDE3PREFIX}/lib
  136. PATHS
  137. /opt/kde3/lib
  138. /opt/kde/lib
  139. )
  140. set(QT_AND_KDECORE_LIBS ${QT_LIBRARIES} ${KDE3_KDECORE_LIBRARY})
  141. get_filename_component(KDE3_LIB_DIR ${KDE3_KDECORE_LIBRARY} PATH )
  142. if(NOT KDE3_LIBTOOL_DIR)
  143. if(KDE3_KDECORE_LIBRARY MATCHES lib64)
  144. set(KDE3_LIBTOOL_DIR /lib64/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})