clang-tidy: Avoid warnings for calling virtual methods from ctor
[quassel.git] / CMakeLists.txt
1 # Main CMake file for building Quassel IRC
2 #
3 # See INSTALL for possible CMake options (or read the code, Luke)
4 #####################################################################
5
6 # General setup
7 #####################################################################
8
9 # Versions
10 set(QUASSEL_MAJOR  0)
11 set(QUASSEL_MINOR 13)
12 set(QUASSEL_PATCH  0)
13 set(QUASSEL_VERSION_STRING "0.13-rc1")
14
15 # Build type
16 if (CMAKE_CONFIGURATION_TYPES)
17     set(CMAKE_CONFIGURATION_TYPES Release RelWithDebInfo Debug Debugfull Profile)
18     set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING "These are the configuration types we support" FORCE)
19 endif()
20
21 if(NOT CMAKE_BUILD_TYPE)
22     set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build, options are: Release RelWithDebInfo Debug Debugfull Profile None" FORCE)
23 endif()
24
25 # Output CMake and Quassel versions as well as build type for debug reasons
26 message(STATUS "Building Quassel ${QUASSEL_VERSION_STRING}...")
27 message(STATUS "Using CMake ${CMAKE_VERSION}")
28 message(STATUS "CMake build type: ${CMAKE_BUILD_TYPE}")
29
30 # Support ccache if found
31 # This should happen before calling project(), so compiler settings are validated.
32 option(USE_CCACHE "Enable support for ccache if available" ON)
33 if (USE_CCACHE)
34     message(STATUS "Checking for ccache")
35     find_program(CCACHE_PROGRAM ccache)
36     if (CCACHE_PROGRAM)
37         set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
38         message(STATUS "Checking for ccache - enabled")
39     else()
40         message(STATUS "Checking for ccache - not found")
41     endif()
42 endif()
43
44 # Set up project
45 project(Quassel C CXX)
46
47 # General conveniences
48 set(CMAKE_AUTOMOC ON)
49 set(CMAKE_INCLUDE_CURRENT_DIR ON)
50
51 # Include various CMake modules
52 include(CMakePushCheckState)
53 include(CheckFunctionExists)
54 include(CheckIncludeFile)
55 include(CheckCXXSourceCompiles)
56 include(CMakeDependentOption)
57 include(FeatureSummary)
58
59 # Tell CMake about or own modules
60 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
61 include(QuasselCompileSettings)
62 include(QuasselMacros)
63
64
65 # Options and variables that can be set on the command line
66 #####################################################################
67
68 # Choose a Qt version. We support USE_QT5 and USE_QT4; if neither is set, Qt5 will be used
69 option(USE_QT5 "Enable support for Qt5" OFF)
70 if (USE_QT5) # takes precedence
71     set(USE_QT4 OFF)
72 else()
73     if (NOT USE_QT4)
74         set(USE_QT5 ON)
75     endif()
76 endif()
77
78 # Select the binaries to build
79 option(WANT_CORE     "Build the core (server) binary"           ON)
80 option(WANT_QTCLIENT "Build the client-only binary"             ON)
81 option(WANT_MONO     "Build the monolithic (all-in-one) binary" ON)
82 add_feature_info(WANT_CORE WANT_CORE "Build the core (server) binary")
83 add_feature_info(WANT_QTCLIENT WANT_QTCLIENT "Build the client-only binary (requires a core to connect to)")
84 add_feature_info(WANT_MONO WANT_MONO "Build the monolithic (all-in-one) binary")
85
86 # Whether to enable KDE integration (work in progress for Qt5 / KDE Frameworks)
87 # Note that when building with Qt5, WITH_KDE enables integration with higher-tier KDE frameworks that
88 # require runtime support. We still optionally make use of certain Tier 1 frameworks even if WITH_KDE
89 # is disabled.
90 if (USE_QT4)
91     option(WITH_KDE "KDE4 integration" OFF)
92     add_feature_info(WITH_KDE WITH_KDE "Enable KDE4 integration")
93 else()
94     option(WITH_KDE "Integration with the KDE Frameworks runtime environment")
95     add_feature_info(WITH_KDE WITH_KDE "Integrate with the KDE Frameworks runtime environment")
96 endif()
97
98 # Icon theme support. By default, install the Breeze icon theme (may be disabled if a system installation is present)
99 option(WITH_BUNDLED_ICONS "Install required icons from the Breeze icon theme" ON)
100 add_feature_info(WITH_BUNDLED_ICONS WITH_BUNDLED_ICONS "Install required icons from the Breeze icon theme")
101
102 # For Qt4, always support Oxygen
103 cmake_dependent_option(WITH_OXYGEN_ICONS "Support the Oxygen icon theme (KDE4)" OFF "USE_QT5" ON)
104 add_feature_info(WITH_OXYGEN_ICONS WITH_OXYGEN_ICONS "Support the Oxygen icon theme (KDE4)" OFF)
105
106 if (WITH_BUNDLED_ICONS)
107     add_definitions(-DWITH_BUNDLED_ICONS)
108 endif()
109 if (WITH_OXYGEN_ICONS)
110     add_definitions(-DWITH_OXYGEN_ICONS)
111 endif()
112
113 # For this, the feature info is added after we know if QtWebkit is installed
114 option(WITH_WEBKIT "WebKit support (for link previews) (legacy)" OFF)
115
116 # For this, the feature info is added after we know if QtWebEngine is installed
117 option(WITH_WEBENGINE "WebEngine support (for link previews)" ON)
118
119 if (APPLE)
120     # Notification Center is only available in > 10.8, which is Darwin v12
121     if (NOT CMAKE_SYSTEM_VERSION VERSION_LESS 12)
122         option(WITH_NOTIFICATION_CENTER "OS X Notification Center support" ON)
123         add_feature_info(WITH_NOTIFICATION_CENTER WITH_NOTIFICATION_CENTER "Use the OS X Notification Center")
124     endif()
125     find_library(CARBON_LIBRARY Carbon)
126     mark_as_advanced(CARBON_LIBRARY)
127     link_libraries(${CARBON_LIBRARY})
128 endif()
129
130 # Always embed on Windows, OSX or for a static build; never embed when enabling KDE integration
131 set(EMBED_DEFAULT OFF)
132 if (STATIC OR WIN32 OR APPLE)
133     set(EMBED_DEFAULT ON)
134 endif()
135 cmake_dependent_option(EMBED_DATA "Embed icons and translations into the binaries instead of installing them" ${EMBED_DEFAULT}
136                                    "NOT STATIC;NOT WIN32;NOT WITH_KDE" ${EMBED_DEFAULT})
137 if (NOT EMBED_DEFAULT)
138     add_feature_info(EMBED_DATA EMBED_DATA "Embed icons and translations in the binaries instead of installing them")
139 endif()
140
141 # The following options are not for end-user consumption, so don't list them in the feature summary
142 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)
143
144 # 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)
145 cmake_dependent_option(STATIC      "Enable static building (not supported)" OFF "NOT WITH_KDE" OFF)
146
147 # For static builds, arbitrary extra libs might need to be linked
148 # Define a comma-separated list here
149 # e.g. for pgsql, we need -DLINK_EXTRA=pq;crypt
150 set(LINK_EXTRA "" CACHE STRING "Semicolon-separated list of libraries to be linked")
151 if (LINK_EXTRA)
152     string(REPLACE "," ";" LINK_EXTRA ${LINK_EXTRA})
153     link_libraries(${LINK_EXTRA})
154 endif()
155
156
157 # List of authenticators and the cmake flags to build them
158 # (currently that's just LDAP, but more can be added here).
159 ####################################################################
160 option(WITH_LDAP "Enable LDAP authentication support if present on system" ON)
161
162 # Setup CMake
163 #####################################################################
164
165 if (USE_QT5 AND WITH_KDE)
166     cmake_minimum_required(VERSION 2.8.12)
167 else()
168     cmake_minimum_required(VERSION 2.8.9)
169 endif()
170
171 # Setting COMPILE_DEFINITIONS_<CONFIG> is deprecated since CMake 3.0 in favor of generator expressions.
172 # These have existed since CMake 2.8.10; until we depend on that, we have to explicitly enable the old policy.
173 if (POLICY CMP0043)
174     cmake_policy(SET CMP0043 OLD)
175 endif()
176
177 # Honor visibility settings for all target types
178 if (POLICY CMP0063)
179     cmake_policy(SET CMP0063 NEW)
180 endif()
181
182 # Don't automoc generated files
183 if (POLICY CMP0071)
184     cmake_policy(SET CMP0071 OLD)
185 endif()
186
187
188 # Simplify later checks
189 #####################################################################
190
191 if (WANT_MONO OR WANT_QTCLIENT)
192     set(BUILD_GUI true)
193 endif()
194 if (WANT_MONO OR WANT_CORE)
195     set(BUILD_CORE true)
196 endif()
197
198
199 # Set up Qt
200 #####################################################################
201
202 # Find package dependencies
203 #
204 # Note that you can forcefully disable optional packages
205 # using -DCMAKE_DISABLE_FIND_PACKAGE_<PkgName>=TRUE
206 #####################################################################
207
208 if (USE_QT5)
209     message(STATUS "Building for Qt5...")
210     set(QT_MIN_VERSION "5.2.0")
211     add_definitions(-DHAVE_QT5)
212
213     find_package(Qt5Core ${QT_MIN_VERSION} QUIET)
214     set_package_properties(Qt5Core PROPERTIES TYPE REQUIRED
215         URL "https://www.qt.io/"
216         DESCRIPTION "contains core functionality for Qt"
217     )
218     # find_package without REQUIRED won't check for the version properly; also, older Qt5 versions
219     # used Qt5Core_VERSION_STRING... let's just make sure here that we bail out here if our Qt5 is not new enough.
220     if (NOT Qt5Core_VERSION OR Qt5Core_VERSION VERSION_LESS ${QT_MIN_VERSION})
221         message(FATAL_ERROR "Could NOT find Qt5 >= version ${QT_MIN_VERSION}!")
222     endif()
223
224     find_package(Qt5Network QUIET)
225     set_package_properties(Qt5Network PROPERTIES TYPE REQUIRED
226         DESCRIPTION "the network module for Qt5"
227     )
228
229     if (BUILD_GUI)
230         find_package(Qt5Gui QUIET)
231         set_package_properties(Qt5Gui PROPERTIES TYPE REQUIRED
232             DESCRIPTION "the GUI module for Qt5"
233         )
234         find_package(Qt5Widgets QUIET)
235         set_package_properties(Qt5Widgets PROPERTIES TYPE REQUIRED
236             DESCRIPTION "the widgets module for Qt5"
237         )
238
239         if (NOT WIN32)
240             find_package(Qt5DBus QUIET)
241             set_package_properties(Qt5DBus PROPERTIES TYPE RECOMMENDED
242                 URL "https://www.qt.io/"
243                 DESCRIPTION "D-Bus support for Qt5"
244                 PURPOSE     "Needed for supporting D-Bus-based notifications and tray icon, used by most modern desktop environments"
245             )
246             if (Qt5DBus_FOUND)
247                 find_package(dbusmenu-qt5 QUIET CONFIG)
248                 set_package_properties(dbusmenu-qt5 PROPERTIES TYPE RECOMMENDED
249                     URL "https://launchpad.net/libdbusmenu-qt"
250                     DESCRIPTION "a library implementing the DBusMenu specification"
251                     PURPOSE     "Required for having a context menu for the D-Bus-based tray icon"
252                 )
253             endif()
254         endif()
255
256         find_package(Qt5Multimedia QUIET)
257         set_package_properties(Qt5Multimedia PROPERTIES TYPE RECOMMENDED
258             URL "https://www.qt.io/"
259             DESCRIPTION "Multimedia support for Qt5"
260             PURPOSE     "Required for audio notifications"
261         )
262
263         if (NOT Qt5Multimedia_FOUND)
264             find_package(Phonon4Qt5 QUIET)
265             set_package_properties(Phonon4Qt5 PROPERTIES TYPE RECOMMENDED
266                 URL "https://projects.kde.org/projects/kdesupport/phonon"
267                 DESCRIPTION "a multimedia abstraction library"
268                 PURPOSE     "Required for audio notifications"
269             )
270         endif()
271
272         find_package(LibsnoreQt5 0.7.0 QUIET)
273         set_package_properties(LibsnoreQt5 PROPERTIES TYPE OPTIONAL
274             URL "https://projects.kde.org/projects/playground/libs/snorenotify"
275             DESCRIPTION "a cross-platform notification framework"
276             PURPOSE     "Enable support for the snorenotify framework"
277         )
278         if(LibsnoreQt5_FOUND)
279             find_package(LibsnoreSettingsQt5)
280             set_package_properties(LibsnoreSettingsQt5 PROPERTIES TYPE REQUIRED
281                 URL "https://projects.kde.org/projects/playground/libs/snorenotify"
282                 DESCRIPTION "a cross-platform notification framework"
283                 PURPOSE     "Enable support for the snorenotify framework"
284             )
285         endif()
286
287
288         if (WITH_WEBKIT)
289             find_package(Qt5WebKit QUIET)
290             set_package_properties(Qt5WebKit PROPERTIES TYPE RECOMMENDED
291                 URL "https://www.qt.io/"
292                 DESCRIPTION "a WebKit implementation for Qt"
293                 PURPOSE     "Needed for displaying previews for URLs in chat"
294             )
295             if (Qt5WebKit_FOUND)
296                 find_package(Qt5WebKitWidgets QUIET)
297                 set_package_properties(Qt5WebKitWidgets PROPERTIES TYPE RECOMMENDED
298                     URL "https://www.qt.io/"
299                     DESCRIPTION "widgets for Qt's WebKit implementation"
300                     PURPOSE     "Needed for displaying previews for URLs in chat"
301                 )
302             endif()
303         endif()
304
305         if (WITH_WEBKIT AND Qt5WebKitWidgets_FOUND)
306             set(HAVE_WEBKIT true)
307         endif()
308         add_feature_info("WITH_WEBKIT, QtWebKit and QtWebKitWidgets modules" HAVE_WEBKIT "Support showing previews for URLs in chat (legacy)")
309
310         if (WITH_WEBENGINE)
311             find_package(Qt5WebEngine QUIET)
312             set_package_properties(Qt5WebEngine PROPERTIES TYPE RECOMMENDED
313                 URL "https://www.qt.io/"
314                 DESCRIPTION "a WebEngine implementation for Qt"
315                 PURPOSE     "Needed for displaying previews for URLs in chat"
316             )
317             if (Qt5WebEngine_FOUND)
318                 find_package(Qt5WebEngineWidgets QUIET)
319                 set_package_properties(Qt5WebEngineWidgets PROPERTIES TYPE RECOMMENDED
320                     URL "https://www.qt.io/"
321                     DESCRIPTION "widgets for Qt's WebEngine implementation"
322                     PURPOSE     "Needed for displaying previews for URLs in chat"
323                 )
324             endif()
325         endif()
326
327         if (WITH_WEBENGINE AND Qt5WebEngineWidgets_FOUND)
328             set(HAVE_WEBENGINE true)
329         endif()
330         add_feature_info("WITH_WEBENGINE, QtWebEngine and QtWebEngineWidgets modules" HAVE_WEBENGINE "Support showing previews for URLs in chat")
331
332         # KDE Frameworks
333         ################
334
335         if (WITH_KDE)
336             set(ecm_find_type "REQUIRED")
337         else()
338             # Even with KDE integration disabled, we optionally use tier1 frameworks if we find them
339             set(ecm_find_type "RECOMMENDED")
340         endif()
341
342         # extra-cmake-modules
343         find_package(ECM NO_MODULE QUIET)
344         set_package_properties(ECM PROPERTIES TYPE ${ecm_find_type}
345             URL "https://projects.kde.org/projects/kdesupport/extra-cmake-modules"
346             DESCRIPTION "extra modules for CMake, maintained by the KDE project"
347             PURPOSE     "Required to find KDE Frameworks components"
348         )
349
350         if (ECM_FOUND)
351             list(APPEND CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
352             if (WITH_KDE)
353                 find_package(KF5 COMPONENTS ConfigWidgets CoreAddons Notifications NotifyConfig Sonnet TextWidgets WidgetsAddons XmlGui QUIET REQUIRED)
354                 set_package_properties(KF5 PROPERTIES TYPE REQUIRED
355                     URL "http://www.kde.org"
356                     DESCRIPTION "KDE Frameworks"
357                     PURPOSE     "Required for integration into the Plasma desktop"
358                 )
359             else()
360                 find_package(KF5Sonnet QUIET)
361                 set_package_properties(KF5Sonnet PROPERTIES TYPE RECOMMENDED
362                     URL "http://api.kde.org/frameworks-api/frameworks5-apidocs/sonnet/html"
363                     DESCRIPTION "framework for providing spell-checking capabilities"
364                     PURPOSE "Enables spell-checking support in input widgets"
365                 )
366             endif()
367         endif()
368
369     endif()
370
371     if (BUILD_CORE)
372         find_package(Qt5Script QUIET)
373         set_package_properties(Qt5Script PROPERTIES TYPE REQUIRED
374             DESCRIPTION "provides scripting support for Qt5"
375         )
376         find_package(Qt5Sql QUIET)
377         set_package_properties(Qt5Sql PROPERTIES TYPE REQUIRED
378             DESCRIPTION "the database support module for Qt5"
379         )
380
381         find_package(QCA2-QT5)
382         set_package_properties(QCA2-QT5 PROPERTIES TYPE RECOMMENDED
383             URL "https://projects.kde.org/projects/kdesupport/qca"
384             DESCRIPTION "Qt Cryptographic Architecture"
385             PURPOSE "Required for encryption support"
386         )
387
388     endif()
389
390     find_package(Qt5LinguistTools QUIET)
391     set_package_properties(Qt5LinguistTools PROPERTIES TYPE RECOMMENDED
392                            DESCRIPTION "contains tools for handling translation files"
393                            PURPOSE "Required for having translations"
394     )
395
396     # Some Qt5 versions do not define a target for lconvert, so we need to find it ourselves
397     if (Qt5LinguistTools_FOUND)
398         if (NOT TARGET Qt5::lconvert AND TARGET Qt5::lrelease)
399             get_target_property(_lrelease_location Qt5::lrelease LOCATION)
400             get_filename_component(_lrelease_path ${_lrelease_location} PATH)
401             find_program(QT_LCONVERT_EXECUTABLE NAMES lconvert-qt5 lconvert PATHS ${_lrelease_path} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
402         elseif(TARGET Qt5::lconvert AND NOT Qt5_LCONVERT_EXECUTABLE)
403             # Newer Qt5 versions define the target, but not the Qt5_LCONVERT_EXECUTABLE variable for some reason
404             get_target_property(QT_LCONVERT_EXECUTABLE Qt5::lconvert LOCATION)
405         endif()
406
407         # Compatibility with the Qt4 variables
408         set(QT_LRELEASE_EXECUTABLE ${Qt5_LRELEASE_EXECUTABLE})
409         set(QT_LUPDATE_EXECUTABLE ${Qt5_LUPDATE_EXECUTABLE})
410         if (Qt5_LCONVERT_EXECUTABLE)
411             set(QT_LCONVERT_EXECUTABLE ${Qt5_LCONVERT_EXECUTABLE})
412         endif()
413     endif()
414
415 else()
416     message(STATUS "Building for Qt4...")
417     set(QT_MIN_VERSION "4.8.0")
418
419     find_package(Qt4 ${QT_MIN_VERSION} QUIET REQUIRED)
420
421     if (BUILD_GUI)
422         add_feature_info("QtDBus module" QT_QTDBUS_FOUND "Needed for supporting D-Bus-based notifications and tray icon, used by most modern desktop environments")
423         if (QT_QTDBUS_FOUND)
424             find_package(dbusmenu-qt QUIET CONFIG)
425             set_package_properties(dbusmenu-qt PROPERTIES TYPE RECOMMENDED
426                 URL "https://launchpad.net/libdbusmenu-qt"
427                 DESCRIPTION "a library implementing the DBusMenu specification"
428                 PURPOSE     "Required for having a context menu for the D-Bus-based tray icon"
429             )
430         endif()
431
432         if (WITH_WEBKIT AND QT_QTWEBKIT_FOUND)
433             set(HAVE_WEBKIT true)
434         endif()
435         add_feature_info("WITH_WEBKIT and QtWebKit module" HAVE_WEBKIT "Support showing previews for URLs in chat")
436
437         if (WITH_KDE)
438             # KDE has overzealous CFLAGS making miniz not compile, so save our old flags
439             set(_cflags ${CMAKE_C_FLAGS})
440             find_package(KDE4 4.4 QUIET)
441             set_package_properties(KDE4 PROPERTIES TYPE REQUIRED
442                 URL "http://www.kde.org"
443                 DESCRIPTION "a world-class desktop environment"
444                 PURPOSE "Enables various bits for improving integration with KDE"
445             )
446             set(CMAKE_C_FLAGS ${_cflags})
447
448         else()
449             find_package(Phonon QUIET)
450             set_package_properties(Phonon PROPERTIES TYPE RECOMMENDED
451                 URL "https://projects.kde.org/projects/kdesupport/phonon"
452                 DESCRIPTION "a multimedia abstraction library"
453                 PURPOSE     "Required for audio notifications"
454             )
455         endif()
456
457         find_package(IndicateQt QUIET)
458         set_package_properties(IndicateQt PROPERTIES TYPE OPTIONAL
459             URL "https://launchpad.net/libindicate-qt/"
460             DESCRIPTION "a library to raise flags on DBus for other components of the desktop to pick up and visualize"
461             PURPOSE     "Provides integration into the Ayatana notification system used by e.g. Ubuntu"
462         )
463
464     endif()
465
466     if (BUILD_CORE)
467
468         find_package(QCA2 QUIET)
469         set_package_properties(QCA2 PROPERTIES TYPE RECOMMENDED
470             URL "https://projects.kde.org/projects/kdesupport/qca"
471             DESCRIPTION "Qt Cryptographic Architecture"
472             PURPOSE     "Required for encryption support"
473         )
474
475
476     endif()
477
478     # Qt4 does not consider lconvert relevant, so they don't support finding it...
479     # Rather than shipping hacked buildsys files, let's just infer the path from lrelease
480     if (QT_LRELEASE_EXECUTABLE)
481         get_filename_component(_lrelease_path ${QT_LRELEASE_EXECUTABLE} PATH)
482         find_program(QT_LCONVERT_EXECUTABLE NAMES lconvert-qt4 lconvert PATHS ${_lrelease_path} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
483     endif()
484 endif()
485
486
487 # Non-Qt-based packages
488
489 # zlib for compression, however we can always fall back to miniz
490 find_package(ZLIB QUIET)
491 set_package_properties(ZLIB PROPERTIES TYPE RECOMMENDED
492     URL "http://www.zlib.net"
493     DESCRIPTION "a popular compression library"
494     PURPOSE     "Use the most common library for protocol compression, instead of the bundled miniz implementation"
495 )
496
497
498 if (NOT WIN32)
499     # Execinfo is needed for generating backtraces
500     find_package(ExecInfo QUIET)
501     set_package_properties(ExecInfo PROPERTIES TYPE OPTIONAL
502         DESCRIPTION "a library for inspecting backtraces"
503         PURPOSE "Used for generating backtraces in case of a crash"
504     )
505 endif()
506
507 # Check for SSL support in Qt
508 # As there's no easy way to get Qt's configuration in particular for Qt5, let's just compile
509 # a small test program checking the defines. This works for both Qt4 and Qt5.
510 cmake_push_check_state(RESET)
511 set(CMAKE_REQUIRED_INCLUDES ${QT_INCLUDES} ${Qt5Core_INCLUDE_DIRS})
512 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
513
514 if (USE_QT5 AND Qt5_POSITION_INDEPENDENT_CODE)
515     set(CMAKE_REQUIRED_FLAGS "-fPIC -DQT_NO_VERSION_TAGGING")
516 endif()
517
518 check_cxx_source_compiles("
519     #include \"qglobal.h\"
520     #if defined QT_NO_SSL
521     #  error \"No SSL support\"
522     #endif
523     int main() {}"
524     HAVE_SSL)
525 cmake_pop_check_state()
526
527 # Additional compile settings
528 #####################################################################
529
530 # This sets -fPIC and friends if required by the installed Qt5 library
531 if (USE_QT5 AND Qt5_POSITION_INDEPENDENT_CODE)
532     set(CMAKE_POSITION_INDEPENDENT_CODE ON)
533 endif()
534
535 # Needed to compile with mingw without kde
536 if (MINGW AND NOT KDE4_FOUND)
537     add_definitions(-D_WIN32_WINNT=0x0500)
538     message(STATUS "Added _WIN32_WINNT=0x0500 definition for MinGW")
539     # workaround for bug in mingw gcc 4.0
540     add_definitions(-U__STRICT_ANSI__)
541 endif()
542
543 # Sanitize compiler flags - old versions of KDE set -ansi, which breaks -std=c++11
544 if (CMAKE_COMPILER_IS_GNUCXX)
545     string(REPLACE "-ansi" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
546 endif()
547
548 # Setup LDAP Authentication support.
549 #####################################################################
550 if (WITH_LDAP)
551     find_package(Ldap)
552     if (LDAP_FOUND)
553         message(STATUS "Enabling LDAP authentication support")
554         set(HAVE_LDAP true)
555         add_definitions(-DHAVE_LDAP)
556     else()
557         message(STATUS "Disabling LDAP authentication support")
558     endif()
559 else()
560     message(STATUS "Not enabling LDAP authentication support")
561 endif()
562
563 # Setup KDE / KDE Frameworks
564 #####################################################################
565
566 # We want to do this up here, so we have the necessary variables and defines set before
567 # compiling anything
568
569 if (KDE4_FOUND)
570     # We always use external icons for KDE4 support, since we use its iconloader rather than Qt's
571     set(EMBED_DATA OFF)
572
573     # Better have the compile flags global, even for the core, to avoid problems with linking the mono client
574     add_definitions(-DHAVE_KDE -DHAVE_KDE4 ${KDE4_DEFINITIONS} ${KDE4_ENABLE_EXCEPTIONS})
575     set(WITH_KDE4 TRUE)
576 endif()
577
578 if (USE_QT5 AND WITH_KDE)
579     # If KDE Frameworks are present, they're most probably providing Qt5 integration including icon loading
580     set(EMBED_DATA OFF)
581
582     include(KDEInstallDirs)
583     include(KDECompilerSettings)
584     include(KDECMakeSettings)
585
586     kde_enable_exceptions()
587     add_definitions(-DHAVE_KDE -DHAVE_KF5)
588     set(WITH_KF5 TRUE)
589 endif()
590
591 # This needs to come after setting up KDE integration, so we can use KDE-specific paths
592 include(QuasselInstallDirs)
593
594 # Various config-dependent checks and settings
595 #####################################################################
596
597 if (NOT ZLIB_FOUND)
598     message(STATUS "zlib NOT found, using bundled miniz for compression")
599     if (${CMAKE_SIZEOF_VOID_P} EQUAL 4)
600         message(STATUS "WARNING: This may be slow on 32 bit systems!")
601     endif()
602 endif()
603
604 if (HAVE_SSL)
605     add_definitions(-DHAVE_SSL)
606 endif()
607 add_feature_info("SSL support in Qt" HAVE_SSL "Use secure network connections")
608
609 # Check for syslog support
610 if (NOT WIN32)
611     check_include_file(syslog.h HAVE_SYSLOG)
612     add_feature_info("syslog.h" HAVE_SYSLOG "Provide support for logging to the syslog")
613 endif()
614
615 add_feature_info("Qt Linguist Tools" QT_LCONVERT_EXECUTABLE "Translation support for Quassel")
616
617 if (EMBED_DATA)
618     message(STATUS "Embedding data files into the binary")
619 else()
620     message(STATUS "Installing data files separately")
621 endif()
622
623 if (INDICATEQT_FOUND)
624     add_definitions(-DXDG_APPS_INSTALL_DIR=${CMAKE_INSTALL_APPDIR})
625 endif()
626
627 if (NOT WIN32)
628     check_function_exists(umask HAVE_UMASK)
629     if(HAVE_UMASK)
630         add_definitions(-DHAVE_UMASK)
631     endif()
632 endif()
633
634
635 # Windows-specific stuff
636 #####################################################################
637
638 if (WIN32)
639     link_libraries(imm32 winmm dbghelp Secur32)  # missing by default :/
640     if (MSVC)
641         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DNOMINMAX")
642         set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBUGINFO "/debug /INCREMENTAL:YES /NODEFAULTLIB:libcmt /DEFAULTLIB:msvcrt")
643         set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/debug /INCREMENTAL:YES /NODEFAULTLIB:libcmt")
644         set(CMAKE_EXE_LINKER_FLAGS_DEBUGFULL "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
645         link_libraries(Version dwmapi shlwapi)
646         if (USE_QT5)
647             set(QT_QTMAIN_LIBRARY Qt5::WinMain)
648         endif()
649     endif()
650     if(HAVE_SSL AND STATIC)
651         find_package(OpenSSL REQUIRED)
652         link_libraries(${OPENSSL_LIBRARIES} ${OPENSSL_EAY_LIBRARIES})
653     endif()
654 endif()
655
656
657 # Static builds (very much non-portable, so don't use -DSTATIC
658 # unless you know what you do!)
659 #####################################################################
660
661 if(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
662     set(CMAKE_CXX_FLAGS "-static-libgcc ${CMAKE_CXX_FLAGS}")
663     link_directories(${CMAKE_BINARY_DIR}/staticlibs) # override dynamic libs
664     if (HAVE_SSL)
665         set(QUASSEL_SSL_LIBRARIES ssl crypto)  # these miss in static builds
666     endif()
667 endif()
668
669
670 # Generate version information from Git
671 #####################################################################
672
673 include(GetGitRevisionDescription)
674 get_git_head_revision(GIT_REFSPEC GIT_HEAD)
675 git_describe(GIT_DESCRIBE --long)
676
677 # If in a Git repo we can get the commit-date from a git command
678 if (GIT_HEAD)
679     execute_process(
680         COMMAND git -c log.showsignature=false show -s --format=%ct
681         WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
682         OUTPUT_VARIABLE GIT_COMMIT_DATE
683         OUTPUT_STRIP_TRAILING_WHITESPACE
684     )
685 endif()
686
687 # If not in a Git repo try to read GIT_HEAD and GIT_DESCRIBE from
688 # enviroment
689 if (NOT GIT_HEAD OR NOT GIT_DESCRIBE)
690   if (DEFINED ENV{GIT_HEAD})
691       set(GIT_HEAD $ENV{GIT_HEAD})
692   endif()
693   if (DEFINED ENV{GIT_DESCRIBE})
694      set(GIT_DESCRIBE $ENV{GIT_DESCRIBE})
695   endif()
696 endif()
697
698 # Sanitize things if we're not in a Git repo
699 if (NOT GIT_HEAD OR NOT GIT_DESCRIBE)
700     set(GIT_HEAD "")
701     set(GIT_DESCRIBE "")
702     set(GIT_COMMIT_DATE 0)
703 endif()
704
705 configure_file(version.h.in ${CMAKE_BINARY_DIR}/version.h @ONLY)
706
707 # Prepare the build
708 #####################################################################
709
710 # These variables will be added to the main targets (CORE, QTCLIENT, MONO)
711 set(COMMON_DEPS ${RC_WIN32})
712 set(CORE_DEPS )
713 set(CLIENT_DEPS )
714
715 # Add needed subdirs - the order is important, since src needs some vars set by other dirs
716 add_subdirectory(data)
717 add_subdirectory(icons)
718 add_subdirectory(pics)
719 add_subdirectory(po)
720
721
722 # Set up and display feature summary
723 #####################################################################
724
725 feature_summary(WHAT ALL
726                 INCLUDE_QUIET_PACKAGES
727                 FATAL_ON_MISSING_REQUIRED_PACKAGES
728 )
729
730 # Finally, compile the sources
731 # We want this after displaying the feature summary to avoid ugly
732 # CMake backtraces in case a required Qt5 module is missing
733 #####################################################################
734
735 add_subdirectory(src)