ChatLine cleanup
[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   # Let's just hope that all gccs support these options and skip the tests...
53   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ansi -Wall -Wextra -Wnon-virtual-dtor")
54 endif(CMAKE_COMPILER_IS_GNUCXX)
55
56 set(QT_MIN_VERSION "4.4.0")
57
58 if(APPLE AND DEPLOY)
59   set(CMAKE_OSX_ARCHITECTURES "i386;ppc")
60   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.4")
61   set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.4u.sdk/")
62   add_definitions(-DMAC_10_4_SDK)
63 endif(APPLE AND DEPLOY)
64
65 # Enable mostly b0rked stuff (new ChatView), do not enable this unless you know what you do...
66 if(SPUTDEV)
67   add_definitions(-DSPUTDEV)
68 endif(SPUTDEV)
69
70 # Set up execinfo
71
72 # The problem with this library is that it is built-in in the Linux glib, 
73 # while on systems like FreeBSD, it is installed separately and thus needs to be linked to.
74 # Therefore, we search for the header to see if the it's available in the first place.
75 # If it is available, we try to locate the library to figure out whether it is built-in or not.
76
77 find_path(EXECINFO_H_DIR "execinfo.h")
78
79 if(NOT EXECINFO_H_DIR STREQUAL "EXECINFO_H_DIR-NOTFOUND")
80   # We found the header file's include dir.
81   # Let's add it so the compiler finds it as well.
82   include_directories(${EXECINFO_H_DIR})
83
84   # Now determine if it's built-in or not, by searching the library file.
85   find_library(EXECINFO_LIB_PATH "execinfo")
86
87   if(EXECINFO_LIB_PATH STREQUAL "EXECINFO_LIB_PATH-NOTFOUND")
88     # Built-in, no further action is needed
89     message(STATUS "Found execinfo")
90   else(EXECINFO_LIB_PATH STREQUAL "EXECINFO_LIB_PATH-NOTFOUND")
91     # It's an external library, link it.
92     link_libraries(${EXECINFO_LIB_PATH})
93     message(STATUS "Found execinfo: ${EXECINFO_LIB_PATH}")
94   endif(EXECINFO_LIB_PATH STREQUAL "EXECINFO_LIB_PATH-NOTFOUND")
95
96   set(HAVE_EXECINFO true)
97
98 endif(NOT EXECINFO_H_DIR STREQUAL "EXECINFO_H_DIR-NOTFOUND")
99
100 if(HAVE_EXECINFO)
101   add_definitions(-DHAVE_EXECINFO)
102 endif(HAVE_EXECINFO)
103
104 # Select a Qt installation here, if you don't want to use system Qt
105 if(QT)
106   # FindQt4 will look for the qmake binary in $PATH, so we just prepend the Qt dir
107   set(ENV{PATH} ${QT}/bin:$ENV{PATH})
108 endif(QT)
109
110 # Now that we have the correct $PATH, lets find Qt!
111 find_package(Qt4 REQUIRED)
112
113 set(QT_DONT_USE_QTGUI 1)
114 include(${QT_USE_FILE})
115 include_directories(${QT_INCLUDES})
116
117 # Setup OpenSSL
118 if(WITH_OPENSSL)
119   find_package(OpenSSL)
120 else(WITH_OPENSSL)
121   message(STATUS "Disabling OpenSSL support")
122 endif(WITH_OPENSSL)
123
124 if(OPENSSL_FOUND)
125   if(NOT QT_DEFINITIONS MATCHES "QT_NO_OPENSSL")
126     message(STATUS "Found OpenSSL support in Qt")
127     add_definitions(-DHAVE_SSL)
128     set(HAVE_SSL true)
129     set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_SSL)
130   else(NOT QT_DEFINITIONS MATCHES "QT_NO_OPENSSL")
131     message(STATUS "No OpenSSL support found in Qt, disabling")
132   endif(NOT QT_DEFINITIONS MATCHES "QT_NO_OPENSSL")
133 else(OPENSSL_FOUND)
134   add_definitions(-DQT_NO_OPENSSL)
135 endif(OPENSSL_FOUND)
136
137 # Setup D-Bus support
138 if(WITH_DBUS)
139   if(QT_QTDBUS_FOUND)
140     message(STATUS "Found QtDBus, enabling D-Bus support")
141     add_definitions(-DHAVE_DBUS)
142     set(LINK_DBUS DBUS)
143     set(HAVE_DBUS true)
144     set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_DBUS)
145   else(QT_QTDBUS_FOUND)
146     message(STATUS "QtDBus not found, disabling D-Bus support")
147   endif(QT_QTDBUS_FOUND)
148 else(WITH_DBUS)
149   message(STATUS "Disabling D-Bus support")
150 endif(WITH_DBUS)
151
152 # We need to create a version.gen
153 # For this, we create our genversion binary and make sure it is run every time.
154 add_executable(genversion ${CMAKE_SOURCE_DIR}/src/common/genversion.cpp)
155 target_link_libraries(genversion ${QT_LIBRARIES} ${QT_CORE_LIB_DEPENDENCIES})
156
157 get_target_property(GENVERSION_EXECUTABLE genversion LOCATION)
158 add_custom_target(genversion_run ALL ${GENVERSION_EXECUTABLE}
159                   ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/src/common/version.gen)
160 add_dependencies(genversion_run genversion)
161
162 # Add needed subdirs
163 add_subdirectory(src/common)
164 include_directories(src/common)
165 if(WANT_CORE OR WANT_MONO)
166   add_subdirectory(src/core)
167   include_directories(src/core)
168 endif(WANT_CORE OR WANT_MONO)
169 if(WANT_QTCLIENT OR WANT_MONO)
170   add_subdirectory(src/client)
171   add_subdirectory(src/uisupport)
172   add_subdirectory(src/qtui)
173   include_directories(src/client)
174   include_directories(src/uisupport)
175   include_directories(src/qtui)
176 endif(WANT_QTCLIENT OR WANT_MONO)
177
178 # Make sure version.gen exists before building mod_common
179 add_dependencies(mod_common genversion_run)
180
181 # Generate binary translation files
182 include(QuasselGenerateTranslations)
183 quassel_generate_i18n_resource(RC_I18N ${LINGUAS})
184
185 # Add resources
186 qt4_add_resources(RC_ICONS src/icons/icons.qrc)
187 qt4_add_resources(RC_QUASSEL_ICONS src/icons/quassel-icons.qrc)
188 qt4_add_resources(RC_SQL src/core/sql.qrc)
189
190 # Set global buildflags
191 # This is very much non-portable, so don't use -DSTATICGCC until you know what
192 # you do.
193 if(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
194   set(CMAKE_CXX_FLAGS "-static-libgcc ${CMAKE_CXX_FLAGS}")
195   link_directories(${CMAKE_BINARY_DIR}/staticlibs) # override dynamic libs
196   if(HAVE_SSL)
197     set(QUASSEL_SSL_LIBRARIES ssl crypto)  # these miss in static builds
198   endif(HAVE_SSL)
199 endif(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
200
201 if(STATIC AND WIN32)
202   link_libraries(imm32 winmm)  # missing by default :/
203    if(HAVE_SSL)
204      link_libraries(${OPENSSL_LIBRARIES} libeay32MD)
205    endif(HAVE_SSL)
206 endif(STATIC AND WIN32)
207
208 if(WIN32)
209   set(WIN32_RC src/icons/win32.rc)  # for app icons on windows
210 endif(WIN32)
211
212 # Here comes the dirty part. Our targets need different Qt4 modules, i.e. different libs
213 # and defines. We can't simply include UseQt4 several times, since definitions add up.
214 # We workaround this by using our own macro to figure out what to add.
215
216 # This macro sets variables for additional Qt modules.
217 macro(setup_qt4_variables)
218   set(QUASSEL_QT_LIBRARIES )
219   IF(WIN32)
220     set(MAIN MAIN)
221   ENDIF(WIN32)
222   foreach(qtmod CORE ${ARGV} ${MAIN})
223     set(QUASSEL_QT_LIBRARIES ${QUASSEL_QT_LIBRARIES} ${QT_QT${qtmod}_LIBRARY} ${QT_${qtmod}_LIB_DEPENDENCIES})
224   endforeach(qtmod ${ARGV})
225   set(QUASSEL_QT_LIBRARIES ${QUASSEL_QT_LIBRARIES} ${QT_LIBRARIES})
226 endmacro(setup_qt4_variables)
227
228 # Now we have everything, so just glue the right pieces together :)
229 if(WANT_CORE)
230   setup_qt4_variables(NETWORK SCRIPT SQL)
231   add_executable(quasselcore src/common/main.cpp
232                              ${RC_SQL} ${RC_I18N} ${WIN32_RC})
233   set_target_properties(quasselcore PROPERTIES 
234                                     COMPILE_FLAGS "-DQT_NETWORK_LIB -DQT_SCRIPT_LIB -DQT_SQL_LIB -DBUILD_CORE")
235   target_link_libraries(quasselcore mod_core mod_common 
236                                     ${QUASSEL_QT_LIBRARIES} ${QUASSEL_SSL_LIBRARIES})
237 endif(WANT_CORE)
238
239 if(WANT_QTCLIENT)
240   setup_qt4_variables(${LINK_DBUS} GUI NETWORK)
241   add_executable(quasselclient WIN32 src/common/main.cpp
242                                      ${RC_ICONS} ${RC_QUASSEL_ICONS} ${RC_I18N} ${WIN32_RC})
243   set_target_properties(quasselclient PROPERTIES
244                                       COMPILE_FLAGS "-DQT_GUI_LIB -DQT_NETWORK_LIB -DBUILD_QTUI")
245   target_link_libraries(quasselclient mod_qtui mod_uisupport mod_client mod_common
246                                       ${QUASSEL_QT_LIBRARIES} ${QUASSEL_SSL_LIBRARIES})
247 endif(WANT_QTCLIENT)
248
249 if(WANT_MONO)
250   setup_qt4_variables(${LINK_DBUS} GUI NETWORK SCRIPT SQL)
251   add_executable(quassel WIN32 src/common/main.cpp src/qtui/monoapplication.cpp
252                                ${RC_ICONS} ${RC_QUASSEL_ICONS} ${RC_SQL} ${RC_I18N} ${WIN32_RC})
253   set_target_properties(quassel PROPERTIES 
254                                 COMPILE_FLAGS "-DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_SCRIPT_LIB -DQT_SQL_LIB -DBUILD_MONO")
255   target_link_libraries(quassel mod_qtui mod_uisupport mod_client mod_core mod_common 
256                                 ${QUASSEL_QT_LIBRARIES} ${QUASSEL_SSL_LIBRARIES})
257 endif(WANT_MONO)
258
259 # Build bundles for MacOSX
260 if(APPLE)
261   add_custom_command(TARGET quasselclient POST_BUILD
262                      COMMAND ${CMAKE_SOURCE_DIR}/scripts/build/macosx_makebundle.py
263                              ${CMAKE_SOURCE_DIR} "Quassel Client" quasselclient)
264   add_custom_command(TARGET quassel POST_BUILD
265                      COMMAND ${CMAKE_SOURCE_DIR}/scripts/build/macosx_makebundle.py
266                              ${CMAKE_SOURCE_DIR} "Quassel" quassel)
267   if(DEPLOY)
268     add_custom_command(TARGET quasselclient POST_BUILD
269                        COMMAND ${CMAKE_SOURCE_DIR}/scripts/build/macosx_makePackage.sh Client)
270     add_custom_command(TARGET quasselcore POST_BUILD
271                        COMMAND ${CMAKE_SOURCE_DIR}/scripts/build/macosx_makePackage.sh Core)
272   endif(DEPLOY)
273 endif(APPLE)
274
275 # Install rules
276 if(WANT_CORE)
277   install(TARGETS quasselcore
278           RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
279 endif(WANT_CORE)
280
281 if(WANT_QTCLIENT)
282   install(TARGETS quasselclient
283           RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
284
285   install(FILES quasselclient.desktop
286           DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications)
287 endif(WANT_QTCLIENT)
288
289 if(WANT_MONO)
290   install(TARGETS quassel
291           RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
292
293   install(FILES quassel.desktop
294           DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications)
295 endif(WANT_MONO)