c162ec4f688865b7b481f176d21b27719466c586
[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 if (WITH_BUNDLED_ICONS)
88     add_definitions(-DWITH_BUNDLED_ICONS)
89 endif()
90 if (WITH_OXYGEN_ICONS)
91     add_definitions(-DWITH_OXYGEN_ICONS)
92 endif()
93
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)
96
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)
99
100 if (APPLE)
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")
105     endif()
106     find_library(CARBON_LIBRARY Carbon)
107     mark_as_advanced(CARBON_LIBRARY)
108     link_libraries(${CARBON_LIBRARY})
109 endif()
110
111 # Always embed on Windows or OSX; never embed when enabling KDE integration
112 set(EMBED_DEFAULT OFF)
113 if (WIN32 OR APPLE)
114     set(EMBED_DEFAULT ON)
115 endif()
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")
120 endif()
121
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)
124
125
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)
130
131 # Setup CMake
132 #####################################################################
133
134 # Let automoc/autouic process generated files
135 if (POLICY CMP0071)
136     cmake_policy(SET CMP0071 NEW)
137 endif()
138
139 # Simplify later checks
140 #####################################################################
141
142 if (WANT_MONO OR WANT_QTCLIENT)
143     set(BUILD_GUI true)
144 endif()
145 if (WANT_MONO OR WANT_CORE)
146     set(BUILD_CORE true)
147 endif()
148
149
150 # Set up Qt
151 #####################################################################
152
153 # Find package dependencies
154 #
155 # Note that you can forcefully disable optional packages
156 # using -DCMAKE_DISABLE_FIND_PACKAGE_<PkgName>=TRUE
157 #####################################################################
158
159 set(QT_MIN_VERSION "5.5.0")
160 add_definitions(-DHAVE_QT5)
161
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"
166 )
167
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}!")
172 endif()
173
174 find_package(Qt5Network QUIET)
175 set_package_properties(Qt5Network PROPERTIES TYPE REQUIRED
176     DESCRIPTION "the network module for Qt5"
177 )
178
179 if (BUILD_GUI)
180     find_package(Qt5Gui QUIET)
181     set_package_properties(Qt5Gui PROPERTIES TYPE REQUIRED
182         DESCRIPTION "the GUI module for Qt5"
183     )
184     find_package(Qt5Widgets QUIET)
185     set_package_properties(Qt5Widgets PROPERTIES TYPE REQUIRED
186         DESCRIPTION "the widgets module for Qt5"
187     )
188
189     if (NOT WIN32)
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"
195         )
196         if (Qt5DBus_FOUND)
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"
202             )
203         endif()
204     endif()
205
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"
211     )
212
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"
218     )
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"
225         )
226     endif()
227
228     if (WITH_WEBKIT)
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"
234         )
235         if (Qt5WebKit_FOUND)
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"
241             )
242         endif()
243     endif()
244
245     if (WITH_WEBKIT AND Qt5WebKitWidgets_FOUND)
246         set(HAVE_WEBKIT true)
247     endif()
248     add_feature_info("WITH_WEBKIT, QtWebKit and QtWebKitWidgets modules" HAVE_WEBKIT "Support showing previews for URLs in chat (legacy)")
249
250     if (WITH_WEBENGINE)
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"
256         )
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"
263             )
264         endif()
265     endif()
266
267     if (WITH_WEBENGINE AND Qt5WebEngineWidgets_FOUND)
268         set(HAVE_WEBENGINE true)
269     endif()
270     add_feature_info("WITH_WEBENGINE, QtWebEngine and QtWebEngineWidgets modules" HAVE_WEBENGINE "Support showing previews for URLs in chat")
271
272     # KDE Frameworks
273     ################
274
275     if (WITH_KDE)
276         set(ecm_find_type "REQUIRED")
277     else()
278         # Even with KDE integration disabled, we optionally use tier1 frameworks if we find them
279         set(ecm_find_type "RECOMMENDED")
280     endif()
281
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"
288     )
289
290     if (ECM_FOUND)
291         list(APPEND CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
292         if (WITH_KDE)
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"
298             )
299         else()
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"
305             )
306         endif()
307     endif()
308
309 endif()
310
311 if (BUILD_CORE)
312     find_package(Qt5Script QUIET)
313     set_package_properties(Qt5Script PROPERTIES TYPE REQUIRED
314         DESCRIPTION "provides scripting support for Qt5"
315     )
316     find_package(Qt5Sql QUIET)
317     set_package_properties(Qt5Sql PROPERTIES TYPE REQUIRED
318         DESCRIPTION "the database support module for Qt5"
319     )
320
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"
326     )
327
328 endif()
329
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"
334 )
335
336 # Some Qt5 versions do not define a target for lconvert, so we need to find it ourselves
337 if (Qt5LinguistTools_FOUND)
338     if (NOT TARGET Qt5::lconvert AND TARGET Qt5::lrelease)
339         get_target_property(_lrelease_location Qt5::lrelease LOCATION)
340         get_filename_component(_lrelease_path ${_lrelease_location} PATH)
341         find_program(QT_LCONVERT_EXECUTABLE NAMES lconvert-qt5 lconvert PATHS ${_lrelease_path} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
342     elseif(TARGET Qt5::lconvert AND NOT Qt5_LCONVERT_EXECUTABLE)
343         # Newer Qt5 versions define the target, but not the Qt5_LCONVERT_EXECUTABLE variable for some reason
344         get_target_property(QT_LCONVERT_EXECUTABLE Qt5::lconvert LOCATION)
345     endif()
346
347     # Compatibility with the Qt4 variables
348     set(QT_LRELEASE_EXECUTABLE ${Qt5_LRELEASE_EXECUTABLE})
349     set(QT_LUPDATE_EXECUTABLE ${Qt5_LUPDATE_EXECUTABLE})
350     if (Qt5_LCONVERT_EXECUTABLE)
351         set(QT_LCONVERT_EXECUTABLE ${Qt5_LCONVERT_EXECUTABLE})
352     endif()
353 endif()
354
355 # Non-Qt-based packages
356
357 find_package(ZLIB REQUIRED)
358 set_package_properties(ZLIB PROPERTIES TYPE REQUIRED
359     URL "http://www.zlib.net"
360     DESCRIPTION "a popular compression library"
361     PURPOSE     "Used for protocol compression"
362 )
363
364 if (NOT WIN32)
365     # Needed for generating backtraces
366     find_package(Backtrace QUIET)
367     set_package_properties(Backtrace PROPERTIES TYPE RECOMMENDED
368         DESCRIPTION "a header (and possibly library) for inspecting backtraces"
369         PURPOSE "Used for generating backtraces in case of a crash"
370     )
371 endif()
372
373 # Check for SSL support in Qt
374 # As there's no easy way to get Qt's configuration in particular for Qt5, let's just compile
375 # a small test program checking the defines. This works for both Qt4 and Qt5.
376 cmake_push_check_state(RESET)
377 set(CMAKE_REQUIRED_INCLUDES ${QT_INCLUDES} ${Qt5Core_INCLUDE_DIRS})
378 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
379
380 if (Qt5_POSITION_INDEPENDENT_CODE)
381     set(CMAKE_REQUIRED_FLAGS "-fPIC -DQT_NO_VERSION_TAGGING")
382 endif()
383
384 check_cxx_source_compiles("
385     #include \"qglobal.h\"
386     #if defined QT_NO_SSL
387     #  error \"No SSL support\"
388     #endif
389     int main() {}"
390     HAVE_SSL)
391 cmake_pop_check_state()
392
393 # Additional compile settings
394 #####################################################################
395
396 # This sets -fPIC and friends if required by the installed Qt5 library
397 if (Qt5_POSITION_INDEPENDENT_CODE)
398     set(CMAKE_POSITION_INDEPENDENT_CODE ON)
399     set(CMAKE_REQUIRED_FLAGS "-DQT_NO_VERSION_TAGGING")
400 endif()
401
402 # Needed to compile with mingw without kde
403 if (MINGW AND NOT WITH_KDE)
404     add_definitions(-D_WIN32_WINNT=0x0500)
405     message(STATUS "Added _WIN32_WINNT=0x0500 definition for MinGW")
406     # workaround for bug in mingw gcc 4.0
407     add_definitions(-U__STRICT_ANSI__)
408 endif()
409
410 # Sanitize compiler flags - old versions of KDE set -ansi, which breaks -std=c++11
411 if (CMAKE_COMPILER_IS_GNUCXX)
412     string(REPLACE "-ansi" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
413 endif()
414
415 # Setup LDAP Authentication support.
416 #####################################################################
417 if (WITH_LDAP)
418     find_package(Ldap)
419     if (LDAP_FOUND)
420         message(STATUS "Enabling LDAP authentication support")
421     else()
422         message(STATUS "Disabling LDAP authentication support")
423     endif()
424 else()
425     message(STATUS "Not enabling LDAP authentication support")
426 endif()
427
428 # Setup support for KDE Frameworks
429 #####################################################################
430
431 # We want to do this up here, so we have the necessary variables and defines set before
432 # compiling anything
433
434 if (WITH_KDE)
435     # If KDE Frameworks are present, they're most probably providing Qt5 integration including icon loading
436     set(EMBED_DATA OFF)
437
438     include(KDEInstallDirs)
439     include(KDECompilerSettings)
440     include(KDECMakeSettings)
441
442     kde_enable_exceptions()
443     add_definitions(-DHAVE_KDE -DHAVE_KF5)
444     set(WITH_KF5 TRUE)
445 endif()
446
447 # This needs to come after setting up KDE integration, so we can use KDE-specific paths
448 include(QuasselInstallDirs)
449
450 # Various config-dependent checks and settings
451 #####################################################################
452
453 if (HAVE_SSL)
454     add_definitions(-DHAVE_SSL)
455 endif()
456 add_feature_info("SSL support in Qt" HAVE_SSL "Use secure network connections")
457
458 # Check for syslog support
459 if (NOT WIN32)
460     check_include_file_cxx(syslog.h HAVE_SYSLOG)
461     add_feature_info("syslog.h" HAVE_SYSLOG "Provide support for logging to the syslog")
462 endif()
463
464 add_feature_info("Qt Linguist Tools" QT_LCONVERT_EXECUTABLE "Translation support for Quassel")
465
466 if (EMBED_DATA)
467     message(STATUS "Embedding data files into the binary")
468 else()
469     message(STATUS "Installing data files separately")
470 endif()
471
472 if (NOT WIN32)
473     check_function_exists(umask HAVE_UMASK)
474     if(HAVE_UMASK)
475         add_definitions(-DHAVE_UMASK)
476     endif()
477 endif()
478
479
480 # Windows-specific stuff
481 #####################################################################
482
483 if (WIN32)
484     link_libraries(imm32 winmm dbghelp Secur32)  # missing by default :/
485     if (MSVC)
486         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DNOMINMAX")
487         set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBUGINFO "/debug /INCREMENTAL:YES /NODEFAULTLIB:libcmt /DEFAULTLIB:msvcrt")
488         set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/debug /INCREMENTAL:YES /NODEFAULTLIB:libcmt")
489         set(CMAKE_EXE_LINKER_FLAGS_DEBUGFULL "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
490         link_libraries(Version dwmapi shlwapi)
491         set(QT_QTMAIN_LIBRARY Qt5::WinMain)
492     endif()
493 endif()
494
495
496 # Generate version information from Git
497 #####################################################################
498
499 include(GetGitRevisionDescription)
500 get_git_head_revision(GIT_REFSPEC GIT_HEAD)
501 git_describe(GIT_DESCRIBE --long)
502
503 # If in a Git repo we can get the commit-date from a git command
504 if (GIT_HEAD)
505     execute_process(
506         COMMAND git -c log.showsignature=false show -s --format=%ct
507         WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
508         OUTPUT_VARIABLE GIT_COMMIT_DATE
509         OUTPUT_STRIP_TRAILING_WHITESPACE
510     )
511 endif()
512
513 # If not in a Git repo try to read GIT_HEAD and GIT_DESCRIBE from
514 # enviroment
515 if (NOT GIT_HEAD OR NOT GIT_DESCRIBE)
516   if (DEFINED ENV{GIT_HEAD})
517       set(GIT_HEAD $ENV{GIT_HEAD})
518   endif()
519   if (DEFINED ENV{GIT_DESCRIBE})
520      set(GIT_DESCRIBE $ENV{GIT_DESCRIBE})
521   endif()
522 endif()
523
524 # Sanitize things if we're not in a Git repo
525 if (NOT GIT_HEAD OR NOT GIT_DESCRIBE)
526     set(GIT_HEAD "")
527     set(GIT_DESCRIBE "")
528     set(GIT_COMMIT_DATE 0)
529 endif()
530
531 configure_file(version.h.in ${CMAKE_BINARY_DIR}/version.h @ONLY)
532
533 # Prepare the build
534 #####################################################################
535
536 # Add needed subdirs - the order is important, since src needs some vars set by other dirs
537 add_subdirectory(data)
538 add_subdirectory(icons)
539 add_subdirectory(pics)
540 add_subdirectory(po)
541
542
543 # Set up and display feature summary
544 #####################################################################
545
546 feature_summary(WHAT ALL
547                 INCLUDE_QUIET_PACKAGES
548                 FATAL_ON_MISSING_REQUIRED_PACKAGES
549 )
550
551 # Finally, compile the sources
552 # We want this after displaying the feature summary to avoid ugly
553 # CMake backtraces in case a required Qt5 module is missing
554 #####################################################################
555
556 add_subdirectory(src)