1 # Main CMake file for building Quassel IRC
3 # See INSTALL for possible CMake options (or read the code, Luke)
4 #####################################################################
7 #####################################################################
9 cmake_minimum_required(VERSION 2.8.9)
16 set(QUASSEL_VERSION_STRING "0.11-pre")
18 # Tell CMake about or own modules
19 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
21 # General conveniences
23 set(CMAKE_INCLUDE_CURRENT_DIR ON)
25 # Include various CMake modules...
26 include(CMakePushCheckState)
27 include(CheckFunctionExists)
28 include(CheckIncludeFile)
29 include(CheckCXXSourceCompiles)
30 include(CMakeDependentOption)
31 include(FeatureSummary)
33 # ... and our own stuff
34 include(QuasselCompileSettings)
35 include(QuasselMacros)
37 # Setting COMPILE_DEFINITIONS_<CONFIG> is deprecated since CMake 3.0 in favor of generator expressions.
38 # These have existed since CMake 2.8.10; until we depend on that, we have to explicitly enable the old policy.
39 cmake_policy(SET CMP0043 OLD)
42 # Options and variables that can be set on the command line
43 #####################################################################
45 # First, choose a Qt version. We support USE_QT4 and USE_QT5; if neither is set, prefer Qt4 for now
46 option(USE_QT5 "Enable support for Qt5 (disables KDE integration)" OFF)
47 if (USE_QT4) # takes precedence
55 # Select the binaries to build
56 option(WANT_CORE "Build the core (server) binary" ON)
57 option(WANT_QTCLIENT "Build the client-only binary" ON)
58 option(WANT_MONO "Build the monolithic (all-in-one) binary" ON)
59 add_feature_info(WANT_CORE WANT_CORE "Build the core (server) binary")
60 add_feature_info(WANT_QTCLIENT WANT_QTCLIENT "Build the client-only binary (requires a core to connect to)")
61 add_feature_info(WANT_MONO WANT_MONO "Build the monolithic (all-in-one) binary")
63 # Whether to enable KDE integration (pulls in kdelibs and friends as a dependency); requires Qt4 for now
64 cmake_dependent_option(WITH_KDE "KDE4 integration" OFF "USE_QT4" OFF)
65 add_feature_info(WITH_KDE WITH_KDE "Enable KDE4 integration")
67 cmake_dependent_option(WITH_OXYGEN "Install Oxygen icon set (usually shipped with KDE)" ON "NOT WITH_KDE" OFF)
69 add_feature_info(WITH_OXYGEN WITH_OXYGEN "Install Oxygen icon set")
72 # For this, the feature info is added after we know if QtWebkit is installed
73 option(WITH_WEBKIT "WebKit support (for link previews)" ON)
76 # Notification Center is only available in > 10.8, which is Darwin v12
77 if (CMAKE_SYSTEM_VERSION VERSION_GREATER "11.9.9")
78 option(WITH_NOTIFICATION_CENTER "OS X Notification Center support" ON)
79 add_feature_info(WITH_NOTIFICATION_CENTER WITH_NOTIFICATION_CENTER "Use the OS X Notification Center")
83 # Always embed on Windows, OSX or for a static build; never embed when enabling KDE integration
84 set(EMBED_DEFAULT OFF)
85 if (STATIC OR WIN32 OR APPLE)
88 cmake_dependent_option(EMBED_DATA "Embed icons and translations into the binaries instead of installing them" ${EMBED_DEFAULT}
89 "NOT STATIC;NOT WIN32;NOT WITH_KDE" ${EMBED_DEFAULT})
90 if (NOT EMBED_DEFAULT)
91 add_feature_info(EMBED_DATA EMBED_DATA "Embed icons and translations in the binaries instead of installing them")
94 # The following options are not for end-user consumption, so don't list them in the feature summary
95 cmake_dependent_option(DEPLOY "Add required libs to bundle resources and create a dmg. Note: requires Qt to be built with 10.4u SDK" OFF "APPLE" OFF)
98 set(QT_PATH "" CACHE PATH "Path to a Qt4 installation to use instead of the system Qt (e.g. for static builds)")
100 # Static builds are not supported and require some manual setup! Don't enable unless you know what you're doing (we don't know either)
101 cmake_dependent_option(STATIC "Enable static building (not supported)" OFF "NOT WITH_KDE" OFF)
103 # For static builds, arbitrary extra libs might need to be linked
104 # Define a comma-separated list here
105 # e.g. for pgsql, we need -DLINK_EXTRA=pq;crypt
106 set(LINK_EXTRA "" CACHE STRING "Semicolon-separated list of libraries to be linked")
108 string(REPLACE "," ";" LINK_EXTRA ${LINK_EXTRA})
109 link_libraries(${LINK_EXTRA})
113 # Simplify later checks
114 #####################################################################
116 if (WANT_MONO OR WANT_QTCLIENT)
119 if (WANT_MONO OR WANT_CORE)
125 #####################################################################
128 message(STATUS "Building for Qt5...")
129 set(QT_MIN_VERSION "5.2.0")
130 add_definitions(-DHAVE_QT5)
132 message(STATUS "Building for Qt4...")
134 set(QT_MIN_VERSION "4.6.0")
136 set(QT_MIN_VERSION "4.4.0")
139 # Select a Qt installation here, if you don't want to use system Qt
141 # FindQt4 will look for the qmake binary in $PATH, so we just prepend QT_PATH
142 set(ENV{PATH} ${QT_PATH}/bin:$ENV{PATH})
146 # Find package dependencies
148 # Note that you can forcefully disable optional packages
149 # using -DCMAKE_DISABLE_FIND_PACKAGE_<PkgName>=TRUE
150 #####################################################################
153 find_package(Qt5Core ${QT_MIN_VERSION} QUIET)
154 set_package_properties(Qt5Core PROPERTIES TYPE REQUIRED
155 URL "http://qt.digia.com"
156 DESCRIPTION "contains core functionality for Qt"
158 # find_package without REQUIRED won't check for the version properly; also, older Qt5 versions
159 # used Qt5Core_VERSION_STRING... let's just make sure here that we bail out here if our Qt5 is not new enough.
160 if (NOT Qt5Core_VERSION OR Qt5Core_VERSION VERSION_LESS ${QT_MIN_VERSION})
161 message(FATAL_ERROR "Could NOT find Qt5 >= version ${QT_MIN_VERSION}!")
164 find_package(Qt5Network QUIET)
165 set_package_properties(Qt5Network PROPERTIES TYPE REQUIRED
166 DESCRIPTION "the network module for Qt5"
170 find_package(Qt5Gui QUIET)
171 set_package_properties(Qt5Gui PROPERTIES TYPE REQUIRED
172 DESCRIPTION "the GUI module for Qt5"
174 find_package(Qt5Widgets QUIET)
175 set_package_properties(Qt5Widgets PROPERTIES TYPE REQUIRED
176 DESCRIPTION "the widgets module for Qt5"
179 find_package(Qt5DBus QUIET)
180 set_package_properties(Qt5DBus PROPERTIES TYPE RECOMMENDED
181 URL "http://qt.digia.com"
182 DESCRIPTION "D-Bus support for Qt5"
183 PURPOSE "Needed for supporting D-Bus-based notifications and tray icon, used by most modern desktop environments"
186 find_package(dbusmenu-qt5 QUIET CONFIG)
187 set_package_properties(dbusmenu-qt5 PROPERTIES TYPE RECOMMENDED
188 URL "https://launchpad.net/libdbusmenu-qt"
189 DESCRIPTION "a library implementing the DBusMenu specification"
190 PURPOSE "Required for having a context menu for the D-Bus-based tray icon"
194 find_package(Phonon4Qt5 QUIET)
195 set_package_properties(Phonon4Qt5 PROPERTIES TYPE RECOMMENDED
196 URL "https://projects.kde.org/projects/kdesupport/phonon"
197 DESCRIPTION "a multimedia abstraction library"
198 PURPOSE "Required for audio notifications"
201 find_package(LibsnoreQt5 QUIET)
202 set_package_properties(LibsnoreQt5 PROPERTIES TYPE OPTIONAL
203 URL "https://github.com/TheOneRing/Snorenotify"
204 DESCRIPTION "a cross-platform notification framework"
205 PURPOSE "Enable support for the snorenotify framework"
209 find_package(Qt5WebKit QUIET)
210 set_package_properties(Qt5WebKit PROPERTIES TYPE RECOMMENDED
211 URL "http://qt.digia.com"
212 DESCRIPTION "a WebKit implementation for Qt"
213 PURPOSE "Needed for displaying previews for URLs in chat"
216 find_package(Qt5WebKitWidgets QUIET)
217 set_package_properties(Qt5WebKitWidgets PROPERTIES TYPE RECOMMENDED
218 URL "http://qt.digia.com"
219 DESCRIPTION "widgets for Qt's WebKit implementation"
220 PURPOSE "Needed for displaying previews for URLs in chat"
224 add_feature_info("WITH_WEBKIT, QtWebKit and QtWebKitWidgets modules" Qt5WebKitWidgets_FOUND "Support showing previews for URLs in chat")
228 find_package(Qt5Script QUIET)
229 set_package_properties(Qt5Script PROPERTIES TYPE REQUIRED
230 DESCRIPTION "provides scripting support for Qt5"
232 find_package(Qt5Sql QUIET)
233 set_package_properties(Qt5Sql PROPERTIES TYPE REQUIRED
234 DESCRIPTION "the database support module for Qt5"
237 # While QCA2 seems to support Qt5, it is not actually co-installable or distinguishable from the Qt4 version...
238 # In order to avoid linking against the Qt4 version (which is probably the one installed), disable this for now
239 #find_package(QCA2 QUIET)
240 #set_package_properties(QCA2 PROPERTIES TYPE RECOMMENDED
241 # URL "https://projects.kde.org/projects/kdesupport/qca"
242 # DESCRIPTION "Qt Cryptographic Architecture"
243 # PURPOSE "Required for encryption support"
248 find_package(Qt5LinguistTools QUIET)
249 set_package_properties(Qt5LinguistTools PROPERTIES TYPE RECOMMENDED
250 DESCRIPTION "contains tools for handling translation files"
251 PURPOSE "Required for having translations"
253 # Some Qt5 versions do not define a target for lconvert, so we need to find it ourselves
254 if (Qt5LinguistTools_FOUND)
255 if (NOT TARGET Qt5::lconvert AND TARGET Qt5::lrelease)
256 get_target_property(_lrelease_location Qt5::lrelease LOCATION)
257 get_filename_component(_lrelease_path ${_lrelease_location} PATH)
258 find_program(QT_LCONVERT_EXECUTABLE NAMES lconvert-qt5 lconvert PATHS ${_lrelease_path} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
259 elseif(TARGET Qt5::lconvert AND NOT Qt5_LCONVERT_EXECUTABLE)
260 # Newer Qt5 versions define the target, but not the Qt5_LCONVERT_EXECUTABLE variable for some reason
261 get_target_property(QT_LCONVERT_EXECUTABLE Qt5::lconvert LOCATION)
264 # Compatibility with the Qt4 variables
265 set(QT_LRELEASE_EXECUTABLE ${Qt5_LRELEASE_EXECUTABLE})
266 set(QT_LUPDATE_EXECUTABLE ${Qt5_LUPDATE_EXECUTABLE})
267 if (Qt5_LCONVERT_EXECUTABLE)
268 set(QT_LCONVERT_EXECUTABLE ${Qt5_LCONVERT_EXECUTABLE})
273 find_package(Qt4 ${QT_MIN_VERSION} QUIET REQUIRED)
276 add_feature_info("QtDBus module" QT_QTDBUS_FOUND "Needed for supporting D-Bus-based notifications and tray icon, used by most modern desktop environments")
278 find_package(dbusmenu-qt QUIET CONFIG)
279 set_package_properties(dbusmenu-qt PROPERTIES TYPE RECOMMENDED
280 URL "https://launchpad.net/libdbusmenu-qt"
281 DESCRIPTION "a library implementing the DBusMenu specification"
282 PURPOSE "Required for having a context menu for the D-Bus-based tray icon"
286 if (WITH_WEBKIT AND QT_QTWEBKIT_FOUND)
287 set(HAVE_WEBKIT true)
289 add_feature_info("WITH_WEBKIT and QtWebKit module" HAVE_WEBKIT "Support showing previews for URLs in chat")
292 # KDE has overzealous CFLAGS making miniz not compile, so save our old flags
293 set(_cflags ${CMAKE_C_FLAGS})
294 find_package(KDE4 4.4 QUIET)
295 set_package_properties(KDE4 PROPERTIES TYPE REQUIRED
296 URL "http://www.kde.org"
297 DESCRIPTION "a world-class desktop environment"
298 PURPOSE "Enables various bits for improving integration with KDE"
300 set(CMAKE_C_FLAGS ${_cflags})
303 find_package(Phonon QUIET)
304 set_package_properties(Phonon PROPERTIES TYPE RECOMMENDED
305 URL "https://projects.kde.org/projects/kdesupport/phonon"
306 DESCRIPTION "a multimedia abstraction library"
307 PURPOSE "Required for audio notifications"
310 find_package(Libsnore QUIET)
311 set_package_properties(Libsnore PROPERTIES TYPE OPTIONAL
312 URL "https://github.com/TheOneRing/Snorenotify"
313 DESCRIPTION "a cross-platform notification framework"
314 PURPOSE "Enable support for the snorenotify framework"
318 find_package(IndicateQt QUIET)
319 set_package_properties(IndicateQt PROPERTIES TYPE OPTIONAL
320 URL "https://launchpad.net/libindicate-qt/"
321 DESCRIPTION "a library to raise flags on DBus for other components of the desktop to pick up and visualize"
322 PURPOSE "Provides integration into the Ayatana notification system used by e.g. Ubuntu"
328 find_package(QCA2 QUIET)
329 set_package_properties(QCA2 PROPERTIES TYPE RECOMMENDED
330 URL "https://projects.kde.org/projects/kdesupport/qca"
331 DESCRIPTION "Qt Cryptographic Architecture"
332 PURPOSE "Required for encryption support"
338 # Qt4 does not consider lconvert relevant, so they don't support finding it...
339 # Rather than shipping hacked buildsys files, let's just infer the path from lrelease
340 if (QT_LRELEASE_EXECUTABLE)
341 get_filename_component(_lrelease_path ${QT_LRELEASE_EXECUTABLE} PATH)
342 find_program(QT_LCONVERT_EXECUTABLE NAMES lconvert-qt4 lconvert PATHS ${_lrelease_path} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
347 # Non-Qt-based packages
349 # zlib for compression, however we can always fall back to miniz
350 find_package(ZLIB QUIET)
351 set_package_properties(ZLIB PROPERTIES TYPE RECOMMENDED
352 URL "http://www.zlib.net"
353 DESCRIPTION "a popular compression library"
354 PURPOSE "Use the most common library for protocol compression, instead of the bundled miniz implementation"
359 # Execinfo is needed for generating backtraces
360 find_package(ExecInfo QUIET)
361 set_package_properties(ExecInfo PROPERTIES TYPE OPTIONAL
362 DESCRIPTION "a library for inspecting backtraces"
363 PURPOSE "Used for generating backtraces in case of a crash"
369 #####################################################################
372 message(STATUS "zlib NOT found, using bundled miniz for compression")
373 if (${CMAKE_SIZEOF_VOID_P} EQUAL 4)
374 message(STATUS "WARNING: This may be slow on 32 bit systems!")
379 # We always use external icons for KDE4 support, since we use its iconloader rather than our own
382 # Better have the compile flags global, even for the core, to avoid problems with linking the mono client
383 add_definitions(-DHAVE_KDE ${KDE4_DEFINITIONS})
386 # Check for SSL support in Qt
387 # As there's no easy way to get Qt's configuration in particular for Qt5, let's just compile
388 # a small test program checking the defines. This works for both Qt4 and Qt5.
389 cmake_push_check_state(RESET)
390 if (Qt5_POSITION_INDEPENDENT_CODE)
391 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
393 set(CMAKE_REQUIRED_INCLUDES ${QT_INCLUDES} ${Qt5Core_INCLUDE_DIRS})
394 check_cxx_source_compiles("
395 #include \"qglobal.h\"
396 #if defined QT_NO_OPENSSL || defined QT_NO_SSL
397 # error \"No SSL support\"
401 cmake_pop_check_state()
404 add_definitions(-DHAVE_SSL)
406 add_feature_info("SSL support in Qt" HAVE_SSL "Use secure network connections")
408 # Check for syslog support
410 check_include_file(syslog.h HAVE_SYSLOG)
411 add_feature_info("syslog.h" HAVE_SYSLOG "Provide support for logging to the syslog")
414 add_feature_info("Qt Linguist Tools" QT_LCONVERT_EXECUTABLE "Translation support for Quassel")
419 # needed to compile with mingw without kde
420 if (MINGW AND NOT KDE4_FOUND)
421 add_definitions(-D_WIN32_WINNT=0x0500)
422 message(STATUS "Added _WIN32_WINNT=0x0500 definition for MinGW")
423 # workaround for bug in mingw gcc 4.0
424 add_definitions(-U__STRICT_ANSI__)
427 # Now set up install locations; those are set by KDE if integration is enabled
430 set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX} CACHE FILEPATH "Install path for binaries")
431 set(DATA_INSTALL_DIR $ENV{APPDATA}/quassel-irc.org/share/apps CACHE FILEPATH "Install path for data files")
432 set(ICON_INSTALL_DIR $ENV{APPDATA}/quassel-irc.org/share/icons CACHE FILEPATH "Global icon install path")
433 set(XDG_APPS_INSTALL_DIR $ENV{APPDATA}/quassel-irc.org/share/applications CACHE FILEPATH "Install path for .desktop files")
435 set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin CACHE FILEPATH "Install path for binaries")
436 set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/apps CACHE FILEPATH "Install path for data files")
437 set(ICON_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/icons CACHE FILEPATH "Global icon install path")
438 set(XDG_APPS_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/applications CACHE FILEPATH "Install path for .desktop files")
443 message(STATUS "Embedding data files into the binary")
445 message(STATUS "Installing data files separately")
448 # RPATH needs to be set correctly
449 # Do this down here, since otherwise KDE wants to handle it itself, and fails
450 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH 1)
451 set(CMAKE_BUILD_WITH_INSTALL_RPATH 1)
453 # Set global buildflags
454 # This is very much non-portable, so don't use -DSTATIC until you know what
456 if(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
457 set(CMAKE_CXX_FLAGS "-static-libgcc ${CMAKE_CXX_FLAGS}")
458 link_directories(${CMAKE_BINARY_DIR}/staticlibs) # override dynamic libs
460 set(QUASSEL_SSL_LIBRARIES ssl crypto) # these miss in static builds
462 endif(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
465 link_libraries(imm32 winmm dbghelp Secur32) # missing by default :/
467 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DNOMINMAX")
468 set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBUGINFO "/debug /INCREMENTAL:YES /NODEFAULTLIB:libcmt /DEFAULTLIB:msvcrt")
469 set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/debug /INCREMENTAL:YES /NODEFAULTLIB:libcmt")
470 set(CMAKE_EXE_LINKER_FLAGS_DEBUGFULL "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
471 link_libraries(Version dwmapi shlwapi)
473 set(QT_QTMAIN_LIBRARY Qt5::WinMain)
476 if(HAVE_SSL AND STATIC)
477 find_package(OpenSSL REQUIRED)
478 link_libraries(${OPENSSL_LIBRARIES} ${OPENSSL_EAY_LIBRARIES})
479 endif(HAVE_SSL AND STATIC)
483 add_definitions(-DXDG_APPS_INSTALL_DIR=${XDG_APPS_INSTALL_DIR})
487 check_function_exists(umask HAVE_UMASK)
489 add_definitions(-DHAVE_UMASK)
493 # Generate version information from Git
494 include(GetGitRevisionDescription)
495 get_git_head_revision(GIT_REFSPEC GIT_HEAD)
496 git_describe(GIT_DESCRIBE --long)
498 # Sanitize things if we're not in a Git repo
499 if(NOT GIT_HEAD OR NOT GIT_DESCRIBE)
504 configure_file(version.h.in ${CMAKE_BINARY_DIR}/version.h @ONLY)
506 # These variables will be added to the main targets (CORE, QTCLIENT, MONO)
507 set(COMMON_DEPS ${RC_WIN32})
511 # Add needed subdirs - the order is important, since src needs some vars set by other dirs
512 add_subdirectory(data)
513 add_subdirectory(icons)
514 add_subdirectory(pics)
517 # Set up and display feature summary
518 #####################################################################
520 feature_summary(WHAT ALL
521 INCLUDE_QUIET_PACKAGES
522 FATAL_ON_MISSING_REQUIRED_PACKAGES
525 # Finally, compile the sources
526 # We want this after displaying the feature summary to avoid ugly
527 # CMake backtraces in case a required Qt5 modules misses
528 #####################################################################
530 add_subdirectory(src)