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