cmake: Set -DHAVE_UMASK only where it's needed
[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 add_definitions(-DHAVE_QT5)
154
155 find_package(Qt5Core ${QT_MIN_VERSION} QUIET)
156 set_package_properties(Qt5Core PROPERTIES TYPE REQUIRED
157     URL "https://www.qt.io/"
158     DESCRIPTION "contains core functionality for Qt"
159 )
160
161 # find_package without REQUIRED won't check for the version properly; also, older Qt5 versions
162 # used Qt5Core_VERSION_STRING... let's just make sure here that we bail out here if our Qt5 is not new enough.
163 if (NOT Qt5Core_VERSION OR Qt5Core_VERSION VERSION_LESS ${QT_MIN_VERSION})
164     message(FATAL_ERROR "Could NOT find Qt5 >= version ${QT_MIN_VERSION}!")
165 endif()
166
167 find_package(Qt5Network QUIET)
168 set_package_properties(Qt5Network PROPERTIES TYPE REQUIRED
169     DESCRIPTION "the network module for Qt5"
170 )
171
172 if (BUILD_GUI)
173     find_package(Qt5Gui QUIET)
174     set_package_properties(Qt5Gui PROPERTIES TYPE REQUIRED
175         DESCRIPTION "the GUI module for Qt5"
176     )
177     find_package(Qt5Widgets QUIET)
178     set_package_properties(Qt5Widgets PROPERTIES TYPE REQUIRED
179         DESCRIPTION "the widgets module for Qt5"
180     )
181
182     if (NOT WIN32)
183         find_package(Qt5DBus QUIET)
184         set_package_properties(Qt5DBus PROPERTIES TYPE RECOMMENDED
185             URL "https://www.qt.io/"
186             DESCRIPTION "D-Bus support for Qt5"
187             PURPOSE     "Needed for supporting D-Bus-based notifications and tray icon, used by most modern desktop environments"
188         )
189         if (Qt5DBus_FOUND)
190             find_package(dbusmenu-qt5 QUIET CONFIG)
191             set_package_properties(dbusmenu-qt5 PROPERTIES TYPE RECOMMENDED
192                 URL "https://launchpad.net/libdbusmenu-qt"
193                 DESCRIPTION "a library implementing the DBusMenu specification"
194                 PURPOSE     "Required for having a context menu for the D-Bus-based tray icon"
195             )
196         endif()
197     endif()
198
199     find_package(Qt5Multimedia QUIET)
200     set_package_properties(Qt5Multimedia PROPERTIES TYPE RECOMMENDED
201         URL "https://www.qt.io/"
202         DESCRIPTION "Multimedia support for Qt5"
203         PURPOSE     "Required for audio notifications"
204     )
205
206     find_package(LibsnoreQt5 0.7.0 QUIET)
207     set_package_properties(LibsnoreQt5 PROPERTIES TYPE OPTIONAL
208         URL "https://projects.kde.org/projects/playground/libs/snorenotify"
209         DESCRIPTION "a cross-platform notification framework"
210         PURPOSE     "Enable support for the snorenotify framework"
211     )
212     if(LibsnoreQt5_FOUND)
213         find_package(LibsnoreSettingsQt5)
214         set_package_properties(LibsnoreSettingsQt5 PROPERTIES TYPE REQUIRED
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     endif()
220
221     if (WITH_WEBKIT)
222         find_package(Qt5WebKit QUIET)
223         set_package_properties(Qt5WebKit PROPERTIES TYPE RECOMMENDED
224             URL "https://www.qt.io/"
225             DESCRIPTION "a WebKit implementation for Qt"
226             PURPOSE     "Needed for displaying previews for URLs in chat"
227         )
228         if (Qt5WebKit_FOUND)
229             find_package(Qt5WebKitWidgets QUIET)
230             set_package_properties(Qt5WebKitWidgets PROPERTIES TYPE RECOMMENDED
231                 URL "https://www.qt.io/"
232                 DESCRIPTION "widgets for Qt's WebKit implementation"
233                 PURPOSE     "Needed for displaying previews for URLs in chat"
234             )
235         endif()
236     endif()
237
238     if (WITH_WEBKIT AND Qt5WebKitWidgets_FOUND)
239         set(HAVE_WEBKIT true)
240     endif()
241     add_feature_info("WITH_WEBKIT, QtWebKit and QtWebKitWidgets modules" HAVE_WEBKIT "Support showing previews for URLs in chat (legacy)")
242
243     if (WITH_WEBENGINE)
244         find_package(Qt5WebEngine QUIET)
245         set_package_properties(Qt5WebEngine PROPERTIES TYPE RECOMMENDED
246             URL "https://www.qt.io/"
247             DESCRIPTION "a WebEngine implementation for Qt"
248             PURPOSE     "Needed for displaying previews for URLs in chat"
249         )
250         if (Qt5WebEngine_FOUND)
251             find_package(Qt5WebEngineWidgets QUIET)
252             set_package_properties(Qt5WebEngineWidgets PROPERTIES TYPE RECOMMENDED
253                 URL "https://www.qt.io/"
254                 DESCRIPTION "widgets for Qt's WebEngine implementation"
255                 PURPOSE     "Needed for displaying previews for URLs in chat"
256             )
257         endif()
258     endif()
259
260     if (WITH_WEBENGINE AND Qt5WebEngineWidgets_FOUND)
261         set(HAVE_WEBENGINE true)
262     endif()
263     add_feature_info("WITH_WEBENGINE, QtWebEngine and QtWebEngineWidgets modules" HAVE_WEBENGINE "Support showing previews for URLs in chat")
264
265     # KDE Frameworks
266     ################
267
268     if (WITH_KDE)
269         set(ecm_find_type "REQUIRED")
270     else()
271         # Even with KDE integration disabled, we optionally use tier1 frameworks if we find them
272         set(ecm_find_type "RECOMMENDED")
273     endif()
274
275     # extra-cmake-modules
276     find_package(ECM NO_MODULE QUIET)
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 COMPONENTS ConfigWidgets CoreAddons Notifications NotifyConfig Sonnet TextWidgets WidgetsAddons XmlGui QUIET)
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         else()
293             find_package(KF5Sonnet QUIET)
294             set_package_properties(KF5Sonnet PROPERTIES TYPE RECOMMENDED
295                 URL "http://api.kde.org/frameworks-api/frameworks5-apidocs/sonnet/html"
296                 DESCRIPTION "framework for providing spell-checking capabilities"
297                 PURPOSE "Enables spell-checking support in input widgets"
298             )
299         endif()
300     endif()
301
302 endif()
303
304 if (BUILD_CORE)
305     find_package(Qt5Script QUIET)
306     set_package_properties(Qt5Script PROPERTIES TYPE REQUIRED
307         DESCRIPTION "provides scripting support for Qt5"
308     )
309     find_package(Qt5Sql QUIET)
310     set_package_properties(Qt5Sql PROPERTIES TYPE REQUIRED
311         DESCRIPTION "the database support module for Qt5"
312     )
313
314     find_package(Qca-qt5 2.0)
315     set_package_properties(Qca-qt5 PROPERTIES TYPE RECOMMENDED
316         URL "https://projects.kde.org/projects/kdesupport/qca"
317         DESCRIPTION "Qt Cryptographic Architecture"
318         PURPOSE "Required for encryption support"
319     )
320
321 endif()
322
323 find_package(Qt5LinguistTools QUIET)
324 set_package_properties(Qt5LinguistTools PROPERTIES TYPE RECOMMENDED
325     DESCRIPTION "contains tools for handling translation files"
326     PURPOSE "Required for having translations"
327 )
328
329 # Non-Qt-based packages
330
331 find_package(ZLIB REQUIRED)
332 set_package_properties(ZLIB PROPERTIES TYPE REQUIRED
333     URL "http://www.zlib.net"
334     DESCRIPTION "a popular compression library"
335     PURPOSE     "Used for protocol compression"
336 )
337
338 if (NOT WIN32)
339     # Needed for generating backtraces
340     find_package(Backtrace QUIET)
341     set_package_properties(Backtrace PROPERTIES TYPE RECOMMENDED
342         DESCRIPTION "a header (and possibly library) for inspecting backtraces"
343         PURPOSE "Used for generating backtraces in case of a crash"
344     )
345 endif()
346
347 # Check for SSL support in Qt
348 cmake_push_check_state(RESET)
349 set(CMAKE_REQUIRED_LIBRARIES Qt5::Core)
350 check_cxx_source_compiles("
351     #include \"qglobal.h\"
352     #if defined QT_NO_SSL
353     #  error \"No SSL support\"
354     #endif
355     int main() {}"
356     HAVE_SSL)
357 cmake_pop_check_state()
358
359 if (HAVE_SSL)
360     add_definitions(-DHAVE_SSL)
361 endif()
362 add_feature_info("SSL support in Qt" HAVE_SSL "Use secure network connections")
363
364 # Additional compile settings
365 #####################################################################
366
367 # This sets -fPIC and friends if required by the installed Qt5 library
368 if (Qt5_POSITION_INDEPENDENT_CODE)
369     set(CMAKE_POSITION_INDEPENDENT_CODE ON)
370     set(CMAKE_REQUIRED_FLAGS "-DQT_NO_VERSION_TAGGING")
371 endif()
372
373 # Needed to compile with mingw without kde
374 if (MINGW AND NOT WITH_KDE)
375     add_definitions(-D_WIN32_WINNT=0x0500)
376     message(STATUS "Added _WIN32_WINNT=0x0500 definition for MinGW")
377     # workaround for bug in mingw gcc 4.0
378     add_definitions(-U__STRICT_ANSI__)
379 endif()
380
381 # Sanitize compiler flags - old versions of KDE set -ansi, which breaks -std=c++11
382 if (CMAKE_COMPILER_IS_GNUCXX)
383     string(REPLACE "-ansi" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
384 endif()
385
386 # Setup LDAP Authentication support.
387 #####################################################################
388 if (WITH_LDAP)
389     find_package(Ldap)
390     if (LDAP_FOUND)
391         message(STATUS "Enabling LDAP authentication support")
392     else()
393         message(STATUS "Disabling LDAP authentication support")
394     endif()
395 else()
396     message(STATUS "Not enabling LDAP authentication support")
397 endif()
398
399 # Setup support for KDE Frameworks
400 #####################################################################
401
402 # We want to do this up here, so we have the necessary variables and defines set before
403 # compiling anything
404
405 if (WITH_KDE)
406     # If KDE Frameworks are present, they're most probably providing Qt5 integration including icon loading
407     set(EMBED_DATA OFF)
408
409     include(KDEInstallDirs)
410     include(KDECompilerSettings)
411     include(KDECMakeSettings)
412
413     kde_enable_exceptions()
414     add_definitions(-DHAVE_KDE -DHAVE_KF5)
415     set(WITH_KF5 TRUE)
416 endif()
417
418 # This needs to come after setting up KDE integration, so we can use KDE-specific paths
419 include(QuasselInstallDirs)
420
421 # Various config-dependent checks and settings
422 #####################################################################
423
424 # Check for syslog support
425 if (NOT WIN32)
426     check_include_file_cxx(syslog.h HAVE_SYSLOG)
427     add_feature_info("syslog.h" HAVE_SYSLOG "Provide support for logging to the syslog")
428 endif()
429
430 if (NOT WIN32)
431     check_function_exists(umask HAVE_UMASK)
432 endif()
433
434 if (EMBED_DATA)
435     message(STATUS "Embedding data files into the binary")
436 else()
437     message(STATUS "Installing data files separately")
438 endif()
439
440 # Windows-specific stuff
441 #####################################################################
442
443 if (WIN32)
444     link_libraries(imm32 winmm dbghelp Secur32)  # missing by default :/
445     if (MSVC)
446         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DNOMINMAX")
447         set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBUGINFO "/debug /INCREMENTAL:YES /NODEFAULTLIB:libcmt /DEFAULTLIB:msvcrt")
448         set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/debug /INCREMENTAL:YES /NODEFAULTLIB:libcmt")
449         set(CMAKE_EXE_LINKER_FLAGS_DEBUGFULL "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
450         link_libraries(Version dwmapi shlwapi)
451         set(QT_QTMAIN_LIBRARY Qt5::WinMain)
452     endif()
453 endif()
454
455
456 # Generate version information from Git
457 #####################################################################
458
459 include(GetGitRevisionDescription)
460 get_git_head_revision(GIT_REFSPEC GIT_HEAD)
461 git_describe(GIT_DESCRIBE --long)
462
463 # If in a Git repo we can get the commit-date from a git command
464 if (GIT_HEAD)
465     execute_process(
466         COMMAND git -c log.showsignature=false show -s --format=%ct
467         WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
468         OUTPUT_VARIABLE GIT_COMMIT_DATE
469         OUTPUT_STRIP_TRAILING_WHITESPACE
470     )
471 endif()
472
473 # If not in a Git repo try to read GIT_HEAD and GIT_DESCRIBE from
474 # enviroment
475 if (NOT GIT_HEAD OR NOT GIT_DESCRIBE)
476   if (DEFINED ENV{GIT_HEAD})
477       set(GIT_HEAD $ENV{GIT_HEAD})
478   endif()
479   if (DEFINED ENV{GIT_DESCRIBE})
480      set(GIT_DESCRIBE $ENV{GIT_DESCRIBE})
481   endif()
482 endif()
483
484 # Sanitize things if we're not in a Git repo
485 if (NOT GIT_HEAD OR NOT GIT_DESCRIBE)
486     set(GIT_HEAD "")
487     set(GIT_DESCRIBE "")
488     set(GIT_COMMIT_DATE 0)
489 endif()
490
491 configure_file(version.h.in ${CMAKE_BINARY_DIR}/version.h @ONLY)
492
493 # Prepare the build
494 #####################################################################
495
496 # Add needed subdirs - the order is important, since src needs some vars set by other dirs
497 add_subdirectory(data)
498 add_subdirectory(icons)
499 add_subdirectory(pics)
500 add_subdirectory(po)
501
502
503 # Set up and display feature summary
504 #####################################################################
505
506 feature_summary(WHAT ALL
507                 INCLUDE_QUIET_PACKAGES
508                 FATAL_ON_MISSING_REQUIRED_PACKAGES
509 )
510
511 # Finally, compile the sources
512 # We want this after displaying the feature summary to avoid ugly
513 # CMake backtraces in case a required Qt5 module is missing
514 #####################################################################
515
516 add_subdirectory(src)