Introduce possibility to use syslog.
[quassel.git] / CMakeLists.txt
1 # This is the cmake-based build system for Quassel IRC.
2 #
3 # You may pass various options to cmake:
4 # -DWANT_(CORE|QTCLIENT|MONO)=(ON|OFF)
5 #                        : select binaries to build
6 # -DWITH_OPENSSL=OFF     : Disable OpenSSL support
7 # -DWITH_DBUS=OFF        : Disable D-Bus support (dbus notifications)
8 # -DWITH_WEBKIT=OFF      : Disable WebKit support (link previews)
9 # -DWITH_PHONON=OFF      : Disable Phonon support (audio notifications)
10 # -DWITH_LIBINDICATE=OFF : Disable libindicate support (Ayatana notifications)
11 # -DWITH_KDE=ON          : Enable KDE4 support
12 # -DWITH_CRYPT=OFF       : Disable encryption support
13 # -DWITH_OXYGEN=(ON|OFF) : Whether to install Oxygen icons (default: yes, unless KDE > 4.3.0 is present and enabled)
14 # -DWITH_SYSLOG=OFF       : Use syslog for logging
15 #
16 # -DEMBED_DATA=ON        : Embed all data files in icons the binary, rather than installing them separately
17 #
18 # -DQT=/path/to/qt       : Choose a Qt4 installation to use instead of the system Qt4
19 # -DSTATIC=ON            : Enable static building of Quassel. Use with care.
20 # -DDEPLOY=ON            : Mac OS X only. Use only for creating Quassel Packages!
21 #
22 # NOTE: You should remove CMakeCache.txt if you plan to change any of these values!
23
24 project(QuasselIRC)
25
26 # cmake 2.6.2 is required for KDE >=4.2 and should be widespread enough now
27 cmake_minimum_required(VERSION 2.6.2 FATAL_ERROR)
28
29 if(COMMAND cmake_policy)
30    cmake_policy(SET CMP0003 NEW)
31 endif(COMMAND cmake_policy)
32
33 # Use our own (well, and KDE's) version of some modules
34 # In particular cmake's own FindQt4 and FindOpenSSL are quite buggy
35 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
36 include(QuasselMacros)
37
38 # Various options and variables that can be set on the command line
39 option(WANT_CORE     "Build the core (server) binary"           ON)
40 option(WANT_QTCLIENT "Build the Qt4 GUI client binary"          ON)
41 option(WANT_MONO     "Build the monolithic (all-in-one) binary" ON)
42
43 option(WITH_OPENSSL  "Enable OpenSSL support if present on the system"  ON)
44 option(WITH_DBUS     "Enable D-Bus support if present on the system"    ON)
45 option(WITH_WEBKIT   "Enable WebKit support (for link previews)"        ON)
46 option(WITH_PHONON   "Enable Phonon support (for audio notifications)"  ON)
47 option(WITH_LIBINDICATE "Enable Ayatana notification support"           ON)
48 option(WITH_KDE      "Enable KDE4 integration"                          OFF)
49 option(WITH_CRYPT    "Enable encryption support if present on system"   ON)
50 option(WITH_SYSLOG    "Use syslog for storing log data"          OFF)
51
52 # We use icon paths from KDE 4.3.x, which are partially invalid on older and possibly
53 # even on newer KDE versions. Do not disable this unless you are sure that your Quassel will
54 # run on a matching KDE version only.
55 set(WITH_OXYGEN AUTO CACHE STRING "Install Oxygen icons (default is \"AUTO\" to install when KDE 4.3 or later is present")
56
57 option(STATIC        "Enable static building (might not be portable)" OFF)
58
59 if(APPLE)
60   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)
61 endif(APPLE)
62
63 if(WITH_SYSLOG)
64   check_include_file(syslog.h HAVE_SYSLOG_H)
65 endif(WITH_SYSLOG)
66
67 # Default to embedding data in the static case
68 if(STATIC OR WIN32)
69   set(EMBED_DEFAULT ON)
70 else(STATIC OR WIN32)
71   set(EMBED_DEFAULT ON) # should be OFF as soon as everything works
72 endif(STATIC OR WIN32)
73
74 option(EMBED_DATA    "Embed all data files in the binary (rather than installing them separately)"   ${EMBED_DEFAULT})
75
76 set(QT "" CACHE STRING "Path to a Qt installation to use instead of the system Qt (e.g. for static builds)")
77
78 # Some settings imply others
79 if(STATIC)
80   add_definitions(-DSTATIC)
81   set(WITH_KDE OFF CACHE BOOL "Static building with KDE is not supported")
82 endif(STATIC)
83
84 if(WIN32)
85   # We don't support separately installed resources yet on Win32
86   set(EMBED_DATA ON)
87 endif(WIN32)
88
89 # For static builds, arbitrary extra libs might need to be linked
90 # Define a comma-separated list here
91 # e.g. for pgsql, we need -DLINK_EXTRA=pq;crypt
92 set(LINK_EXTRA "" CACHE STRING "Semicolon-separated list of libraries to be linked")
93 if(LINK_EXTRA)
94   string(REPLACE "," ";" LINK_EXTRA ${LINK_EXTRA})
95   link_libraries(${LINK_EXTRA})
96 endif(LINK_EXTRA)
97
98 # Build Type
99 # We need to make sure it's not empty
100 # Supported: Release, RelWithDebugInfo, Debug, Debugfull
101
102 # On WIN32, only Release seems to work correctly (?)
103 if(WIN32)
104   set(DEFAULT_BUILD_TYPE "Release")
105 else(WIN32)
106   set(DEFAULT_BUILD_TYPE "RelWithDebugInfo")
107 endif(WIN32)
108
109 set(CMAKE_BUILD_TYPE ${DEFAULT_BUILD_TYPE} CACHE STRING "CMake Build Type")
110 if(NOT CMAKE_BUILD_TYPE)
111   set(CMAKE_BUILD_TYPE ${DEFAULT_BUILD_TYPE} CACHE STRING "CMake Build Type" FORCE)
112 endif(NOT CMAKE_BUILD_TYPE)
113
114 # Enable various flags on gcc
115 if(CMAKE_COMPILER_IS_GNUCXX)
116   # Let's just hope that all gccs support these options and skip the tests...
117   # -fno-strict-aliasing is needed apparently for Qt < 4.6
118   set(CMAKE_CXX_FLAGS                  "${CMAKE_CXX_FLAGS} -ansi -Wall -Wextra -Wnon-virtual-dtor -fno-strict-aliasing")
119   set(CMAKE_CXX_FLAGS_RELEASE          "-O2 ${CMAKE_CXX_FLAGS}")
120   set(CMAKE_CXX_FLAGS_RELWITHDEBUGINFO "-g -O2 ${CMAKE_CXX_FLAGS}")
121   set(CMAKE_CXX_FLAGS_DEBUG            "-g -ggdb -fno-reorder-blocks -fno-schedule-insns -fno-inline ${CMAKE_CXX_FLAGS}")
122   set(CMAKE_CXX_FLAGS_DEBUGFULL        "-g3 ${CMAKE_CXX_FLAGS_DEBUG}")
123 endif(CMAKE_COMPILER_IS_GNUCXX)
124
125 string(TOUPPER ${CMAKE_BUILD_TYPE} upper_build_type)
126 if(upper_build_type STREQUAL "RELEASE" OR upper_build_type STREQUAL "RELWITHDEBUGINFO")
127   add_definitions(-DNDEBUG -DQT_NO_DEBUG)
128 else(upper_build_type STREQUAL "RELEASE" OR upper_build_type STREQUAL "RELWITHDEBUGINFO")
129   set(DEBUG 1)
130 endif(upper_build_type STREQUAL "RELEASE" OR upper_build_type STREQUAL "RELWITHDEBUGINFO")
131
132 if(APPLE AND DEPLOY)
133   set(CMAKE_OSX_ARCHITECTURES "i386;ppc")
134   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.4")
135   set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.4u.sdk/")
136   add_definitions(-DMAC_10_4_SDK)
137 endif(APPLE AND DEPLOY)
138
139 # Simplify checks
140 if(WANT_MONO OR WANT_QTCLIENT)
141   set(BUILD_GUI true)
142 endif(WANT_MONO OR WANT_QTCLIENT)
143 if(WANT_MONO OR WANT_CORE)
144   set(BUILD_CORE true)
145 endif(WANT_MONO OR WANT_CORE)
146
147 # Dependencies
148 ##############
149
150 # GUI stuff needs some new features
151 if(BUILD_GUI)
152   set(QT_MIN_VERSION "4.6.0")
153 else(BUILD_GUI)
154   set(QT_MIN_VERSION "4.4.0")
155 endif(BUILD_GUI)
156
157 # Execinfo is needed for generating backtraces
158 find_package(ExecInfo)
159 if(EXECINFO_FOUND)
160   add_definitions(-DHAVE_EXECINFO)
161   include_directories(${EXECINFO_INCLUDES})
162   link_libraries(${EXECINFO_LIBRARIES})
163 endif(EXECINFO_FOUND)
164
165 # Select a Qt installation here, if you don't want to use system Qt
166 if(QT)
167   # FindQt4 will look for the qmake binary in $PATH, so we just prepend the Qt dir
168   set(ENV{PATH} ${QT}/bin:$ENV{PATH})
169 endif(QT)
170
171 # Now that we have the correct $PATH, lets find Qt!
172 find_package(Qt4 REQUIRED)
173
174 set(QT_DONT_USE_QTGUI 1)
175 include(${QT_USE_FILE})
176 include_directories(${QT_INCLUDES})
177
178 # PkgConfig isn't strictly required.
179 # However, some optional deps might not be found if it's not present, so warn!
180 find_package(PkgConfig)
181 if(NOT PKG_CONFIG_FOUND)
182   message(STATUS "WARNING: PkgConfig not available! Some dependencies for optional features might not be found.")
183   message(STATUS "         Affected features might include encryption support, DBus menus and Ayatana notifications.")
184 endif(NOT PKG_CONFIG_FOUND)
185
186 # Setup OpenSSL
187 # We don't link to or include OpenSSL ourselves, but use exclusively the Qt API.
188 # Thus, we simply check if OpenSSL support is present in Qt's config and enable our
189 # own SSL stuff in this case. Qt should care for adding what it needs itself.
190 if(WITH_OPENSSL)
191   if(QT_QCONFIG MATCHES "openssl")
192     message(STATUS "Found OpenSSL support in Qt, enabling SSL")
193     add_definitions(-DHAVE_SSL)
194     set(HAVE_SSL true)
195   else(QT_QCONFIG MATCHES "openssl")
196     message(STATUS "No OpenSSL support found in Qt, disabling SSL")
197     add_definitions(-DQT_NO_OPENSSL)
198   endif(QT_QCONFIG MATCHES "openssl")
199 else(WITH_OPENSSL)
200   message(STATUS "Not enabling OpenSSL support")
201 endif(WITH_OPENSSL)
202
203 # Check for GUI specific stuff
204 if(BUILD_GUI)
205
206   # Setup D-Bus support
207   if(WITH_DBUS)
208     if(QT_QTDBUS_FOUND)
209       message(STATUS "Found QtDBus, enabling D-Bus support")
210       add_definitions(-DHAVE_DBUS)
211       set(CLIENT_QT4_VARS ${CLIENT_QT4_VARS} DBUS)
212       set(CLIENT_COMPILE_FLAGS "${CLIENT_COMPILE_FLAGS} -DQT_DBUS_LIB")
213       set(HAVE_DBUS true)
214
215       # check if we have dbusmenu as well
216       find_package(DBusMenuQt)
217       if(DBUSMENUQT_FOUND)
218         message(STATUS "Enabling support for exporting the tray menu via D-Bus")
219         add_definitions(-DHAVE_DBUSMENU)
220         include_directories(${DBUSMENUQT_INCLUDE_DIR})
221         set(CLIENT_LIBRARIES ${CLIENT_LIBRARIES} ${DBUSMENUQT_LIBRARIES})
222         set(CLIENT_COMPILE_FLAGS "${CLIENT_COMPILE_FLAGS} ${DBUSMENUQT_DEFINITIONS}")
223       else(DBUSMENUQT_FOUND)
224         message(STATUS "Disabling support for exporting the tray menu via D-Bus")
225       endif(DBUSMENUQT_FOUND)
226
227     else(QT_QTDBUS_FOUND)
228       message(STATUS "QtDBus not found, disabling D-Bus support")
229     endif(QT_QTDBUS_FOUND)
230   else(WITH_DBUS)
231     message(STATUS "Not enabling D-Bus support")
232   endif(WITH_DBUS)
233
234   # Setup QtWebKit support
235   if(WITH_WEBKIT)
236     if(QT_QTWEBKIT_FOUND)
237       message(STATUS "Found QtWebKit, enabling WebKit support")
238       add_definitions(-DHAVE_WEBKIT)
239       set(CLIENT_QT4_VARS ${CLIENT_QT4_VARS} WEBKIT XMLPATTERNS)
240       set(CLIENT_COMPILE_FLAGS "${CLIENT_COMPILE_FLAGS} -DQT_WEBKIT_LIB -DQT_XMLPATTERNS_LIB")
241       set(HAVE_WEBKIT true)
242     else(QT_QTWEBKIT_FOUND)
243       message(STATUS "QtWebKit not found, disabling WebKit support")
244     endif(QT_QTWEBKIT_FOUND)
245   else(WITH_WEBKIT)
246     message(STATUS "Not enabling WebKit support")
247   endif(WITH_WEBKIT)
248
249   # Setup KDE4 support
250   if(WITH_KDE)
251     find_package(KDE4)
252     if(KDE4_FOUND)
253       message(STATUS "Enabling KDE4 integration")
254       include_directories(${KDE4_INCLUDES})
255       add_definitions(-DHAVE_KDE ${KDE4_DEFINITIONS})
256       set(HAVE_KDE 1)
257       set(CLIENT_LIBRARIES ${CLIENT_LIBRARIES} ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBRARY} ${KDE4_SOLID_LIBS} knotifyconfig)
258       # We always use external icons for KDE4 support, since we use its iconloader rather than our own
259       set(EMBED_DATA OFF)
260     else(KDE4_FOUND)
261       message(STATUS "KDE4 not found, disabling KDE integration")
262     endif(KDE4_FOUND)
263   else(WITH_KDE)
264     message(STATUS "Not enabling KDE4 integration")
265   endif(WITH_KDE)
266
267   # Setup Phonon support - we only need this if we don't have or want KDE4
268   if(NOT HAVE_KDE)
269     if(WITH_PHONON)
270       find_package(Phonon)
271       if(PHONON_FOUND)
272         message(STATUS "Enabling Phonon support")
273         add_definitions(-DHAVE_PHONON)
274         include_directories(${PHONON_INCLUDES})
275         set(CLIENT_LIBRARIES ${CLIENT_LIBRARIES} ${PHONON_LIBS})
276         set(HAVE_PHONON true)
277       else(PHONON_FOUND)
278         message(STATUS "Phonon not found, disabling audio notifications")
279       endif(PHONON_FOUND)
280     else(WITH_PHONON)
281       message(STATUS "Not enabling Phonon support")
282     endif(WITH_PHONON)
283   endif(NOT HAVE_KDE)
284
285   # Setup libindicate-qt support
286   if(WITH_LIBINDICATE)
287     pkg_check_modules(INDICATEQT QUIET indicate-qt>=0.2.1)
288     if(INDICATEQT_FOUND)
289       message(STATUS "Enabling Ayatana notification support")
290       set(HAVE_INDICATEQT true)
291       add_definitions(-DHAVE_INDICATEQT)
292       link_directories(${INDICATEQT_LIBRARY_DIRS})
293       set(CLIENT_LIBRARIES ${CLIENT_LIBRARIES} ${INDICATEQT_LIBRARIES})
294     else(INDICATEQT_FOUND)
295       message(STATUS "Disabling Ayatana notification support")
296     endif(INDICATEQT_FOUND)
297   else(WITH_LIBINDICATE)
298     message(STATUS "Not enabling Ayatana notification support")
299     # We don't want to link against it even if another package has found it
300     set(INDICATEQT_LIBRARIES "")
301   endif(WITH_LIBINDICATE)
302
303 endif(BUILD_GUI)
304
305 # Core-only deps
306 if(BUILD_CORE)
307
308   # Setup encryption support
309   if(WITH_CRYPT)
310     find_package(QCA2)
311     if(QCA2_FOUND)
312       message(STATUS "Found QCA2, enabling encryption support")
313       add_definitions(-DHAVE_QCA2)
314       set(LINK_QCA2 QCA2)
315       set(HAVE_QCA2 true)
316       set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_QCA2)
317     else(QCA2_FOUND)
318       message(STATUS "QCA2 not found, disabling encryption support")
319     endif(QCA2_FOUND)
320   else(WITH_CRYPT)
321     message(STATUS "Not enabling encryption support")
322   endif(WITH_CRYPT)
323
324 endif(BUILD_CORE)
325
326 # needed to compile with mingw without kde
327 if(MINGW AND NOT HAVE_KDE)
328     add_definitions(-D_WIN32_WINNT=0x0500)
329     message(STATUS "Added _WIN32_WINNT=0x0500 definition for MinGW")
330 # workaround for bug in mingw gcc 4.0
331     add_definitions(-U__STRICT_ANSI__)
332 endif(MINGW AND NOT HAVE_KDE)
333
334 # Now set up install locations; those are set by KDE if integration is enabled
335 if(NOT HAVE_KDE)
336   if(WIN32)
337     set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX} CACHE FILEPATH "Install path for binaries")
338     set(DATA_INSTALL_DIR $ENV{APPDATA}/quassel-irc.org/share/apps CACHE FILEPATH "Install path for data files")
339     set(ICON_INSTALL_DIR $ENV{APPDATA}/quassel-irc.org/share/icons CACHE FILEPATH "Global icon install path")
340     set(XDG_APPS_INSTALL_DIR $ENV{APPDATA}/quassel-irc.org/share/applications CACHE FILEPATH "Install path for .desktop files")
341   else(WIN32)
342     set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin CACHE FILEPATH "Install path for binaries")
343     set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/apps CACHE FILEPATH "Install path for data files")
344     set(ICON_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/icons CACHE FILEPATH "Global icon install path")
345     set(XDG_APPS_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/applications CACHE FILEPATH "Install path for .desktop files")
346   endif(WIN32)
347 endif(NOT HAVE_KDE)
348
349 if(EMBED_DATA)
350   message(STATUS "Embedding data files into the binary")
351 else(EMBED_DATA)
352   message(STATUS "Installing data files separately")
353 endif(EMBED_DATA)
354
355 # RPATH needs to be set correctly
356 # Do this down here, since otherwise KDE wants to handle it itself, and fails
357 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH 1)
358 set(CMAKE_BUILD_WITH_INSTALL_RPATH 1)
359
360 # Set global buildflags
361 # This is very much non-portable, so don't use -DSTATIC until you know what
362 # you do.
363 if(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
364   set(CMAKE_CXX_FLAGS "-static-libgcc ${CMAKE_CXX_FLAGS}")
365   link_directories(${CMAKE_BINARY_DIR}/staticlibs) # override dynamic libs
366   if(HAVE_SSL)
367     set(QUASSEL_SSL_LIBRARIES ssl crypto)  # these miss in static builds
368   endif(HAVE_SSL)
369 endif(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
370
371 if(WIN32)
372   link_libraries(imm32 winmm dbghelp Secur32)  # missing by default :/
373   if(MSVC)
374     set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBUGINFO "/debug /INCREMENTAL:YES /NODEFAULTLIB:libcmt /DEFAULTLIB:msvcrt")
375     set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBUGINFO}")
376     set(CMAKE_EXE_LINKER_FLAGS_DEBUGFULL "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBUGINFO}")
377     link_libraries(Version dwmapi shlwapi)
378   endif(MSVC)
379   if(HAVE_SSL AND STATIC)
380      find_package(OpenSSL REQUIRED)
381      link_libraries(${OPENSSL_LIBRARIES} ${OPENSSL_EAY_LIBRARIES})
382   endif(HAVE_SSL AND STATIC)
383 endif(WIN32)
384
385 if(HAVE_INDICATEQT)
386   add_definitions(-DXDG_APPS_INSTALL_DIR=${XDG_APPS_INSTALL_DIR})
387 endif(HAVE_INDICATEQT)
388
389 # We need to create a version.gen
390 # For this, we create our genversion binary and make sure it is run every time.
391 add_executable(genversion ${CMAKE_SOURCE_DIR}/src/common/genversion.cpp)
392 target_link_libraries(genversion ${QT_LIBRARIES} ${QT_CORE_LIB_DEPENDENCIES})
393
394 get_target_property(GENVERSION_EXECUTABLE genversion LOCATION)
395 add_custom_target(genversion_run ALL ${GENVERSION_EXECUTABLE}
396                   ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/src/version.gen)
397 add_dependencies(genversion_run genversion)
398
399 # These variables will be added to the main targets (CORE, QTCLIENT, MONO)
400 set(COMMON_DEPS ${RC_WIN32})
401 set(CORE_DEPS )
402 set(CLIENT_DEPS )
403
404 # Add needed subdirs - the order is important, since src needs some vars set by other dirs
405 add_subdirectory(data)
406 add_subdirectory(icons)
407 add_subdirectory(pics)
408 add_subdirectory(po)
409 add_subdirectory(src)