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)
11 # Tell CMake about or own modules
12 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
18 set(QUASSEL_VERSION_STRING "0.14-pre")
20 # Output CMake and Quassel versions as well as build type for debug reasons
21 message(STATUS "Building Quassel ${QUASSEL_VERSION_STRING}...")
22 message(STATUS "Using CMake ${CMAKE_VERSION}")
24 # Set up build type rather early
27 # Support ccache if found
28 # This should happen before calling project(), so compiler settings are validated.
29 option(USE_CCACHE "Enable support for ccache if available" ON)
31 message(STATUS "Checking for ccache")
32 find_program(CCACHE_PROGRAM ccache)
34 set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
35 message(STATUS "Checking for ccache - enabled")
37 message(STATUS "Checking for ccache - not found")
44 # Let CMake handle file generation for Qt
49 # Needed, otherwise some .moc files won't be found with older CMake versions
50 set(CMAKE_INCLUDE_CURRENT_DIR ON)
52 # Include various CMake modules...
53 include(CMakePushCheckState)
54 include(CheckFunctionExists)
55 include(CheckIncludeFileCXX)
56 include(CheckCXXSourceCompiles)
57 include(CMakeDependentOption)
58 include(FeatureSummary)
61 include(QuasselCompileSettings)
62 include(QuasselMacros)
64 # Options and variables that can be set on the command line
65 #####################################################################
67 # Select the binaries to build
68 option(WANT_CORE "Build the core (server) binary" ON)
69 option(WANT_QTCLIENT "Build the client-only binary" ON)
70 option(WANT_MONO "Build the monolithic (all-in-one) binary" ON)
71 add_feature_info(WANT_CORE WANT_CORE "Build the core (server) binary")
72 add_feature_info(WANT_QTCLIENT WANT_QTCLIENT "Build the client-only binary (requires a core to connect to)")
73 add_feature_info(WANT_MONO WANT_MONO "Build the monolithic (all-in-one) binary")
75 # Whether to enable integration with higher-tier KDE frameworks that require runtime support.
76 # We still optionally make use of certain Tier 1 frameworks even if WITH_KDE is disabled.
77 option(WITH_KDE "Integration with the KDE Frameworks runtime environment")
78 add_feature_info(WITH_KDE WITH_KDE "Integrate with the KDE Frameworks runtime environment")
80 # Icon theme support. By default, install the Breeze icon theme (may be disabled if a system installation is present)
81 option(WITH_BUNDLED_ICONS "Install required icons from the Breeze icon theme" ON)
82 add_feature_info(WITH_BUNDLED_ICONS WITH_BUNDLED_ICONS "Install required icons from the Breeze icon theme")
84 option(WITH_OXYGEN_ICONS "Support the Oxygen icon theme (KDE4)" OFF)
85 add_feature_info(WITH_OXYGEN_ICONS WITH_OXYGEN_ICONS "Support the Oxygen icon theme (KDE4)")
87 if (WITH_BUNDLED_ICONS)
88 add_definitions(-DWITH_BUNDLED_ICONS)
90 if (WITH_OXYGEN_ICONS)
91 add_definitions(-DWITH_OXYGEN_ICONS)
94 # For this, the feature info is added after we know if QtWebkit is installed
95 option(WITH_WEBKIT "WebKit support (for link previews) (legacy)" OFF)
97 # For this, the feature info is added after we know if QtWebEngine is installed
98 option(WITH_WEBENGINE "WebEngine support (for link previews)" ON)
101 # Notification Center is only available in > 10.8, which is Darwin v12
102 if (NOT CMAKE_SYSTEM_VERSION VERSION_LESS 12)
103 option(WITH_NOTIFICATION_CENTER "OS X Notification Center support" ON)
104 add_feature_info(WITH_NOTIFICATION_CENTER WITH_NOTIFICATION_CENTER "Use the OS X Notification Center")
106 find_library(CARBON_LIBRARY Carbon)
107 mark_as_advanced(CARBON_LIBRARY)
108 link_libraries(${CARBON_LIBRARY})
111 # Always embed on Windows or OSX; never embed when enabling KDE integration
112 set(EMBED_DEFAULT OFF)
114 set(EMBED_DEFAULT ON)
116 cmake_dependent_option(EMBED_DATA "Embed icons and translations into the binaries instead of installing them" ${EMBED_DEFAULT}
117 "NOT WIN32;NOT WITH_KDE" ${EMBED_DEFAULT})
118 if (NOT EMBED_DEFAULT)
119 add_feature_info(EMBED_DATA EMBED_DATA "Embed icons and translations in the binaries instead of installing them")
122 # The following options are not for end-user consumption, so don't list them in the feature summary
123 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)
126 # List of authenticators and the cmake flags to build them
127 # (currently that's just LDAP, but more can be added here).
128 ####################################################################
129 option(WITH_LDAP "Enable LDAP authentication support if present on system" ON)
132 #####################################################################
134 # Let automoc/autouic process generated files
136 cmake_policy(SET CMP0071 NEW)
139 # Simplify later checks
140 #####################################################################
142 if (WANT_MONO OR WANT_QTCLIENT)
145 if (WANT_MONO OR WANT_CORE)
151 #####################################################################
153 # Find package dependencies
155 # Note that you can forcefully disable optional packages
156 # using -DCMAKE_DISABLE_FIND_PACKAGE_<PkgName>=TRUE
157 #####################################################################
159 set(QT_MIN_VERSION "5.5.0")
160 add_definitions(-DHAVE_QT5)
162 find_package(Qt5Core ${QT_MIN_VERSION} QUIET)
163 set_package_properties(Qt5Core PROPERTIES TYPE REQUIRED
164 URL "https://www.qt.io/"
165 DESCRIPTION "contains core functionality for Qt"
168 # find_package without REQUIRED won't check for the version properly; also, older Qt5 versions
169 # used Qt5Core_VERSION_STRING... let's just make sure here that we bail out here if our Qt5 is not new enough.
170 if (NOT Qt5Core_VERSION OR Qt5Core_VERSION VERSION_LESS ${QT_MIN_VERSION})
171 message(FATAL_ERROR "Could NOT find Qt5 >= version ${QT_MIN_VERSION}!")
174 find_package(Qt5Network QUIET)
175 set_package_properties(Qt5Network PROPERTIES TYPE REQUIRED
176 DESCRIPTION "the network module for Qt5"
180 find_package(Qt5Gui QUIET)
181 set_package_properties(Qt5Gui PROPERTIES TYPE REQUIRED
182 DESCRIPTION "the GUI module for Qt5"
184 find_package(Qt5Widgets QUIET)
185 set_package_properties(Qt5Widgets PROPERTIES TYPE REQUIRED
186 DESCRIPTION "the widgets module for Qt5"
190 find_package(Qt5DBus QUIET)
191 set_package_properties(Qt5DBus PROPERTIES TYPE RECOMMENDED
192 URL "https://www.qt.io/"
193 DESCRIPTION "D-Bus support for Qt5"
194 PURPOSE "Needed for supporting D-Bus-based notifications and tray icon, used by most modern desktop environments"
197 find_package(dbusmenu-qt5 QUIET CONFIG)
198 set_package_properties(dbusmenu-qt5 PROPERTIES TYPE RECOMMENDED
199 URL "https://launchpad.net/libdbusmenu-qt"
200 DESCRIPTION "a library implementing the DBusMenu specification"
201 PURPOSE "Required for having a context menu for the D-Bus-based tray icon"
206 find_package(Qt5Multimedia QUIET)
207 set_package_properties(Qt5Multimedia PROPERTIES TYPE RECOMMENDED
208 URL "https://www.qt.io/"
209 DESCRIPTION "Multimedia support for Qt5"
210 PURPOSE "Required for audio notifications"
213 find_package(LibsnoreQt5 0.7.0 QUIET)
214 set_package_properties(LibsnoreQt5 PROPERTIES TYPE OPTIONAL
215 URL "https://projects.kde.org/projects/playground/libs/snorenotify"
216 DESCRIPTION "a cross-platform notification framework"
217 PURPOSE "Enable support for the snorenotify framework"
219 if(LibsnoreQt5_FOUND)
220 find_package(LibsnoreSettingsQt5)
221 set_package_properties(LibsnoreSettingsQt5 PROPERTIES TYPE REQUIRED
222 URL "https://projects.kde.org/projects/playground/libs/snorenotify"
223 DESCRIPTION "a cross-platform notification framework"
224 PURPOSE "Enable support for the snorenotify framework"
229 find_package(Qt5WebKit QUIET)
230 set_package_properties(Qt5WebKit PROPERTIES TYPE RECOMMENDED
231 URL "https://www.qt.io/"
232 DESCRIPTION "a WebKit implementation for Qt"
233 PURPOSE "Needed for displaying previews for URLs in chat"
236 find_package(Qt5WebKitWidgets QUIET)
237 set_package_properties(Qt5WebKitWidgets PROPERTIES TYPE RECOMMENDED
238 URL "https://www.qt.io/"
239 DESCRIPTION "widgets for Qt's WebKit implementation"
240 PURPOSE "Needed for displaying previews for URLs in chat"
245 if (WITH_WEBKIT AND Qt5WebKitWidgets_FOUND)
246 set(HAVE_WEBKIT true)
248 add_feature_info("WITH_WEBKIT, QtWebKit and QtWebKitWidgets modules" HAVE_WEBKIT "Support showing previews for URLs in chat (legacy)")
251 find_package(Qt5WebEngine QUIET)
252 set_package_properties(Qt5WebEngine PROPERTIES TYPE RECOMMENDED
253 URL "https://www.qt.io/"
254 DESCRIPTION "a WebEngine implementation for Qt"
255 PURPOSE "Needed for displaying previews for URLs in chat"
257 if (Qt5WebEngine_FOUND)
258 find_package(Qt5WebEngineWidgets QUIET)
259 set_package_properties(Qt5WebEngineWidgets PROPERTIES TYPE RECOMMENDED
260 URL "https://www.qt.io/"
261 DESCRIPTION "widgets for Qt's WebEngine implementation"
262 PURPOSE "Needed for displaying previews for URLs in chat"
267 if (WITH_WEBENGINE AND Qt5WebEngineWidgets_FOUND)
268 set(HAVE_WEBENGINE true)
270 add_feature_info("WITH_WEBENGINE, QtWebEngine and QtWebEngineWidgets modules" HAVE_WEBENGINE "Support showing previews for URLs in chat")
276 set(ecm_find_type "REQUIRED")
278 # Even with KDE integration disabled, we optionally use tier1 frameworks if we find them
279 set(ecm_find_type "RECOMMENDED")
282 # extra-cmake-modules
283 find_package(ECM NO_MODULE QUIET)
284 set_package_properties(ECM PROPERTIES TYPE ${ecm_find_type}
285 URL "https://projects.kde.org/projects/kdesupport/extra-cmake-modules"
286 DESCRIPTION "extra modules for CMake, maintained by the KDE project"
287 PURPOSE "Required to find KDE Frameworks components"
291 list(APPEND CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
293 find_package(KF5 COMPONENTS ConfigWidgets CoreAddons Notifications NotifyConfig Sonnet TextWidgets WidgetsAddons XmlGui QUIET)
294 set_package_properties(KF5 PROPERTIES TYPE REQUIRED
295 URL "http://www.kde.org"
296 DESCRIPTION "KDE Frameworks"
297 PURPOSE "Required for integration into the Plasma desktop"
300 find_package(KF5Sonnet QUIET)
301 set_package_properties(KF5Sonnet PROPERTIES TYPE RECOMMENDED
302 URL "http://api.kde.org/frameworks-api/frameworks5-apidocs/sonnet/html"
303 DESCRIPTION "framework for providing spell-checking capabilities"
304 PURPOSE "Enables spell-checking support in input widgets"
312 find_package(Qt5Script QUIET)
313 set_package_properties(Qt5Script PROPERTIES TYPE REQUIRED
314 DESCRIPTION "provides scripting support for Qt5"
316 find_package(Qt5Sql QUIET)
317 set_package_properties(Qt5Sql PROPERTIES TYPE REQUIRED
318 DESCRIPTION "the database support module for Qt5"
321 find_package(Qca-qt5 2.0)
322 set_package_properties(Qca-qt5 PROPERTIES TYPE RECOMMENDED
323 URL "https://projects.kde.org/projects/kdesupport/qca"
324 DESCRIPTION "Qt Cryptographic Architecture"
325 PURPOSE "Required for encryption support"
330 find_package(Qt5LinguistTools QUIET)
331 set_package_properties(Qt5LinguistTools PROPERTIES TYPE RECOMMENDED
332 DESCRIPTION "contains tools for handling translation files"
333 PURPOSE "Required for having translations"
336 # Some Qt5 versions do not define a target for lconvert, so we need to find it ourselves
337 if (Qt5LinguistTools_FOUND)
338 if (NOT TARGET Qt5::lconvert AND TARGET Qt5::lrelease)
339 get_target_property(_lrelease_location Qt5::lrelease LOCATION)
340 get_filename_component(_lrelease_path ${_lrelease_location} PATH)
341 find_program(QT_LCONVERT_EXECUTABLE NAMES lconvert-qt5 lconvert PATHS ${_lrelease_path} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
342 elseif(TARGET Qt5::lconvert AND NOT Qt5_LCONVERT_EXECUTABLE)
343 # Newer Qt5 versions define the target, but not the Qt5_LCONVERT_EXECUTABLE variable for some reason
344 get_target_property(QT_LCONVERT_EXECUTABLE Qt5::lconvert LOCATION)
347 # Compatibility with the Qt4 variables
348 set(QT_LRELEASE_EXECUTABLE ${Qt5_LRELEASE_EXECUTABLE})
349 set(QT_LUPDATE_EXECUTABLE ${Qt5_LUPDATE_EXECUTABLE})
350 if (Qt5_LCONVERT_EXECUTABLE)
351 set(QT_LCONVERT_EXECUTABLE ${Qt5_LCONVERT_EXECUTABLE})
355 # Non-Qt-based packages
357 find_package(ZLIB REQUIRED)
358 set_package_properties(ZLIB PROPERTIES TYPE REQUIRED
359 URL "http://www.zlib.net"
360 DESCRIPTION "a popular compression library"
361 PURPOSE "Used for protocol compression"
365 # Needed for generating backtraces
366 find_package(Backtrace QUIET)
367 set_package_properties(Backtrace PROPERTIES TYPE RECOMMENDED
368 DESCRIPTION "a header (and possibly library) for inspecting backtraces"
369 PURPOSE "Used for generating backtraces in case of a crash"
373 # Check for SSL support in Qt
374 # As there's no easy way to get Qt's configuration in particular for Qt5, let's just compile
375 # a small test program checking the defines. This works for both Qt4 and Qt5.
376 cmake_push_check_state(RESET)
377 set(CMAKE_REQUIRED_INCLUDES ${QT_INCLUDES} ${Qt5Core_INCLUDE_DIRS})
378 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
380 if (Qt5_POSITION_INDEPENDENT_CODE)
381 set(CMAKE_REQUIRED_FLAGS "-fPIC -DQT_NO_VERSION_TAGGING")
384 check_cxx_source_compiles("
385 #include \"qglobal.h\"
386 #if defined QT_NO_SSL
387 # error \"No SSL support\"
391 cmake_pop_check_state()
393 # Additional compile settings
394 #####################################################################
396 # This sets -fPIC and friends if required by the installed Qt5 library
397 if (Qt5_POSITION_INDEPENDENT_CODE)
398 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
399 set(CMAKE_REQUIRED_FLAGS "-DQT_NO_VERSION_TAGGING")
402 # Needed to compile with mingw without kde
403 if (MINGW AND NOT WITH_KDE)
404 add_definitions(-D_WIN32_WINNT=0x0500)
405 message(STATUS "Added _WIN32_WINNT=0x0500 definition for MinGW")
406 # workaround for bug in mingw gcc 4.0
407 add_definitions(-U__STRICT_ANSI__)
410 # Sanitize compiler flags - old versions of KDE set -ansi, which breaks -std=c++11
411 if (CMAKE_COMPILER_IS_GNUCXX)
412 string(REPLACE "-ansi" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
415 # Setup LDAP Authentication support.
416 #####################################################################
420 message(STATUS "Enabling LDAP authentication support")
422 message(STATUS "Disabling LDAP authentication support")
425 message(STATUS "Not enabling LDAP authentication support")
428 # Setup support for KDE Frameworks
429 #####################################################################
431 # We want to do this up here, so we have the necessary variables and defines set before
435 # If KDE Frameworks are present, they're most probably providing Qt5 integration including icon loading
438 include(KDEInstallDirs)
439 include(KDECompilerSettings)
440 include(KDECMakeSettings)
442 kde_enable_exceptions()
443 add_definitions(-DHAVE_KDE -DHAVE_KF5)
447 # This needs to come after setting up KDE integration, so we can use KDE-specific paths
448 include(QuasselInstallDirs)
450 # Various config-dependent checks and settings
451 #####################################################################
454 add_definitions(-DHAVE_SSL)
456 add_feature_info("SSL support in Qt" HAVE_SSL "Use secure network connections")
458 # Check for syslog support
460 check_include_file_cxx(syslog.h HAVE_SYSLOG)
461 add_feature_info("syslog.h" HAVE_SYSLOG "Provide support for logging to the syslog")
464 add_feature_info("Qt Linguist Tools" QT_LCONVERT_EXECUTABLE "Translation support for Quassel")
467 message(STATUS "Embedding data files into the binary")
469 message(STATUS "Installing data files separately")
473 check_function_exists(umask HAVE_UMASK)
475 add_definitions(-DHAVE_UMASK)
480 # Windows-specific stuff
481 #####################################################################
484 link_libraries(imm32 winmm dbghelp Secur32) # missing by default :/
486 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DNOMINMAX")
487 set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBUGINFO "/debug /INCREMENTAL:YES /NODEFAULTLIB:libcmt /DEFAULTLIB:msvcrt")
488 set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/debug /INCREMENTAL:YES /NODEFAULTLIB:libcmt")
489 set(CMAKE_EXE_LINKER_FLAGS_DEBUGFULL "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
490 link_libraries(Version dwmapi shlwapi)
491 set(QT_QTMAIN_LIBRARY Qt5::WinMain)
496 # Generate version information from Git
497 #####################################################################
499 include(GetGitRevisionDescription)
500 get_git_head_revision(GIT_REFSPEC GIT_HEAD)
501 git_describe(GIT_DESCRIBE --long)
503 # If in a Git repo we can get the commit-date from a git command
506 COMMAND git -c log.showsignature=false show -s --format=%ct
507 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
508 OUTPUT_VARIABLE GIT_COMMIT_DATE
509 OUTPUT_STRIP_TRAILING_WHITESPACE
513 # If not in a Git repo try to read GIT_HEAD and GIT_DESCRIBE from
515 if (NOT GIT_HEAD OR NOT GIT_DESCRIBE)
516 if (DEFINED ENV{GIT_HEAD})
517 set(GIT_HEAD $ENV{GIT_HEAD})
519 if (DEFINED ENV{GIT_DESCRIBE})
520 set(GIT_DESCRIBE $ENV{GIT_DESCRIBE})
524 # Sanitize things if we're not in a Git repo
525 if (NOT GIT_HEAD OR NOT GIT_DESCRIBE)
528 set(GIT_COMMIT_DATE 0)
531 configure_file(version.h.in ${CMAKE_BINARY_DIR}/version.h @ONLY)
534 #####################################################################
536 # Add needed subdirs - the order is important, since src needs some vars set by other dirs
537 add_subdirectory(data)
538 add_subdirectory(icons)
539 add_subdirectory(pics)
543 # Set up and display feature summary
544 #####################################################################
546 feature_summary(WHAT ALL
547 INCLUDE_QUIET_PACKAGES
548 FATAL_ON_MISSING_REQUIRED_PACKAGES
551 # Finally, compile the sources
552 # We want this after displaying the feature summary to avoid ugly
553 # CMake backtraces in case a required Qt5 module is missing
554 #####################################################################
556 add_subdirectory(src)