Fix Qt resource handling
[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 2.8.9)
10 project(QuasselIRC)
11
12 # Versions
13 set(QUASSEL_MAJOR  0)
14 set(QUASSEL_MINOR 11)
15 set(QUASSEL_PATCH  0)
16 set(QUASSEL_VERSION_STRING "0.11-pre")
17
18 # Tell CMake about or own modules
19 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
20
21 # General conveniences
22 set(CMAKE_AUTOMOC ON)
23 set(CMAKE_INCLUDE_CURRENT_DIR ON)
24
25 # Include various CMake modules...
26 include(CMakePushCheckState)
27 include(CheckFunctionExists)
28 include(CheckIncludeFile)
29 include(CheckCXXSourceCompiles)
30 include(CMakeDependentOption)
31 include(FeatureSummary)
32
33 # ... and our own stuff
34 include(QuasselCompileSettings)
35 include(QuasselMacros)
36
37
38 # Options and variables that can be set on the command line
39 #####################################################################
40
41 # First, choose a Qt version. We support USE_QT4 and USE_QT5; if neither is set, prefer Qt4 for now
42 option(USE_QT5 "Enable support for Qt5 (disables KDE integration)" OFF)
43 if (USE_QT4) # takes precedence
44     set(USE_QT5 OFF)
45 else()
46     if (NOT USE_QT5)
47         set(USE_QT4 ON)
48     endif()
49 endif()
50
51 # Select the binaries to build
52 option(WANT_CORE     "Build the core (server) binary"           ON)
53 option(WANT_QTCLIENT "Build the client-only binary"             ON)
54 option(WANT_MONO     "Build the monolithic (all-in-one) binary" ON)
55 add_feature_info(WANT_CORE WANT_CORE "Build the core (server) binary")
56 add_feature_info(WANT_QTCLIENT WANT_QTCLIENT "Build the client-only binary (requires a core to connect to)")
57 add_feature_info(WANT_MONO WANT_MONO "Build the monolithic (all-in-one) binary")
58
59 # Whether to enable KDE integration (pulls in kdelibs and friends as a dependency); requires Qt4 for now
60 cmake_dependent_option(WITH_KDE "KDE4 integration" OFF "USE_QT4" OFF)
61 add_feature_info(WITH_KDE WITH_KDE "Enable KDE4 integration")
62
63 cmake_dependent_option(WITH_OXYGEN "Install Oxygen icon set (usually shipped with KDE)" ON "NOT WITH_KDE" OFF)
64 if (NOT WITH_KDE)
65     add_feature_info(WITH_OXYGEN WITH_OXYGEN "Install Oxygen icon set")
66 endif()
67
68 # For this, the feature info is added after we know if QtWebkit is installed
69 option(WITH_WEBKIT "WebKit support (for link previews)" ON)
70
71 if (APPLE)
72     # Notification Center is only available in > 10.8, which is Darwin v12
73     if (CMAKE_SYSTEM_VERSION VERSION_GREATER "11.9.9")
74         option(WITH_NOTIFICATION_CENTER "OS X Notification Center support" ON)
75         add_feature_info(WITH_NOTIFICATION_CENTER WITH_NOTIFICATION_CENTER "Use the OS X Notification Center")
76     endif()
77 endif()
78
79 # Always embed on Windows, OSX or for a static build; never embed when enabling KDE integration
80 set(EMBED_DEFAULT OFF)
81 if (STATIC OR WIN32 OR APPLE)
82     set(EMBED_DEFAULT ON)
83 endif()
84 cmake_dependent_option(EMBED_DATA "Embed icons and translations into the binaries instead of installing them" ${EMBED_DEFAULT}
85                                    "NOT STATIC;NOT WIN32;NOT WITH_KDE" ${EMBED_DEFAULT})
86 if (NOT EMBED_DEFAULT)
87     add_feature_info(EMBED_DATA EMBED_DATA "Embed icons and translations in the binaries instead of installing them")
88 endif()
89
90 # The following options are not for end-user consumption, so don't list them in the feature summary
91 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)
92
93 # Handle with care
94 set(QT_PATH "" CACHE PATH "Path to a Qt4 installation to use instead of the system Qt (e.g. for static builds)")
95
96 # 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)
97 cmake_dependent_option(STATIC      "Enable static building (not supported)" OFF "NOT WITH_KDE" OFF)
98
99 # For static builds, arbitrary extra libs might need to be linked
100 # Define a comma-separated list here
101 # e.g. for pgsql, we need -DLINK_EXTRA=pq;crypt
102 set(LINK_EXTRA "" CACHE STRING "Semicolon-separated list of libraries to be linked")
103 if (LINK_EXTRA)
104     string(REPLACE "," ";" LINK_EXTRA ${LINK_EXTRA})
105     link_libraries(${LINK_EXTRA})
106 endif()
107
108
109 # Simplify later checks
110 #####################################################################
111
112 if (WANT_MONO OR WANT_QTCLIENT)
113     set(BUILD_GUI true)
114 endif()
115 if (WANT_MONO OR WANT_CORE)
116     set(BUILD_CORE true)
117 endif()
118
119
120 # Set up Qt
121 #####################################################################
122
123 if (USE_QT5)
124     message(STATUS "Building for Qt5...")
125     set(QT_MIN_VERSION "5.2.0")
126     add_definitions(-DHAVE_QT5)
127 else()
128     message(STATUS "Building for Qt4...")
129     if (BUILD_GUI)
130         set(QT_MIN_VERSION "4.6.0")
131     else()
132         set(QT_MIN_VERSION "4.4.0")
133     endif()
134
135     # Select a Qt installation here, if you don't want to use system Qt
136     if(QT_PATH)
137         # FindQt4 will look for the qmake binary in $PATH, so we just prepend QT_PATH
138         set(ENV{PATH} ${QT_PATH}/bin:$ENV{PATH})
139     endif()
140 endif()
141
142 # Find package dependencies
143 #
144 # Note that you can forcefully disable optional packages
145 # using -DCMAKE_DISABLE_FIND_PACKAGE_<PkgName>=TRUE
146 #####################################################################
147
148 if(USE_QT5)
149     find_package(Qt5Core ${QT_MIN_VERSION} QUIET)
150     set_package_properties(Qt5Core PROPERTIES TYPE REQUIRED
151         URL "http://qt.digia.com"
152         DESCRIPTION "contains core functionality for Qt"
153     )
154     find_package(Qt5Network QUIET)
155     set_package_properties(Qt5Network PROPERTIES TYPE REQUIRED
156         DESCRIPTION "the network module for Qt5"
157     )
158
159     if (BUILD_GUI)
160         find_package(Qt5Gui QUIET)
161         set_package_properties(Qt5Gui PROPERTIES TYPE REQUIRED
162             DESCRIPTION "the GUI module for Qt5"
163         )
164         find_package(Qt5Widgets QUIET)
165         set_package_properties(Qt5Widgets PROPERTIES TYPE REQUIRED
166             DESCRIPTION "the widgets module for Qt5"
167         )
168
169         find_package(Qt5DBus QUIET)
170         set_package_properties(Qt5DBus PROPERTIES TYPE RECOMMENDED
171             URL "http://qt.digia.com"
172             DESCRIPTION "D-Bus support for Qt5"
173             PURPOSE     "Needed for supporting D-Bus-based notifications and tray icon, used by most modern desktop environments"
174         )
175         if (Qt5DBus_FOUND)
176             find_package(dbusmenu-qt5 QUIET CONFIG)
177             set_package_properties(dbusmenu-qt5 PROPERTIES TYPE RECOMMENDED
178                 URL "https://launchpad.net/libdbusmenu-qt"
179                 DESCRIPTION "a library implementing the DBusMenu specification"
180                 PURPOSE     "Required for having a context menu for the D-Bus-based tray icon"
181             )
182         endif()
183
184         find_package(Phonon4Qt5 QUIET)
185         set_package_properties(Phonon4Qt5 PROPERTIES TYPE RECOMMENDED
186             URL "https://projects.kde.org/projects/kdesupport/phonon"
187             DESCRIPTION "a multimedia abstraction library"
188             PURPOSE     "Required for audio notifications"
189         )
190         
191         find_package(LibsnoreQt5 QUIET)
192         set_package_properties(LibsnoreQt5 PROPERTIES TYPE OPTIONAL
193             URL "https://github.com/TheOneRing/Snorenotify"
194             DESCRIPTION "a cross-platform notification framework"
195             PURPOSE     "Enable support for the snorenotify framework"
196         )
197
198         if (WITH_WEBKIT)
199             find_package(Qt5WebKit QUIET)
200             set_package_properties(Qt5WebKit PROPERTIES TYPE RECOMMENDED
201                 URL "http://qt.digia.com"
202                 DESCRIPTION "a WebKit implementation for Qt"
203                 PURPOSE     "Needed for displaying previews for URLs in chat"
204             )
205             if (Qt5WebKit_FOUND)
206                 find_package(Qt5WebKitWidgets QUIET)
207                 set_package_properties(Qt5WebKitWidgets PROPERTIES TYPE RECOMMENDED
208                     URL "http://qt.digia.com"
209                     DESCRIPTION "widgets for Qt's WebKit implementation"
210                     PURPOSE     "Needed for displaying previews for URLs in chat"
211                 )
212             endif()
213         endif()
214         add_feature_info("WITH_WEBKIT, QtWebKit and QtWebKitWidgets modules" Qt5WebKitWidgets_FOUND "Support showing previews for URLs in chat")
215
216     endif(BUILD_GUI)
217     if (BUILD_CORE)
218         find_package(Qt5Script QUIET)
219         set_package_properties(Qt5Script PROPERTIES TYPE REQUIRED
220             DESCRIPTION "provides scripting support for Qt5"
221         )
222         find_package(Qt5Sql QUIET)
223         set_package_properties(Qt5Sql PROPERTIES TYPE REQUIRED
224             DESCRIPTION "the database support module for Qt5"
225         )
226
227         # While QCA2 seems to support Qt5, it is not actually co-installable or distinguishable from the Qt4 version...
228         # In order to avoid linking against the Qt4 version (which is probably the one installed), disable this for now
229         #find_package(QCA2 QUIET)
230         #set_package_properties(QCA2 PROPERTIES TYPE RECOMMENDED
231         #    URL "https://projects.kde.org/projects/kdesupport/qca"
232         #    DESCRIPTION "Qt Cryptographic Architecture"
233         #    PURPOSE "Required for encryption support"
234         #)
235
236     endif(BUILD_CORE)
237
238     find_package(Qt5LinguistTools QUIET)
239     set_package_properties(Qt5LinguistTools PROPERTIES TYPE RECOMMENDED
240                            DESCRIPTION "contains tools for handling translation files"
241                            PURPOSE "Required for having translations"
242     )
243     # Qt5 does not define a target for lconvert, so we need to find it ourselves
244     if (Qt5LinguistTools_FOUND)
245         if (NOT TARGET Qt5::lconvert AND TARGET Qt5::lrelease)
246             get_target_property(_lrelease_location Qt5::lrelease LOCATION)
247             get_filename_component(_lrelease_path ${_lrelease_location} PATH)
248             find_program(QT_LCONVERT_EXECUTABLE NAMES lconvert-qt5 lconvert PATHS ${_lrelease_path} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
249         endif()
250         # Compatibility with the Qt4 variables
251         set (QT_LRELEASE_EXECUTABLE ${Qt5_LRELEASE_EXECUTABLE})
252         set (QT_LUPDATE_EXECUTABLE ${Qt5_LUPDATE_EXECUTABLE})
253     endif()
254
255 else(USE_QT5)
256     find_package(Qt4 ${QT_MIN_VERSION} QUIET REQUIRED)
257
258     if (BUILD_GUI)
259         add_feature_info("QtDBus module" QT_QTDBUS_FOUND "Needed for supporting D-Bus-based notifications and tray icon, used by most modern desktop environments")
260         if (QT_QTDBUS_FOUND)
261             find_package(dbusmenu-qt QUIET CONFIG)
262             set_package_properties(dbusmenu-qt PROPERTIES TYPE RECOMMENDED
263                 URL "https://launchpad.net/libdbusmenu-qt"
264                 DESCRIPTION "a library implementing the DBusMenu specification"
265                 PURPOSE     "Required for having a context menu for the D-Bus-based tray icon"
266             )
267         endif()
268
269         if (WITH_WEBKIT AND QT_QTWEBKIT_FOUND)
270             set(HAVE_WEBKIT true)
271         endif()
272         add_feature_info("WITH_WEBKIT and QtWebKit module" HAVE_WEBKIT "Support showing previews for URLs in chat")
273
274         if (WITH_KDE)
275             # KDE has overzealous CFLAGS making miniz not compile, so save our old flags
276             set(_cflags ${CMAKE_C_FLAGS})
277             find_package(KDE4 4.4 QUIET)
278             set_package_properties(KDE4 PROPERTIES TYPE REQUIRED
279                 URL "http://www.kde.org"
280                 DESCRIPTION "a world-class desktop environment"
281                 PURPOSE "Enables various bits for improving integration with KDE"
282             )
283             set(CMAKE_C_FLAGS ${_cflags})
284
285         else(WITH_KDE)
286             find_package(Phonon QUIET)
287             set_package_properties(Phonon PROPERTIES TYPE RECOMMENDED
288                 URL "https://projects.kde.org/projects/kdesupport/phonon"
289                 DESCRIPTION "a multimedia abstraction library"
290                 PURPOSE     "Required for audio notifications"
291             )
292
293             find_package(Libsnore QUIET)
294             set_package_properties(Libsnore PROPERTIES TYPE OPTIONAL
295                 URL "https://github.com/TheOneRing/Snorenotify"
296                 DESCRIPTION "a cross-platform notification framework"
297                 PURPOSE     "Enable support for the snorenotify framework"
298             )
299         endif(WITH_KDE)
300
301         find_package(IndicateQt QUIET)
302         set_package_properties(IndicateQt PROPERTIES TYPE OPTIONAL
303             URL "https://launchpad.net/libindicate-qt/"
304             DESCRIPTION "a library to raise flags on DBus for other components of the desktop to pick up and visualize"
305             PURPOSE     "Provides integration into the Ayatana notification system used by e.g. Ubuntu"
306         )
307
308     endif(BUILD_GUI)
309     if (BUILD_CORE)
310
311         find_package(QCA2 QUIET)
312         set_package_properties(QCA2 PROPERTIES TYPE RECOMMENDED
313             URL "https://projects.kde.org/projects/kdesupport/qca"
314             DESCRIPTION "Qt Cryptographic Architecture"
315             PURPOSE     "Required for encryption support"
316         )
317
318
319     endif()
320
321     # Qt4 does not consider lconvert relevant, so they don't support finding it...
322     # Rather than shipping hacked buildsys files, let's just infer the path from lrelease
323     if (QT_LRELEASE_EXECUTABLE)
324         get_filename_component(_lrelease_path ${QT_LRELEASE_EXECUTABLE} PATH)
325         find_program(QT_LCONVERT_EXECUTABLE NAMES lconvert-qt4 lconvert PATHS ${_lrelease_path} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
326     endif()
327 endif()
328
329
330 # Non-Qt-based packages
331
332 # zlib for compression, however we can always fall back to miniz
333 find_package(ZLIB QUIET)
334 set_package_properties(ZLIB PROPERTIES TYPE RECOMMENDED
335     URL "http://www.zlib.net"
336     DESCRIPTION "a popular compression library"
337     PURPOSE     "Use the most common library for protocol compression, instead of the bundled miniz implementation"
338 )
339
340
341 if (NOT WIN32)
342     # Execinfo is needed for generating backtraces
343     find_package(ExecInfo QUIET)
344     set_package_properties(ExecInfo PROPERTIES TYPE OPTIONAL
345         DESCRIPTION "a library for inspecting backtraces"
346         PURPOSE "Used for generating backtraces in case of a crash"
347     )
348 endif()
349
350
351 # Various checks
352 #####################################################################
353
354 if (NOT ZLIB_FOUND)
355     message(STATUS "zlib NOT found, using bundled miniz for compression")
356     if (${CMAKE_SIZEOF_VOID_P} EQUAL 4)
357         message(STATUS "WARNING: This may be slow on 32 bit systems!")
358     endif()
359 endif()
360
361 if (KDE4_FOUND)
362     # We always use external icons for KDE4 support, since we use its iconloader rather than our own
363     set(EMBED_DATA OFF)
364
365     # Better have the compile flags global, even for the core, to avoid problems with linking the mono client
366     add_definitions(-DHAVE_KDE ${KDE4_DEFINITIONS})
367 endif()
368
369 # Check for SSL support in Qt
370 # As there's no easy way to get Qt's configuration in particular for Qt5, let's just compile
371 # a small test program checking the defines. This works for both Qt4 and Qt5.
372 cmake_push_check_state(RESET)
373 if (Qt5_POSITION_INDEPENDENT_CODE)
374     set(CMAKE_POSITION_INDEPENDENT_CODE ON)
375 endif()
376 set(CMAKE_REQUIRED_INCLUDES ${QT_INCLUDES} ${Qt5Core_INCLUDE_DIRS})
377 check_cxx_source_compiles("
378     #include \"qglobal.h\"
379     #if defined QT_NO_OPENSSL || defined QT_NO_SSL
380     #  error \"No SSL support\"
381     #endif
382     int main() {}"
383     HAVE_SSL)
384 cmake_pop_check_state()
385
386 if (HAVE_SSL)
387     add_definitions(-DHAVE_SSL)
388 endif()
389 add_feature_info("SSL support in Qt" HAVE_SSL "Use secure network connections")
390
391 # Check for syslog support
392 if (NOT WIN32)
393     check_include_file(syslog.h HAVE_SYSLOG)
394     add_feature_info("syslog.h" HAVE_SYSLOG "Provide support for logging to the syslog")
395 endif()
396
397 add_feature_info("Qt Linguist Tools" QT_LCONVERT_EXECUTABLE "Translation support for Quassel")
398
399 # Various settings
400 ##################
401
402 # needed to compile with mingw without kde
403 if (MINGW AND NOT KDE4_FOUND)
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 # Now set up install locations; those are set by KDE if integration is enabled
411 if(NOT KDE4_FOUND)
412   if(WIN32)
413     set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX} CACHE FILEPATH "Install path for binaries")
414     set(DATA_INSTALL_DIR $ENV{APPDATA}/quassel-irc.org/share/apps CACHE FILEPATH "Install path for data files")
415     set(ICON_INSTALL_DIR $ENV{APPDATA}/quassel-irc.org/share/icons CACHE FILEPATH "Global icon install path")
416     set(XDG_APPS_INSTALL_DIR $ENV{APPDATA}/quassel-irc.org/share/applications CACHE FILEPATH "Install path for .desktop files")
417   else(WIN32)
418     set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin CACHE FILEPATH "Install path for binaries")
419     set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/apps CACHE FILEPATH "Install path for data files")
420     set(ICON_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/icons CACHE FILEPATH "Global icon install path")
421     set(XDG_APPS_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/applications CACHE FILEPATH "Install path for .desktop files")
422   endif(WIN32)
423 endif()
424
425 if(EMBED_DATA)
426   message(STATUS "Embedding data files into the binary")
427 else(EMBED_DATA)
428   message(STATUS "Installing data files separately")
429 endif(EMBED_DATA)
430
431 # RPATH needs to be set correctly
432 # Do this down here, since otherwise KDE wants to handle it itself, and fails
433 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH 1)
434 set(CMAKE_BUILD_WITH_INSTALL_RPATH 1)
435
436 # Set global buildflags
437 # This is very much non-portable, so don't use -DSTATIC until you know what
438 # you do.
439 if(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
440   set(CMAKE_CXX_FLAGS "-static-libgcc ${CMAKE_CXX_FLAGS}")
441   link_directories(${CMAKE_BINARY_DIR}/staticlibs) # override dynamic libs
442   if(HAVE_SSL)
443     set(QUASSEL_SSL_LIBRARIES ssl crypto)  # these miss in static builds
444   endif(HAVE_SSL)
445 endif(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
446
447 if(WIN32)
448   link_libraries(imm32 winmm dbghelp Secur32)  # missing by default :/
449   if(MSVC)
450     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DNOMINMAX")
451     set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBUGINFO "/debug /INCREMENTAL:YES /NODEFAULTLIB:libcmt /DEFAULTLIB:msvcrt")
452     set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/debug /INCREMENTAL:YES /NODEFAULTLIB:libcmt")
453     set(CMAKE_EXE_LINKER_FLAGS_DEBUGFULL "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
454     link_libraries(Version dwmapi shlwapi)
455     if(USE_QT5)
456       set(QT_QTMAIN_LIBRARY Qt5::WinMain)
457     endif(USE_QT5)
458   endif(MSVC)
459   if(HAVE_SSL AND STATIC)
460      find_package(OpenSSL REQUIRED)
461      link_libraries(${OPENSSL_LIBRARIES} ${OPENSSL_EAY_LIBRARIES})
462   endif(HAVE_SSL AND STATIC)
463 endif(WIN32)
464
465 if(INDICATEQT_FOUND)
466   add_definitions(-DXDG_APPS_INSTALL_DIR=${XDG_APPS_INSTALL_DIR})
467 endif()
468
469 if(NOT WIN32)
470   check_function_exists(umask HAVE_UMASK)
471   if(HAVE_UMASK)
472     add_definitions(-DHAVE_UMASK)
473   endif(HAVE_UMASK)
474 endif(NOT WIN32)
475
476 # Generate version information from Git
477 include(GetGitRevisionDescription)
478 get_git_head_revision(GIT_REFSPEC GIT_HEAD)
479 git_describe(GIT_DESCRIBE --long)
480
481 # Sanitize things if we're not in a Git repo
482 if(NOT GIT_HEAD OR NOT GIT_DESCRIBE)
483     set(GIT_HEAD "")
484     set(GIT_DESCRIBE "")
485 endif()
486
487 configure_file(version.h.in ${CMAKE_BINARY_DIR}/version.h @ONLY)
488
489 # These variables will be added to the main targets (CORE, QTCLIENT, MONO)
490 set(COMMON_DEPS ${RC_WIN32})
491 set(CORE_DEPS )
492 set(CLIENT_DEPS )
493
494 # Add needed subdirs - the order is important, since src needs some vars set by other dirs
495 add_subdirectory(data)
496 add_subdirectory(icons)
497 add_subdirectory(pics)
498 add_subdirectory(po)
499
500 # Set up and display feature summary
501 #####################################################################
502
503 feature_summary(WHAT ALL
504                 INCLUDE_QUIET_PACKAGES
505                 FATAL_ON_MISSING_REQUIRED_PACKAGES
506 )
507
508 # Finally, compile the sources
509 # We want this after displaying the feature summary to avoid ugly
510 # CMake backtraces in case a required Qt5 modules misses
511 #####################################################################
512
513 add_subdirectory(src)