cmake: Set proper install paths for Windows
[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 endif()
97
98 # Always embed on Windows or OSX; never embed when enabling KDE integration
99 set(EMBED_DEFAULT OFF)
100 if (WIN32 OR APPLE)
101     set(EMBED_DEFAULT ON)
102 endif()
103 cmake_dependent_option(EMBED_DATA "Embed icons and translations into the binaries instead of installing them" ${EMBED_DEFAULT}
104                                    "NOT WIN32;NOT WITH_KDE" ${EMBED_DEFAULT})
105 if (NOT EMBED_DEFAULT)
106     add_feature_info(EMBED_DATA EMBED_DATA "Embed icons and translations in the binaries instead of installing them")
107 endif()
108
109 # The following options are not for end-user consumption, so don't list them in the feature summary
110 cmake_dependent_option(DEPLOY "Add required libs to bundle resources and create a dmg" OFF "APPLE" OFF)
111
112 # List of authenticators and the cmake flags to build them
113 # (currently that's just LDAP, but more can be added here).
114 ####################################################################
115 option(WITH_LDAP "Enable LDAP authentication support if present on system" ON)
116
117 # Setup CMake
118 #####################################################################
119
120 # Visibility settings apply to all targets
121 if (POLICY CMP0063)
122     cmake_policy(SET CMP0063 NEW)
123 endif()
124
125 # Let automoc/autouic process generated files
126 if (POLICY CMP0071)
127     cmake_policy(SET CMP0071 NEW)
128 endif()
129
130 set(BUILD_SHARED_LIBS TRUE CACHE BOOL "" FORCE)
131
132 # Don't use X11 on OSX
133 if (APPLE)
134     set(CMAKE_DISABLE_FIND_PACKAGE_X11 true)
135     set(CMAKE_DISABLE_FIND_PACKAGE_XCB true)
136     set(CMAKE_DISABLE_FIND_PACKAGE_Qt5X11Extras true)
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 # Set up Qt
150 #####################################################################
151
152 # Find package dependencies
153 #
154 # Note that you can forcefully disable optional packages
155 # using -DCMAKE_DISABLE_FIND_PACKAGE_<PkgName>=TRUE
156 #####################################################################
157
158 set(QT_MIN_VERSION "5.5.0")
159
160 # Required Qt components
161 set(qt_components Core Network)
162 if (BUILD_GUI)
163     list(APPEND qt_components Gui Widgets)
164 endif()
165 if (BUILD_CORE)
166     list(APPEND qt_components Script Sql)
167 endif()
168
169 find_package(Qt5 ${QT_MIN_VERSION} REQUIRED COMPONENTS ${qt_components})
170 set_package_properties(Qt5 PROPERTIES TYPE REQUIRED
171     URL "https://www.qt.io/"
172     DESCRIPTION "the Qt libraries"
173 )
174 message(STATUS "Found Qt ${Qt5Core_VERSION}")
175
176 # Optional Qt components
177
178 find_package(Qt5LinguistTools QUIET)
179 set_package_properties(Qt5LinguistTools PROPERTIES TYPE RECOMMENDED
180     DESCRIPTION "contains tools for handling translation files"
181     PURPOSE "Required for having translations"
182 )
183
184 if (BUILD_GUI)
185     if (NOT WIN32)
186         find_package(Qt5DBus QUIET)
187         set_package_properties(Qt5DBus PROPERTIES TYPE RECOMMENDED
188             URL "https://www.qt.io/"
189             DESCRIPTION "D-Bus support for Qt5"
190             PURPOSE     "Needed for supporting D-Bus-based notifications and tray icon, used by most modern desktop environments"
191         )
192         if (Qt5DBus_FOUND)
193             find_package(dbusmenu-qt5 QUIET CONFIG)
194             set_package_properties(dbusmenu-qt5 PROPERTIES TYPE RECOMMENDED
195                 URL "https://launchpad.net/libdbusmenu-qt"
196                 DESCRIPTION "a library implementing the DBusMenu specification"
197                 PURPOSE     "Required for having a context menu for the D-Bus-based tray icon"
198             )
199         endif()
200     endif()
201
202     find_package(Qt5Multimedia QUIET)
203     set_package_properties(Qt5Multimedia PROPERTIES TYPE RECOMMENDED
204         URL "https://www.qt.io/"
205         DESCRIPTION "Multimedia support for Qt5"
206         PURPOSE     "Required for audio notifications"
207     )
208
209     find_package(LibsnoreQt5 0.7.0 QUIET)
210     set_package_properties(LibsnoreQt5 PROPERTIES TYPE OPTIONAL
211         URL "https://projects.kde.org/projects/playground/libs/snorenotify"
212         DESCRIPTION "a cross-platform notification framework"
213         PURPOSE     "Enable support for the snorenotify framework"
214     )
215     if (LibsnoreQt5_FOUND)
216         find_package(LibsnoreSettingsQt5 QUIET)
217         set_package_properties(LibsnoreSettingsQt5 PROPERTIES TYPE OPTIONAL
218             URL "https://projects.kde.org/projects/playground/libs/snorenotify"
219             DESCRIPTION "a cross-platform notification framework"
220             PURPOSE     "Enable support for the snorenotify framework"
221         )
222     endif()
223
224     if (WITH_WEBENGINE)
225         find_package(Qt5WebEngine QUIET)
226         set_package_properties(Qt5WebEngine PROPERTIES TYPE RECOMMENDED
227             URL "https://www.qt.io/"
228             DESCRIPTION "a WebEngine implementation for Qt"
229             PURPOSE     "Needed for displaying previews for URLs in chat"
230         )
231         if (Qt5WebEngine_FOUND)
232             find_package(Qt5WebEngineWidgets QUIET)
233             set_package_properties(Qt5WebEngineWidgets PROPERTIES TYPE RECOMMENDED
234                 URL "https://www.qt.io/"
235                 DESCRIPTION "widgets for Qt's WebEngine implementation"
236                 PURPOSE     "Needed for displaying previews for URLs in chat"
237             )
238         endif()
239     endif()
240
241     if (WITH_WEBENGINE AND Qt5WebEngineWidgets_FOUND)
242         set(HAVE_WEBENGINE true)
243     endif()
244     add_feature_info("WITH_WEBENGINE, QtWebEngine and QtWebEngineWidgets modules" HAVE_WEBENGINE "Support showing previews for URLs in chat")
245
246     if (NOT HAVE_WEBENGINE)
247         if (WITH_WEBKIT)
248             find_package(Qt5WebKit QUIET)
249             set_package_properties(Qt5WebKit PROPERTIES TYPE OPTIONAL
250                 URL "https://www.qt.io/"
251                 DESCRIPTION "a WebKit implementation for Qt"
252                 PURPOSE     "Needed for displaying previews for URLs in chat"
253                 )
254             if (Qt5WebKit_FOUND)
255                 find_package(Qt5WebKitWidgets QUIET)
256                 set_package_properties(Qt5WebKitWidgets PROPERTIES TYPE OPTIONAL
257                     URL "https://www.qt.io/"
258                     DESCRIPTION "widgets for Qt's WebKit implementation"
259                     PURPOSE     "Needed for displaying previews for URLs in chat"
260                     )
261             endif()
262         endif()
263
264         if (WITH_WEBKIT AND Qt5WebKitWidgets_FOUND)
265             set(HAVE_WEBKIT true)
266         endif()
267         add_feature_info("WITH_WEBKIT, QtWebKit and QtWebKitWidgets modules" HAVE_WEBKIT "Support showing previews for URLs in chat (legacy)")
268     endif()
269
270     # KDE Frameworks
271     ################
272
273     # extra-cmake-modules
274     if (WITH_KDE)
275         set(ecm_find_type "REQUIRED")
276         find_package(ECM NO_MODULE 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         find_package(ECM NO_MODULE QUIET)
281     endif()
282
283     set_package_properties(ECM PROPERTIES TYPE ${ecm_find_type}
284         URL "https://projects.kde.org/projects/kdesupport/extra-cmake-modules"
285         DESCRIPTION "extra modules for CMake, maintained by the KDE project"
286         PURPOSE     "Required to find KDE Frameworks components"
287     )
288
289     if (ECM_FOUND)
290         list(APPEND CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
291         if (WITH_KDE)
292             find_package(KF5 REQUIRED COMPONENTS ConfigWidgets CoreAddons Notifications NotifyConfig Sonnet TextWidgets WidgetsAddons XmlGui)
293             set_package_properties(KF5 PROPERTIES TYPE REQUIRED
294                 URL "http://www.kde.org"
295                 DESCRIPTION "KDE Frameworks"
296                 PURPOSE     "Required for integration into the Plasma desktop"
297             )
298             message(STATUS "Found KDE Frameworks ${KF5_VERSION}")
299         endif()
300
301         # Optional KF5 tier1 components
302         find_package(KF5Sonnet QUIET)
303         set_package_properties(KF5Sonnet PROPERTIES TYPE RECOMMENDED
304             URL "http://api.kde.org/frameworks-api/frameworks5-apidocs/sonnet/html"
305             DESCRIPTION "framework for providing spell-checking capabilities"
306             PURPOSE "Enables spell-checking support in input widgets"
307         )
308     endif()
309 endif()
310
311 if (BUILD_CORE)
312     find_package(Qca-qt5 2.0 QUIET)
313     set_package_properties(Qca-qt5 PROPERTIES TYPE RECOMMENDED
314         URL "https://projects.kde.org/projects/kdesupport/qca"
315         DESCRIPTION "Qt Cryptographic Architecture"
316         PURPOSE "Required for encryption support"
317     )
318
319     if (WITH_LDAP)
320         find_package(Ldap QUIET)
321         set_package_properties(Ldap PROPERTIES TYPE OPTIONAL
322             URL "http://www.openldap.org/"
323             DESCRIPTION "LDAP (Lightweight Directory Access Protocol) libraries"
324             PURPOSE "Enables core user authentication via LDAP"
325         )
326     endif()
327 endif()
328
329 # Non-Qt-based packages
330 #####################################################################
331
332 find_package(Boost 1.56 REQUIRED)
333 set_package_properties(Boost PROPERTIES TYPE REQUIRED
334     URL "https://www.boost.org/"
335     DESCRIPTION "Boost libraries for C++"
336 )
337
338 find_package(ZLIB REQUIRED)
339 set_package_properties(ZLIB PROPERTIES TYPE REQUIRED
340     URL "http://www.zlib.net"
341     DESCRIPTION "a popular compression library"
342     PURPOSE     "Used for protocol compression"
343 )
344
345 if (NOT WIN32)
346     # Needed for generating backtraces
347     find_package(Backtrace QUIET)
348     set_package_properties(Backtrace PROPERTIES TYPE RECOMMENDED
349         DESCRIPTION "a header (and possibly library) for inspecting backtraces"
350         PURPOSE "Used for generating backtraces in case of a crash"
351     )
352 endif()
353
354 # Setup unit testing
355 #####################################################################
356
357 option(BUILD_TESTING "Enable unit tests" OFF)
358 add_feature_info(BUILD_TESTING BUILD_TESTING "Build unit tests")
359
360 if (BUILD_TESTING)
361     find_package(GTest QUIET)
362     set_package_properties(GTest PROPERTIES TYPE REQUIRED
363         DESCRIPTION "Google's unit testing framework"
364         PURPOSE "Required for building unit tests"
365     )
366
367     find_package(Qt5Test QUIET)
368     set_package_properties(Qt5Test PROPERTIES TYPE REQUIRED
369         DESCRIPTION "unit testing library for the Qt5 framework"
370         PURPOSE "Required for building unit tests"
371     )
372     enable_testing()
373
374     # GTest messes with CMAKE_CXX_FLAGS, so process them again
375     process_cmake_cxx_flags()
376 endif()
377
378 # Check for SSL support in Qt
379 #####################################################################
380
381 cmake_push_check_state(RESET)
382 set(CMAKE_REQUIRED_LIBRARIES Qt5::Core)
383 check_cxx_source_compiles("
384     #include \"qglobal.h\"
385     #if defined QT_NO_SSL
386     #  error \"No SSL support\"
387     #endif
388     int main() {}"
389     HAVE_SSL)
390 cmake_pop_check_state()
391
392 if (HAVE_SSL)
393     add_definitions(-DHAVE_SSL)
394 endif()
395 add_feature_info("SSL support in Qt" HAVE_SSL "Use secure network connections")
396
397 # Setup support for KDE Frameworks
398 #####################################################################
399
400 if (WITH_KDE)
401     add_definitions(-DHAVE_KDE -DHAVE_KF5)
402     set(WITH_KF5 TRUE)
403
404     # If KDE Frameworks are present, they're most probably providing Qt5 integration including icon loading
405     set(EMBED_DATA OFF)
406
407     include(KDEInstallDirs)
408 endif()
409
410 # This needs to come after setting up KDE integration, so we can use KDE-specific paths
411 include(QuasselInstallDirs)
412
413 # RPATH and output settings
414 #####################################################################
415
416 # Build artifacts in a well-known location; especially important for Windows DLLs
417 # (which go into RUNTIME_OUTPUT_DIRECTORY and can thus be found by executables)
418 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
419 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
420 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
421
422 # These RPATH settings allow for running directly from the build dir
423 set(CMAKE_SKIP_BUILD_RPATH            FALSE)
424 set(CMAKE_BUILD_WITH_INSTALL_RPATH    FALSE)
425 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE )
426
427 # Set install RPATH only if libdir isn't a system directory
428 if (IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
429     set(libdir "${CMAKE_INSTALL_LIBDIR}")
430 else()
431     set(libdir "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
432 endif()
433 list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${libdir}" is_systemdir)
434 if ("${is_systemdir}" STREQUAL "-1")
435    set(CMAKE_INSTALL_RPATH "${libdir}")
436 endif()
437
438 # Various config-dependent checks and settings
439 #####################################################################
440
441 # Check for syslog support
442 if (NOT WIN32)
443     check_include_file_cxx(syslog.h HAVE_SYSLOG)
444     add_feature_info("syslog.h" HAVE_SYSLOG "Provide support for logging to the syslog")
445 endif()
446
447 if (NOT WIN32)
448     check_function_exists(umask HAVE_UMASK)
449 endif()
450
451 if (EMBED_DATA)
452     message(STATUS "Embedding data files into the binary")
453 else()
454     message(STATUS "Installing data files separately")
455 endif()
456
457 # Windows-specific stuff
458 #####################################################################
459
460 if (WIN32)
461     link_libraries(imm32 winmm dbghelp Secur32)  # missing by default :/
462     if (MSVC)
463         link_libraries(Version dwmapi shlwapi)
464     endif()
465 endif()
466
467 # Prepare the build
468 #####################################################################
469
470 # Add needed subdirs - the order is important, since src needs some vars set by other dirs
471 add_subdirectory(data)
472 add_subdirectory(icons)
473 add_subdirectory(pics)
474 add_subdirectory(po)
475
476 # Set up and display feature summary
477 #####################################################################
478
479 feature_summary(WHAT ALL
480                 INCLUDE_QUIET_PACKAGES
481                 FATAL_ON_MISSING_REQUIRED_PACKAGES
482 )
483
484 # Finally, compile the sources
485 # We want this after displaying the feature summary to avoid ugly
486 # CMake backtraces in case a required Qt5 module is missing
487 #####################################################################
488
489 add_subdirectory(src)
490
491 # Build tests if so desired
492 if (BUILD_TESTING)
493     add_subdirectory(tests)
494 endif()