chatscene allows now inserting and removing of items at arbitrary positions (not...
[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 # -DQT=/path/to/qt    : Choose a Qt4 installation to use instead of the system Qt4
8 # -DSTATIC=ON         : Enable static building of Quassel. Use with care.
9 # -DSPUTDEV=ON        : Do not use.
10 # -DDEPLOY=ON         : Mac OS X only. Use only fore redistribution Quassel Packages!!
11 #
12 # NOTE: You need to remove CMakeCache.txt if you plan to change any of these values!
13
14 project(QuasselIRC)
15
16 # Target scopes don't work in older versions
17 cmake_minimum_required(VERSION 2.4.7 FATAL_ERROR)
18
19 if(COMMAND cmake_policy)
20    cmake_policy(SET CMP0003 NEW)
21 endif(COMMAND cmake_policy)
22
23 # Use our own (well, KDE's) version of some modules
24 # In particular cmake's FindQt4 and FindOpenSSL are quite buggy
25 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
26
27 # Various options and variables that can be set on the command line
28 option(WANT_CORE     "Build the core (server) binary"           ON)
29 option(WANT_QTCLIENT "Build the Qt4 GUI client binary"          ON)
30 option(WANT_MONO     "Build the monolithic (all-in-one) binary" OFF)
31
32 option(WITH_OPENSSL  "Enable OpenSSL support if present on the system"  ON)
33 option(WITH_DBUS     "Enable D-Bus support if present on the system"    ON)
34
35 option(STATIC        "Enable static building (might not be portable)" OFF)
36 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)
37 option(SPUTDEV       "Do not use!" OFF)
38
39 set(QT "" CACHE STRING "Path to a Qt installation to use instead of the system Qt")
40 set(LINGUAS "" CACHE STRING "Space-separated List of locales specifying languages that should be compiled")
41
42 if(STATIC)
43   set(CMAKE_BUILD_TYPE Release)
44 endif(STATIC)
45
46 # RPATH needs to be set correctly
47 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH 1) 
48 set(CMAKE_BUILD_WITH_INSTALL_RPATH 1)
49
50 # Enable various flags on gcc
51 if(CMAKE_COMPILER_IS_GNUCXX)
52   include(CheckCXXCompilerFlag)
53   check_cxx_compiler_flag(-Wall HAVE_WALL)
54   if(HAVE_WALL)
55     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
56   endif(HAVE_WALL)
57   check_cxx_compiler_flag(-Wextra HAVE_WEXTRA)
58   if(HAVE_WEXTRA)
59     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
60   endif(HAVE_WEXTRA)
61   check_cxx_compiler_flag(-ansi HAVE_ANSI)
62   if(HAVE_ANSI)
63     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ansi")
64   endif(HAVE_ANSI)
65 endif(CMAKE_COMPILER_IS_GNUCXX)
66
67 set(QT_MIN_VERSION "4.4.0")
68
69 if(APPLE AND DEPLOY)
70   set(CMAKE_OSX_ARCHITECTURES "i386;ppc")
71   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.4")
72   set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.4u.sdk/")
73   add_definitions(-DMAC_10_4_SDK)
74 endif(APPLE AND DEPLOY)
75
76 # Enable mostly b0rked stuff (new ChatView), do not enable this unless you know what you do...
77 if(SPUTDEV)
78   add_definitions(-DSPUTDEV)
79 endif(SPUTDEV)
80
81 # Set up execinfo
82
83 # The problem with this library is that it is built-in in the Linux glib, 
84 # while on systems like FreeBSD, it is installed separately and thus needs to be linked to.
85 # Therefore, we search for the header to see if the it's available in the first place.
86 # If it is available, we try to locate the library to figure out whether it is built-in or not.
87
88 find_path(EXECINFO_H_DIR "execinfo.h")
89
90 if(NOT EXECINFO_H_DIR STREQUAL "EXECINFO_H_DIR-NOTFOUND")
91   # We found the header file's include dir.
92   # Let's add it so the compiler finds it as well.
93   include_directories(${EXECINFO_H_DIR})
94
95   # Now determine if it's built-in or not, by searching the library file.
96   find_library(EXECINFO_LIB_PATH "execinfo")
97
98   if(EXECINFO_LIB_PATH STREQUAL "EXECINFO_LIB_PATH-NOTFOUND")
99     # Built-in, no further action is needed
100     message(STATUS "Found execinfo")
101   else(EXECINFO_LIB_PATH STREQUAL "EXECINFO_LIB_PATH-NOTFOUND")
102     # It's an external library, link it.
103     link_libraries(${EXECINFO_LIB_PATH})
104     message(STATUS "Found execinfo: ${EXECINFO_LIB_PATH}")
105   endif(EXECINFO_LIB_PATH STREQUAL "EXECINFO_LIB_PATH-NOTFOUND")
106
107   set(HAVE_EXECINFO true)
108
109 endif(NOT EXECINFO_H_DIR STREQUAL "EXECINFO_H_DIR-NOTFOUND")
110
111 if(HAVE_EXECINFO)
112   add_definitions(-DHAVE_EXECINFO)
113 endif(HAVE_EXECINFO)
114
115 # Select a Qt installation here, if you don't want to use system Qt
116 if(QT)
117   # FindQt4 will look for the qmake binary in $PATH, so we just prepend the Qt dir
118   set(ENV{PATH} ${QT}/bin:$ENV{PATH})
119 endif(QT)
120
121 # Now that we have the correct $PATH, lets find Qt!
122 find_package(Qt4 REQUIRED)
123
124 set(QT_DONT_USE_QTGUI 1)
125 include(${QT_USE_FILE})
126 include_directories(${QT_INCLUDES})
127
128 # Setup OpenSSL
129 if(WITH_OPENSSL)
130   find_package(OpenSSL)
131 else(WITH_OPENSSL)
132   message(STATUS "Disabling OpenSSL support")
133 endif(WITH_OPENSSL)
134
135 if(OPENSSL_FOUND)
136   if(NOT QT_DEFINITIONS MATCHES "QT_NO_OPENSSL")
137     message(STATUS "Found OpenSSL support in Qt")
138     add_definitions(-DHAVE_SSL)
139     set(HAVE_SSL true)
140     set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_SSL)
141   else(NOT QT_DEFINITIONS MATCHES "QT_NO_OPENSSL")
142     message(STATUS "No OpenSSL support found in Qt, disabling")
143   endif(NOT QT_DEFINITIONS MATCHES "QT_NO_OPENSSL")
144 else(OPENSSL_FOUND)
145   add_definitions(-DQT_NO_OPENSSL)
146 endif(OPENSSL_FOUND)
147
148 # Setup D-Bus support
149 if(WITH_DBUS)
150   if(QT_QTDBUS_FOUND)
151     message(STATUS "Found QtDBus, enabling D-Bus support")
152     add_definitions(-DHAVE_DBUS)
153     set(LINK_DBUS DBUS)
154     set(HAVE_DBUS true)
155     set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_DBUS)
156   else(QT_QTDBUS_FOUND)
157     message(STATUS "QtDBus not found, disabling D-Bus support")
158   endif(QT_QTDBUS_FOUND)
159 else(WITH_DBUS)
160   message(STATUS "Disabling D-Bus support")
161 endif(WITH_DBUS)
162
163 # We need to create a version.gen
164 # For this, we create our genversion binary and make sure it is run every time.
165 add_executable(genversion ${CMAKE_SOURCE_DIR}/src/common/genversion.cpp)
166 target_link_libraries(genversion ${QT_LIBRARIES} ${QT_CORE_LIB_DEPENDENCIES})
167
168 get_target_property(GENVERSION_EXECUTABLE genversion LOCATION)
169 add_custom_target(genversion_run ALL ${GENVERSION_EXECUTABLE}
170                   ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/src/common/version.gen)
171 add_dependencies(genversion_run genversion)
172
173 # Add needed subdirs
174 add_subdirectory(src/common)
175 include_directories(src/common)
176 if(WANT_CORE OR WANT_MONO)
177   add_subdirectory(src/core)
178   include_directories(src/core)
179 endif(WANT_CORE OR WANT_MONO)
180 if(WANT_QTCLIENT OR WANT_MONO)
181   add_subdirectory(src/client)
182   add_subdirectory(src/uisupport)
183   add_subdirectory(src/qtui)
184   include_directories(src/client)
185   include_directories(src/uisupport)
186   include_directories(src/qtui)
187 endif(WANT_QTCLIENT OR WANT_MONO)
188
189 # Make sure version.gen exists before building mod_common
190 add_dependencies(mod_common genversion_run)
191
192 # Generate binary translation files
193 include(QuasselGenerateTranslations)
194 quassel_generate_i18n_resource(RC_I18N ${LINGUAS})
195
196 # Add resources
197 qt4_add_resources(RC_ICONS src/icons/icons.qrc)
198 qt4_add_resources(RC_QUASSEL_ICONS src/icons/quassel-icons.qrc)
199 qt4_add_resources(RC_SQL src/core/sql.qrc)
200
201 # Set global buildflags
202 # This is very much non-portable, so don't use -DSTATICGCC until you know what
203 # you do.
204 if(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
205   set(CMAKE_CXX_FLAGS "-static-libgcc ${CMAKE_CXX_FLAGS}")
206   link_directories(${CMAKE_BINARY_DIR}/staticlibs) # override dynamic libs
207   if(HAVE_SSL)
208     set(QUASSEL_SSL_LIBRARIES ssl crypto)  # these miss in static builds
209   endif(HAVE_SSL)
210 endif(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
211
212 if(STATIC AND WIN32)
213   link_libraries(imm32 winmm)  # missing by default :/
214    if(HAVE_SSL)
215      link_libraries(${OPENSSL_LIBRARIES} libeay32MD)
216    endif(HAVE_SSL)
217 endif(STATIC AND WIN32)
218
219 if(WIN32)
220   set(WIN32_RC src/icons/win32.rc)  # for app icons on windows
221 endif(WIN32)
222
223 # Here comes the dirty part. Our targets need different Qt4 modules, i.e. different libs
224 # and defines. We can't simply include UseQt4 several times, since definitions add up.
225 # We workaround this by using our own macro to figure out what to add.
226
227 # This macro sets variables for additional Qt modules.
228 macro(setup_qt4_variables)
229   set(QUASSEL_QT_LIBRARIES )
230   IF(WIN32)
231     set(MAIN MAIN)
232   ENDIF(WIN32)
233   foreach(qtmod CORE ${ARGV} ${MAIN})
234     set(QUASSEL_QT_LIBRARIES ${QUASSEL_QT_LIBRARIES} ${QT_QT${qtmod}_LIBRARY} ${QT_${qtmod}_LIB_DEPENDENCIES})
235   endforeach(qtmod ${ARGV})
236   set(QUASSEL_QT_LIBRARIES ${QUASSEL_QT_LIBRARIES} ${QT_LIBRARIES})
237 endmacro(setup_qt4_variables)
238
239 # Now we have everything, so just glue the right pieces together :)
240 if(WANT_CORE)
241   setup_qt4_variables(NETWORK SCRIPT SQL)
242   add_executable(quasselcore ${CMAKE_SOURCE_DIR}/src/common/main.cpp
243                              ${RC_SQL} ${RC_I18N} ${WIN32_RC})
244   set_target_properties(quasselcore PROPERTIES 
245                                     COMPILE_FLAGS "-DQT_NETWORK_LIB -DQT_SCRIPT_LIB -DQT_SQL_LIB -DBUILD_CORE")
246   target_link_libraries(quasselcore mod_core mod_common 
247                                     ${QUASSEL_QT_LIBRARIES} ${QUASSEL_SSL_LIBRARIES})
248 endif(WANT_CORE)
249
250 if(WANT_QTCLIENT)
251   setup_qt4_variables(${LINK_DBUS} GUI NETWORK)
252   add_executable(quasselclient WIN32 ${CMAKE_SOURCE_DIR}/src/common/main.cpp
253                                      ${RC_ICONS} ${RC_QUASSEL_ICONS} ${RC_I18N} ${WIN32_RC})
254   set_target_properties(quasselclient PROPERTIES
255                                       COMPILE_FLAGS "-DQT_GUI_LIB -DQT_NETWORK_LIB -DBUILD_QTUI")
256   target_link_libraries(quasselclient mod_qtui mod_uisupport mod_client mod_common
257                                       ${QUASSEL_QT_LIBRARIES} ${QUASSEL_SSL_LIBRARIES})
258 endif(WANT_QTCLIENT)
259
260 if(WANT_MONO)
261   setup_qt4_variables(${LINK_DBUS} GUI NETWORK SCRIPT SQL)
262   add_executable(quassel WIN32 ${CMAKE_SOURCE_DIR}/src/common/main.cpp
263                                ${RC_ICONS} ${RC_QUASSEL_ICONS} ${RC_SQL} ${RC_I18N} ${WIN32_RC})
264   set_target_properties(quassel PROPERTIES 
265                                 COMPILE_FLAGS "-DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_SCRIPT_LIB -DQT_SQL_LIB -DBUILD_MONO")
266   target_link_libraries(quassel mod_qtui mod_uisupport mod_client mod_core mod_common 
267                                 ${QUASSEL_QT_LIBRARIES} ${QUASSEL_SSL_LIBRARIES})
268 endif(WANT_MONO)
269
270 # Build bundles for MacOSX
271 if(APPLE)
272   add_custom_command(TARGET quasselclient POST_BUILD
273                      COMMAND ${CMAKE_SOURCE_DIR}/scripts/build/macosx_makebundle.py
274                              ${CMAKE_SOURCE_DIR} "Quassel Client" quasselclient)
275   add_custom_command(TARGET quassel POST_BUILD
276                      COMMAND ${CMAKE_SOURCE_DIR}/scripts/build/macosx_makebundle.py
277                              ${CMAKE_SOURCE_DIR} "Quassel" quassel)
278   if(DEPLOY)
279     add_custom_command(TARGET quasselclient POST_BUILD
280                        COMMAND ${CMAKE_SOURCE_DIR}/scripts/build/macosx_makePackage.sh Client)
281     add_custom_command(TARGET quasselcore POST_BUILD
282                        COMMAND ${CMAKE_SOURCE_DIR}/scripts/build/macosx_makePackage.sh Core)
283   endif(DEPLOY)
284 endif(APPLE)
285
286 # Install rules
287 if(WANT_CORE)
288   install(TARGETS quasselcore
289           RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
290 endif(WANT_CORE)
291
292 if(WANT_QTCLIENT)
293   install(TARGETS quasselclient
294           RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
295
296   install(FILES quasselclient.desktop
297           DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications)
298 endif(WANT_QTCLIENT)
299
300 if(WANT_MONO)
301   install(TARGETS quassel
302           RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
303
304   install(FILES quassel.desktop
305           DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications)
306 endif(WANT_MONO)