c1fee4a9b606e028d10b32725755369b12bfd5ad
[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 2.6.2 is required for KDE >=4.2 and should be widespread enough now
25 cmake_minimum_required(VERSION 2.6.2 FATAL_ERROR)
26
27 if(COMMAND cmake_policy)
28    cmake_policy(SET CMP0003 NEW)
29 endif(COMMAND cmake_policy)
30
31 # Use our own (well, and KDE's) version of some modules
32 # In particular cmake's own FindQt4 and FindOpenSSL are quite buggy
33 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
34 include(QuasselMacros)
35
36 # Various options and variables that can be set on the command line
37 option(WANT_CORE     "Build the core (server) binary"           ON)
38 option(WANT_QTCLIENT "Build the Qt4 GUI client binary"          ON)
39 option(WANT_MONO     "Build the monolithic (all-in-one) binary" ON)
40
41 option(WITH_OPENSSL  "Enable OpenSSL support if present on the system"  ON)
42 option(WITH_DBUS     "Enable D-Bus support if present on the system"    ON)
43 option(WITH_WEBKIT   "Enable WebKit support (for link previews)"        ON)
44 option(WITH_PHONON   "Enable Phonon support (for audio notifications)"  ON)
45 option(WITH_LIBINDICATE "Enable Ayatana notification support"           ON)
46 option(WITH_KDE      "Enable KDE4 integration"                          OFF)
47
48 # We use icon paths from KDE 4.3.x, which are partially invalid on older and possibly
49 # even on newer KDE versions. Do not disable this unless you are sure that your Quassel will
50 # run on a matching KDE version only.
51 set(WITH_OXYGEN AUTO CACHE STRING "Install Oxygen icons (default is \"AUTO\" to install when KDE 4.3 or later is present")
52
53 option(STATIC        "Enable static building (might not be portable)" OFF)
54
55 if(APPLE)
56   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)
57 endif(APPLE)
58
59 # Default to embedding data in the static case
60 if(STATIC OR WIN32)
61   set(EMBED_DEFAULT ON)
62 else(STATIC OR WIN32)
63   set(EMBED_DEFAULT ON) # should be OFF as soon as everything works
64 endif(STATIC OR WIN32)
65
66 option(EMBED_DATA    "Embed all data files in the binary (rather than installing them separately)"   ${EMBED_DEFAULT})
67
68 set(QT "" CACHE STRING "Path to a Qt installation to use instead of the system Qt (e.g. for static builds)")
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_RELEASE          "-O2 ${CMAKE_CXX_FLAGS}")
112   set(CMAKE_CXX_FLAGS_RELWITHDEBUGINFO "-g -O2 ${CMAKE_CXX_FLAGS}")
113   set(CMAKE_CXX_FLAGS_DEBUG            "-g -ggdb -fno-reorder-blocks -fno-schedule-insns -fno-inline ${CMAKE_CXX_FLAGS}")
114   set(CMAKE_CXX_FLAGS_DEBUGFULL        "-g3 ${CMAKE_CXX_FLAGS_DEBUG}")
115 endif(CMAKE_COMPILER_IS_GNUCXX)
116
117 string(TOUPPER ${CMAKE_BUILD_TYPE} upper_build_type)
118 if(upper_build_type STREQUAL "RELEASE" OR upper_build_type STREQUAL "RELWITHDEBUGINFO")
119   add_definitions(-DNDEBUG -DQT_NO_DEBUG)
120 else(upper_build_type STREQUAL "RELEASE" OR upper_build_type STREQUAL "RELWITHDEBUGINFO")
121   set(DEBUG 1)
122 endif(upper_build_type STREQUAL "RELEASE" OR upper_build_type STREQUAL "RELWITHDEBUGINFO")
123
124 if(WANT_MONO OR WANT_QTCLIENT)
125   set(QT_MIN_VERSION "4.6.0")
126 else(WANT_MONO OR WANT_QTCLIENT)
127   set(QT_MIN_VERSION "4.4.0")
128 endif(WANT_MONO OR WANT_QTCLIENT)
129
130 if(APPLE AND DEPLOY)
131   set(CMAKE_OSX_ARCHITECTURES "i386;ppc")
132   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.4")
133   set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.4u.sdk/")
134   add_definitions(-DMAC_10_4_SDK)
135 endif(APPLE AND DEPLOY)
136
137 # Execinfo is needed for generating backtraces
138 find_package(ExecInfo)
139 if(EXECINFO_FOUND)
140   add_definitions(-DHAVE_EXECINFO)
141   include_directories(${EXECINFO_INCLUDES})
142   link_libraries(${EXECINFO_LIBRARIES})
143 endif(EXECINFO_FOUND)
144
145 # Select a Qt installation here, if you don't want to use system Qt
146 if(QT)
147   # FindQt4 will look for the qmake binary in $PATH, so we just prepend the Qt dir
148   set(ENV{PATH} ${QT}/bin:$ENV{PATH})
149 endif(QT)
150
151 # Now that we have the correct $PATH, lets find Qt!
152 find_package(Qt4 REQUIRED)
153
154 set(QT_DONT_USE_QTGUI 1)
155 include(${QT_USE_FILE})
156 include_directories(${QT_INCLUDES})
157
158 # Setup OpenSSL
159 # We don't link to or include OpenSSL ourselves, but use exclusively the Qt API.
160 # Thus, we simply check if OpenSSL support is present in Qt's config and enable our
161 # own SSL stuff in this case. Qt should care for adding what it needs itself.
162 if(WITH_OPENSSL)
163   if(QT_QCONFIG MATCHES "openssl")
164     message(STATUS "Found OpenSSL support in Qt, enabling SSL")
165     add_definitions(-DHAVE_SSL)
166     set(HAVE_SSL true)
167   else(QT_QCONFIG MATCHES "openssl")
168     message(STATUS "No OpenSSL support found in Qt, disabling SSL")
169     add_definitions(-DQT_NO_OPENSSL)
170   endif(QT_QCONFIG MATCHES "openssl")
171 else(WITH_OPENSSL)
172   message(STATUS "Not enabling OpenSSL support")
173 endif(WITH_OPENSSL)
174
175 # Setup D-Bus support
176 if(WITH_DBUS)
177   if(QT_QTDBUS_FOUND)
178     message(STATUS "Found QtDBus, enabling D-Bus support")
179     add_definitions(-DHAVE_DBUS)
180     set(CLIENT_QT4_VARS ${CLIENT_QT4_VARS} DBUS)
181     set(CLIENT_COMPILE_FLAGS "${CLIENT_COMPILE_FLAGS} -DQT_DBUS_LIB")
182     set(HAVE_DBUS true)
183   else(QT_QTDBUS_FOUND)
184     message(STATUS "QtDBus not found, disabling D-Bus support")
185   endif(QT_QTDBUS_FOUND)
186 else(WITH_DBUS)
187   message(STATUS "Not enabling D-Bus support")
188 endif(WITH_DBUS)
189
190 # Setup QtWebKit support
191 if(WITH_WEBKIT)
192   if(QT_QTWEBKIT_FOUND)
193     message(STATUS "Found QtWebKit, enabling WebKit support")
194     add_definitions(-DHAVE_WEBKIT)
195     set(CLIENT_QT4_VARS ${CLIENT_QT4_VARS} WEBKIT XMLPATTERNS)
196     set(CLIENT_COMPILE_FLAGS "${CLIENT_COMPILE_FLAGS} -DQT_WEBKIT_LIB -DQT_XMLPATTERNS_LIB")
197     set(HAVE_WEBKIT true)
198   else(QT_QTWEBKIT_FOUND)
199     message(STATUS "QtWebKit not found, disabling WebKit support")
200   endif(QT_QTWEBKIT_FOUND)
201 else(WITH_WEBKIT)
202   message(STATUS "Not enabling WebKit support")
203 endif(WITH_WEBKIT)
204
205 # Setup KDE4 support
206 if(WITH_KDE)
207   find_package(KDE4)
208   if(KDE4_FOUND)
209     message(STATUS "Enabling KDE4 integration")
210     include_directories(${KDE4_INCLUDES})
211     add_definitions(-DHAVE_KDE ${KDE4_DEFINITIONS})
212     set(HAVE_KDE 1)
213     set(QUASSEL_KDE_LIBRARIES ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBRARY} ${KDE4_SOLID_LIBS} knotifyconfig)
214     # We always use external icons for KDE4 support, since we use its iconloader rather than our own
215     set(EMBED_DATA OFF)
216   else(KDE4_FOUND)
217     message(STATUS "KDE4 not found, disabling KDE integration")
218   endif(KDE4_FOUND)
219 else(WITH_KDE)
220   message(STATUS "Not enabling KDE4 integration")
221 endif(WITH_KDE)
222
223 # needed to compile with mingw without kde
224 if(MINGW AND NOT HAVE_KDE)
225     add_definitions(-D_WIN32_WINNT=0x0500)
226     message(STATUS "Added _WIN32_WINNT=0x0500 definition for MinGW")
227 # workaround for bug in mingw gcc 4.0
228     add_definitions(-U__STRICT_ANSI__)
229 endif(MINGW AND NOT HAVE_KDE)
230
231 # Setup Phonon support - we only need this if we don't have or want KDE4
232 if(NOT HAVE_KDE)
233   if(WITH_PHONON)
234     find_package(Phonon)
235     if(PHONON_FOUND)
236       message(STATUS "Enabling Phonon support")
237       add_definitions(-DHAVE_PHONON)
238       set(HAVE_PHONON true)
239     else(PHONON_FOUND)
240       message(STATUS "Phonon not found, disabling audio notifications")
241     endif(PHONON_FOUND)
242   else(WITH_PHONON)
243     message(STATUS "Not enabling Phonon support")
244   endif(WITH_PHONON)
245 endif(NOT HAVE_KDE)
246
247 # Setup libindicate-qt support
248 if(WITH_LIBINDICATE)
249   find_package(PkgConfig QUIET)
250   if(PKG_CONFIG_FOUND)
251     pkg_check_modules(INDICATEQT indicate-qt>=0.2.1)
252     if(INDICATEQT_FOUND)
253       message(STATUS "Enabling Ayatana notification support")
254       set(HAVE_INDICATEQT true)
255       add_definitions(-DHAVE_INDICATEQT)
256     else(INDICATEQT_FOUND)
257       message(STATUS "Disabling Ayatana notification support")
258     endif(INDICATEQT_FOUND)
259   endif(PKG_CONFIG_FOUND)
260 else(WITH_LIBINDICATE)
261   message(STATUS "Not enabling Ayatana notification support")
262   # We don't want to link against it even if another package has found it
263   set(INDICATEQT_LIBRARIES "")
264 endif(WITH_LIBINDICATE)
265
266 # Now set up install locations; those are set by KDE if integration is enabled
267 if(NOT HAVE_KDE)
268   if(WIN32)
269     set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX} CACHE FILEPATH "Install path for binaries")
270     set(DATA_INSTALL_DIR $ENV{APPDATA}/quassel-irc.org/share/apps CACHE FILEPATH "Install path for data files")
271     set(ICON_INSTALL_DIR $ENV{APPDATA}/quassel-irc.org/share/icons CACHE FILEPATH "Global icon install path")
272     set(XDG_APPS_INSTALL_DIR $ENV{APPDATA}/quassel-irc.org/share/applications CACHE FILEPATH "Install path for .desktop files")
273   else(WIN32)
274     set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin CACHE FILEPATH "Install path for binaries")
275     set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/apps CACHE FILEPATH "Install path for data files")
276     set(ICON_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/icons CACHE FILEPATH "Global icon install path")
277     set(XDG_APPS_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/applications CACHE FILEPATH "Install path for .desktop files")
278   endif(WIN32)
279 endif(NOT HAVE_KDE)
280
281 if(EMBED_DATA)
282   message(STATUS "Embedding data files into the binary")
283 else(EMBED_DATA)
284   message(STATUS "Installing data files separately")
285 endif(EMBED_DATA)
286
287 # RPATH needs to be set correctly
288 # Do this down here, since otherwise KDE wants to handle it itself, and fails
289 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH 1)
290 set(CMAKE_BUILD_WITH_INSTALL_RPATH 1)
291
292 # Set global buildflags
293 # This is very much non-portable, so don't use -DSTATIC until you know what
294 # you do.
295 if(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
296   set(CMAKE_CXX_FLAGS "-static-libgcc ${CMAKE_CXX_FLAGS}")
297   link_directories(${CMAKE_BINARY_DIR}/staticlibs) # override dynamic libs
298   if(HAVE_SSL)
299     set(QUASSEL_SSL_LIBRARIES ssl crypto)  # these miss in static builds
300   endif(HAVE_SSL)
301 endif(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
302
303 if(WIN32)
304   link_libraries(imm32 winmm dbghelp Secur32)  # missing by default :/
305   if(MSVC)
306     set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBUGINFO "/debug /INCREMENTAL:YES /NODEFAULTLIB:libcmt /DEFAULTLIB:msvcrt")
307     set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBUGINFO}")
308     set(CMAKE_EXE_LINKER_FLAGS_DEBUGFULL "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBUGINFO}")
309     link_libraries(Version dwmapi shlwapi)
310   endif(MSVC)
311   if(HAVE_SSL AND STATIC)
312      find_package(OpenSSL REQUIRED)
313      link_libraries(${OPENSSL_LIBRARIES} ${OPENSSL_EAY_LIBRARIES})
314   endif(HAVE_SSL AND STATIC)
315 endif(WIN32)
316
317 if(HAVE_INDICATEQT)
318   add_definitions(-DXDG_APPS_INSTALL_DIR=${XDG_APPS_INSTALL_DIR})
319 endif(HAVE_INDICATEQT)
320
321 # We need to create a version.gen
322 # For this, we create our genversion binary and make sure it is run every time.
323 add_executable(genversion ${CMAKE_SOURCE_DIR}/src/common/genversion.cpp)
324 target_link_libraries(genversion ${QT_LIBRARIES} ${QT_CORE_LIB_DEPENDENCIES})
325
326 get_target_property(GENVERSION_EXECUTABLE genversion LOCATION)
327 add_custom_target(genversion_run ALL ${GENVERSION_EXECUTABLE}
328                   ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/src/version.gen)
329 add_dependencies(genversion_run genversion)
330
331 # These variables will be added to the main targets (CORE, QTCLIENT, MONO)
332 set(COMMON_DEPS ${RC_WIN32})
333 set(CORE_DEPS )
334 set(CLIENT_DEPS )
335
336 # Add needed subdirs - the order is important, since src needs some vars set by other dirs
337 add_subdirectory(data)
338 add_subdirectory(icons)
339 add_subdirectory(pics)
340 add_subdirectory(po)
341 add_subdirectory(src)