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