Improvements in the build system
[quassel.git] / CMakeLists.txt
1 # This is the cmake-based build system for Quassel IRC.
2 # You may pass various options to cmake:
3 # -DWANT_(CORE|QTCLIENT|MONO)=(ON|OFF)
4 #                     : select binaries to build
5 # -DWITH_OPENSSL=OFF  : Disable OpenSSL support
6 # -DWITH_DBUS=OFF     : Disable D-Bus support (dbus notifications)
7 # -DWITH_WEBKIT=OFF   : Disable WebKit support (link previews)
8 # -DWITH_PHONON=OFF   : Disable Phonon support (audio notifications)
9 # -DWITH_KDE=ON       : Enable KDE4 support
10 # -DOXYGEN_ICONS=(Builtin|External)  : If "Builtin" (the default), compile our Oxygen Icon Theme subset into the binary
11 #                                    : If "External", we assume Oxygen is already installed on the system
12 # -DQUASSEL_ICONS=(Builtin|External) : If "Builtin" (the default), put our own icons into the binary
13 #                                    : If "External", we install our icons into $PREFIX/share/apps/quassel (UNIX only)
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 need to 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 FindQt4 and FindOpenSSL are quite buggy
30 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
31
32 # Various options and variables that can be set on the command line
33 option(WANT_CORE     "Build the core (server) binary"           ON)
34 option(WANT_QTCLIENT "Build the Qt4 GUI client binary"          ON)
35 option(WANT_MONO     "Build the monolithic (all-in-one) binary" ON)
36
37 option(WITH_OPENSSL  "Enable OpenSSL support if present on the system"  ON)
38 option(WITH_DBUS     "Enable D-Bus support if present on the system"    ON)
39 option(WITH_WEBKIT   "Enable WebKit support (for link previews)"        ON)
40 option(WITH_PHONON   "Enable Phonon support (for audio notifications)"  ON)
41 option(WITH_KDE      "Enable KDE4 integration"                          OFF)
42
43 option(STATIC        "Enable static building (might not be portable)" OFF)
44 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)
45 option(SPUTDEV       "Do not use!" OFF)
46
47 set(OXYGEN_ICONS "Builtin" CACHE STRING "Builtin: Compile Oxygen icons into the binary; External: Use system-installed Oxygen")
48 set(QUASSEL_ICONS "Builtin" CACHE STRING "Builtin: Compile Quassel icons into the binary; External: Install them separately")
49
50 set(QT "" CACHE STRING "Path to a Qt installation to use instead of the system Qt")
51 set(LINGUAS "" CACHE STRING "Space-separated List of locales specifying languages that should be compiled")
52
53 if(STATIC)
54   set(CMAKE_BUILD_TYPE Release)
55   set(OXYGEN_ICONS "Builtin")
56   set(QUASSEL_ICONS "Builtin")
57   set(WITH_KDE OFF)
58 endif(STATIC)
59
60 # Define install locations. Using variables will allow overriding this by the KDE macros later.
61 set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin)
62 set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/apps)
63 set(ICON_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/icons)
64 set(XDG_APPS_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/applications)
65
66 # Enable various flags on gcc
67 if(CMAKE_COMPILER_IS_GNUCXX)
68   # Let's just hope that all gccs support these options and skip the tests...
69   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ansi -Wall -Wextra -Wnon-virtual-dtor")
70 endif(CMAKE_COMPILER_IS_GNUCXX)
71
72 set(QT_MIN_VERSION "4.4.0")
73
74 if(APPLE AND DEPLOY)
75   set(CMAKE_OSX_ARCHITECTURES "i386;ppc")
76   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.4")
77   set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.4u.sdk/")
78   add_definitions(-DMAC_10_4_SDK)
79 endif(APPLE AND DEPLOY)
80
81 include(QuasselMacros)
82
83 # Execinfo is needed for generating backtraces
84 find_package(ExecInfo)
85 if(EXECINFO_FOUND)
86   add_definitions(-DHAVE_EXECINFO)
87   include_directories(${EXECINFO_INCLUDES})
88   link_libraries(${EXECINFO_LIBRARIES})
89 endif(EXECINFO_FOUND)
90
91 # Select a Qt installation here, if you don't want to use system Qt
92 if(QT)
93   # FindQt4 will look for the qmake binary in $PATH, so we just prepend the Qt dir
94   set(ENV{PATH} ${QT}/bin:$ENV{PATH})
95 endif(QT)
96
97 # Now that we have the correct $PATH, lets find Qt!
98 find_package(Qt4 REQUIRED)
99
100 set(QT_DONT_USE_QTGUI 1)
101 include(${QT_USE_FILE})
102 include_directories(${QT_INCLUDES})
103
104 # Setup OpenSSL
105 if(WITH_OPENSSL)
106   find_package(OpenSSL)
107 else(WITH_OPENSSL)
108   message(STATUS "Disabling OpenSSL support")
109 endif(WITH_OPENSSL)
110
111 if(OPENSSL_FOUND)
112   if(NOT QT_DEFINITIONS MATCHES "QT_NO_OPENSSL")
113     message(STATUS "Found OpenSSL support in Qt")
114     add_definitions(-DHAVE_SSL)
115     set(HAVE_SSL true)
116     set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_SSL)
117   else(NOT QT_DEFINITIONS MATCHES "QT_NO_OPENSSL")
118     message(STATUS "No OpenSSL support found in Qt, disabling")
119   endif(NOT QT_DEFINITIONS MATCHES "QT_NO_OPENSSL")
120 else(OPENSSL_FOUND)
121   add_definitions(-DQT_NO_OPENSSL)
122 endif(OPENSSL_FOUND)
123
124 # Setup D-Bus support
125 if(WITH_DBUS)
126   if(QT_QTDBUS_FOUND)
127     message(STATUS "Found QtDBus, enabling D-Bus support")
128     add_definitions(-DHAVE_DBUS)
129     set(LINK_DBUS DBUS)
130     set(HAVE_DBUS true)
131     set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_DBUS)
132   else(QT_QTDBUS_FOUND)
133     message(STATUS "QtDBus not found, disabling D-Bus support")
134   endif(QT_QTDBUS_FOUND)
135 else(WITH_DBUS)
136   message(STATUS "Disabling D-Bus support")
137 endif(WITH_DBUS)
138
139 # Setup QtWebKit support
140 if(WITH_WEBKIT)
141   if(QT_QTWEBKIT_FOUND)
142     message(STATUS "Found QtWebKit, enabling WebKit support")
143     add_definitions(-DHAVE_WEBKIT)
144     set(LINK_WEBKIT WEBKIT)
145     set(HAVE_WEBKIT true)
146     set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_WEBKIT)
147   else(QT_QTWEBKIT_FOUND)
148     message(STATUS "QtWebKit not found, disabling WebKit support")
149   endif(QT_QTWEBKIT_FOUND)
150 else(WITH_WEBKIT)
151   message(STATUS "Disabling WebKit support")
152 endif(WITH_WEBKIT)
153
154 # Setup KDE4 support
155 if(WITH_KDE)
156   find_package(KDE4)
157   if(KDE4_FOUND)
158     message(STATUS "Enabling KDE4 integration")
159     include_directories(${KDE4_INCLUDES})
160     add_definitions(-DHAVE_KDE ${KDE4_DEFINITIONS})
161     set(HAVE_KDE 1)
162     set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_KDE)
163     set(QUASSEL_KDE_LIBRARIES ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBRARY} knotifyconfig)
164     # We always use external icons for KDE4 support, since we use its iconloader rather than our own
165     set(OXYGEN_ICONS "External")
166     set(QUASSEL_ICONS "External")
167   else(KDE4_FOUND)
168     message(STATUS "KDE4 not found, disabling KDE integration")
169   endif(KDE4_FOUND)
170 else(WITH_KDE)
171   message(STATUS "Disabling KDE4 integration")
172 endif(WITH_KDE)
173
174 # Setup Phonon support - we only need this if we don't have or want KDE4
175 if(NOT HAVE_KDE)
176   if(WITH_PHONON)
177     find_package(Phonon)
178     if(PHONON_FOUND)
179       message(STATUS "Enabling Phonon support")
180       add_definitions(-DHAVE_PHONON)
181       set(HAVE_PHONON true)
182       set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_PHONON)
183     else(PHONON_FOUND)
184       message(STATUS "Phonon not found, disabling audio notifications")
185     endif(PHONON_FOUND)
186   else(WITH_PHONON)
187     message(STATUS "Disabling Phonon support")
188   endif(WITH_PHONON)
189 endif(NOT HAVE_KDE)
190
191 # RPATH needs to be set correctly
192 # Do this down here, since otherwise KDE wants to handle it itself, and fails
193 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH 1)
194 set(CMAKE_BUILD_WITH_INSTALL_RPATH 1)
195
196 # Set global buildflags
197 # This is very much non-portable, so don't use -DSTATIC until you know what
198 # you do.
199 if(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
200   set(CMAKE_CXX_FLAGS "-static-libgcc ${CMAKE_CXX_FLAGS}")
201   link_directories(${CMAKE_BINARY_DIR}/staticlibs) # override dynamic libs
202   if(HAVE_SSL)
203     set(QUASSEL_SSL_LIBRARIES ssl crypto)  # these miss in static builds
204   endif(HAVE_SSL)
205 endif(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
206
207 if(WIN32)
208   #if(STATIC)
209   link_libraries(imm32 winmm dbghelp)  # missing by default :/
210   #endif(STATIC)
211   if(HAVE_SSL)
212      link_libraries(${OPENSSL_LIBRARIES} libeay32MD)
213   endif(HAVE_SSL)
214 endif(WIN32)
215
216 if(WIN32)
217   set(RC_WIN32 ../pics/win32.rc)  # for app icons on windows
218 endif(WIN32)
219
220 # This is dirty, but I haven't found a cleaner way to ensure that the generated .qrc files
221 # (which will be removed with make clean) are regenerated :/
222 set_directory_properties(PROPERTIES
223                          ADDITIONAL_MAKE_CLEAN_FILES CMakeCache.txt)
224
225 # We need to create a version.gen
226 # For this, we create our genversion binary and make sure it is run every time.
227 add_executable(genversion ${CMAKE_SOURCE_DIR}/src/common/genversion.cpp)
228 target_link_libraries(genversion ${QT_LIBRARIES} ${QT_CORE_LIB_DEPENDENCIES})
229
230 get_target_property(GENVERSION_EXECUTABLE genversion LOCATION)
231 add_custom_target(genversion_run ALL ${GENVERSION_EXECUTABLE}
232                   ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/src/version.gen)
233 add_dependencies(genversion_run genversion)
234
235 # Decide what to do with icons
236 if(WANT_QTCLIENT OR WANT_MONO)
237   if(QUASSEL_ICONS MATCHES "External")
238     message(STATUS "Install Quassel icons to ${CMAKE_INSTALL_PREFIX}/share/apps/quassel")
239   else(QUASSEL_ICONS MATCHES "External")
240     set(QUASSEL_ICONS "Builtin")
241     message(STATUS "Compile Quassel icons into the binary")
242   endif(QUASSEL_ICONS MATCHES "External")
243
244   if(OXYGEN_ICONS MATCHES "External")
245     message(STATUS "Use system-installed icon theme")
246   else(OXYGEN_ICONS MATCHES "External")
247     set(OXYGEN_ICONS "Builtin")
248     message(STATUS "Compile Oxygen icon theme subset into the binary")
249   endif(OXYGEN_ICONS MATCHES "External")
250 endif(WANT_QTCLIENT OR WANT_MONO)
251
252 # These variables will be added to the main targets (CORE, QTCLIENT, MONO)
253
254 set(COMMON_DEPS ${RC_WIN32})
255 set(CORE_DEPS )
256 set(CLIENT_DEPS )
257 set(KDE_DEPS )
258
259 # Add needed subdirs - the order is important, since src needs some vars set by other dirs
260 add_subdirectory(data)
261 add_subdirectory(icons)
262 #add_subdirectory(pics)
263 add_subdirectory(i18n)
264 add_subdirectory(src)