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