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