ci: Adapt warning configuration to new release of MSVC 19
[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 include(QuasselVersion)
15
16 message(STATUS "Using CMake ${CMAKE_VERSION}")
17
18 # Set up build type rather early
19 include(BuildType)
20
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)
24 if (USE_CCACHE)
25     message(STATUS "Checking for ccache")
26     find_program(CCACHE_PROGRAM ccache)
27     if (CCACHE_PROGRAM)
28         set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
29         message(STATUS "Checking for ccache - enabled")
30     else()
31         message(STATUS "Checking for ccache - not found")
32     endif()
33 endif()
34
35 # Set up project
36 project(Quassel CXX)
37
38 # Let CMake handle file generation for Qt
39 set(CMAKE_AUTOMOC ON)
40 set(CMAKE_AUTORCC ON)
41 set(CMAKE_AUTOUIC ON)
42
43 # Needed, otherwise some .moc files won't be found with older CMake versions
44 set(CMAKE_INCLUDE_CURRENT_DIR ON)
45
46 # Include various CMake modules...
47 include(CMakePushCheckState)
48 include(CheckFunctionExists)
49 include(CheckIncludeFileCXX)
50 include(CheckCXXSourceCompiles)
51 include(CMakeDependentOption)
52 include(FeatureSummary)
53
54 # ... and our own
55 include(QuasselCompileSettings)
56 include(QuasselMacros)
57
58 # Options and variables that can be set on the command line
59 #####################################################################
60
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")
68
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")
73
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")
77
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)")
80
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)
83
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)
86
87 if (APPLE)
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")
92     endif()
93     find_library(CARBON_LIBRARY Carbon)
94     mark_as_advanced(CARBON_LIBRARY)
95     link_libraries(${CARBON_LIBRARY})
96
97     # Whether to enable the creation of bundles and DMG images
98     cmake_dependent_option(BUNDLE "Create bundles and DMG images" OFF "APPLE" OFF)
99     add_feature_info(BUNDLE BUNDLE "Create bundles and DMG images")
100 endif()
101
102 # Always embed on Windows or OSX; never embed when enabling KDE integration
103 set(EMBED_DEFAULT OFF)
104 if (WIN32 OR APPLE)
105     set(EMBED_DEFAULT ON)
106 endif()
107 cmake_dependent_option(EMBED_DATA "Embed icons and translations into the binaries instead of installing them" ${EMBED_DEFAULT}
108                                   "NOT WIN32;NOT WITH_KDE" ${EMBED_DEFAULT})
109 if (NOT EMBED_DEFAULT)
110     add_feature_info(EMBED_DATA EMBED_DATA "Embed icons and translations in the binaries instead of installing them")
111 endif()
112
113 # The following option is not for end-user consumption, so don't list it in the feature summary
114 option(FATAL_WARNINGS "Make compile warnings fatal (most useful for CI builds)" OFF)
115
116 # List of authenticators and the cmake flags to build them
117 # (currently that's just LDAP, but more can be added here).
118 ####################################################################
119 option(WITH_LDAP "Enable LDAP authentication support if present on system" ON)
120
121 # Setup CMake
122 #####################################################################
123
124 # Visibility settings apply to all targets
125 if (POLICY CMP0063)
126     cmake_policy(SET CMP0063 NEW)
127 endif()
128
129 # Let automoc/autouic process generated files
130 if (POLICY CMP0071)
131     cmake_policy(SET CMP0071 NEW)
132 endif()
133
134 set(BUILD_SHARED_LIBS TRUE CACHE BOOL "" FORCE)
135
136 # Don't use X11 on OSX
137 if (APPLE)
138     set(CMAKE_DISABLE_FIND_PACKAGE_X11 true)
139     set(CMAKE_DISABLE_FIND_PACKAGE_XCB true)
140     set(CMAKE_DISABLE_FIND_PACKAGE_Qt5X11Extras true)
141 endif()
142
143 # Simplify later checks
144 #####################################################################
145
146 if (WANT_MONO OR WANT_QTCLIENT)
147     set(BUILD_GUI true)
148 endif()
149 if (WANT_MONO OR WANT_CORE)
150     set(BUILD_CORE true)
151 endif()
152
153 # Set up Qt
154 #####################################################################
155
156 set(QT_MIN_VERSION "5.5.0")
157
158 # Enable Qt deprecation warnings for Qt < 5.13 (on by default in newer versions)
159 add_definitions(-DQT_DEPRECATED_WARNINGS)
160
161 # Disable all Qt APIs that were deprecated in 5.5 and before
162 add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x050500)
163
164 # Find package dependencies
165 #
166 # Note that you can forcefully disable optional packages
167 # using -DCMAKE_DISABLE_FIND_PACKAGE_<PkgName>=TRUE
168 #####################################################################
169
170 # Required Qt components
171 set(qt_components Core Network)
172 if (BUILD_GUI)
173     list(APPEND qt_components Gui Widgets)
174 endif()
175 if (BUILD_CORE)
176     list(APPEND qt_components Sql)
177 endif()
178
179 find_package(Qt5 ${QT_MIN_VERSION} REQUIRED COMPONENTS ${qt_components})
180 set_package_properties(Qt5 PROPERTIES TYPE REQUIRED
181     URL "https://www.qt.io/"
182     DESCRIPTION "the Qt libraries"
183 )
184 message(STATUS "Found Qt ${Qt5Core_VERSION}")
185
186 # Determine minimum deployment target for macOS supported by Qt
187 if(APPLE)
188     if(NOT QMAKE_MACOSX_DEPLOYMENT_TARGET)
189         # qmake cannot be queried directly for QMAKE_MACOSX_DEPLOYMENT_TARGET (it is a mkspec, not a property).
190         # Instead, invoke qmake on an empty project file, which causes it to output the relevant keys and their values
191         # for subsequent parsing.
192         # A file named .qmake.stash is always created, so remove it (and empty.pro) afterwards.
193         set(qmakeEmptyProjectFile "${CMAKE_BINARY_DIR}/empty.pro")
194         set(qmakeStashFile "${CMAKE_BINARY_DIR}/.qmake.stash")
195         file(WRITE ${qmakeEmptyProjectFile} "")
196         get_target_property(QMAKE_EXECUTABLE Qt5::qmake IMPORTED_LOCATION)
197         execute_process(
198             COMMAND ${QMAKE_EXECUTABLE} -E ${qmakeEmptyProjectFile}
199             WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
200             OUTPUT_VARIABLE qmakeOutput
201         )
202         file(REMOVE ${qmakeEmptyProjectFile} ${qmakeStashFile})
203         string(REGEX MATCH "QMAKE_MACOSX_DEPLOYMENT_TARGET[ ]*=[ ]*([0-9.]+)" foo ${qmakeOutput})
204         if(NOT CMAKE_MATCH_1)
205             message(FATAL_ERROR "Could not determine the deployment target for Qt")
206         endif()
207         set(QMAKE_MACOSX_DEPLOYMENT_TARGET ${CMAKE_MATCH_1} CACHE INTERNAL "")
208         mark_as_advanced(QMAKE_MACOSX_DEPLOYMENT_TARGET)
209     endif()
210     message(STATUS "Minimum macOS version supported by Qt: ${QMAKE_MACOSX_DEPLOYMENT_TARGET}")
211 endif()
212
213 # Check for SSL support in Qt
214 cmake_push_check_state(RESET)
215 set(CMAKE_REQUIRED_LIBRARIES Qt5::Core)
216 check_cxx_source_compiles("
217     #include \"qglobal.h\"
218     #if defined QT_NO_SSL
219     #  error \"No SSL support\"
220     #endif
221     int main() {}"
222     HAVE_SSL)
223 cmake_pop_check_state()
224
225 if (NOT HAVE_SSL)
226     message(FATAL_ERROR "Quassel requires SSL support, but Qt is built with QT_NO_SSL")
227 endif()
228
229 # Optional Qt components
230
231 find_package(Qt5LinguistTools QUIET)
232 set_package_properties(Qt5LinguistTools PROPERTIES TYPE RECOMMENDED
233     DESCRIPTION "contains tools for handling translation files"
234     PURPOSE "Required for having translations"
235 )
236
237 if (BUILD_GUI)
238     if (NOT WIN32)
239         find_package(Qt5DBus QUIET)
240         set_package_properties(Qt5DBus PROPERTIES TYPE RECOMMENDED
241             URL "https://www.qt.io/"
242             DESCRIPTION "D-Bus support for Qt5"
243             PURPOSE     "Needed for supporting D-Bus-based notifications and tray icon, used by most modern desktop environments"
244         )
245         if (Qt5DBus_FOUND)
246             find_package(dbusmenu-qt5 QUIET CONFIG)
247             set_package_properties(dbusmenu-qt5 PROPERTIES TYPE RECOMMENDED
248                 URL "https://launchpad.net/libdbusmenu-qt"
249                 DESCRIPTION "a library implementing the DBusMenu specification"
250                 PURPOSE     "Required for having a context menu for the D-Bus-based tray icon"
251             )
252         endif()
253     endif()
254
255     find_package(Qt5Multimedia QUIET)
256     set_package_properties(Qt5Multimedia PROPERTIES TYPE RECOMMENDED
257         URL "https://www.qt.io/"
258         DESCRIPTION "Multimedia support for Qt5"
259         PURPOSE     "Required for audio notifications"
260     )
261
262     # snorenotify segfaults on startup on msys2
263     # we don't check for just MSYS to support the Ninja generator
264     if(NOT (WIN32 AND (NOT $ENV{MSYSTEM} STREQUAL "")))
265         find_package(LibsnoreQt5 0.7.0 QUIET)
266         set_package_properties(LibsnoreQt5 PROPERTIES TYPE OPTIONAL
267             URL "https://projects.kde.org/projects/playground/libs/snorenotify"
268             DESCRIPTION "a cross-platform notification framework"
269             PURPOSE     "Enable support for the snorenotify framework"
270         )
271         if (LibsnoreQt5_FOUND)
272             find_package(LibsnoreSettingsQt5 QUIET)
273             set_package_properties(LibsnoreSettingsQt5 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         endif()
279     endif()
280
281     if (WITH_WEBENGINE)
282         find_package(Qt5WebEngine QUIET)
283         set_package_properties(Qt5WebEngine PROPERTIES TYPE RECOMMENDED
284             URL "https://www.qt.io/"
285             DESCRIPTION "a WebEngine implementation for Qt"
286             PURPOSE     "Needed for displaying previews for URLs in chat"
287         )
288         if (Qt5WebEngine_FOUND)
289             find_package(Qt5WebEngineWidgets QUIET)
290             set_package_properties(Qt5WebEngineWidgets PROPERTIES TYPE RECOMMENDED
291                 URL "https://www.qt.io/"
292                 DESCRIPTION "widgets for Qt's WebEngine implementation"
293                 PURPOSE     "Needed for displaying previews for URLs in chat"
294             )
295         endif()
296     endif()
297
298     if (WITH_WEBENGINE AND Qt5WebEngineWidgets_FOUND)
299         set(HAVE_WEBENGINE true)
300     endif()
301     add_feature_info("WITH_WEBENGINE, QtWebEngine and QtWebEngineWidgets modules" HAVE_WEBENGINE "Support showing previews for URLs in chat")
302
303     if (NOT HAVE_WEBENGINE)
304         if (WITH_WEBKIT)
305             find_package(Qt5WebKit QUIET)
306             set_package_properties(Qt5WebKit PROPERTIES TYPE OPTIONAL
307                 URL "https://www.qt.io/"
308                 DESCRIPTION "a WebKit implementation for Qt"
309                 PURPOSE     "Needed for displaying previews for URLs in chat"
310                 )
311             if (Qt5WebKit_FOUND)
312                 find_package(Qt5WebKitWidgets QUIET)
313                 set_package_properties(Qt5WebKitWidgets PROPERTIES TYPE OPTIONAL
314                     URL "https://www.qt.io/"
315                     DESCRIPTION "widgets for Qt's WebKit implementation"
316                     PURPOSE     "Needed for displaying previews for URLs in chat"
317                     )
318             endif()
319         endif()
320
321         if (WITH_WEBKIT AND Qt5WebKitWidgets_FOUND)
322             set(HAVE_WEBKIT true)
323         endif()
324         add_feature_info("WITH_WEBKIT, QtWebKit and QtWebKitWidgets modules" HAVE_WEBKIT "Support showing previews for URLs in chat (legacy)")
325     endif()
326
327     # KDE Frameworks
328     ################
329
330     # extra-cmake-modules
331     if (WITH_KDE)
332         set(ecm_find_type "REQUIRED")
333         find_package(ECM NO_MODULE REQUIRED)
334     else()
335         # Even with KDE integration disabled, we optionally use tier1 frameworks if we find them
336         set(ecm_find_type "RECOMMENDED")
337         find_package(ECM NO_MODULE QUIET)
338     endif()
339
340     set_package_properties(ECM PROPERTIES TYPE ${ecm_find_type}
341         URL "https://projects.kde.org/projects/kdesupport/extra-cmake-modules"
342         DESCRIPTION "extra modules for CMake, maintained by the KDE project"
343         PURPOSE     "Required to find KDE Frameworks components"
344     )
345
346     if (ECM_FOUND)
347         list(APPEND CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
348         if (WITH_KDE)
349             find_package(KF5 REQUIRED COMPONENTS ConfigWidgets CoreAddons Notifications NotifyConfig Sonnet TextWidgets WidgetsAddons XmlGui)
350             set_package_properties(KF5 PROPERTIES TYPE REQUIRED
351                 URL "http://www.kde.org"
352                 DESCRIPTION "KDE Frameworks"
353                 PURPOSE     "Required for integration into the Plasma desktop"
354             )
355             message(STATUS "Found KDE Frameworks ${KF5_VERSION}")
356         endif()
357
358         # Optional KF5 tier1 components
359         find_package(KF5Sonnet QUIET)
360         set_package_properties(KF5Sonnet PROPERTIES TYPE RECOMMENDED
361             URL "http://api.kde.org/frameworks-api/frameworks5-apidocs/sonnet/html"
362             DESCRIPTION "framework for providing spell-checking capabilities"
363             PURPOSE "Enables spell-checking support in input widgets"
364         )
365     endif()
366 endif()
367
368 if (BUILD_CORE)
369     find_package(Qca-qt5 2.0 QUIET)
370     set_package_properties(Qca-qt5 PROPERTIES TYPE RECOMMENDED
371         URL "https://projects.kde.org/projects/kdesupport/qca"
372         DESCRIPTION "Qt Cryptographic Architecture"
373         PURPOSE "Required for encryption support"
374     )
375
376     if (WITH_LDAP)
377         find_package(Ldap QUIET)
378         set_package_properties(Ldap PROPERTIES TYPE OPTIONAL
379             URL "http://www.openldap.org/"
380             DESCRIPTION "LDAP (Lightweight Directory Access Protocol) libraries"
381             PURPOSE "Enables core user authentication via LDAP"
382         )
383     endif()
384 endif()
385
386 # Non-Qt-based packages
387 #####################################################################
388
389 find_package(Boost 1.54 REQUIRED)
390 set_package_properties(Boost PROPERTIES TYPE REQUIRED
391     URL "https://www.boost.org/"
392     DESCRIPTION "Boost libraries for C++"
393 )
394 # Older versions don't define the imported target
395 if (NOT TARGET Boost::boost)
396     add_library(Boost::boost INTERFACE IMPORTED GLOBAL)
397     if (Boost_INCLUDE_DIRS)
398         set_target_properties(Boost::boost PROPERTIES
399             INTERFACE_INCLUDE_DIRECTORIES "${Boost_INCLUDE_DIRS}")
400     endif()
401 endif()
402
403 find_package(ZLIB REQUIRED)
404 set_package_properties(ZLIB PROPERTIES TYPE REQUIRED
405     URL "http://www.zlib.net"
406     DESCRIPTION "a popular compression library"
407     PURPOSE     "Used for protocol compression"
408 )
409
410 if (NOT WIN32)
411     # Needed for generating backtraces
412     find_package(Backtrace QUIET)
413     set_package_properties(Backtrace PROPERTIES TYPE RECOMMENDED
414         DESCRIPTION "a header (and possibly library) for inspecting backtraces"
415         PURPOSE "Used for generating backtraces in case of a crash"
416     )
417 endif()
418
419 # Shared library support
420 #####################################################################
421
422 option(ENABLE_SHARED "Build modules as shared libraries" ON)
423 add_feature_info(ENABLE_SHARED ENABLE_SHARED "Build modules as shared libraries")
424
425 # Setup unit testing
426 #####################################################################
427
428 option(BUILD_TESTING "Enable unit tests" OFF)
429 add_feature_info(BUILD_TESTING BUILD_TESTING "Build unit tests")
430
431 if (BUILD_TESTING)
432     find_package(GTest QUIET)
433     set_package_properties(GTest PROPERTIES TYPE REQUIRED
434         DESCRIPTION "Google's unit testing framework"
435         PURPOSE "Required for building unit tests"
436     )
437
438     find_package(Qt5Test QUIET)
439     set_package_properties(Qt5Test PROPERTIES TYPE REQUIRED
440         DESCRIPTION "unit testing library for the Qt5 framework"
441         PURPOSE "Required for building unit tests"
442     )
443     enable_testing()
444
445     # GTest messes with CMAKE_CXX_FLAGS, so process them again
446     process_cmake_cxx_flags()
447 endif()
448
449 # Setup support for KDE Frameworks
450 #####################################################################
451
452 if (WITH_KDE)
453     add_definitions(-DHAVE_KDE -DHAVE_KF5)
454     set(WITH_KF5 TRUE)
455
456     # If KDE Frameworks are present, they're most probably providing Qt5 integration including icon loading
457     set(EMBED_DATA OFF)
458
459     include(KDEInstallDirs)
460 endif()
461
462 # This needs to come after setting up KDE integration, so we can use KDE-specific paths
463 include(QuasselInstallDirs)
464
465 # RPATH and output settings
466 #####################################################################
467
468 # Build artifacts in a well-known location; especially important for Windows DLLs
469 # (which go into RUNTIME_OUTPUT_DIRECTORY and can thus be found by executables)
470 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
471 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
472 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
473
474 # These RPATH settings allow for running directly from the build dir
475 set(CMAKE_SKIP_BUILD_RPATH            FALSE)
476 set(CMAKE_BUILD_WITH_INSTALL_RPATH    FALSE)
477 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE )
478
479 # Set install RPATH only if libdir isn't a system directory
480 if (IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
481     set(libdir "${CMAKE_INSTALL_LIBDIR}")
482 else()
483     set(libdir "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
484 endif()
485 list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${libdir}" is_systemdir)
486 if ("${is_systemdir}" STREQUAL "-1")
487    set(CMAKE_INSTALL_RPATH "${libdir}")
488 endif()
489
490 # Various config-dependent checks and settings
491 #####################################################################
492
493 # Check for syslog support
494 if (NOT WIN32)
495     check_include_file_cxx(syslog.h HAVE_SYSLOG)
496     add_feature_info("syslog.h" HAVE_SYSLOG "Provide support for logging to the syslog")
497 endif()
498
499 if (NOT WIN32)
500     check_function_exists(umask HAVE_UMASK)
501 endif()
502
503 if (EMBED_DATA)
504     message(STATUS "Embedding data files into the binary")
505 else()
506     message(STATUS "Installing data files separately")
507 endif()
508
509 # Windows-specific stuff
510 #####################################################################
511
512 if (WIN32)
513     link_libraries(imm32 winmm dbghelp Secur32)  # missing by default :/
514     if (MSVC)
515         link_libraries(Version dwmapi shlwapi)
516     endif()
517 endif()
518
519 # Prepare the build
520 #####################################################################
521
522 # Add needed subdirs - the order is important, since src needs some vars set by other dirs
523 add_subdirectory(data)
524 add_subdirectory(icons)
525 add_subdirectory(pics)
526 add_subdirectory(po)
527
528 # Set up and display feature summary
529 #####################################################################
530
531 feature_summary(WHAT ALL
532                 INCLUDE_QUIET_PACKAGES
533                 FATAL_ON_MISSING_REQUIRED_PACKAGES
534 )
535
536 # Finally, compile the sources
537 # We want this after displaying the feature summary to avoid ugly
538 # CMake backtraces in case a required Qt5 module is missing
539 #####################################################################
540
541 add_subdirectory(src)
542
543 # Build tests if so desired
544 if (BUILD_TESTING)
545     add_subdirectory(tests)
546 endif()