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