Enable KDE support in the build system
[quassel.git] / CMakeLists.txt
1 # This is the cmake-based build system for Quassel IRC.
2 # You may pass various options to cmake:
3 # -DWANT_(CORE|QTCLIENT|MONO)=(ON|OFF)
4 #                     : select binaries to build
5 # -DWITH_OPENSSL=OFF  : Disable OpenSSL support
6 # -DWITH_DBUS=OFF     : Disable D-Bus support (dbus notifications)
7 # -DWITH_WEBKIT=OFF   : Disable WebKit support (link previews)
8 # -DWITH_PHONON=OFF   : Disable Phonon support (audio notifications)
9 # -DWITH_KDE=ON       : Enable KDE4 support
10 # -DOXYGEN_ICONS=(Builtin|External)  : If "Builtin" (the default), compile our Oxygen Icon Theme subset into the binary
11 #                                    : If "External", we assume Oxygen is already installed on the system
12 # -DQUASSEL_ICONS=(Builtin|External) : If "Builtin" (the default), put our own icons into the binary
13 #                                    : If "External", we install our icons into $PREFIX/share/apps/quassel (UNIX only)
14 # -DQT=/path/to/qt    : Choose a Qt4 installation to use instead of the system Qt4
15 # -DSTATIC=ON         : Enable static building of Quassel. Use with care.
16 # -DDEPLOY=ON         : Mac OS X only. Use only for creating Quassel Packages!
17 #
18 # NOTE: You need to remove CMakeCache.txt if you plan to change any of these values!
19
20 project(QuasselIRC)
21
22 cmake_minimum_required(VERSION 2.6.0 FATAL_ERROR)
23
24 if(COMMAND cmake_policy)
25    cmake_policy(SET CMP0003 NEW)
26 endif(COMMAND cmake_policy)
27
28 # Use our own (well, and KDE's) version of some modules
29 # In particular cmake's FindQt4 and FindOpenSSL are quite buggy
30 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
31
32 # Various options and variables that can be set on the command line
33 option(WANT_CORE     "Build the core (server) binary"           ON)
34 option(WANT_QTCLIENT "Build the Qt4 GUI client binary"          ON)
35 option(WANT_MONO     "Build the monolithic (all-in-one) binary" ON)
36
37 option(WITH_OPENSSL  "Enable OpenSSL support if present on the system"  ON)
38 option(WITH_DBUS     "Enable D-Bus support if present on the system"    ON)
39 option(WITH_WEBKIT   "Enable WebKit support (for link previews)"        ON)
40 option(WITH_PHONON   "Enable Phonon support (for audio notifications)"  ON)
41 option(WITH_KDE      "Enable KDE4 integration"                          OFF)
42
43 option(STATIC        "Enable static building (might not be portable)" OFF)
44 option(DEPLOY        "Mac OS X only! Adds required libs to bundle resources and create a dmg. Note: requires Qt to be built with 10.4u SDK" OFF)
45 option(SPUTDEV       "Do not use!" OFF)
46
47 set(OXYGEN_ICONS "Builtin" CACHE STRING "Builtin: Compile Oxygen icons into the binary; External: Use system-installed Oxygen")
48 set(QUASSEL_ICONS "Builtin" CACHE STRING "Builtin: Compile Quassel icons into the binary; External: Install them separately")
49
50 set(QT "" CACHE STRING "Path to a Qt installation to use instead of the system Qt")
51 set(LINGUAS "" CACHE STRING "Space-separated List of locales specifying languages that should be compiled")
52
53 if(STATIC)
54   set(CMAKE_BUILD_TYPE Release)
55   set(OXYGEN_ICONS "Builtin")
56   set(QUASSEL_ICONS "Builtin")
57 endif(STATIC)
58
59 # RPATH needs to be set correctly
60 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH 1) 
61 set(CMAKE_BUILD_WITH_INSTALL_RPATH 1)
62
63 # Define install locations. Using variables will allow overriding this by the KDE macros later.
64 set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin)
65 set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/apps)
66 set(ICON_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/icons)
67 set(XDG_APPS_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/applications)
68
69 # Enable various flags on gcc
70 if(CMAKE_COMPILER_IS_GNUCXX)
71   # Let's just hope that all gccs support these options and skip the tests...
72   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ansi -Wall -Wextra -Wnon-virtual-dtor")
73 endif(CMAKE_COMPILER_IS_GNUCXX)
74
75 set(QT_MIN_VERSION "4.4.0")
76
77 if(APPLE AND DEPLOY)
78   set(CMAKE_OSX_ARCHITECTURES "i386;ppc")
79   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.4")
80   set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.4u.sdk/")
81   add_definitions(-DMAC_10_4_SDK)
82 endif(APPLE AND DEPLOY)
83
84 include(QuasselMacros)
85
86 # Execinfo is needed for generating backtraces
87 find_package(ExecInfo)
88 if(EXECINFO_FOUND)
89   add_definitions(-DHAVE_EXECINFO)
90   include_directories(${EXECINFO_INCLUDES})
91   link_libraries(${EXECINFO_LIBRARIES})
92 endif(EXECINFO_FOUND)
93
94 # Select a Qt installation here, if you don't want to use system Qt
95 if(QT)
96   # FindQt4 will look for the qmake binary in $PATH, so we just prepend the Qt dir
97   set(ENV{PATH} ${QT}/bin:$ENV{PATH})
98 endif(QT)
99
100 # Now that we have the correct $PATH, lets find Qt!
101 find_package(Qt4 REQUIRED)
102
103 set(QT_DONT_USE_QTGUI 1)
104 include(${QT_USE_FILE})
105 include_directories(${QT_INCLUDES})
106
107 # Setup OpenSSL
108 if(WITH_OPENSSL)
109   find_package(OpenSSL)
110 else(WITH_OPENSSL)
111   message(STATUS "Disabling OpenSSL support")
112 endif(WITH_OPENSSL)
113
114 if(OPENSSL_FOUND)
115   if(NOT QT_DEFINITIONS MATCHES "QT_NO_OPENSSL")
116     message(STATUS "Found OpenSSL support in Qt")
117     add_definitions(-DHAVE_SSL)
118     set(HAVE_SSL true)
119     set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_SSL)
120   else(NOT QT_DEFINITIONS MATCHES "QT_NO_OPENSSL")
121     message(STATUS "No OpenSSL support found in Qt, disabling")
122   endif(NOT QT_DEFINITIONS MATCHES "QT_NO_OPENSSL")
123 else(OPENSSL_FOUND)
124   add_definitions(-DQT_NO_OPENSSL)
125 endif(OPENSSL_FOUND)
126
127 # Setup D-Bus support
128 if(WITH_DBUS)
129   if(QT_QTDBUS_FOUND)
130     message(STATUS "Found QtDBus, enabling D-Bus support")
131     add_definitions(-DHAVE_DBUS)
132     set(LINK_DBUS DBUS)
133     set(HAVE_DBUS true)
134     set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_DBUS)
135   else(QT_QTDBUS_FOUND)
136     message(STATUS "QtDBus not found, disabling D-Bus support")
137   endif(QT_QTDBUS_FOUND)
138 else(WITH_DBUS)
139   message(STATUS "Disabling D-Bus support")
140 endif(WITH_DBUS)
141
142 # Setup QtWebKit support
143 if(WITH_WEBKIT)
144   if(QT_QTWEBKIT_FOUND)
145     message(STATUS "Found QtWebKit, enabling WebKit support")
146     add_definitions(-DHAVE_WEBKIT)
147     set(LINK_WEBKIT WEBKIT)
148     set(HAVE_WEBKIT true)
149     set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_WEBKIT)
150   else(QT_QTWEBKIT_FOUND)
151     message(STATUS "QtWebKit not found, disabling D-Bus support")
152   endif(QT_QTWEBKIT_FOUND)
153 else(WITH_WEBKIT)
154   message(STATUS "Disabling WebKit support")
155 endif(WITH_WEBKIT)
156
157 # Setup Phonon support
158 if(WITH_PHONON)
159   find_package(Phonon)
160   if(PHONON_FOUND)
161     message(STATUS "Enabling Phonon support")
162     add_definitions(-DHAVE_PHONON)
163     set(HAVE_PHONON true)
164     set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_PHONON)
165   else(PHONON_FOUND)
166     message(STATUS "Phonon not found, disabling audio notifications")
167   endif(PHONON_FOUND)
168 else(WITH_PHONON)
169   message(STATUS "Disabling Phonon support")
170 endif(WITH_PHONON)
171
172 # Setup KDE4 support
173 if(WITH_KDE)
174   find_package(KDE4)
175   if(KDE4_FOUND)
176     message(STATUS "Enabling KDE4 integration")
177     include_directories(${KDE4_INCLUDES})
178     add_definitions(-DHAVE_KDE ${KDE4_DEFINITIONS})
179     set(HAVE_KDE 1)
180     set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_KDE)
181     set(QUASSEL_KDE_LIBRARIES ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBRARY})
182   else(KDE4_FOUND)
183     message(STATUS "KDE4 not found, disabling KDE integration")
184   endif(KDE4_FOUND)
185 else(WITH_KDE)
186   message(STATUS "Disabling KDE4 integration")
187 endif(WITH_KDE)
188
189 # Set global buildflags
190 # This is very much non-portable, so don't use -DSTATIC until you know what
191 # you do.
192 if(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
193   set(CMAKE_CXX_FLAGS "-static-libgcc ${CMAKE_CXX_FLAGS}")
194   link_directories(${CMAKE_BINARY_DIR}/staticlibs) # override dynamic libs
195   if(HAVE_SSL)
196     set(QUASSEL_SSL_LIBRARIES ssl crypto)  # these miss in static builds
197   endif(HAVE_SSL)
198 endif(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
199
200 if(WIN32)
201   #if(STATIC)
202   link_libraries(imm32 winmm dbghelp)  # missing by default :/
203   #endif(STATIC)
204   if(HAVE_SSL)
205      link_libraries(${OPENSSL_LIBRARIES} libeay32MD)
206   endif(HAVE_SSL)
207 endif(WIN32)
208
209 if(WIN32)
210   set(RC_WIN32 ../pics/win32.rc)  # for app icons on windows
211 endif(WIN32)
212
213 # This is dirty, but I haven't found a cleaner way to ensure that the generated .qrc files
214 # (which will be removed with make clean) are regenerated :/
215 set_directory_properties(PROPERTIES
216                          ADDITIONAL_MAKE_CLEAN_FILES CMakeCache.txt)
217
218 # We need to create a version.gen
219 # For this, we create our genversion binary and make sure it is run every time.
220 add_executable(genversion ${CMAKE_SOURCE_DIR}/src/common/genversion.cpp)
221 target_link_libraries(genversion ${QT_LIBRARIES} ${QT_CORE_LIB_DEPENDENCIES})
222
223 get_target_property(GENVERSION_EXECUTABLE genversion LOCATION)
224 add_custom_target(genversion_run ALL ${GENVERSION_EXECUTABLE}
225                   ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/src/version.gen)
226 add_dependencies(genversion_run genversion)
227
228 # Decide what to do with icons
229 if(WANT_QTCLIENT OR WANT_MONO)
230   if(QUASSEL_ICONS MATCHES "External")
231     message(STATUS "Install Quassel icons to ${CMAKE_INSTALL_PREFIX}/share/apps/quassel")
232   else(QUASSEL_ICONS MATCHES "External")
233     set(QUASSEL_ICONS "Builtin")
234     message(STATUS "Compile Quassel icons into the binary")
235   endif(QUASSEL_ICONS MATCHES "External")
236
237   if(OXYGEN_ICONS MATCHES "External")
238     message(STATUS "Use system-installed Oxygen icon theme")
239   else(OXYGEN_ICONS MATCHES "External")
240     set(OXYGEN_ICONS "Builtin")
241     message(STATUS "Compile Oxygen icon theme subset into the binary")
242   endif(OXYGEN_ICONS MATCHES "External")
243 endif(WANT_QTCLIENT OR WANT_MONO)
244
245 # These variables will be added to the main targets (CORE, QTCLIENT, MONO)
246
247 set(COMMON_DEPS ${RC_WIN32})
248 set(CORE_DEPS )
249 set(CLIENT_DEPS )
250 set(KDE_DEPS )
251
252 # Add needed subdirs - the order is important, since src needs some vars set by other dirs
253 add_subdirectory(data)
254 add_subdirectory(icons)
255 #add_subdirectory(pics)
256 add_subdirectory(i18n)
257 add_subdirectory(src)