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