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)
14 include(QuasselVersion)
16 message(STATUS "Using CMake ${CMAKE_VERSION}")
18 # Set up build type rather early
21 # Support ccache if found
22 # This should happen before calling project(), so compiler settings are validated.
23 option(USE_CCACHE "Enable support for ccache if available" ON)
25 message(STATUS "Checking for ccache")
26 find_program(CCACHE_PROGRAM ccache)
28 set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
29 message(STATUS "Checking for ccache - enabled")
31 message(STATUS "Checking for ccache - not found")
38 # Let CMake handle file generation for Qt
43 # Needed, otherwise some .moc files won't be found with older CMake versions
44 set(CMAKE_INCLUDE_CURRENT_DIR ON)
46 # Include various CMake modules...
47 include(CMakePushCheckState)
48 include(CheckFunctionExists)
49 include(CheckIncludeFileCXX)
50 include(CheckCXXSourceCompiles)
51 include(CMakeDependentOption)
52 include(FeatureSummary)
55 include(QuasselCompileSettings)
56 include(QuasselMacros)
58 # Options and variables that can be set on the command line
59 #####################################################################
61 # Select the binaries to build
62 option(WANT_CORE "Build the core (server) binary" ON)
63 option(WANT_QTCLIENT "Build the client-only binary" ON)
64 option(WANT_MONO "Build the monolithic (all-in-one) binary" ON)
65 add_feature_info(WANT_CORE WANT_CORE "Build the core (server) binary")
66 add_feature_info(WANT_QTCLIENT WANT_QTCLIENT "Build the client-only binary (requires a core to connect to)")
67 add_feature_info(WANT_MONO WANT_MONO "Build the monolithic (all-in-one) binary")
69 # Whether to enable integration with higher-tier KDE frameworks that require runtime support.
70 # We still optionally make use of certain Tier 1 frameworks even if WITH_KDE is disabled.
71 option(WITH_KDE "Integration with the KDE Frameworks runtime environment")
72 add_feature_info(WITH_KDE WITH_KDE "Integrate with the KDE Frameworks runtime environment")
74 # Icon theme support. By default, install the Breeze icon theme (may be disabled if a system installation is present)
75 option(WITH_BUNDLED_ICONS "Install required icons from the Breeze icon theme" ON)
76 add_feature_info(WITH_BUNDLED_ICONS WITH_BUNDLED_ICONS "Install required icons from the Breeze icon theme")
78 option(WITH_OXYGEN_ICONS "Support the Oxygen icon theme (KDE4)" OFF)
79 add_feature_info(WITH_OXYGEN_ICONS WITH_OXYGEN_ICONS "Support the Oxygen icon theme (KDE4)")
81 # For this, the feature info is added after we know if QtWebkit is installed
82 option(WITH_WEBKIT "WebKit support (for link previews) (legacy)" OFF)
84 # For this, the feature info is added after we know if QtWebEngine is installed
85 option(WITH_WEBENGINE "WebEngine support (for link previews)" ON)
88 # Notification Center is only available in > 10.8, which is Darwin v12
89 if (NOT CMAKE_SYSTEM_VERSION VERSION_LESS 12)
90 option(WITH_NOTIFICATION_CENTER "OS X Notification Center support" ON)
91 add_feature_info(WITH_NOTIFICATION_CENTER WITH_NOTIFICATION_CENTER "Use the OS X Notification Center")
93 find_library(CARBON_LIBRARY Carbon)
94 mark_as_advanced(CARBON_LIBRARY)
95 link_libraries(${CARBON_LIBRARY})
98 # Always embed on Windows or OSX; never embed when enabling KDE integration
99 set(EMBED_DEFAULT OFF)
101 set(EMBED_DEFAULT ON)
103 cmake_dependent_option(EMBED_DATA "Embed icons and translations into the binaries instead of installing them" ${EMBED_DEFAULT}
104 "NOT WIN32;NOT WITH_KDE" ${EMBED_DEFAULT})
105 if (NOT EMBED_DEFAULT)
106 add_feature_info(EMBED_DATA EMBED_DATA "Embed icons and translations in the binaries instead of installing them")
109 # The following options are not for end-user consumption, so don't list them in the feature summary
110 option(FATAL_WARNINGS "Make compile warnings fatal (most useful for CI builds)" OFF)
111 option(WARN_QT_DEPRECATION "Warn about deprecated Qt functionality" OFF)
112 if (WARN_QT_DEPRECATION)
113 # Enable Qt deprecation warnings for Qt < 5.13 (on by default in newer versions)
114 add_definitions("-DQT_DEPRECATED_WARNINGS")
116 cmake_dependent_option(DEPLOY "Add required libs to bundle resources and create a dmg" OFF "APPLE" OFF)
118 # List of authenticators and the cmake flags to build them
119 # (currently that's just LDAP, but more can be added here).
120 ####################################################################
121 option(WITH_LDAP "Enable LDAP authentication support if present on system" ON)
124 #####################################################################
126 # Visibility settings apply to all targets
128 cmake_policy(SET CMP0063 NEW)
131 # Let automoc/autouic process generated files
133 cmake_policy(SET CMP0071 NEW)
136 set(BUILD_SHARED_LIBS TRUE CACHE BOOL "" FORCE)
138 # Don't use X11 on OSX
140 set(CMAKE_DISABLE_FIND_PACKAGE_X11 true)
141 set(CMAKE_DISABLE_FIND_PACKAGE_XCB true)
142 set(CMAKE_DISABLE_FIND_PACKAGE_Qt5X11Extras true)
145 # Simplify later checks
146 #####################################################################
148 if (WANT_MONO OR WANT_QTCLIENT)
151 if (WANT_MONO OR WANT_CORE)
156 #####################################################################
158 # Find package dependencies
160 # Note that you can forcefully disable optional packages
161 # using -DCMAKE_DISABLE_FIND_PACKAGE_<PkgName>=TRUE
162 #####################################################################
164 set(QT_MIN_VERSION "5.5.0")
166 # Required Qt components
167 set(qt_components Core Network)
169 list(APPEND qt_components Gui Widgets)
172 list(APPEND qt_components Sql)
175 find_package(Qt5 ${QT_MIN_VERSION} REQUIRED COMPONENTS ${qt_components})
176 set_package_properties(Qt5 PROPERTIES TYPE REQUIRED
177 URL "https://www.qt.io/"
178 DESCRIPTION "the Qt libraries"
180 message(STATUS "Found Qt ${Qt5Core_VERSION}")
182 # Check for SSL support in Qt
183 cmake_push_check_state(RESET)
184 set(CMAKE_REQUIRED_LIBRARIES Qt5::Core)
185 check_cxx_source_compiles("
186 #include \"qglobal.h\"
187 #if defined QT_NO_SSL
188 # error \"No SSL support\"
192 cmake_pop_check_state()
195 message(FATAL_ERROR "Quassel requires SSL support, but Qt is built with QT_NO_SSL")
198 # Compat until fallback code paths have been disabled
199 add_definitions(-DHAVE_SSL)
201 # Optional Qt components
203 find_package(Qt5LinguistTools QUIET)
204 set_package_properties(Qt5LinguistTools PROPERTIES TYPE RECOMMENDED
205 DESCRIPTION "contains tools for handling translation files"
206 PURPOSE "Required for having translations"
211 find_package(Qt5DBus QUIET)
212 set_package_properties(Qt5DBus PROPERTIES TYPE RECOMMENDED
213 URL "https://www.qt.io/"
214 DESCRIPTION "D-Bus support for Qt5"
215 PURPOSE "Needed for supporting D-Bus-based notifications and tray icon, used by most modern desktop environments"
218 find_package(dbusmenu-qt5 QUIET CONFIG)
219 set_package_properties(dbusmenu-qt5 PROPERTIES TYPE RECOMMENDED
220 URL "https://launchpad.net/libdbusmenu-qt"
221 DESCRIPTION "a library implementing the DBusMenu specification"
222 PURPOSE "Required for having a context menu for the D-Bus-based tray icon"
227 find_package(Qt5Multimedia QUIET)
228 set_package_properties(Qt5Multimedia PROPERTIES TYPE RECOMMENDED
229 URL "https://www.qt.io/"
230 DESCRIPTION "Multimedia support for Qt5"
231 PURPOSE "Required for audio notifications"
234 # snorenotify segfaults on startup on msys2
235 # we don't check for just MSYS to support the Ninja generator
236 if(NOT (WIN32 AND (NOT $ENV{MSYSTEM} STREQUAL "")))
237 find_package(LibsnoreQt5 0.7.0 QUIET)
238 set_package_properties(LibsnoreQt5 PROPERTIES TYPE OPTIONAL
239 URL "https://projects.kde.org/projects/playground/libs/snorenotify"
240 DESCRIPTION "a cross-platform notification framework"
241 PURPOSE "Enable support for the snorenotify framework"
243 if (LibsnoreQt5_FOUND)
244 find_package(LibsnoreSettingsQt5 QUIET)
245 set_package_properties(LibsnoreSettingsQt5 PROPERTIES TYPE OPTIONAL
246 URL "https://projects.kde.org/projects/playground/libs/snorenotify"
247 DESCRIPTION "a cross-platform notification framework"
248 PURPOSE "Enable support for the snorenotify framework"
254 find_package(Qt5WebEngine QUIET)
255 set_package_properties(Qt5WebEngine PROPERTIES TYPE RECOMMENDED
256 URL "https://www.qt.io/"
257 DESCRIPTION "a WebEngine implementation for Qt"
258 PURPOSE "Needed for displaying previews for URLs in chat"
260 if (Qt5WebEngine_FOUND)
261 find_package(Qt5WebEngineWidgets QUIET)
262 set_package_properties(Qt5WebEngineWidgets PROPERTIES TYPE RECOMMENDED
263 URL "https://www.qt.io/"
264 DESCRIPTION "widgets for Qt's WebEngine implementation"
265 PURPOSE "Needed for displaying previews for URLs in chat"
270 if (WITH_WEBENGINE AND Qt5WebEngineWidgets_FOUND)
271 set(HAVE_WEBENGINE true)
273 add_feature_info("WITH_WEBENGINE, QtWebEngine and QtWebEngineWidgets modules" HAVE_WEBENGINE "Support showing previews for URLs in chat")
275 if (NOT HAVE_WEBENGINE)
277 find_package(Qt5WebKit QUIET)
278 set_package_properties(Qt5WebKit PROPERTIES TYPE OPTIONAL
279 URL "https://www.qt.io/"
280 DESCRIPTION "a WebKit implementation for Qt"
281 PURPOSE "Needed for displaying previews for URLs in chat"
284 find_package(Qt5WebKitWidgets QUIET)
285 set_package_properties(Qt5WebKitWidgets PROPERTIES TYPE OPTIONAL
286 URL "https://www.qt.io/"
287 DESCRIPTION "widgets for Qt's WebKit implementation"
288 PURPOSE "Needed for displaying previews for URLs in chat"
293 if (WITH_WEBKIT AND Qt5WebKitWidgets_FOUND)
294 set(HAVE_WEBKIT true)
296 add_feature_info("WITH_WEBKIT, QtWebKit and QtWebKitWidgets modules" HAVE_WEBKIT "Support showing previews for URLs in chat (legacy)")
302 # extra-cmake-modules
304 set(ecm_find_type "REQUIRED")
305 find_package(ECM NO_MODULE REQUIRED)
307 # Even with KDE integration disabled, we optionally use tier1 frameworks if we find them
308 set(ecm_find_type "RECOMMENDED")
309 find_package(ECM NO_MODULE QUIET)
312 set_package_properties(ECM PROPERTIES TYPE ${ecm_find_type}
313 URL "https://projects.kde.org/projects/kdesupport/extra-cmake-modules"
314 DESCRIPTION "extra modules for CMake, maintained by the KDE project"
315 PURPOSE "Required to find KDE Frameworks components"
319 list(APPEND CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
321 find_package(KF5 REQUIRED COMPONENTS ConfigWidgets CoreAddons Notifications NotifyConfig Sonnet TextWidgets WidgetsAddons XmlGui)
322 set_package_properties(KF5 PROPERTIES TYPE REQUIRED
323 URL "http://www.kde.org"
324 DESCRIPTION "KDE Frameworks"
325 PURPOSE "Required for integration into the Plasma desktop"
327 message(STATUS "Found KDE Frameworks ${KF5_VERSION}")
330 # Optional KF5 tier1 components
331 find_package(KF5Sonnet QUIET)
332 set_package_properties(KF5Sonnet PROPERTIES TYPE RECOMMENDED
333 URL "http://api.kde.org/frameworks-api/frameworks5-apidocs/sonnet/html"
334 DESCRIPTION "framework for providing spell-checking capabilities"
335 PURPOSE "Enables spell-checking support in input widgets"
341 find_package(Qca-qt5 2.0 QUIET)
342 set_package_properties(Qca-qt5 PROPERTIES TYPE RECOMMENDED
343 URL "https://projects.kde.org/projects/kdesupport/qca"
344 DESCRIPTION "Qt Cryptographic Architecture"
345 PURPOSE "Required for encryption support"
349 find_package(Ldap QUIET)
350 set_package_properties(Ldap PROPERTIES TYPE OPTIONAL
351 URL "http://www.openldap.org/"
352 DESCRIPTION "LDAP (Lightweight Directory Access Protocol) libraries"
353 PURPOSE "Enables core user authentication via LDAP"
358 # Non-Qt-based packages
359 #####################################################################
361 find_package(Boost 1.54 REQUIRED)
362 set_package_properties(Boost PROPERTIES TYPE REQUIRED
363 URL "https://www.boost.org/"
364 DESCRIPTION "Boost libraries for C++"
366 # Older versions don't define the imported target
367 if (NOT TARGET Boost::boost)
368 add_library(Boost::boost INTERFACE IMPORTED GLOBAL)
369 if (Boost_INCLUDE_DIRS)
370 set_target_properties(Boost::boost PROPERTIES
371 INTERFACE_INCLUDE_DIRECTORIES "${Boost_INCLUDE_DIRS}")
375 find_package(ZLIB REQUIRED)
376 set_package_properties(ZLIB PROPERTIES TYPE REQUIRED
377 URL "http://www.zlib.net"
378 DESCRIPTION "a popular compression library"
379 PURPOSE "Used for protocol compression"
383 # Needed for generating backtraces
384 find_package(Backtrace QUIET)
385 set_package_properties(Backtrace PROPERTIES TYPE RECOMMENDED
386 DESCRIPTION "a header (and possibly library) for inspecting backtraces"
387 PURPOSE "Used for generating backtraces in case of a crash"
391 # Shared library support
392 #####################################################################
394 option(ENABLE_SHARED "Build modules as shared libraries" ON)
395 add_feature_info(ENABLE_SHARED ENABLE_SHARED "Build modules as shared libraries")
398 #####################################################################
400 option(BUILD_TESTING "Enable unit tests" OFF)
401 add_feature_info(BUILD_TESTING BUILD_TESTING "Build unit tests")
404 find_package(GTest QUIET)
405 set_package_properties(GTest PROPERTIES TYPE REQUIRED
406 DESCRIPTION "Google's unit testing framework"
407 PURPOSE "Required for building unit tests"
410 find_package(Qt5Test QUIET)
411 set_package_properties(Qt5Test PROPERTIES TYPE REQUIRED
412 DESCRIPTION "unit testing library for the Qt5 framework"
413 PURPOSE "Required for building unit tests"
417 # GTest messes with CMAKE_CXX_FLAGS, so process them again
418 process_cmake_cxx_flags()
421 # Setup support for KDE Frameworks
422 #####################################################################
425 add_definitions(-DHAVE_KDE -DHAVE_KF5)
428 # If KDE Frameworks are present, they're most probably providing Qt5 integration including icon loading
431 include(KDEInstallDirs)
434 # This needs to come after setting up KDE integration, so we can use KDE-specific paths
435 include(QuasselInstallDirs)
437 # RPATH and output settings
438 #####################################################################
440 # Build artifacts in a well-known location; especially important for Windows DLLs
441 # (which go into RUNTIME_OUTPUT_DIRECTORY and can thus be found by executables)
442 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
443 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
444 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
446 # These RPATH settings allow for running directly from the build dir
447 set(CMAKE_SKIP_BUILD_RPATH FALSE)
448 set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
449 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE )
451 # Set install RPATH only if libdir isn't a system directory
452 if (IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
453 set(libdir "${CMAKE_INSTALL_LIBDIR}")
455 set(libdir "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
457 list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${libdir}" is_systemdir)
458 if ("${is_systemdir}" STREQUAL "-1")
459 set(CMAKE_INSTALL_RPATH "${libdir}")
462 # Various config-dependent checks and settings
463 #####################################################################
465 # Check for syslog support
467 check_include_file_cxx(syslog.h HAVE_SYSLOG)
468 add_feature_info("syslog.h" HAVE_SYSLOG "Provide support for logging to the syslog")
472 check_function_exists(umask HAVE_UMASK)
476 message(STATUS "Embedding data files into the binary")
478 message(STATUS "Installing data files separately")
481 # Windows-specific stuff
482 #####################################################################
485 link_libraries(imm32 winmm dbghelp Secur32) # missing by default :/
487 link_libraries(Version dwmapi shlwapi)
492 #####################################################################
494 # Add needed subdirs - the order is important, since src needs some vars set by other dirs
495 add_subdirectory(data)
496 add_subdirectory(icons)
497 add_subdirectory(pics)
500 # Set up and display feature summary
501 #####################################################################
503 feature_summary(WHAT ALL
504 INCLUDE_QUIET_PACKAGES
505 FATAL_ON_MISSING_REQUIRED_PACKAGES
508 # Finally, compile the sources
509 # We want this after displaying the feature summary to avoid ugly
510 # CMake backtraces in case a required Qt5 module is missing
511 #####################################################################
513 add_subdirectory(src)
515 # Build tests if so desired
517 add_subdirectory(tests)