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