Add SystrayNotificationBackend (untested yet and still somewhat rudimentary), evolve...
[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
7 # -DWITH_WEBKIT=OFF   : Disable WebKit support
8 # -DOXYGEN_ICONS=(Builtin|External)  : If "Builtin" (the default), compile our Oxygen Icon Theme subset into the binary
9 #                                    : If "External", we assume Oxygen is already installed on the system
10 # -DQUASSEL_ICONS=(Builtin|External) : If "Builtin" (the default), put our own icons into the binary
11 #                                    : If "External", we install our icons into $PREFIX/share/apps/quassel (UNIX only)
12 # -DQT=/path/to/qt    : Choose a Qt4 installation to use instead of the system Qt4
13 # -DSTATIC=ON         : Enable static building of Quassel. Use with care.
14 # -DDEPLOY=ON         : Mac OS X only. Use only for creating Quassel Packages!
15 #
16 # NOTE: You need to remove CMakeCache.txt if you plan to change any of these values!
17
18 project(QuasselIRC)
19
20 cmake_minimum_required(VERSION 2.6.0 FATAL_ERROR)
21
22 if(COMMAND cmake_policy)
23    cmake_policy(SET CMP0003 NEW)
24 endif(COMMAND cmake_policy)
25
26 # Use our own (well, and KDE's) version of some modules
27 # In particular cmake's FindQt4 and FindOpenSSL are quite buggy
28 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
29
30 # Various options and variables that can be set on the command line
31 option(WANT_CORE     "Build the core (server) binary"           ON)
32 option(WANT_QTCLIENT "Build the Qt4 GUI client binary"          ON)
33 option(WANT_MONO     "Build the monolithic (all-in-one) binary" OFF)
34
35 option(WITH_OPENSSL  "Enable OpenSSL support if present on the system"  ON)
36 option(WITH_DBUS     "Enable D-Bus support if present on the system"    ON)
37 option(WITH_WEBKIT   "Enable WebKit support if present on the system"   ON)
38
39 option(STATIC        "Enable static building (might not be portable)" OFF)
40 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)
41 option(SPUTDEV       "Do not use!" OFF)
42
43 set(OXYGEN_ICONS "Builtin" CACHE STRING "Builtin: Compile Oxygen icons into the binary; External: Use system-installed Oxygen")
44 set(QUASSEL_ICONS "Builtin" CACHE STRING "Builtin: Compile Quassel icons into the binary; External: Install them separately")
45
46 set(QT "" CACHE STRING "Path to a Qt installation to use instead of the system Qt")
47 set(LINGUAS "" CACHE STRING "Space-separated List of locales specifying languages that should be compiled")
48
49 if(STATIC)
50   set(CMAKE_BUILD_TYPE Release)
51   set(OXYGEN_ICONS "Builtin")
52   set(QUASSEL_ICONS "Builtin")
53 endif(STATIC)
54
55 # RPATH needs to be set correctly
56 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH 1) 
57 set(CMAKE_BUILD_WITH_INSTALL_RPATH 1)
58
59 # Define install locations. Using variables will allow overriding this by the KDE macros later.
60 set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin)
61 set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/apps)
62 set(ICON_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/icons)
63 set(XDG_APPS_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/applications)
64
65 # Enable various flags on gcc
66 if(CMAKE_COMPILER_IS_GNUCXX)
67   # Let's just hope that all gccs support these options and skip the tests...
68   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ansi -Wall -Wextra -Wnon-virtual-dtor")
69 endif(CMAKE_COMPILER_IS_GNUCXX)
70
71 set(QT_MIN_VERSION "4.4.0")
72
73 if(APPLE AND DEPLOY)
74   set(CMAKE_OSX_ARCHITECTURES "i386;ppc")
75   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.4")
76   set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.4u.sdk/")
77   add_definitions(-DMAC_10_4_SDK)
78 endif(APPLE AND DEPLOY)
79
80 include(QuasselMacros)
81
82 # Execinfo is needed for generating backtraces
83 find_package(ExecInfo)
84 if(EXECINFO_FOUND)
85   add_definitions(-DHAVE_EXECINFO)
86   include_directories(${EXECINFO_INCLUDES})
87   link_libraries(${EXECINFO_LIBRARIES})
88 endif(EXECINFO_FOUND)
89
90 # Select a Qt installation here, if you don't want to use system Qt
91 if(QT)
92   # FindQt4 will look for the qmake binary in $PATH, so we just prepend the Qt dir
93   set(ENV{PATH} ${QT}/bin:$ENV{PATH})
94 endif(QT)
95
96 # Now that we have the correct $PATH, lets find Qt!
97 find_package(Qt4 REQUIRED)
98
99 set(QT_DONT_USE_QTGUI 1)
100 include(${QT_USE_FILE})
101 include_directories(${QT_INCLUDES})
102
103 # Setup OpenSSL
104 if(WITH_OPENSSL)
105   find_package(OpenSSL)
106 else(WITH_OPENSSL)
107   message(STATUS "Disabling OpenSSL support")
108 endif(WITH_OPENSSL)
109
110 if(OPENSSL_FOUND)
111   if(NOT QT_DEFINITIONS MATCHES "QT_NO_OPENSSL")
112     message(STATUS "Found OpenSSL support in Qt")
113     add_definitions(-DHAVE_SSL)
114     set(HAVE_SSL true)
115     set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_SSL)
116   else(NOT QT_DEFINITIONS MATCHES "QT_NO_OPENSSL")
117     message(STATUS "No OpenSSL support found in Qt, disabling")
118   endif(NOT QT_DEFINITIONS MATCHES "QT_NO_OPENSSL")
119 else(OPENSSL_FOUND)
120   add_definitions(-DQT_NO_OPENSSL)
121 endif(OPENSSL_FOUND)
122
123 # Setup D-Bus support
124 if(WITH_DBUS)
125   if(QT_QTDBUS_FOUND)
126     message(STATUS "Found QtDBus, enabling D-Bus support")
127     add_definitions(-DHAVE_DBUS)
128     set(LINK_DBUS DBUS)
129     set(HAVE_DBUS true)
130     set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_DBUS)
131   else(QT_QTDBUS_FOUND)
132     message(STATUS "QtDBus not found, disabling D-Bus support")
133   endif(QT_QTDBUS_FOUND)
134 else(WITH_DBUS)
135   message(STATUS "Disabling D-Bus support")
136 endif(WITH_DBUS)
137
138 # Setup QtWebKit support
139 if(WITH_WEBKIT)
140   if(QT_QTWEBKIT_FOUND)
141     message(STATUS "Found QtWebKit, enabling WebKit support")
142     add_definitions(-DHAVE_WEBKIT)
143     set(LINK_WEBKIT WEBKIT)
144     set(HAVE_WEBKIT true)
145     set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_WEBKIT)
146   else(QT_QTWEBKIT_FOUND)
147     message(STATUS "QtWebKit not found, disabling D-Bus support")
148   endif(QT_QTWEBKIT_FOUND)
149 else(WITH_WEBKIT)
150   message(STATUS "Disabling WebKit support")
151 endif(WITH_WEBKIT)
152
153
154 # Set global buildflags
155 # This is very much non-portable, so don't use -DSTATIC until you know what
156 # you do.
157 if(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
158   set(CMAKE_CXX_FLAGS "-static-libgcc ${CMAKE_CXX_FLAGS}")
159   link_directories(${CMAKE_BINARY_DIR}/staticlibs) # override dynamic libs
160   if(HAVE_SSL)
161     set(QUASSEL_SSL_LIBRARIES ssl crypto)  # these miss in static builds
162   endif(HAVE_SSL)
163 endif(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
164
165 if(STATIC AND WIN32)
166   link_libraries(imm32 winmm)  # missing by default :/
167    if(HAVE_SSL)
168      link_libraries(${OPENSSL_LIBRARIES} libeay32MD)
169    endif(HAVE_SSL)
170 endif(STATIC AND WIN32)
171
172 if(WIN32)
173   set(RC_WIN32 ../pics/win32.rc)  # for app icons on windows
174 endif(WIN32)
175
176 # This is dirty, but I haven't found a cleaner way to ensure that the generated .qrc files
177 # (which will be removed with make clean) are regenerated :/
178 set_directory_properties(PROPERTIES
179                          ADDITIONAL_MAKE_CLEAN_FILES CMakeCache.txt)
180
181 # We need to create a version.gen
182 # For this, we create our genversion binary and make sure it is run every time.
183 add_executable(genversion ${CMAKE_SOURCE_DIR}/src/common/genversion.cpp)
184 target_link_libraries(genversion ${QT_LIBRARIES} ${QT_CORE_LIB_DEPENDENCIES})
185
186 get_target_property(GENVERSION_EXECUTABLE genversion LOCATION)
187 add_custom_target(genversion_run ALL ${GENVERSION_EXECUTABLE}
188                   ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/src/version.gen)
189 add_dependencies(genversion_run genversion)
190
191 # Decide what to do with icons
192 if(WANT_QTCLIENT OR WANT_MONO)
193   if(QUASSEL_ICONS MATCHES "External")
194     message(STATUS "Install Quassel icons to ${CMAKE_INSTALL_PREFIX}/share/apps/quassel")
195   else(QUASSEL_ICONS MATCHES "External")
196     set(QUASSEL_ICONS "Builtin")
197     message(STATUS "Compile Quassel icons into the binary")
198   endif(QUASSEL_ICONS MATCHES "External")
199
200   if(OXYGEN_ICONS MATCHES "External")
201     message(STATUS "Use system-installed Oxygen icon theme")
202   else(OXYGEN_ICONS MATCHES "External")
203     set(OXYGEN_ICONS "Builtin")
204     message(STATUS "Compile Oxygen icon theme subset into the binary")
205   endif(OXYGEN_ICONS MATCHES "External")
206 endif(WANT_QTCLIENT OR WANT_MONO)
207
208 # These variables will be added to the main targets (CORE, QTCLIENT, MONO)
209
210 set(COMMON_DEPS ${RC_WIN32})
211 set(CORE_DEPS )
212 set(CLIENT_DEPS )
213 set(KDE_DEPS )
214
215 # Add needed subdirs - the order is important, since src needs some vars set by other dirs
216 add_subdirectory(data)
217 add_subdirectory(icons)
218 #add_subdirectory(pics)
219 add_subdirectory(i18n)
220 add_subdirectory(src)