Always embed pics/* until we actually support loading from external files
[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   set(WITH_KDE OFF CACHE BOOL "Static building with KDE is not supported")
70 endif(STATIC)
71
72 if(WIN32)
73   # We don't support separately installed resources yet on Win32
74   set(EMBED_DATA ON)
75 endif(WIN32)
76
77 # Enable various flags on gcc
78 if(CMAKE_COMPILER_IS_GNUCXX)
79   # Let's just hope that all gccs support these options and skip the tests...
80   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ansi -Wall -Wextra -Wnon-virtual-dtor")
81 endif(CMAKE_COMPILER_IS_GNUCXX)
82
83 set(QT_MIN_VERSION "4.4.0")
84
85 if(APPLE AND DEPLOY)
86   set(CMAKE_OSX_ARCHITECTURES "i386;ppc")
87   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.4")
88   set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.4u.sdk/")
89   add_definitions(-DMAC_10_4_SDK)
90 endif(APPLE AND DEPLOY)
91
92 # Execinfo is needed for generating backtraces
93 find_package(ExecInfo)
94 if(EXECINFO_FOUND)
95   add_definitions(-DHAVE_EXECINFO)
96   include_directories(${EXECINFO_INCLUDES})
97   link_libraries(${EXECINFO_LIBRARIES})
98 endif(EXECINFO_FOUND)
99
100 # Select a Qt installation here, if you don't want to use system Qt
101 if(QT)
102   # FindQt4 will look for the qmake binary in $PATH, so we just prepend the Qt dir
103   set(ENV{PATH} ${QT}/bin:$ENV{PATH})
104 endif(QT)
105
106 # Now that we have the correct $PATH, lets find Qt!
107 find_package(Qt4 REQUIRED)
108
109 set(QT_DONT_USE_QTGUI 1)
110 include(${QT_USE_FILE})
111 include_directories(${QT_INCLUDES})
112
113 # Setup OpenSSL
114 if(WITH_OPENSSL)
115   find_package(OpenSSL)
116 else(WITH_OPENSSL)
117   message(STATUS "Disabling OpenSSL support")
118 endif(WITH_OPENSSL)
119
120 if(OPENSSL_FOUND)
121   if(NOT QT_DEFINITIONS MATCHES "QT_NO_OPENSSL")
122     message(STATUS "Found OpenSSL support in Qt")
123     add_definitions(-DHAVE_SSL)
124     set(HAVE_SSL true)
125     set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_SSL)
126   else(NOT QT_DEFINITIONS MATCHES "QT_NO_OPENSSL")
127     message(STATUS "No OpenSSL support found in Qt, disabling")
128   endif(NOT QT_DEFINITIONS MATCHES "QT_NO_OPENSSL")
129 else(OPENSSL_FOUND)
130   add_definitions(-DQT_NO_OPENSSL)
131 endif(OPENSSL_FOUND)
132
133 # Setup D-Bus support
134 if(WITH_DBUS)
135   if(QT_QTDBUS_FOUND)
136     message(STATUS "Found QtDBus, enabling D-Bus support")
137     add_definitions(-DHAVE_DBUS)
138     set(LINK_DBUS DBUS)
139     set(HAVE_DBUS true)
140     set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_DBUS)
141   else(QT_QTDBUS_FOUND)
142     message(STATUS "QtDBus not found, disabling D-Bus support")
143   endif(QT_QTDBUS_FOUND)
144 else(WITH_DBUS)
145   message(STATUS "Disabling D-Bus support")
146 endif(WITH_DBUS)
147
148 # Setup QtWebKit support
149 if(WITH_WEBKIT)
150   if(QT_QTWEBKIT_FOUND)
151     message(STATUS "Found QtWebKit, enabling WebKit support")
152     add_definitions(-DHAVE_WEBKIT)
153     set(LINK_WEBKIT WEBKIT)
154     set(HAVE_WEBKIT true)
155     set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_WEBKIT)
156   else(QT_QTWEBKIT_FOUND)
157     message(STATUS "QtWebKit not found, disabling WebKit support")
158   endif(QT_QTWEBKIT_FOUND)
159 else(WITH_WEBKIT)
160   message(STATUS "Disabling WebKit support")
161 endif(WITH_WEBKIT)
162
163 # Setup KDE4 support
164 if(WITH_KDE)
165   find_package(KDE4)
166   if(KDE4_FOUND)
167     message(STATUS "Enabling KDE4 integration")
168     include_directories(${KDE4_INCLUDES})
169     add_definitions(-DHAVE_KDE ${KDE4_DEFINITIONS})
170     set(HAVE_KDE 1)
171     set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_KDE)
172     set(QUASSEL_KDE_LIBRARIES ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBRARY} knotifyconfig)
173     # We always use external icons for KDE4 support, since we use its iconloader rather than our own
174     set(EMBED_DATA OFF)
175   else(KDE4_FOUND)
176     message(STATUS "KDE4 not found, disabling KDE integration")
177   endif(KDE4_FOUND)
178 else(WITH_KDE)
179   message(STATUS "Disabling KDE4 integration")
180 endif(WITH_KDE)
181
182 # Setup Phonon support - we only need this if we don't have or want KDE4
183 if(NOT HAVE_KDE)
184   if(WITH_PHONON)
185     find_package(Phonon)
186     if(PHONON_FOUND)
187       message(STATUS "Enabling Phonon support")
188       add_definitions(-DHAVE_PHONON)
189       set(HAVE_PHONON true)
190       set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_PHONON)
191     else(PHONON_FOUND)
192       message(STATUS "Phonon not found, disabling audio notifications")
193     endif(PHONON_FOUND)
194   else(WITH_PHONON)
195     message(STATUS "Disabling Phonon support")
196   endif(WITH_PHONON)
197 endif(NOT HAVE_KDE)
198
199 # Now set up install locations; those are set by KDE if integration is enabled
200 if(NOT HAVE_KDE)
201   if(WIN32)
202     set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX} CACHE FILEPATH "Install path for binaries")
203     set(DATA_INSTALL_DIR $ENV{APPDATA}/quassel-irc.org/share/apps CACHE FILEPATH "Install path for data files")
204     set(ICON_INSTALL_DIR $ENV{APPDATA}/quassel-irc.org/share/icons CACHE FILEPATH "Global icon install path")
205     set(XDG_APPS_INSTALL_DIR $ENV{APPDATA}/quassel-irc.org/share/applications CACHE FILEPATH "Install path for .desktop files")
206   else(WIN32)
207     set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin CACHE FILEPATH "Install path for binaries")
208     set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/apps CACHE FILEPATH "Install path for data files")
209     set(ICON_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/icons CACHE FILEPATH "Global icon install path")
210     set(XDG_APPS_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/applications CACHE FILEPATH "Install path for .desktop files")
211   endif(WIN32)
212 endif(NOT HAVE_KDE)
213
214 # RPATH needs to be set correctly
215 # Do this down here, since otherwise KDE wants to handle it itself, and fails
216 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH 1)
217 set(CMAKE_BUILD_WITH_INSTALL_RPATH 1)
218
219 # Set global buildflags
220 # This is very much non-portable, so don't use -DSTATIC until you know what
221 # you do.
222 if(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
223   set(CMAKE_CXX_FLAGS "-static-libgcc ${CMAKE_CXX_FLAGS}")
224   link_directories(${CMAKE_BINARY_DIR}/staticlibs) # override dynamic libs
225   if(HAVE_SSL)
226     set(QUASSEL_SSL_LIBRARIES ssl crypto)  # these miss in static builds
227   endif(HAVE_SSL)
228 endif(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
229
230 if(WIN32)
231   #if(STATIC)
232   link_libraries(imm32 winmm dbghelp)  # missing by default :/
233   #endif(STATIC)
234   if(HAVE_SSL)
235      link_libraries(${OPENSSL_LIBRARIES} libeay32MD)
236   endif(HAVE_SSL)
237 endif(WIN32)
238
239 if(WIN32)
240   set(RC_WIN32 ../pics/win32.rc)  # for app icons on windows
241 endif(WIN32)
242
243 # We need to create a version.gen
244 # For this, we create our genversion binary and make sure it is run every time.
245 add_executable(genversion ${CMAKE_SOURCE_DIR}/src/common/genversion.cpp)
246 target_link_libraries(genversion ${QT_LIBRARIES} ${QT_CORE_LIB_DEPENDENCIES})
247
248 get_target_property(GENVERSION_EXECUTABLE genversion LOCATION)
249 add_custom_target(genversion_run ALL ${GENVERSION_EXECUTABLE}
250                   ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/src/version.gen)
251 add_dependencies(genversion_run genversion)
252
253 # These variables will be added to the main targets (CORE, QTCLIENT, MONO)
254 set(COMMON_DEPS ${RC_WIN32})
255 set(CORE_DEPS )
256 set(CLIENT_DEPS )
257
258 # Add needed subdirs - the order is important, since src needs some vars set by other dirs
259 add_subdirectory(data)
260 add_subdirectory(icons)
261 add_subdirectory(pics)
262 add_subdirectory(i18n)
263 add_subdirectory(src)