1 # This is the cmake-based build system for Quassel IRC.
3 # You may pass various options to cmake:
5 # -DWANT_(CORE|QTCLIENT|MONO)=(ON|OFF)
6 # : select binaries to build
7 # -DWITH_OPENSSL=OFF : Disable OpenSSL support
8 # -DWITH_DBUS=OFF : Disable D-Bus support (dbus notifications)
9 # -DWITH_WEBKIT=OFF : Disable WebKit support (link previews)
10 # -DWITH_PHONON=OFF : Disable Phonon support (audio notifications)
11 # -DWITH_LIBINDICATE=OFF : Disable libindicate support (Ayatana notifications)
12 # -DWITH_KDE=ON : Enable KDE4 support
13 # -DWITH_CRYPT=OFF : Disable encryption support
14 # -DWITH_OXYGEN=(ON|OFF) : Whether to install Oxygen icons (default: yes, unless KDE > 4.3.0 is present and enabled)
15 # -DWITH_SYSLOG=OFF : Disable syslog support
17 # -DEMBED_DATA=ON : Embed all data files in icons the binary, rather than installing them separately
19 # -DQT=/path/to/qt : Choose a Qt4 installation to use instead of the system Qt4
20 # -DSTATIC=ON : Enable static building of Quassel. Use with care.
21 # -DDEPLOY=ON : Mac OS X only. Use only for creating Quassel Packages!
23 # -DWITH_QT5=ON : Enable (very) experimental support for Qt5 (see doc/README.Qt5!)
25 # NOTE: You should remove CMakeCache.txt if you plan to change any of these values!
30 include(CheckFunctionExists)
31 include(CheckIncludeFile)
33 # cmake 2.6.2 is required for KDE >=4.2 and should be widespread enough now
34 # For building against Qt5, we check for an even newer cmake version below!
35 cmake_minimum_required(VERSION 2.6.2 FATAL_ERROR)
37 if(COMMAND cmake_policy)
38 cmake_policy(SET CMP0003 NEW)
39 endif(COMMAND cmake_policy)
41 # Use our own (well, and KDE's) version of some modules
42 # In particular cmake's own FindQt4 and FindOpenSSL are quite buggy
43 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
44 include(QuasselMacros)
46 # Various options and variables that can be set on the command line
47 option(WANT_CORE "Build the core (server) binary" ON)
48 option(WANT_QTCLIENT "Build the Qt4 GUI client binary" ON)
49 option(WANT_MONO "Build the monolithic (all-in-one) binary" ON)
51 option(WITH_OPENSSL "Enable OpenSSL support if present on the system" ON)
52 option(WITH_DBUS "Enable D-Bus support if present on the system" ON)
53 option(WITH_WEBKIT "Enable WebKit support (for link previews)" ON)
54 option(WITH_PHONON "Enable Phonon support (for audio notifications)" ON)
55 option(WITH_LIBINDICATE "Enable Ayatana notification support" ON)
56 option(WITH_KDE "Enable KDE4 integration" OFF)
57 option(WITH_CRYPT "Enable encryption support if present on system" ON)
58 option(WITH_SYSLOG "Use syslog for storing log data" ON)
60 # We use icon paths from KDE 4.3.x, which are partially invalid on older and possibly
61 # even on newer KDE versions. Do not disable this unless you are sure that your Quassel will
62 # run on a matching KDE version only.
63 set(WITH_OXYGEN AUTO CACHE STRING "Install Oxygen icons (default is \"AUTO\" to install when KDE 4.3 or later is present")
65 # Enable very experimental support for Qt5. Might break the compilation, or even more!
66 option(WITH_QT5 "Enable (very) experimental support for Qt5" OFF)
68 option(STATIC "Enable static building (might not be portable)" OFF)
71 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)
74 # Default to embedding data in the static case
78 set(EMBED_DEFAULT ON) # should be OFF as soon as everything works
79 endif(STATIC OR WIN32)
81 option(EMBED_DATA "Embed all data files in the binary (rather than installing them separately)" ${EMBED_DEFAULT})
83 set(QT "" CACHE STRING "Path to a Qt installation to use instead of the system Qt (e.g. for static builds)")
85 # Some settings imply others
87 add_definitions(-DSTATIC)
88 set(WITH_KDE OFF CACHE BOOL "Static building with KDE is not supported")
92 # We don't support separately installed resources yet on Win32
96 # For static builds, arbitrary extra libs might need to be linked
97 # Define a comma-separated list here
98 # e.g. for pgsql, we need -DLINK_EXTRA=pq;crypt
99 set(LINK_EXTRA "" CACHE STRING "Semicolon-separated list of libraries to be linked")
101 string(REPLACE "," ";" LINK_EXTRA ${LINK_EXTRA})
102 link_libraries(${LINK_EXTRA})
106 # We need to make sure it's not empty
107 # Supported: Release, RelWithDebugInfo, Debug, Debugfull
109 # On WIN32, only Release seems to work correctly (?)
111 set(DEFAULT_BUILD_TYPE "Release")
113 set(DEFAULT_BUILD_TYPE "RelWithDebugInfo")
116 set(CMAKE_BUILD_TYPE ${DEFAULT_BUILD_TYPE} CACHE STRING "CMake Build Type")
117 if(NOT CMAKE_BUILD_TYPE)
118 set(CMAKE_BUILD_TYPE ${DEFAULT_BUILD_TYPE} CACHE STRING "CMake Build Type" FORCE)
119 endif(NOT CMAKE_BUILD_TYPE)
122 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG QT_DEBUG)
123 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_FULLDEBUG QT_DEBUG)
124 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE QT_NO_DEBUG NDEBUG)
125 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO QT_NO_DEBUG NDEBUG)
126 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_MINSIZEREL QT_NO_DEBUG NDEBUG)
128 IF(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
129 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_DEBUG NDEBUG)
132 # Enable various flags on gcc
133 if(CMAKE_COMPILER_IS_GNUCXX)
134 # Let's just hope that all gccs support these options and skip the tests...
135 # -fno-strict-aliasing is needed apparently for Qt < 4.6
136 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ansi -Wall -Wextra -Wnon-virtual-dtor -fno-strict-aliasing")
137 set(CMAKE_CXX_FLAGS_RELEASE "-O2 ${CMAKE_CXX_FLAGS}")
138 set(CMAKE_CXX_FLAGS_RELWITHDEBUGINFO "-g -O2 ${CMAKE_CXX_FLAGS}")
139 set(CMAKE_CXX_FLAGS_DEBUG "-g -ggdb -fno-reorder-blocks -fno-schedule-insns -fno-inline ${CMAKE_CXX_FLAGS}")
140 set(CMAKE_CXX_FLAGS_DEBUGFULL "-g3 ${CMAKE_CXX_FLAGS_DEBUG}")
141 endif(CMAKE_COMPILER_IS_GNUCXX)
145 set(CMAKE_OSX_ARCHITECTURES "i386;ppc")
146 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.4")
147 set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.4u.sdk/")
148 add_definitions(-DMAC_10_4_SDK)
149 endif(APPLE AND DEPLOY)
152 if(WANT_MONO OR WANT_QTCLIENT)
154 endif(WANT_MONO OR WANT_QTCLIENT)
155 if(WANT_MONO OR WANT_CORE)
157 endif(WANT_MONO OR WANT_CORE)
164 set(QT_MIN_VERSION "5.0.0")
165 add_definitions(-DHAVE_QT5)
167 # Qt5 needs a new enough cmake...
168 cmake_minimum_required(VERSION 2.8.6 FATAL_ERROR)
171 set(CMAKE_AUTOMOC ON)
174 # GUI stuff needs some new features
176 set(QT_MIN_VERSION "4.6.0")
178 set(QT_MIN_VERSION "4.4.0")
187 find_package(Qt5Core ${QT_MIN_VERSION} REQUIRED)
189 set(CLIENT_QT_MODULES ${CLIENT_QT_MODULES} Widgets)
191 # Select a Qt installation here, if you don't want to use system Qt
193 # FindQt4 will look for the qmake binary in $PATH, so we just prepend the Qt dir
194 set(ENV{PATH} ${QT}/bin:$ENV{PATH})
197 # Now that we have the correct $PATH, lets find Qt!
198 find_package(Qt4 REQUIRED)
202 # Execinfo is needed for generating backtraces
203 find_package(ExecInfo)
205 add_definitions(-DHAVE_EXECINFO)
206 include_directories(${EXECINFO_INCLUDES})
207 link_libraries(${EXECINFO_LIBRARIES})
208 endif(EXECINFO_FOUND)
211 # PkgConfig isn't strictly required.
212 # However, some optional deps might not be found if it's not present, so warn!
213 find_package(PkgConfig)
214 if(NOT PKG_CONFIG_FOUND)
215 message(STATUS "WARNING: PkgConfig not available! Some dependencies for optional features might not be found.")
216 message(STATUS " Affected features might include encryption support, DBus menus and Ayatana notifications.")
217 endif(NOT PKG_CONFIG_FOUND)
221 # We don't link to or include OpenSSL ourselves, but use exclusively the Qt API.
222 # Thus, we simply check if OpenSSL support is present in Qt's config and enable our
223 # own SSL stuff in this case. Qt should care for adding what it needs itself.
225 if(QT_QCONFIG MATCHES "openssl")
226 message(STATUS "Found OpenSSL support in Qt, enabling SSL")
227 add_definitions(-DHAVE_SSL)
229 else(QT_QCONFIG MATCHES "openssl")
230 message(STATUS "No OpenSSL support found in Qt, disabling SSL")
231 add_definitions(-DQT_NO_OPENSSL)
232 endif(QT_QCONFIG MATCHES "openssl")
234 message(STATUS "Not enabling OpenSSL support")
238 # Check for GUI specific stuff
241 # Setup D-Bus support
244 find_package(Qt5DBus ${QT_MIN_VERSION})
245 find_package(Qt5DBusTools)
248 if(QT_QTDBUS_FOUND OR (Qt5DBus_FOUND AND Qt5DBusTools_FOUND))
249 message(STATUS "Found QtDBus, enabling D-Bus support")
250 add_definitions(-DHAVE_DBUS)
252 set(CLIENT_QT_MODULES ${CLIENT_QT_MODULES} DBus)
254 # check if we have dbusmenu as well
256 find_package(DBusMenuQt)
258 message(STATUS "Enabling support for exporting the tray menu via D-Bus")
259 add_definitions(-DHAVE_DBUSMENU)
260 include_directories(${DBUSMENUQT_INCLUDE_DIR})
261 set(CLIENT_LIBRARIES ${CLIENT_LIBRARIES} ${DBUSMENUQT_LIBRARIES})
262 set(CLIENT_COMPILE_FLAGS "${CLIENT_COMPILE_FLAGS} ${DBUSMENUQT_DEFINITIONS}")
263 else(DBUSMENUQT_FOUND)
264 message(STATUS "Disabling support for exporting the tray menu via D-Bus")
265 endif(DBUSMENUQT_FOUND)
268 else(QT_QTDBUS_FOUND OR (Qt5DBus_FOUND AND Qt5DBusTools_FOUND))
269 message(STATUS "QtDBus not found, disabling D-Bus support")
270 endif(QT_QTDBUS_FOUND OR (Qt5DBus_FOUND AND Qt5DBusTools_FOUND))
272 message(STATUS "Not enabling D-Bus support")
275 # Setup QtWebkit support
278 find_package(Qt5Webkit ${QT_MIN_VERSION} QUIET)
280 if(QT_QTWEBKIT_FOUND OR Qt5Webkit_FOUND)
281 message(STATUS "Found QtWebKit, enabling WebKit support")
282 add_definitions(-DHAVE_WEBKIT)
283 set(CLIENT_QT_MODULES ${CLIENT_QT_MODULES} Webkit XmlPatterns)
284 set(HAVE_WEBKIT true)
285 else(QT_QTWEBKIT_FOUND OR Qt5Webkit_FOUND)
286 message(STATUS "QtWebkit not found, disabling Webkit support")
287 endif(QT_QTWEBKIT_FOUND OR Qt5Webkit_FOUND)
289 message(STATUS "Not enabling Webkit support")
293 if(WITH_KDE AND NOT WITH_QT5)
296 message(STATUS "Enabling KDE4 integration")
297 include_directories(${KDE4_INCLUDES})
298 add_definitions(-DHAVE_KDE ${KDE4_DEFINITIONS})
300 set(CLIENT_LIBRARIES ${CLIENT_LIBRARIES} ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBRARY} ${KDE4_SOLID_LIBS} knotifyconfig)
301 # We always use external icons for KDE4 support, since we use its iconloader rather than our own
304 message(STATUS "KDE4 not found, disabling KDE integration")
306 else(WITH_KDE AND NOT WITH_QT5)
307 message(STATUS "Not enabling KDE4 integration")
308 endif(WITH_KDE AND NOT WITH_QT5)
310 # Setup Phonon support - we only need this if we don't have or want KDE4
314 find_package(Qt5phonon)
316 message(STATUS "Enabling Phonon support")
317 add_definitions(-DHAVE_PHONON)
318 set(HAVE_PHONON true)
319 set(CLIENT_QT_MODULES ${CLIENT_QT_MODULES} phonon)
320 else(Qt5phonon_FOUND)
321 message(STATUS "Phonon not found, disabling audio notifications")
322 endif(Qt5phonon_FOUND)
326 message(STATUS "Enabling Phonon support")
327 add_definitions(-DHAVE_PHONON)
328 include_directories(${PHONON_INCLUDES})
329 set(CLIENT_LIBRARIES ${CLIENT_LIBRARIES} ${PHONON_LIBS})
330 set(HAVE_PHONON true)
332 message(STATUS "Phonon not found, disabling audio notifications")
336 message(STATUS "Not enabling Phonon support")
340 # Setup libindicate-qt support
341 if(WITH_LIBINDICATE AND NOT WITH_QT5)
342 pkg_check_modules(INDICATEQT QUIET indicate-qt>=0.2.1)
344 message(STATUS "Enabling Ayatana notification support")
345 set(HAVE_INDICATEQT true)
346 add_definitions(-DHAVE_INDICATEQT)
347 link_directories(${INDICATEQT_LIBRARY_DIRS})
348 set(CLIENT_LIBRARIES ${CLIENT_LIBRARIES} ${INDICATEQT_LIBRARIES})
349 else(INDICATEQT_FOUND)
350 message(STATUS "Disabling Ayatana notification support")
351 endif(INDICATEQT_FOUND)
352 else(WITH_LIBINDICATE AND NOT WITH_QT5)
353 message(STATUS "Not enabling Ayatana notification support")
354 # We don't want to link against it even if another package has found it
355 set(INDICATEQT_LIBRARIES "")
356 endif(WITH_LIBINDICATE AND NOT WITH_QT5)
363 # Setup encryption support
364 if(WITH_CRYPT AND NOT WITH_QT5)
367 message(STATUS "Enabling encryption support")
368 add_definitions(-DHAVE_QCA2)
371 set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_QCA2)
373 message(STATUS "Disabling encryption support")
375 else(WITH_CRYPT AND NOT WITH_QT5)
376 message(STATUS "Not enabling encryption support")
377 endif(WITH_CRYPT AND NOT WITH_QT5)
379 # Setup syslog support
381 check_include_file(syslog.h HAVE_SYSLOG_H)
383 message(STATUS "Enabling syslog support")
384 set(HAVE_SYSLOG true)
385 add_definitions(-DHAVE_SYSLOG)
387 message(STATUS "Disabling syslog support")
390 message(STATUS "Not enabling syslog support")
399 # needed to compile with mingw without kde
400 if(MINGW AND NOT HAVE_KDE)
401 add_definitions(-D_WIN32_WINNT=0x0500)
402 message(STATUS "Added _WIN32_WINNT=0x0500 definition for MinGW")
403 # workaround for bug in mingw gcc 4.0
404 add_definitions(-U__STRICT_ANSI__)
405 endif(MINGW AND NOT HAVE_KDE)
407 # Now set up install locations; those are set by KDE if integration is enabled
410 set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX} CACHE FILEPATH "Install path for binaries")
411 set(DATA_INSTALL_DIR $ENV{APPDATA}/quassel-irc.org/share/apps CACHE FILEPATH "Install path for data files")
412 set(ICON_INSTALL_DIR $ENV{APPDATA}/quassel-irc.org/share/icons CACHE FILEPATH "Global icon install path")
413 set(XDG_APPS_INSTALL_DIR $ENV{APPDATA}/quassel-irc.org/share/applications CACHE FILEPATH "Install path for .desktop files")
415 set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin CACHE FILEPATH "Install path for binaries")
416 set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/apps CACHE FILEPATH "Install path for data files")
417 set(ICON_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/icons CACHE FILEPATH "Global icon install path")
418 set(XDG_APPS_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/applications CACHE FILEPATH "Install path for .desktop files")
423 message(STATUS "Embedding data files into the binary")
425 message(STATUS "Installing data files separately")
428 # RPATH needs to be set correctly
429 # Do this down here, since otherwise KDE wants to handle it itself, and fails
430 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH 1)
431 set(CMAKE_BUILD_WITH_INSTALL_RPATH 1)
433 # Set global buildflags
434 # This is very much non-portable, so don't use -DSTATIC until you know what
436 if(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
437 set(CMAKE_CXX_FLAGS "-static-libgcc ${CMAKE_CXX_FLAGS}")
438 link_directories(${CMAKE_BINARY_DIR}/staticlibs) # override dynamic libs
440 set(QUASSEL_SSL_LIBRARIES ssl crypto) # these miss in static builds
442 endif(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
445 link_libraries(imm32 winmm dbghelp Secur32) # missing by default :/
447 set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBUGINFO "/debug /INCREMENTAL:YES /NODEFAULTLIB:libcmt /DEFAULTLIB:msvcrt")
448 set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/debug /INCREMENTAL:YES /NODEFAULTLIB:libcmt")
449 set(CMAKE_EXE_LINKER_FLAGS_DEBUGFULL "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
450 link_libraries(Version dwmapi shlwapi)
452 if(HAVE_SSL AND STATIC)
453 find_package(OpenSSL REQUIRED)
454 link_libraries(${OPENSSL_LIBRARIES} ${OPENSSL_EAY_LIBRARIES})
455 endif(HAVE_SSL AND STATIC)
459 add_definitions(-DXDG_APPS_INSTALL_DIR=${XDG_APPS_INSTALL_DIR})
460 endif(HAVE_INDICATEQT)
463 check_function_exists(umask HAVE_UMASK)
465 add_definitions(-DHAVE_UMASK)
470 # We need to create a version.gen
471 # For this, we create our genversion binary and make sure it is run every time.
474 include_directories(${QUASSEL_QT_INCLUDES})
476 add_executable(genversion ${CMAKE_SOURCE_DIR}/src/common/genversion.cpp)
477 target_link_libraries(genversion ${QUASSEL_QT_LIBRARIES})
478 set_target_properties(genversion PROPERTIES COMPILE_FLAGS "${QUASSEL_QT_COMPILEFLAGS}")
480 get_target_property(GENVERSION_EXECUTABLE genversion LOCATION)
481 add_custom_target(genversion_run ALL ${GENVERSION_EXECUTABLE}
482 ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/src/version.gen)
483 add_dependencies(genversion_run genversion)
485 # These variables will be added to the main targets (CORE, QTCLIENT, MONO)
486 set(COMMON_DEPS ${RC_WIN32})
490 # Add needed subdirs - the order is important, since src needs some vars set by other dirs
491 add_subdirectory(data)
492 add_subdirectory(icons)
493 add_subdirectory(pics)
495 add_subdirectory(src)