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 3.5)
15 set(QUASSEL_VERSION_STRING "0.14-pre")
18 if (CMAKE_CONFIGURATION_TYPES)
19 set(CMAKE_CONFIGURATION_TYPES Release RelWithDebInfo Debug Debugfull Profile)
20 set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING "These are the configuration types we support" FORCE)
23 if(NOT CMAKE_BUILD_TYPE)
24 set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build, options are: Release RelWithDebInfo Debug Debugfull Profile None" FORCE)
27 # Output CMake and Quassel versions as well as build type for debug reasons
28 message(STATUS "Building Quassel ${QUASSEL_VERSION_STRING}...")
29 message(STATUS "Using CMake ${CMAKE_VERSION}")
30 message(STATUS "CMake build type: ${CMAKE_BUILD_TYPE}")
32 # Support ccache if found
33 # This should happen before calling project(), so compiler settings are validated.
34 option(USE_CCACHE "Enable support for ccache if available" ON)
36 message(STATUS "Checking for ccache")
37 find_program(CCACHE_PROGRAM ccache)
39 set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
40 message(STATUS "Checking for ccache - enabled")
42 message(STATUS "Checking for ccache - not found")
49 # General conveniences
51 set(CMAKE_INCLUDE_CURRENT_DIR ON)
53 # Include various CMake modules
54 include(CMakePushCheckState)
55 include(CheckFunctionExists)
56 include(CheckIncludeFileCXX)
57 include(CheckCXXSourceCompiles)
58 include(CMakeDependentOption)
59 include(FeatureSummary)
61 # Tell CMake about or own modules
62 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
63 include(QuasselCompileSettings)
64 include(QuasselMacros)
67 # Options and variables that can be set on the command line
68 #####################################################################
70 # Select the binaries to build
71 option(WANT_CORE "Build the core (server) binary" ON)
72 option(WANT_QTCLIENT "Build the client-only binary" ON)
73 option(WANT_MONO "Build the monolithic (all-in-one) binary" ON)
74 add_feature_info(WANT_CORE WANT_CORE "Build the core (server) binary")
75 add_feature_info(WANT_QTCLIENT WANT_QTCLIENT "Build the client-only binary (requires a core to connect to)")
76 add_feature_info(WANT_MONO WANT_MONO "Build the monolithic (all-in-one) binary")
78 # Whether to enable integration with higher-tier KDE frameworks that require runtime support.
79 # We still optionally make use of certain Tier 1 frameworks even if WITH_KDE is disabled.
80 option(WITH_KDE "Integration with the KDE Frameworks runtime environment")
81 add_feature_info(WITH_KDE WITH_KDE "Integrate with the KDE Frameworks runtime environment")
83 # Icon theme support. By default, install the Breeze icon theme (may be disabled if a system installation is present)
84 option(WITH_BUNDLED_ICONS "Install required icons from the Breeze icon theme" ON)
85 add_feature_info(WITH_BUNDLED_ICONS WITH_BUNDLED_ICONS "Install required icons from the Breeze icon theme")
87 option(WITH_OXYGEN_ICONS "Support the Oxygen icon theme (KDE4)" OFF)
88 add_feature_info(WITH_OXYGEN_ICONS WITH_OXYGEN_ICONS "Support the Oxygen icon theme (KDE4)")
90 if (WITH_BUNDLED_ICONS)
91 add_definitions(-DWITH_BUNDLED_ICONS)
93 if (WITH_OXYGEN_ICONS)
94 add_definitions(-DWITH_OXYGEN_ICONS)
97 # For this, the feature info is added after we know if QtWebkit is installed
98 option(WITH_WEBKIT "WebKit support (for link previews) (legacy)" OFF)
100 # For this, the feature info is added after we know if QtWebEngine is installed
101 option(WITH_WEBENGINE "WebEngine support (for link previews)" ON)
104 # Notification Center is only available in > 10.8, which is Darwin v12
105 if (NOT CMAKE_SYSTEM_VERSION VERSION_LESS 12)
106 option(WITH_NOTIFICATION_CENTER "OS X Notification Center support" ON)
107 add_feature_info(WITH_NOTIFICATION_CENTER WITH_NOTIFICATION_CENTER "Use the OS X Notification Center")
109 find_library(CARBON_LIBRARY Carbon)
110 mark_as_advanced(CARBON_LIBRARY)
111 link_libraries(${CARBON_LIBRARY})
114 # Always embed on Windows or OSX; never embed when enabling KDE integration
115 set(EMBED_DEFAULT OFF)
117 set(EMBED_DEFAULT ON)
119 cmake_dependent_option(EMBED_DATA "Embed icons and translations into the binaries instead of installing them" ${EMBED_DEFAULT}
120 "NOT WIN32;NOT WITH_KDE" ${EMBED_DEFAULT})
121 if (NOT EMBED_DEFAULT)
122 add_feature_info(EMBED_DATA EMBED_DATA "Embed icons and translations in the binaries instead of installing them")
125 # The following options are not for end-user consumption, so don't list them in the feature summary
126 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)
129 # List of authenticators and the cmake flags to build them
130 # (currently that's just LDAP, but more can be added here).
131 ####################################################################
132 option(WITH_LDAP "Enable LDAP authentication support if present on system" ON)
135 #####################################################################
137 # Setting COMPILE_DEFINITIONS_<CONFIG> is deprecated since CMake 3.0 in favor of generator expressions.
138 # These have existed since CMake 2.8.10; until we depend on that, we have to explicitly enable the old policy.
140 cmake_policy(SET CMP0043 OLD)
143 # Honor visibility settings for all target types
145 cmake_policy(SET CMP0063 NEW)
148 # Don't automoc generated files
150 cmake_policy(SET CMP0071 OLD)
154 # Simplify later checks
155 #####################################################################
157 if (WANT_MONO OR WANT_QTCLIENT)
160 if (WANT_MONO OR WANT_CORE)
166 #####################################################################
168 # Find package dependencies
170 # Note that you can forcefully disable optional packages
171 # using -DCMAKE_DISABLE_FIND_PACKAGE_<PkgName>=TRUE
172 #####################################################################
174 set(QT_MIN_VERSION "5.5.0")
175 add_definitions(-DHAVE_QT5)
177 find_package(Qt5Core ${QT_MIN_VERSION} QUIET)
178 set_package_properties(Qt5Core PROPERTIES TYPE REQUIRED
179 URL "https://www.qt.io/"
180 DESCRIPTION "contains core functionality for Qt"
183 # find_package without REQUIRED won't check for the version properly; also, older Qt5 versions
184 # used Qt5Core_VERSION_STRING... let's just make sure here that we bail out here if our Qt5 is not new enough.
185 if (NOT Qt5Core_VERSION OR Qt5Core_VERSION VERSION_LESS ${QT_MIN_VERSION})
186 message(FATAL_ERROR "Could NOT find Qt5 >= version ${QT_MIN_VERSION}!")
189 find_package(Qt5Network QUIET)
190 set_package_properties(Qt5Network PROPERTIES TYPE REQUIRED
191 DESCRIPTION "the network module for Qt5"
195 find_package(Qt5Gui QUIET)
196 set_package_properties(Qt5Gui PROPERTIES TYPE REQUIRED
197 DESCRIPTION "the GUI module for Qt5"
199 find_package(Qt5Widgets QUIET)
200 set_package_properties(Qt5Widgets PROPERTIES TYPE REQUIRED
201 DESCRIPTION "the widgets module for Qt5"
205 find_package(Qt5DBus QUIET)
206 set_package_properties(Qt5DBus PROPERTIES TYPE RECOMMENDED
207 URL "https://www.qt.io/"
208 DESCRIPTION "D-Bus support for Qt5"
209 PURPOSE "Needed for supporting D-Bus-based notifications and tray icon, used by most modern desktop environments"
212 find_package(dbusmenu-qt5 QUIET CONFIG)
213 set_package_properties(dbusmenu-qt5 PROPERTIES TYPE RECOMMENDED
214 URL "https://launchpad.net/libdbusmenu-qt"
215 DESCRIPTION "a library implementing the DBusMenu specification"
216 PURPOSE "Required for having a context menu for the D-Bus-based tray icon"
221 find_package(Qt5Multimedia QUIET)
222 set_package_properties(Qt5Multimedia PROPERTIES TYPE RECOMMENDED
223 URL "https://www.qt.io/"
224 DESCRIPTION "Multimedia support for Qt5"
225 PURPOSE "Required for audio notifications"
228 find_package(LibsnoreQt5 0.7.0 QUIET)
229 set_package_properties(LibsnoreQt5 PROPERTIES TYPE OPTIONAL
230 URL "https://projects.kde.org/projects/playground/libs/snorenotify"
231 DESCRIPTION "a cross-platform notification framework"
232 PURPOSE "Enable support for the snorenotify framework"
234 if(LibsnoreQt5_FOUND)
235 find_package(LibsnoreSettingsQt5)
236 set_package_properties(LibsnoreSettingsQt5 PROPERTIES TYPE REQUIRED
237 URL "https://projects.kde.org/projects/playground/libs/snorenotify"
238 DESCRIPTION "a cross-platform notification framework"
239 PURPOSE "Enable support for the snorenotify framework"
244 find_package(Qt5WebKit QUIET)
245 set_package_properties(Qt5WebKit PROPERTIES TYPE RECOMMENDED
246 URL "https://www.qt.io/"
247 DESCRIPTION "a WebKit implementation for Qt"
248 PURPOSE "Needed for displaying previews for URLs in chat"
251 find_package(Qt5WebKitWidgets QUIET)
252 set_package_properties(Qt5WebKitWidgets PROPERTIES TYPE RECOMMENDED
253 URL "https://www.qt.io/"
254 DESCRIPTION "widgets for Qt's WebKit implementation"
255 PURPOSE "Needed for displaying previews for URLs in chat"
260 if (WITH_WEBKIT AND Qt5WebKitWidgets_FOUND)
261 set(HAVE_WEBKIT true)
263 add_feature_info("WITH_WEBKIT, QtWebKit and QtWebKitWidgets modules" HAVE_WEBKIT "Support showing previews for URLs in chat (legacy)")
266 find_package(Qt5WebEngine QUIET)
267 set_package_properties(Qt5WebEngine PROPERTIES TYPE RECOMMENDED
268 URL "https://www.qt.io/"
269 DESCRIPTION "a WebEngine implementation for Qt"
270 PURPOSE "Needed for displaying previews for URLs in chat"
272 if (Qt5WebEngine_FOUND)
273 find_package(Qt5WebEngineWidgets QUIET)
274 set_package_properties(Qt5WebEngineWidgets PROPERTIES TYPE RECOMMENDED
275 URL "https://www.qt.io/"
276 DESCRIPTION "widgets for Qt's WebEngine implementation"
277 PURPOSE "Needed for displaying previews for URLs in chat"
282 if (WITH_WEBENGINE AND Qt5WebEngineWidgets_FOUND)
283 set(HAVE_WEBENGINE true)
285 add_feature_info("WITH_WEBENGINE, QtWebEngine and QtWebEngineWidgets modules" HAVE_WEBENGINE "Support showing previews for URLs in chat")
291 set(ecm_find_type "REQUIRED")
293 # Even with KDE integration disabled, we optionally use tier1 frameworks if we find them
294 set(ecm_find_type "RECOMMENDED")
297 # extra-cmake-modules
298 find_package(ECM NO_MODULE QUIET)
299 set_package_properties(ECM PROPERTIES TYPE ${ecm_find_type}
300 URL "https://projects.kde.org/projects/kdesupport/extra-cmake-modules"
301 DESCRIPTION "extra modules for CMake, maintained by the KDE project"
302 PURPOSE "Required to find KDE Frameworks components"
306 list(APPEND CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
308 find_package(KF5 COMPONENTS ConfigWidgets CoreAddons Notifications NotifyConfig Sonnet TextWidgets WidgetsAddons XmlGui QUIET)
309 set_package_properties(KF5 PROPERTIES TYPE REQUIRED
310 URL "http://www.kde.org"
311 DESCRIPTION "KDE Frameworks"
312 PURPOSE "Required for integration into the Plasma desktop"
315 find_package(KF5Sonnet QUIET)
316 set_package_properties(KF5Sonnet PROPERTIES TYPE RECOMMENDED
317 URL "http://api.kde.org/frameworks-api/frameworks5-apidocs/sonnet/html"
318 DESCRIPTION "framework for providing spell-checking capabilities"
319 PURPOSE "Enables spell-checking support in input widgets"
327 find_package(Qt5Script QUIET)
328 set_package_properties(Qt5Script PROPERTIES TYPE REQUIRED
329 DESCRIPTION "provides scripting support for Qt5"
331 find_package(Qt5Sql QUIET)
332 set_package_properties(Qt5Sql PROPERTIES TYPE REQUIRED
333 DESCRIPTION "the database support module for Qt5"
336 find_package(Qca-qt5 2.0)
337 set_package_properties(Qca-qt5 PROPERTIES TYPE RECOMMENDED
338 URL "https://projects.kde.org/projects/kdesupport/qca"
339 DESCRIPTION "Qt Cryptographic Architecture"
340 PURPOSE "Required for encryption support"
345 find_package(Qt5LinguistTools QUIET)
346 set_package_properties(Qt5LinguistTools PROPERTIES TYPE RECOMMENDED
347 DESCRIPTION "contains tools for handling translation files"
348 PURPOSE "Required for having translations"
351 # Some Qt5 versions do not define a target for lconvert, so we need to find it ourselves
352 if (Qt5LinguistTools_FOUND)
353 if (NOT TARGET Qt5::lconvert AND TARGET Qt5::lrelease)
354 get_target_property(_lrelease_location Qt5::lrelease LOCATION)
355 get_filename_component(_lrelease_path ${_lrelease_location} PATH)
356 find_program(QT_LCONVERT_EXECUTABLE NAMES lconvert-qt5 lconvert PATHS ${_lrelease_path} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
357 elseif(TARGET Qt5::lconvert AND NOT Qt5_LCONVERT_EXECUTABLE)
358 # Newer Qt5 versions define the target, but not the Qt5_LCONVERT_EXECUTABLE variable for some reason
359 get_target_property(QT_LCONVERT_EXECUTABLE Qt5::lconvert LOCATION)
362 # Compatibility with the Qt4 variables
363 set(QT_LRELEASE_EXECUTABLE ${Qt5_LRELEASE_EXECUTABLE})
364 set(QT_LUPDATE_EXECUTABLE ${Qt5_LUPDATE_EXECUTABLE})
365 if (Qt5_LCONVERT_EXECUTABLE)
366 set(QT_LCONVERT_EXECUTABLE ${Qt5_LCONVERT_EXECUTABLE})
370 # Non-Qt-based packages
372 find_package(ZLIB REQUIRED)
373 set_package_properties(ZLIB PROPERTIES TYPE REQUIRED
374 URL "http://www.zlib.net"
375 DESCRIPTION "a popular compression library"
376 PURPOSE "Used for protocol compression"
380 # Needed for generating backtraces
381 find_package(Backtrace QUIET)
382 set_package_properties(Backtrace PROPERTIES TYPE RECOMMENDED
383 DESCRIPTION "a header (and possibly library) for inspecting backtraces"
384 PURPOSE "Used for generating backtraces in case of a crash"
388 # Check for SSL support in Qt
389 # As there's no easy way to get Qt's configuration in particular for Qt5, let's just compile
390 # a small test program checking the defines. This works for both Qt4 and Qt5.
391 cmake_push_check_state(RESET)
392 set(CMAKE_REQUIRED_INCLUDES ${QT_INCLUDES} ${Qt5Core_INCLUDE_DIRS})
393 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
395 if (Qt5_POSITION_INDEPENDENT_CODE)
396 set(CMAKE_REQUIRED_FLAGS "-fPIC -DQT_NO_VERSION_TAGGING")
399 check_cxx_source_compiles("
400 #include \"qglobal.h\"
401 #if defined QT_NO_SSL
402 # error \"No SSL support\"
406 cmake_pop_check_state()
408 # Additional compile settings
409 #####################################################################
411 # This sets -fPIC and friends if required by the installed Qt5 library
412 if (Qt5_POSITION_INDEPENDENT_CODE)
413 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
414 set(CMAKE_REQUIRED_FLAGS "-DQT_NO_VERSION_TAGGING")
417 # Needed to compile with mingw without kde
418 if (MINGW AND NOT WITH_KDE)
419 add_definitions(-D_WIN32_WINNT=0x0500)
420 message(STATUS "Added _WIN32_WINNT=0x0500 definition for MinGW")
421 # workaround for bug in mingw gcc 4.0
422 add_definitions(-U__STRICT_ANSI__)
425 # Sanitize compiler flags - old versions of KDE set -ansi, which breaks -std=c++11
426 if (CMAKE_COMPILER_IS_GNUCXX)
427 string(REPLACE "-ansi" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
430 # Setup LDAP Authentication support.
431 #####################################################################
435 message(STATUS "Enabling LDAP authentication support")
437 add_definitions(-DHAVE_LDAP)
439 message(STATUS "Disabling LDAP authentication support")
442 message(STATUS "Not enabling LDAP authentication support")
445 # Setup support for KDE Frameworks
446 #####################################################################
448 # We want to do this up here, so we have the necessary variables and defines set before
452 # If KDE Frameworks are present, they're most probably providing Qt5 integration including icon loading
455 include(KDEInstallDirs)
456 include(KDECompilerSettings)
457 include(KDECMakeSettings)
459 kde_enable_exceptions()
460 add_definitions(-DHAVE_KDE -DHAVE_KF5)
464 # This needs to come after setting up KDE integration, so we can use KDE-specific paths
465 include(QuasselInstallDirs)
467 # Various config-dependent checks and settings
468 #####################################################################
471 add_definitions(-DHAVE_SSL)
473 add_feature_info("SSL support in Qt" HAVE_SSL "Use secure network connections")
475 # Check for syslog support
477 check_include_file_cxx(syslog.h HAVE_SYSLOG)
478 add_feature_info("syslog.h" HAVE_SYSLOG "Provide support for logging to the syslog")
481 add_feature_info("Qt Linguist Tools" QT_LCONVERT_EXECUTABLE "Translation support for Quassel")
484 message(STATUS "Embedding data files into the binary")
486 message(STATUS "Installing data files separately")
490 check_function_exists(umask HAVE_UMASK)
492 add_definitions(-DHAVE_UMASK)
497 # Windows-specific stuff
498 #####################################################################
501 link_libraries(imm32 winmm dbghelp Secur32) # missing by default :/
503 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DNOMINMAX")
504 set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBUGINFO "/debug /INCREMENTAL:YES /NODEFAULTLIB:libcmt /DEFAULTLIB:msvcrt")
505 set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/debug /INCREMENTAL:YES /NODEFAULTLIB:libcmt")
506 set(CMAKE_EXE_LINKER_FLAGS_DEBUGFULL "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
507 link_libraries(Version dwmapi shlwapi)
508 set(QT_QTMAIN_LIBRARY Qt5::WinMain)
513 # Generate version information from Git
514 #####################################################################
516 include(GetGitRevisionDescription)
517 get_git_head_revision(GIT_REFSPEC GIT_HEAD)
518 git_describe(GIT_DESCRIBE --long)
520 # If in a Git repo we can get the commit-date from a git command
523 COMMAND git -c log.showsignature=false show -s --format=%ct
524 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
525 OUTPUT_VARIABLE GIT_COMMIT_DATE
526 OUTPUT_STRIP_TRAILING_WHITESPACE
530 # If not in a Git repo try to read GIT_HEAD and GIT_DESCRIBE from
532 if (NOT GIT_HEAD OR NOT GIT_DESCRIBE)
533 if (DEFINED ENV{GIT_HEAD})
534 set(GIT_HEAD $ENV{GIT_HEAD})
536 if (DEFINED ENV{GIT_DESCRIBE})
537 set(GIT_DESCRIBE $ENV{GIT_DESCRIBE})
541 # Sanitize things if we're not in a Git repo
542 if (NOT GIT_HEAD OR NOT GIT_DESCRIBE)
545 set(GIT_COMMIT_DATE 0)
548 configure_file(version.h.in ${CMAKE_BINARY_DIR}/version.h @ONLY)
551 #####################################################################
553 # These variables will be added to the main targets (CORE, QTCLIENT, MONO)
554 set(COMMON_DEPS ${RC_WIN32})
558 # Add needed subdirs - the order is important, since src needs some vars set by other dirs
559 add_subdirectory(data)
560 add_subdirectory(icons)
561 add_subdirectory(pics)
565 # Set up and display feature summary
566 #####################################################################
568 feature_summary(WHAT ALL
569 INCLUDE_QUIET_PACKAGES
570 FATAL_ON_MISSING_REQUIRED_PACKAGES
573 # Finally, compile the sources
574 # We want this after displaying the feature summary to avoid ugly
575 # CMake backtraces in case a required Qt5 module is missing
576 #####################################################################
578 add_subdirectory(src)