Fix Quassel not rejoining newly joined channels
[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_OXYGEN=(ON|OFF) : Whether to install Oxygen icons (default: yes, unless KDE > 4.3.0 is present and enabled)
13 #
14 # -DEMBED_DATA=ON        : Embed all data files in icons the binary, rather than installing them separately
15 #
16 # -DQT=/path/to/qt       : Choose a Qt4 installation to use instead of the system Qt4
17 # -DSTATIC=ON            : Enable static building of Quassel. Use with care.
18 # -DDEPLOY=ON            : Mac OS X only. Use only for creating Quassel Packages!
19 #
20 # NOTE: You should remove CMakeCache.txt if you plan to change any of these values!
21
22 project(QuasselIRC)
23
24 cmake_minimum_required(VERSION 2.6.0 FATAL_ERROR)
25
26 if(COMMAND cmake_policy)
27    cmake_policy(SET CMP0003 NEW)
28 endif(COMMAND cmake_policy)
29
30 # Use our own (well, and KDE's) version of some modules
31 # In particular cmake's own FindQt4 and FindOpenSSL are quite buggy
32 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
33 include(QuasselMacros)
34
35 # Various options and variables that can be set on the command line
36 option(WANT_CORE     "Build the core (server) binary"           ON)
37 option(WANT_QTCLIENT "Build the Qt4 GUI client binary"          ON)
38 option(WANT_MONO     "Build the monolithic (all-in-one) binary" ON)
39
40 option(WITH_OPENSSL  "Enable OpenSSL support if present on the system"  ON)
41 option(WITH_DBUS     "Enable D-Bus support if present on the system"    ON)
42 option(WITH_WEBKIT   "Enable WebKit support (for link previews)"        ON)
43 option(WITH_PHONON   "Enable Phonon support (for audio notifications)"  ON)
44 option(WITH_LIBINDICATE "Enable Ayatana notification support"           ON)
45 option(WITH_KDE      "Enable KDE4 integration"                          OFF)
46
47 # We use icon paths from KDE 4.3.x, which are partially invalid on older and possibly
48 # even on newer KDE versions. Do not disable this unless you are sure that your Quassel will
49 # run on a matching KDE version only.
50 set(WITH_OXYGEN AUTO CACHE STRING "Install Oxygen icons (default is \"AUTO\" to install when KDE 4.3 or later is present")
51
52 option(STATIC        "Enable static building (might not be portable)" OFF)
53
54 if(APPLE)
55   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)
56 endif(APPLE)
57
58 # Default to embedding data in the static case
59 if(STATIC OR WIN32)
60   set(EMBED_DEFAULT ON)
61 else(STATIC OR WIN32)
62   set(EMBED_DEFAULT ON) # should be OFF as soon as everything works
63 endif(STATIC OR WIN32)
64
65 option(EMBED_DATA    "Embed all data files in the binary (rather than installing them separately)"   ${EMBED_DEFAULT})
66
67 set(QT "" CACHE STRING "Path to a Qt installation to use instead of the system Qt (e.g. for static builds)")
68 set(LINGUAS "" CACHE STRING "Comma-separated list of locales specifying languages that should be compiled")
69
70 # Some settings imply others
71 if(STATIC)
72   add_definitions(-DSTATIC)
73   set(WITH_KDE OFF CACHE BOOL "Static building with KDE is not supported")
74 endif(STATIC)
75
76 if(WIN32)
77   # We don't support separately installed resources yet on Win32
78   set(EMBED_DATA ON)
79 endif(WIN32)
80
81 # For static builds, arbitrary extra libs might need to be linked
82 # Define a comma-separated list here
83 # e.g. for pgsql, we need -DLINK_EXTRA=pq;crypt
84 set(LINK_EXTRA "" CACHE STRING "Semicolon-separated list of libraries to be linked")
85 if(LINK_EXTRA)
86   string(REPLACE "," ";" LINK_EXTRA ${LINK_EXTRA})
87   link_libraries(${LINK_EXTRA})
88 endif(LINK_EXTRA)
89
90 # Build Type
91 # We need to make sure it's not empty
92 # Supported: Release, RelWithDebugInfo, Debug, Debugfull
93
94 # On WIN32, only Release seems to work correctly (?)
95 if(WIN32)
96   set(DEFAULT_BUILD_TYPE "Release")
97 else(WIN32)
98   set(DEFAULT_BUILD_TYPE "RelWithDebugInfo")
99 endif(WIN32)
100
101 set(CMAKE_BUILD_TYPE ${DEFAULT_BUILD_TYPE} CACHE STRING "CMake Build Type")
102 if(NOT CMAKE_BUILD_TYPE)
103   set(CMAKE_BUILD_TYPE ${DEFAULT_BUILD_TYPE} CACHE STRING "CMake Build Type" FORCE)
104 endif(NOT CMAKE_BUILD_TYPE)
105
106 # Enable various flags on gcc
107 if(CMAKE_COMPILER_IS_GNUCXX)
108   # Let's just hope that all gccs support these options and skip the tests...
109   # -fno-strict-aliasing is needed apparently for Qt < 4.6
110   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ansi -Wall -Wextra -Wnon-virtual-dtor -fno-strict-aliasing")
111   set(CMAKE_CXX_FLAGS_RELWITHDEBUGINFO "-O2")
112   set(CMAKE_CXX_FLAGS_DEBUG "-g -fno-reorder-blocks -fno-schedule-insns -fno-inline")
113   set(CMAKE_CXX_FLAGS_DEBUGFULL "-g3")
114 endif(CMAKE_COMPILER_IS_GNUCXX)
115
116 if(WANT_MONO OR WANT_QTCLIENT)
117   set(QT_MIN_VERSION "4.4.1") # Client crashes often with 4.4.0
118 else(WANT_MONO OR WANT_QTCLIENT)
119   set(QT_MIN_VERSION "4.4.0")
120 endif(WANT_MONO OR WANT_QTCLIENT)
121
122 if(APPLE AND DEPLOY)
123   set(CMAKE_OSX_ARCHITECTURES "i386;ppc")
124   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.4")
125   set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.4u.sdk/")
126   add_definitions(-DMAC_10_4_SDK)
127 endif(APPLE AND DEPLOY)
128
129 # Execinfo is needed for generating backtraces
130 find_package(ExecInfo)
131 if(EXECINFO_FOUND)
132   add_definitions(-DHAVE_EXECINFO)
133   include_directories(${EXECINFO_INCLUDES})
134   link_libraries(${EXECINFO_LIBRARIES})
135 endif(EXECINFO_FOUND)
136
137 # Select a Qt installation here, if you don't want to use system Qt
138 if(QT)
139   # FindQt4 will look for the qmake binary in $PATH, so we just prepend the Qt dir
140   set(ENV{PATH} ${QT}/bin:$ENV{PATH})
141 endif(QT)
142
143 # Now that we have the correct $PATH, lets find Qt!
144 find_package(Qt4 REQUIRED)
145
146 set(QT_DONT_USE_QTGUI 1)
147 include(${QT_USE_FILE})
148 include_directories(${QT_INCLUDES})
149
150 # Setup OpenSSL
151 if(WITH_OPENSSL)
152   find_package(OpenSSL)
153 else(WITH_OPENSSL)
154   message(STATUS "Not enabling OpenSSL support")
155 endif(WITH_OPENSSL)
156
157 if(OPENSSL_FOUND)
158   if(NOT QT_DEFINITIONS MATCHES "QT_NO_OPENSSL")
159     message(STATUS "Found OpenSSL support in Qt")
160     add_definitions(-DHAVE_SSL)
161     set(HAVE_SSL true)
162     set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_SSL)
163   else(NOT QT_DEFINITIONS MATCHES "QT_NO_OPENSSL")
164     message(STATUS "No OpenSSL support found in Qt, disabling")
165   endif(NOT QT_DEFINITIONS MATCHES "QT_NO_OPENSSL")
166 else(OPENSSL_FOUND)
167   add_definitions(-DQT_NO_OPENSSL)
168 endif(OPENSSL_FOUND)
169
170 # Setup D-Bus support
171 if(WITH_DBUS)
172   if(QT_QTDBUS_FOUND)
173     message(STATUS "Found QtDBus, enabling D-Bus support")
174     add_definitions(-DHAVE_DBUS)
175     set(LINK_DBUS DBUS)
176     set(HAVE_DBUS true)
177     set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_DBUS)
178   else(QT_QTDBUS_FOUND)
179     message(STATUS "QtDBus not found, disabling D-Bus support")
180   endif(QT_QTDBUS_FOUND)
181 else(WITH_DBUS)
182   message(STATUS "Not enabling D-Bus support")
183 endif(WITH_DBUS)
184
185 # Setup QtWebKit support
186 if(WITH_WEBKIT)
187   if(QT_QTWEBKIT_FOUND)
188     message(STATUS "Found QtWebKit, enabling WebKit support")
189     add_definitions(-DHAVE_WEBKIT)
190     set(LINK_WEBKIT WEBKIT)
191     set(HAVE_WEBKIT true)
192     set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_WEBKIT)
193   else(QT_QTWEBKIT_FOUND)
194     message(STATUS "QtWebKit not found, disabling WebKit support")
195   endif(QT_QTWEBKIT_FOUND)
196 else(WITH_WEBKIT)
197   message(STATUS "Not enabling WebKit support")
198 endif(WITH_WEBKIT)
199
200 # Setup KDE4 support
201 if(WITH_KDE)
202   find_package(KDE4)
203   if(KDE4_FOUND)
204     message(STATUS "Enabling KDE4 integration")
205     include_directories(${KDE4_INCLUDES})
206     add_definitions(-DHAVE_KDE ${KDE4_DEFINITIONS})
207     set(HAVE_KDE 1)
208     set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_KDE)
209     set(QUASSEL_KDE_LIBRARIES ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBRARY} knotifyconfig)
210     # We always use external icons for KDE4 support, since we use its iconloader rather than our own
211     set(EMBED_DATA OFF)
212   else(KDE4_FOUND)
213     message(STATUS "KDE4 not found, disabling KDE integration")
214   endif(KDE4_FOUND)
215 else(WITH_KDE)
216   message(STATUS "Not enabling KDE4 integration")
217 endif(WITH_KDE)
218
219 # Setup Phonon support - we only need this if we don't have or want KDE4
220 if(NOT HAVE_KDE)
221   if(WITH_PHONON)
222     find_package(Phonon)
223     if(PHONON_FOUND)
224       message(STATUS "Enabling Phonon support")
225       add_definitions(-DHAVE_PHONON)
226       set(HAVE_PHONON true)
227       set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_PHONON)
228     else(PHONON_FOUND)
229       message(STATUS "Phonon not found, disabling audio notifications")
230     endif(PHONON_FOUND)
231   else(WITH_PHONON)
232     message(STATUS "Not enabling Phonon support")
233   endif(WITH_PHONON)
234 endif(NOT HAVE_KDE)
235
236 # Setup libindicate-qt support
237 if(WITH_LIBINDICATE)
238   find_package(PkgConfig QUIET)
239   if(PKG_CONFIG_FOUND)
240     pkg_check_modules(INDICATEQT indicate-qt>=0.2.1)
241     if(INDICATEQT_FOUND)
242       message(STATUS "Enabling Ayatana notification support")
243       add_definitions(-DHAVE_INDICATEQT)
244     else(INDICATEQT_FOUND)
245       message(STATUS "Disabling Ayatana notification support")
246     endif(INDICATEQT_FOUND)
247   endif(PKG_CONFIG_FOUND)
248 else(WITH_LIBINDICATE)
249   message(STATUS "Not enabling Ayatana notification support")
250 endif(WITH_LIBINDICATE)
251
252 # Now set up install locations; those are set by KDE if integration is enabled
253 if(NOT HAVE_KDE)
254   if(WIN32)
255     set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX} CACHE FILEPATH "Install path for binaries")
256     set(DATA_INSTALL_DIR $ENV{APPDATA}/quassel-irc.org/share/apps CACHE FILEPATH "Install path for data files")
257     set(ICON_INSTALL_DIR $ENV{APPDATA}/quassel-irc.org/share/icons CACHE FILEPATH "Global icon install path")
258     set(XDG_APPS_INSTALL_DIR $ENV{APPDATA}/quassel-irc.org/share/applications CACHE FILEPATH "Install path for .desktop files")
259   else(WIN32)
260     set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin CACHE FILEPATH "Install path for binaries")
261     set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/apps CACHE FILEPATH "Install path for data files")
262     set(ICON_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/icons CACHE FILEPATH "Global icon install path")
263     set(XDG_APPS_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/applications CACHE FILEPATH "Install path for .desktop files")
264   endif(WIN32)
265 endif(NOT HAVE_KDE)
266
267 if(EMBED_DATA)
268   message(STATUS "Embedding data files into the binary")
269 else(EMBED_DATA)
270   message(STATUS "Installing data files separately")
271 endif(EMBED_DATA)
272
273 # RPATH needs to be set correctly
274 # Do this down here, since otherwise KDE wants to handle it itself, and fails
275 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH 1)
276 set(CMAKE_BUILD_WITH_INSTALL_RPATH 1)
277
278 # Set global buildflags
279 # This is very much non-portable, so don't use -DSTATIC until you know what
280 # you do.
281 if(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
282   set(CMAKE_CXX_FLAGS "-static-libgcc ${CMAKE_CXX_FLAGS}")
283   link_directories(${CMAKE_BINARY_DIR}/staticlibs) # override dynamic libs
284   if(HAVE_SSL)
285     set(QUASSEL_SSL_LIBRARIES ssl crypto)  # these miss in static builds
286   endif(HAVE_SSL)
287 endif(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
288
289 if(WIN32)
290   link_libraries(imm32 winmm dbghelp Secur32)  # missing by default :/
291
292   if(HAVE_SSL)
293      link_libraries(${OPENSSL_LIBRARIES} libeay32MD)
294   endif(HAVE_SSL)
295 endif(WIN32)
296
297 if(INDICATEQT_FOUND)
298   if(WANT_QTCLIENT)
299     set(DESKTOP_FILE ${XDG_APPS_INSTALL_DIR}/quasselclient.desktop)
300   endif(WANT_QTCLIENT)
301   if(WANT_MONO)
302     set(DESKTOP_FILE ${XDG_APPS_INSTALL_DIR}/quassel.desktop)
303   endif(WANT_MONO)
304   add_definitions(-DDESKTOP_FILE=${DESKTOP_FILE})
305 endif(INDICATEQT_FOUND)
306
307 # We need to create a version.gen
308 # For this, we create our genversion binary and make sure it is run every time.
309 add_executable(genversion ${CMAKE_SOURCE_DIR}/src/common/genversion.cpp)
310 target_link_libraries(genversion ${QT_LIBRARIES} ${QT_CORE_LIB_DEPENDENCIES})
311
312 get_target_property(GENVERSION_EXECUTABLE genversion LOCATION)
313 add_custom_target(genversion_run ALL ${GENVERSION_EXECUTABLE}
314                   ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/src/version.gen)
315 add_dependencies(genversion_run genversion)
316
317 # These variables will be added to the main targets (CORE, QTCLIENT, MONO)
318 set(COMMON_DEPS ${RC_WIN32})
319 set(CORE_DEPS )
320 set(CLIENT_DEPS )
321
322 # Add needed subdirs - the order is important, since src needs some vars set by other dirs
323 add_subdirectory(data)
324 add_subdirectory(icons)
325 add_subdirectory(pics)
326 add_subdirectory(i18n)
327 add_subdirectory(src)