Introduce Clickable::activate() to put handling clicks in a single place
[quassel.git] / CMakeLists.txt
1 # This is the cmake-based build system for Quassel IRC.
2 #
3 # You may pass various options to cmake:
4 # -DWANT_(CORE|QTCLIENT|MONO)=(ON|OFF)
5 #                     : select binaries to build
6 # -DWITH_OPENSSL=OFF  : Disable OpenSSL support
7 # -DWITH_DBUS=OFF     : Disable D-Bus support (dbus notifications)
8 # -DWITH_WEBKIT=OFF   : Disable WebKit support (link previews)
9 # -DWITH_PHONON=OFF   : Disable Phonon support (audio notifications)
10 # -DWITH_KDE=ON       : Enable KDE4 support
11 #
12 # -DEMBED_DATA=ON     : Embed all data files in icons the binary, rather than installing them separately
13 #
14 # -DQT=/path/to/qt    : Choose a Qt4 installation to use instead of the system Qt4
15 # -DSTATIC=ON         : Enable static building of Quassel. Use with care.
16 # -DDEPLOY=ON         : Mac OS X only. Use only for creating Quassel Packages!
17 #
18 # NOTE: You should remove CMakeCache.txt if you plan to change any of these values!
19
20 project(QuasselIRC)
21
22 cmake_minimum_required(VERSION 2.6.0 FATAL_ERROR)
23
24 if(COMMAND cmake_policy)
25    cmake_policy(SET CMP0003 NEW)
26 endif(COMMAND cmake_policy)
27
28 # Use our own (well, and KDE's) version of some modules
29 # In particular cmake's own FindQt4 and FindOpenSSL are quite buggy
30 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
31 include(QuasselMacros)
32
33 # Various options and variables that can be set on the command line
34 option(WANT_CORE     "Build the core (server) binary"           ON)
35 option(WANT_QTCLIENT "Build the Qt4 GUI client binary"          ON)
36 option(WANT_MONO     "Build the monolithic (all-in-one) binary" ON)
37
38 option(WITH_OPENSSL  "Enable OpenSSL support if present on the system"  ON)
39 option(WITH_DBUS     "Enable D-Bus support if present on the system"    ON)
40 option(WITH_WEBKIT   "Enable WebKit support (for link previews)"        ON)
41 option(WITH_PHONON   "Enable Phonon support (for audio notifications)"  ON)
42 option(WITH_KDE      "Enable KDE4 integration"                          OFF)
43
44 # We use icon paths from KDE 4.3 trunk, which are partially invalid on older and possibly
45 # even on newer KDE versions. Do not disable this unless you are sure that your Quassel will
46 # run on a matching KDE version only.
47 option(WITH_OXYGEN   "Install Oxygen icons. Heavily recommended unless you use KDE 4.3" ON)
48
49 option(STATIC        "Enable static building (might not be portable)" OFF)
50
51 if(APPLE)
52   option(DEPLOY        "Mac OS X only! Adds required libs to bundle resources and create a dmg. Note: requires Qt to be built with 10.4u SDK" OFF)
53 endif(APPLE)
54
55 # Default to embedding data in the static case
56 if(STATIC OR WIN32)
57   set(EMBED_DEFAULT ON)
58 else(STATIC OR WIN32)
59   set(EMBED_DEFAULT ON) # should be OFF as soon as everything works
60 endif(STATIC OR WIN32)
61
62 option(EMBED_DATA    "Embed all data files in the binary (rather than installing them separately)"   ${EMBED_DEFAULT})
63
64 set(QT "" CACHE STRING "Path to a Qt installation to use instead of the system Qt (e.g. for static builds)")
65 set(LINGUAS "" CACHE STRING "Comma-separated list of locales specifying languages that should be compiled")
66
67 # Some settings imply others
68 if(STATIC)
69   add_definitions(-DSTATIC)
70   set(WITH_KDE OFF CACHE BOOL "Static building with KDE is not supported")
71 endif(STATIC)
72
73 if(WIN32)
74   # We don't support separately installed resources yet on Win32
75   set(EMBED_DATA ON)
76 endif(WIN32)
77
78 # For static builds, arbitrary extra libs might need to be linked
79 # Define a comma-separated list here
80 # e.g. for pgsql, we need -DLINK_EXTRA=pq;crypt
81 set(LINK_EXTRA "" CACHE STRING "Semicolon-separated list of libraries to be linked")
82 if(LINK_EXTRA)
83   string(REPLACE "," ";" LINK_EXTRA ${LINK_EXTRA})
84   link_libraries(${LINK_EXTRA})
85 endif(LINK_EXTRA)
86
87 # Build Type
88 # We need to make sure it's not empty
89 # Supported: Release, RelWithDebugInfo, Debug, Debugfull
90
91 # On WIN32, only Release seems to work correctly (?)
92 if(WIN32)
93   set(DEFAULT_BUILD_TYPE "Release")
94 else(WIN32)
95   set(DEFAULT_BUILD_TYPE "RelWithDebugInfo")
96 endif(WIN32)
97
98 set(CMAKE_BUILD_TYPE ${DEFAULT_BUILD_TYPE} CACHE STRING "CMake Build Type")
99 if(NOT CMAKE_BUILD_TYPE)
100   set(CMAKE_BUILD_TYPE ${DEFAULT_BUILD_TYPE} CACHE STRING "CMake Build Type" FORCE)
101 endif(NOT CMAKE_BUILD_TYPE)
102
103 # Enable various flags on gcc
104 if(CMAKE_COMPILER_IS_GNUCXX)
105   # Let's just hope that all gccs support these options and skip the tests...
106   # -fno-strict-aliasing is needed apparently for Qt < 4.6
107   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ansi -Wall -Wextra -Wnon-virtual-dtor -fno-strict-aliasing")
108   set(CMAKE_CXX_FLAGS_RELWITHDEBUGINFO "-O2")
109   set(CMAKE_CXX_FLAGS_DEBUG "-g -fno-reorder-blocks -fno-schedule-insns -fno-inline")
110   set(CMAKE_CXX_FLAGS_DEBUGFULL "-g3")
111 endif(CMAKE_COMPILER_IS_GNUCXX)
112
113 if(WANT_MONO OR WANT_QTCLIENT)
114   set(QT_MIN_VERSION "4.4.1") # Client crashes often with 4.4.0
115 else(WANT_MONO OR WANT_QTCLIENT)
116   set(QT_MIN_VERSION "4.4.0")
117 endif(WANT_MONO OR WANT_QTCLIENT)
118
119 if(APPLE AND DEPLOY)
120   set(CMAKE_OSX_ARCHITECTURES "i386;ppc")
121   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.4")
122   set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.4u.sdk/")
123   add_definitions(-DMAC_10_4_SDK)
124 endif(APPLE AND DEPLOY)
125
126 # Execinfo is needed for generating backtraces
127 find_package(ExecInfo)
128 if(EXECINFO_FOUND)
129   add_definitions(-DHAVE_EXECINFO)
130   include_directories(${EXECINFO_INCLUDES})
131   link_libraries(${EXECINFO_LIBRARIES})
132 endif(EXECINFO_FOUND)
133
134 # Select a Qt installation here, if you don't want to use system Qt
135 if(QT)
136   # FindQt4 will look for the qmake binary in $PATH, so we just prepend the Qt dir
137   set(ENV{PATH} ${QT}/bin:$ENV{PATH})
138 endif(QT)
139
140 # Now that we have the correct $PATH, lets find Qt!
141 find_package(Qt4 REQUIRED)
142
143 set(QT_DONT_USE_QTGUI 1)
144 include(${QT_USE_FILE})
145 include_directories(${QT_INCLUDES})
146
147 # Setup OpenSSL
148 if(WITH_OPENSSL)
149   find_package(OpenSSL)
150 else(WITH_OPENSSL)
151   message(STATUS "Disabling OpenSSL support")
152 endif(WITH_OPENSSL)
153
154 if(OPENSSL_FOUND)
155   if(NOT QT_DEFINITIONS MATCHES "QT_NO_OPENSSL")
156     message(STATUS "Found OpenSSL support in Qt")
157     add_definitions(-DHAVE_SSL)
158     set(HAVE_SSL true)
159     set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_SSL)
160   else(NOT QT_DEFINITIONS MATCHES "QT_NO_OPENSSL")
161     message(STATUS "No OpenSSL support found in Qt, disabling")
162   endif(NOT QT_DEFINITIONS MATCHES "QT_NO_OPENSSL")
163 else(OPENSSL_FOUND)
164   add_definitions(-DQT_NO_OPENSSL)
165 endif(OPENSSL_FOUND)
166
167 # Setup D-Bus support
168 if(WITH_DBUS)
169   if(QT_QTDBUS_FOUND)
170     message(STATUS "Found QtDBus, enabling D-Bus support")
171     add_definitions(-DHAVE_DBUS)
172     set(LINK_DBUS DBUS)
173     set(HAVE_DBUS true)
174     set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_DBUS)
175   else(QT_QTDBUS_FOUND)
176     message(STATUS "QtDBus not found, disabling D-Bus support")
177   endif(QT_QTDBUS_FOUND)
178 else(WITH_DBUS)
179   message(STATUS "Disabling D-Bus support")
180 endif(WITH_DBUS)
181
182 # Setup QtWebKit support
183 if(WITH_WEBKIT)
184   if(QT_QTWEBKIT_FOUND)
185     message(STATUS "Found QtWebKit, enabling WebKit support")
186     add_definitions(-DHAVE_WEBKIT)
187     set(LINK_WEBKIT WEBKIT)
188     set(HAVE_WEBKIT true)
189     set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_WEBKIT)
190   else(QT_QTWEBKIT_FOUND)
191     message(STATUS "QtWebKit not found, disabling WebKit support")
192   endif(QT_QTWEBKIT_FOUND)
193 else(WITH_WEBKIT)
194   message(STATUS "Disabling WebKit support")
195 endif(WITH_WEBKIT)
196
197 # Setup KDE4 support
198 if(WITH_KDE)
199   find_package(KDE4)
200   if(KDE4_FOUND)
201     message(STATUS "Enabling KDE4 integration")
202     include_directories(${KDE4_INCLUDES})
203     add_definitions(-DHAVE_KDE ${KDE4_DEFINITIONS})
204     set(HAVE_KDE 1)
205     set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_KDE)
206     set(QUASSEL_KDE_LIBRARIES ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBRARY} knotifyconfig)
207     # We always use external icons for KDE4 support, since we use its iconloader rather than our own
208     set(EMBED_DATA OFF)
209   else(KDE4_FOUND)
210     message(STATUS "KDE4 not found, disabling KDE integration")
211   endif(KDE4_FOUND)
212 else(WITH_KDE)
213   message(STATUS "Disabling KDE4 integration")
214 endif(WITH_KDE)
215
216 # Setup Phonon support - we only need this if we don't have or want KDE4
217 if(NOT HAVE_KDE)
218   if(WITH_PHONON)
219     find_package(Phonon)
220     if(PHONON_FOUND)
221       message(STATUS "Enabling Phonon support")
222       add_definitions(-DHAVE_PHONON)
223       set(HAVE_PHONON true)
224       set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_PHONON)
225     else(PHONON_FOUND)
226       message(STATUS "Phonon not found, disabling audio notifications")
227     endif(PHONON_FOUND)
228   else(WITH_PHONON)
229     message(STATUS "Disabling Phonon support")
230   endif(WITH_PHONON)
231 endif(NOT HAVE_KDE)
232
233 # Now set up install locations; those are set by KDE if integration is enabled
234 if(NOT HAVE_KDE)
235   if(WIN32)
236     set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX} CACHE FILEPATH "Install path for binaries")
237     set(DATA_INSTALL_DIR $ENV{APPDATA}/quassel-irc.org/share/apps CACHE FILEPATH "Install path for data files")
238     set(ICON_INSTALL_DIR $ENV{APPDATA}/quassel-irc.org/share/icons CACHE FILEPATH "Global icon install path")
239     set(XDG_APPS_INSTALL_DIR $ENV{APPDATA}/quassel-irc.org/share/applications CACHE FILEPATH "Install path for .desktop files")
240   else(WIN32)
241     set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin CACHE FILEPATH "Install path for binaries")
242     set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/apps CACHE FILEPATH "Install path for data files")
243     set(ICON_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/icons CACHE FILEPATH "Global icon install path")
244     set(XDG_APPS_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/applications CACHE FILEPATH "Install path for .desktop files")
245   endif(WIN32)
246 endif(NOT HAVE_KDE)
247
248 # RPATH needs to be set correctly
249 # Do this down here, since otherwise KDE wants to handle it itself, and fails
250 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH 1)
251 set(CMAKE_BUILD_WITH_INSTALL_RPATH 1)
252
253 # Set global buildflags
254 # This is very much non-portable, so don't use -DSTATIC until you know what
255 # you do.
256 if(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
257   set(CMAKE_CXX_FLAGS "-static-libgcc ${CMAKE_CXX_FLAGS}")
258   link_directories(${CMAKE_BINARY_DIR}/staticlibs) # override dynamic libs
259   if(HAVE_SSL)
260     set(QUASSEL_SSL_LIBRARIES ssl crypto)  # these miss in static builds
261   endif(HAVE_SSL)
262 endif(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
263
264 if(WIN32)
265   link_libraries(imm32 winmm dbghelp Secur32)  # missing by default :/
266
267   if(HAVE_SSL)
268      link_libraries(${OPENSSL_LIBRARIES} libeay32MD)
269   endif(HAVE_SSL)
270 endif(WIN32)
271
272 # We need to create a version.gen
273 # For this, we create our genversion binary and make sure it is run every time.
274 add_executable(genversion ${CMAKE_SOURCE_DIR}/src/common/genversion.cpp)
275 target_link_libraries(genversion ${QT_LIBRARIES} ${QT_CORE_LIB_DEPENDENCIES})
276
277 get_target_property(GENVERSION_EXECUTABLE genversion LOCATION)
278 add_custom_target(genversion_run ALL ${GENVERSION_EXECUTABLE}
279                   ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/src/version.gen)
280 add_dependencies(genversion_run genversion)
281
282 # These variables will be added to the main targets (CORE, QTCLIENT, MONO)
283 set(COMMON_DEPS ${RC_WIN32})
284 set(CORE_DEPS )
285 set(CLIENT_DEPS )
286
287 # Add needed subdirs - the order is important, since src needs some vars set by other dirs
288 add_subdirectory(data)
289 add_subdirectory(icons)
290 add_subdirectory(pics)
291 add_subdirectory(i18n)
292 add_subdirectory(src)