clang-tidy: Mark several settingspage methods as final
[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 cmake_minimum_required(VERSION 3.5)
10
11 # Tell CMake about or own modules
12 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
13
14 # Versions
15 set(QUASSEL_MAJOR  0)
16 set(QUASSEL_MINOR 13)
17 set(QUASSEL_PATCH 50)
18 set(QUASSEL_VERSION_STRING "0.14-pre")
19
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}")
23
24 # Set up build type rather early
25 include(BuildType)
26
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)
30 if (USE_CCACHE)
31     message(STATUS "Checking for ccache")
32     find_program(CCACHE_PROGRAM ccache)
33     if (CCACHE_PROGRAM)
34         set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
35         message(STATUS "Checking for ccache - enabled")
36     else()
37         message(STATUS "Checking for ccache - not found")
38     endif()
39 endif()
40
41 # Set up project
42 project(Quassel CXX)
43
44 # Let CMake handle file generation for Qt
45 set(CMAKE_AUTOMOC ON)
46 set(CMAKE_AUTORCC ON)
47 set(CMAKE_AUTOUIC ON)
48
49 # Needed, otherwise some .moc files won't be found with older CMake versions
50 set(CMAKE_INCLUDE_CURRENT_DIR ON)
51
52 # Include various CMake modules...
53 include(CMakePushCheckState)
54 include(CheckFunctionExists)
55 include(CheckIncludeFileCXX)
56 include(CheckCXXSourceCompiles)
57 include(CMakeDependentOption)
58 include(FeatureSummary)
59
60 # ... and our own
61 include(QuasselCompileSettings)
62 include(QuasselMacros)
63
64 # Options and variables that can be set on the command line
65 #####################################################################
66
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")
74
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")
79
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")
83
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)")
86
87 # For this, the feature info is added after we know if QtWebkit is installed
88 option(WITH_WEBKIT "WebKit support (for link previews) (legacy)" OFF)
89
90 # For this, the feature info is added after we know if QtWebEngine is installed
91 option(WITH_WEBENGINE "WebEngine support (for link previews)" ON)
92
93 if (APPLE)
94     # Notification Center is only available in > 10.8, which is Darwin v12
95     if (NOT CMAKE_SYSTEM_VERSION VERSION_LESS 12)
96         option(WITH_NOTIFICATION_CENTER "OS X Notification Center support" ON)
97         add_feature_info(WITH_NOTIFICATION_CENTER WITH_NOTIFICATION_CENTER "Use the OS X Notification Center")
98     endif()
99     find_library(CARBON_LIBRARY Carbon)
100     mark_as_advanced(CARBON_LIBRARY)
101     link_libraries(${CARBON_LIBRARY})
102 endif()
103
104 # Always embed on Windows or OSX; never embed when enabling KDE integration
105 set(EMBED_DEFAULT OFF)
106 if (WIN32 OR APPLE)
107     set(EMBED_DEFAULT ON)
108 endif()
109 cmake_dependent_option(EMBED_DATA "Embed icons and translations into the binaries instead of installing them" ${EMBED_DEFAULT}
110                                    "NOT WIN32;NOT WITH_KDE" ${EMBED_DEFAULT})
111 if (NOT EMBED_DEFAULT)
112     add_feature_info(EMBED_DATA EMBED_DATA "Embed icons and translations in the binaries instead of installing them")
113 endif()
114
115 # The following options are not for end-user consumption, so don't list them in the feature summary
116 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)
117
118
119 # List of authenticators and the cmake flags to build them
120 # (currently that's just LDAP, but more can be added here).
121 ####################################################################
122 option(WITH_LDAP "Enable LDAP authentication support if present on system" ON)
123
124 # Setup CMake
125 #####################################################################
126
127 # Let automoc/autouic process generated files
128 if (POLICY CMP0071)
129     cmake_policy(SET CMP0071 NEW)
130 endif()
131
132 # Simplify later checks
133 #####################################################################
134
135 if (WANT_MONO OR WANT_QTCLIENT)
136     set(BUILD_GUI true)
137 endif()
138 if (WANT_MONO OR WANT_CORE)
139     set(BUILD_CORE true)
140 endif()
141
142
143 # Set up Qt
144 #####################################################################
145
146 # Find package dependencies
147 #
148 # Note that you can forcefully disable optional packages
149 # using -DCMAKE_DISABLE_FIND_PACKAGE_<PkgName>=TRUE
150 #####################################################################
151
152 set(QT_MIN_VERSION "5.5.0")
153
154 # Required Qt components
155 set(qt_components Core Network)
156 if (BUILD_GUI)
157     list(APPEND qt_components Gui Widgets)
158 endif()
159 if (BUILD_CORE)
160     list(APPEND qt_components Script Sql)
161 endif()
162
163 find_package(Qt5 ${QT_MIN_VERSION} REQUIRED COMPONENTS ${qt_components})
164 set_package_properties(Qt5 PROPERTIES TYPE REQUIRED
165     URL "https://www.qt.io/"
166     DESCRIPTION "the Qt libraries"
167 )
168 message(STATUS "Found Qt ${Qt5Core_VERSION}")
169
170 # Optional Qt components
171
172 find_package(Qt5LinguistTools QUIET)
173 set_package_properties(Qt5LinguistTools PROPERTIES TYPE RECOMMENDED
174     DESCRIPTION "contains tools for handling translation files"
175     PURPOSE "Required for having translations"
176 )
177
178 if (BUILD_GUI)
179     if (NOT WIN32)
180         find_package(Qt5DBus QUIET)
181         set_package_properties(Qt5DBus PROPERTIES TYPE RECOMMENDED
182             URL "https://www.qt.io/"
183             DESCRIPTION "D-Bus support for Qt5"
184             PURPOSE     "Needed for supporting D-Bus-based notifications and tray icon, used by most modern desktop environments"
185         )
186         if (Qt5DBus_FOUND)
187             find_package(dbusmenu-qt5 QUIET CONFIG)
188             set_package_properties(dbusmenu-qt5 PROPERTIES TYPE RECOMMENDED
189                 URL "https://launchpad.net/libdbusmenu-qt"
190                 DESCRIPTION "a library implementing the DBusMenu specification"
191                 PURPOSE     "Required for having a context menu for the D-Bus-based tray icon"
192             )
193         endif()
194     endif()
195
196     find_package(Qt5Multimedia QUIET)
197     set_package_properties(Qt5Multimedia PROPERTIES TYPE RECOMMENDED
198         URL "https://www.qt.io/"
199         DESCRIPTION "Multimedia support for Qt5"
200         PURPOSE     "Required for audio notifications"
201     )
202
203     find_package(LibsnoreQt5 0.7.0 QUIET)
204     set_package_properties(LibsnoreQt5 PROPERTIES TYPE OPTIONAL
205         URL "https://projects.kde.org/projects/playground/libs/snorenotify"
206         DESCRIPTION "a cross-platform notification framework"
207         PURPOSE     "Enable support for the snorenotify framework"
208     )
209     if (LibsnoreQt5_FOUND)
210         find_package(LibsnoreSettingsQt5 QUIET)
211         set_package_properties(LibsnoreSettingsQt5 PROPERTIES TYPE OPTIONAL
212             URL "https://projects.kde.org/projects/playground/libs/snorenotify"
213             DESCRIPTION "a cross-platform notification framework"
214             PURPOSE     "Enable support for the snorenotify framework"
215         )
216     endif()
217
218     if (WITH_WEBENGINE)
219         find_package(Qt5WebEngine QUIET)
220         set_package_properties(Qt5WebEngine PROPERTIES TYPE RECOMMENDED
221             URL "https://www.qt.io/"
222             DESCRIPTION "a WebEngine implementation for Qt"
223             PURPOSE     "Needed for displaying previews for URLs in chat"
224         )
225         if (Qt5WebEngine_FOUND)
226             find_package(Qt5WebEngineWidgets QUIET)
227             set_package_properties(Qt5WebEngineWidgets PROPERTIES TYPE RECOMMENDED
228                 URL "https://www.qt.io/"
229                 DESCRIPTION "widgets for Qt's WebEngine implementation"
230                 PURPOSE     "Needed for displaying previews for URLs in chat"
231             )
232         endif()
233     endif()
234
235     if (WITH_WEBENGINE AND Qt5WebEngineWidgets_FOUND)
236         set(HAVE_WEBENGINE true)
237     endif()
238     add_feature_info("WITH_WEBENGINE, QtWebEngine and QtWebEngineWidgets modules" HAVE_WEBENGINE "Support showing previews for URLs in chat")
239
240     if (NOT HAVE_WEBENGINE)
241         if (WITH_WEBKIT)
242             find_package(Qt5WebKit QUIET)
243             set_package_properties(Qt5WebKit PROPERTIES TYPE OPTIONAL
244                 URL "https://www.qt.io/"
245                 DESCRIPTION "a WebKit implementation for Qt"
246                 PURPOSE     "Needed for displaying previews for URLs in chat"
247                 )
248             if (Qt5WebKit_FOUND)
249                 find_package(Qt5WebKitWidgets QUIET)
250                 set_package_properties(Qt5WebKitWidgets PROPERTIES TYPE OPTIONAL
251                     URL "https://www.qt.io/"
252                     DESCRIPTION "widgets for Qt's WebKit implementation"
253                     PURPOSE     "Needed for displaying previews for URLs in chat"
254                     )
255             endif()
256         endif()
257
258         if (WITH_WEBKIT AND Qt5WebKitWidgets_FOUND)
259             set(HAVE_WEBKIT true)
260         endif()
261         add_feature_info("WITH_WEBKIT, QtWebKit and QtWebKitWidgets modules" HAVE_WEBKIT "Support showing previews for URLs in chat (legacy)")
262     endif()
263
264     # KDE Frameworks
265     ################
266
267     # extra-cmake-modules
268     if (WITH_KDE)
269         set(ecm_find_type "REQUIRED")
270         find_package(ECM NO_MODULE REQUIRED)
271     else()
272         # Even with KDE integration disabled, we optionally use tier1 frameworks if we find them
273         set(ecm_find_type "RECOMMENDED")
274         find_package(ECM NO_MODULE QUIET)
275     endif()
276
277     set_package_properties(ECM PROPERTIES TYPE ${ecm_find_type}
278         URL "https://projects.kde.org/projects/kdesupport/extra-cmake-modules"
279         DESCRIPTION "extra modules for CMake, maintained by the KDE project"
280         PURPOSE     "Required to find KDE Frameworks components"
281     )
282
283     if (ECM_FOUND)
284         list(APPEND CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
285         if (WITH_KDE)
286             find_package(KF5 REQUIRED COMPONENTS ConfigWidgets CoreAddons Notifications NotifyConfig Sonnet TextWidgets WidgetsAddons XmlGui)
287             set_package_properties(KF5 PROPERTIES TYPE REQUIRED
288                 URL "http://www.kde.org"
289                 DESCRIPTION "KDE Frameworks"
290                 PURPOSE     "Required for integration into the Plasma desktop"
291             )
292             message(STATUS "Found KDE Frameworks ${KF5_VERSION}")
293         endif()
294
295         # Optional KF5 tier1 components
296         find_package(KF5Sonnet QUIET)
297         set_package_properties(KF5Sonnet PROPERTIES TYPE RECOMMENDED
298             URL "http://api.kde.org/frameworks-api/frameworks5-apidocs/sonnet/html"
299             DESCRIPTION "framework for providing spell-checking capabilities"
300             PURPOSE "Enables spell-checking support in input widgets"
301         )
302     endif()
303 endif()
304
305 if (BUILD_CORE)
306     find_package(Qca-qt5 2.0 QUIET)
307     set_package_properties(Qca-qt5 PROPERTIES TYPE RECOMMENDED
308         URL "https://projects.kde.org/projects/kdesupport/qca"
309         DESCRIPTION "Qt Cryptographic Architecture"
310         PURPOSE "Required for encryption support"
311     )
312
313     if (WITH_LDAP)
314         find_package(Ldap QUIET)
315         set_package_properties(Ldap PROPERTIES TYPE OPTIONAL
316             URL "http://www.openldap.org/"
317             DESCRIPTION "LDAP (Lightweight Directory Access Protocol) libraries"
318             PURPOSE "Enables core user authentication via LDAP"
319         )
320     endif()
321 endif()
322
323 # Non-Qt-based packages
324
325 find_package(ZLIB REQUIRED)
326 set_package_properties(ZLIB PROPERTIES TYPE REQUIRED
327     URL "http://www.zlib.net"
328     DESCRIPTION "a popular compression library"
329     PURPOSE     "Used for protocol compression"
330 )
331
332 if (NOT WIN32)
333     # Needed for generating backtraces
334     find_package(Backtrace QUIET)
335     set_package_properties(Backtrace PROPERTIES TYPE RECOMMENDED
336         DESCRIPTION "a header (and possibly library) for inspecting backtraces"
337         PURPOSE "Used for generating backtraces in case of a crash"
338     )
339 endif()
340
341 # Check for SSL support in Qt
342 cmake_push_check_state(RESET)
343 set(CMAKE_REQUIRED_LIBRARIES Qt5::Core)
344 check_cxx_source_compiles("
345     #include \"qglobal.h\"
346     #if defined QT_NO_SSL
347     #  error \"No SSL support\"
348     #endif
349     int main() {}"
350     HAVE_SSL)
351 cmake_pop_check_state()
352
353 if (HAVE_SSL)
354     add_definitions(-DHAVE_SSL)
355 endif()
356 add_feature_info("SSL support in Qt" HAVE_SSL "Use secure network connections")
357
358 # Additional compile settings
359 #####################################################################
360
361 # Needed to compile with mingw without kde
362 if (MINGW AND NOT WITH_KDE)
363     add_definitions(-D_WIN32_WINNT=0x0500)
364     message(STATUS "Added _WIN32_WINNT=0x0500 definition for MinGW")
365     # workaround for bug in mingw gcc 4.0
366     add_definitions(-U__STRICT_ANSI__)
367 endif()
368
369 # Setup support for KDE Frameworks
370 #####################################################################
371
372 # We want to do this up here, so we have the necessary variables and defines set before
373 # compiling anything
374
375 if (WITH_KDE)
376     # If KDE Frameworks are present, they're most probably providing Qt5 integration including icon loading
377     set(EMBED_DATA OFF)
378
379     include(KDEInstallDirs)
380     include(KDECompilerSettings)
381     include(KDECMakeSettings)
382
383     kde_enable_exceptions()
384     add_definitions(-DHAVE_KDE -DHAVE_KF5)
385     set(WITH_KF5 TRUE)
386 endif()
387
388 # This needs to come after setting up KDE integration, so we can use KDE-specific paths
389 include(QuasselInstallDirs)
390
391 # RPATH and output settings
392 #####################################################################
393
394 # Build artifacts in a well-known location; especially important for Windows DLLs
395 # (which go into RUNTIME_OUTPUT_DIRECTORY and can thus be found by executables)
396 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
397 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
398 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
399
400 # These RPATH settings allow for running directly from the build dir
401 set(CMAKE_SKIP_BUILD_RPATH            FALSE)
402 set(CMAKE_BUILD_WITH_INSTALL_RPATH    FALSE)
403 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE )
404
405 # Set install RPATH only if libdir isn't a system directory
406 if (IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
407     set(libdir "${CMAKE_INSTALL_LIBDIR}")
408 else()
409     set(libdir "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
410 endif()
411 list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${libdir}" is_systemdir)
412 if ("${is_systemdir}" STREQUAL "-1")
413    set(CMAKE_INSTALL_RPATH "${libdir}")
414 endif()
415
416 # Various config-dependent checks and settings
417 #####################################################################
418
419 # Check for syslog support
420 if (NOT WIN32)
421     check_include_file_cxx(syslog.h HAVE_SYSLOG)
422     add_feature_info("syslog.h" HAVE_SYSLOG "Provide support for logging to the syslog")
423 endif()
424
425 if (NOT WIN32)
426     check_function_exists(umask HAVE_UMASK)
427 endif()
428
429 if (EMBED_DATA)
430     message(STATUS "Embedding data files into the binary")
431 else()
432     message(STATUS "Installing data files separately")
433 endif()
434
435 # Windows-specific stuff
436 #####################################################################
437
438 if (WIN32)
439     link_libraries(imm32 winmm dbghelp Secur32)  # missing by default :/
440     if (MSVC)
441         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DNOMINMAX")
442         set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBUGINFO "/debug /INCREMENTAL:YES /NODEFAULTLIB:libcmt /DEFAULTLIB:msvcrt")
443         set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/debug /INCREMENTAL:YES /NODEFAULTLIB:libcmt")
444         set(CMAKE_EXE_LINKER_FLAGS_DEBUGFULL "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
445         link_libraries(Version dwmapi shlwapi)
446     endif()
447 endif()
448
449
450 # Generate version information from Git
451 #####################################################################
452
453 include(GetGitRevisionDescription)
454 get_git_head_revision(GIT_REFSPEC GIT_HEAD)
455 git_describe(GIT_DESCRIBE --long)
456
457 # If in a Git repo we can get the commit-date from a git command
458 if (GIT_HEAD)
459     execute_process(
460         COMMAND git -c log.showsignature=false show -s --format=%ct
461         WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
462         OUTPUT_VARIABLE GIT_COMMIT_DATE
463         OUTPUT_STRIP_TRAILING_WHITESPACE
464     )
465 endif()
466
467 # If not in a Git repo try to read GIT_HEAD and GIT_DESCRIBE from
468 # enviroment
469 if (NOT GIT_HEAD OR NOT GIT_DESCRIBE)
470   if (DEFINED ENV{GIT_HEAD})
471       set(GIT_HEAD $ENV{GIT_HEAD})
472   endif()
473   if (DEFINED ENV{GIT_DESCRIBE})
474      set(GIT_DESCRIBE $ENV{GIT_DESCRIBE})
475   endif()
476 endif()
477
478 # Sanitize things if we're not in a Git repo
479 if (NOT GIT_HEAD OR NOT GIT_DESCRIBE)
480     set(GIT_HEAD "")
481     set(GIT_DESCRIBE "")
482     set(GIT_COMMIT_DATE 0)
483 endif()
484
485 configure_file(version.h.in ${CMAKE_BINARY_DIR}/version.h @ONLY)
486
487 # Prepare the build
488 #####################################################################
489
490 # Add needed subdirs - the order is important, since src needs some vars set by other dirs
491 add_subdirectory(data)
492 add_subdirectory(icons)
493 add_subdirectory(pics)
494 add_subdirectory(po)
495
496 # Set up and display feature summary
497 #####################################################################
498
499 feature_summary(WHAT ALL
500                 INCLUDE_QUIET_PACKAGES
501                 FATAL_ON_MISSING_REQUIRED_PACKAGES
502 )
503
504 # Finally, compile the sources
505 # We want this after displaying the feature summary to avoid ugly
506 # CMake backtraces in case a required Qt5 module is missing
507 #####################################################################
508
509 add_subdirectory(src)