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 # Non-Qt-based packages
338 find_package(ZLIB REQUIRED)
339 set_package_properties(ZLIB PROPERTIES TYPE REQUIRED
340 URL "http://www.zlib.net"
341 DESCRIPTION "a popular compression library"
342 PURPOSE "Used for protocol compression"
346 # Needed for generating backtraces
347 find_package(Backtrace QUIET)
348 set_package_properties(Backtrace PROPERTIES TYPE RECOMMENDED
349 DESCRIPTION "a header (and possibly library) for inspecting backtraces"
350 PURPOSE "Used for generating backtraces in case of a crash"
354 # Check for SSL support in Qt
355 cmake_push_check_state(RESET)
356 set(CMAKE_REQUIRED_LIBRARIES Qt5::Core)
357 check_cxx_source_compiles("
358 #include \"qglobal.h\"
359 #if defined QT_NO_SSL
360 # error \"No SSL support\"
364 cmake_pop_check_state()
367 add_definitions(-DHAVE_SSL)
369 add_feature_info("SSL support in Qt" HAVE_SSL "Use secure network connections")
371 # Additional compile settings
372 #####################################################################
374 # This sets -fPIC and friends if required by the installed Qt5 library
375 if (Qt5_POSITION_INDEPENDENT_CODE)
376 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
377 set(CMAKE_REQUIRED_FLAGS "-DQT_NO_VERSION_TAGGING")
380 # Needed to compile with mingw without kde
381 if (MINGW AND NOT WITH_KDE)
382 add_definitions(-D_WIN32_WINNT=0x0500)
383 message(STATUS "Added _WIN32_WINNT=0x0500 definition for MinGW")
384 # workaround for bug in mingw gcc 4.0
385 add_definitions(-U__STRICT_ANSI__)
388 # Sanitize compiler flags - old versions of KDE set -ansi, which breaks -std=c++11
389 if (CMAKE_COMPILER_IS_GNUCXX)
390 string(REPLACE "-ansi" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
393 # Setup LDAP Authentication support.
394 #####################################################################
398 message(STATUS "Enabling LDAP authentication support")
400 message(STATUS "Disabling LDAP authentication support")
403 message(STATUS "Not enabling LDAP authentication support")
406 # Setup support for KDE Frameworks
407 #####################################################################
409 # We want to do this up here, so we have the necessary variables and defines set before
413 # If KDE Frameworks are present, they're most probably providing Qt5 integration including icon loading
416 include(KDEInstallDirs)
417 include(KDECompilerSettings)
418 include(KDECMakeSettings)
420 kde_enable_exceptions()
421 add_definitions(-DHAVE_KDE -DHAVE_KF5)
425 # This needs to come after setting up KDE integration, so we can use KDE-specific paths
426 include(QuasselInstallDirs)
428 # Various config-dependent checks and settings
429 #####################################################################
431 # Check for syslog support
433 check_include_file_cxx(syslog.h HAVE_SYSLOG)
434 add_feature_info("syslog.h" HAVE_SYSLOG "Provide support for logging to the syslog")
438 message(STATUS "Embedding data files into the binary")
440 message(STATUS "Installing data files separately")
444 check_function_exists(umask HAVE_UMASK)
446 add_definitions(-DHAVE_UMASK)
451 # Windows-specific stuff
452 #####################################################################
455 link_libraries(imm32 winmm dbghelp Secur32) # missing by default :/
457 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DNOMINMAX")
458 set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBUGINFO "/debug /INCREMENTAL:YES /NODEFAULTLIB:libcmt /DEFAULTLIB:msvcrt")
459 set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/debug /INCREMENTAL:YES /NODEFAULTLIB:libcmt")
460 set(CMAKE_EXE_LINKER_FLAGS_DEBUGFULL "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
461 link_libraries(Version dwmapi shlwapi)
462 set(QT_QTMAIN_LIBRARY Qt5::WinMain)
467 # Generate version information from Git
468 #####################################################################
470 include(GetGitRevisionDescription)
471 get_git_head_revision(GIT_REFSPEC GIT_HEAD)
472 git_describe(GIT_DESCRIBE --long)
474 # If in a Git repo we can get the commit-date from a git command
477 COMMAND git -c log.showsignature=false show -s --format=%ct
478 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
479 OUTPUT_VARIABLE GIT_COMMIT_DATE
480 OUTPUT_STRIP_TRAILING_WHITESPACE
484 # If not in a Git repo try to read GIT_HEAD and GIT_DESCRIBE from
486 if (NOT GIT_HEAD OR NOT GIT_DESCRIBE)
487 if (DEFINED ENV{GIT_HEAD})
488 set(GIT_HEAD $ENV{GIT_HEAD})
490 if (DEFINED ENV{GIT_DESCRIBE})
491 set(GIT_DESCRIBE $ENV{GIT_DESCRIBE})
495 # Sanitize things if we're not in a Git repo
496 if (NOT GIT_HEAD OR NOT GIT_DESCRIBE)
499 set(GIT_COMMIT_DATE 0)
502 configure_file(version.h.in ${CMAKE_BINARY_DIR}/version.h @ONLY)
505 #####################################################################
507 # Add needed subdirs - the order is important, since src needs some vars set by other dirs
508 add_subdirectory(data)
509 add_subdirectory(icons)
510 add_subdirectory(pics)
514 # Set up and display feature summary
515 #####################################################################
517 feature_summary(WHAT ALL
518 INCLUDE_QUIET_PACKAGES
519 FATAL_ON_MISSING_REQUIRED_PACKAGES
522 # Finally, compile the sources
523 # We want this after displaying the feature summary to avoid ugly
524 # CMake backtraces in case a required Qt5 module is missing
525 #####################################################################
527 add_subdirectory(src)