debug--
[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 # Enable various flags on gcc
42 if(CMAKE_COMPILER_IS_GNUCXX)
43   include(CheckCXXCompilerFlag)
44   check_cxx_compiler_flag(-Wall HAVE_WALL)
45   if(HAVE_WALL)
46     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
47   endif(HAVE_WALL)
48   check_cxx_compiler_flag(-Wextra HAVE_WEXTRA)
49   if(HAVE_WEXTRA)
50     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
51   endif(HAVE_WEXTRA)
52   check_cxx_compiler_flag(-ansi HAVE_ANSI)
53   if(HAVE_ANSI)
54     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ansi")
55   endif(HAVE_ANSI)
56 endif(CMAKE_COMPILER_IS_GNUCXX)
57
58 set(QT_MIN_VERSION "4.3.0")
59
60 if(APPLE AND DEPLOY)
61   set(CMAKE_OSX_ARCHITECTURES "i386;ppc")
62   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.4")
63   set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.4u.sdk/")
64 endif(APPLE AND DEPLOY)
65
66 # Enable mostly b0rked stuff (new ChatView), do not enable this unless you know what you do...
67 if(SPUTDEV)
68   add_definitions(-DSPUTDEV)
69 endif(SPUTDEV)
70
71 # Set up OpenSSL
72 find_package(OpenSSL)
73 if(NOT OPENSSL_FOUND)
74   add_definitions(-DQT_NO_OPENSSL)
75 endif(NOT OPENSSL_FOUND)
76
77 # Select a Qt installation here, if you don't want to use system Qt
78 if(QT)
79   # FindQt4 will look for the qmake binary in $PATH, so we just prepend the Qt dir
80   set(ENV{PATH} ${QT}/bin:$ENV{PATH})
81 endif(QT)
82
83 # Now that we have the correct $PATH, lets find Qt!
84 find_package(Qt4 REQUIRED)
85
86 if(QT_QTDBUS_FOUND)
87   add_definitions(-DHAVE_DBUS)
88   set(LINK_DBUS DBUS)
89   set(HAVE_DBUS true)
90 endif(QT_QTDBUS_FOUND)
91
92 set(QT_DONT_USE_QTGUI 1)
93 include(${QT_USE_FILE})
94 include_directories(${QT_INCLUDES})
95
96 # We need to create a version.gen
97 # For this, we create our genversion binary and make sure it is run every time.
98 add_executable(genversion ${CMAKE_SOURCE_DIR}/src/common/genversion.cpp)
99 target_link_libraries(genversion ${QT_LIBRARIES} ${QT_CORE_LIB_DEPENDENCIES})
100
101 add_custom_target(genversion_run ALL ${CMAKE_BINARY_DIR}/genversion
102                   ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/src/common/version.gen)
103 add_dependencies(genversion_run genversion)
104
105 # Add needed subdirs
106 add_subdirectory(src/common)
107 include_directories(src/common)
108 if(WANT_CORE OR WANT_MONO)
109   add_subdirectory(src/core)
110   include_directories(src/core)
111 endif(WANT_CORE OR WANT_MONO)
112 if(WANT_QTCLIENT OR WANT_MONO)
113   add_subdirectory(src/client)
114   add_subdirectory(src/uisupport)
115   add_subdirectory(src/qtui)
116   include_directories(src/client)
117   include_directories(src/uisupport)
118   include_directories(src/qtui)
119 endif(WANT_QTCLIENT OR WANT_MONO)
120
121 # Make sure version.gen exists before building mod_common
122 add_dependencies(mod_common genversion_run)
123
124 # Generate binary translation files
125 include(QuasselGenerateTranslations)
126 quassel_generate_i18n_resource(RC_I18N ${LINGUAS})
127
128 # Add resources
129 qt4_add_resources(RC_ICONS src/icons/icons.qrc)
130 qt4_add_resources(RC_QUASSEL_ICONS src/icons/quassel-icons.qrc)
131 qt4_add_resources(RC_SQL src/core/sql.qrc)
132
133 # Set global buildflags
134 # This is very much non-portable, so don't use -DSTATICGCC until you know what
135 # you do.
136 if(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
137   set(CMAKE_CXX_FLAGS "-static-libgcc ${CMAKE_CXX_FLAGS}")
138   link_directories(${CMAKE_BINARY_DIR}/staticlibs) # override dynamic libs
139   if(OPENSSL_FOUND)
140     set(QUASSEL_SSL_LIBRARIES ssl crypto)  # these miss in static builds
141   endif(OPENSSL_FOUND)
142 endif(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
143
144 if(STATIC AND WIN32)
145   link_libraries(imm32 winmm)  # missing by default :/
146    if(OPENSSL_FOUND)
147      link_libraries(${OPENSSL_LIBRARIES} libeay32MD)
148    endif(OPENSSL_FOUND)
149 endif(STATIC AND WIN32)
150
151 if(WIN32)
152   set(WIN32_RC src/icons/win32.rc)  # for app icons on windows
153 endif(WIN32)
154
155 # Here comes the dirty part. Our targets need different Qt4 modules, i.e. different libs
156 # and defines. We can't simply include UseQt4 several times, since definitions add up.
157 # We workaround this by using our own macro to figure out what to add.
158
159 # This macro sets variables for additional Qt modules.
160 macro(setup_qt4_variables)
161   set(QUASSEL_QT_LIBRARIES )
162   IF(WIN32)
163     set(MAIN MAIN)
164   ENDIF(WIN32)
165   foreach(qtmod CORE ${ARGV} ${MAIN})
166     set(QUASSEL_QT_LIBRARIES ${QUASSEL_QT_LIBRARIES} ${QT_QT${qtmod}_LIBRARY} ${QT_${qtmod}_LIB_DEPENDENCIES})
167   endforeach(qtmod ${ARGV})
168   set(QUASSEL_QT_LIBRARIES ${QUASSEL_QT_LIBRARIES} ${QT_LIBRARIES})
169 endmacro(setup_qt4_variables)
170
171 # Now we have everything, so just glue the right pieces together :)
172 if(WANT_CORE)
173   setup_qt4_variables(NETWORK SCRIPT SQL)
174   add_executable(quasselcore ${CMAKE_SOURCE_DIR}/src/common/main.cpp
175                              ${RC_SQL} ${RC_I18N} ${WIN32_RC})
176   set_target_properties(quasselcore PROPERTIES 
177                                     COMPILE_FLAGS "-DQT_NETWORK_LIB -DQT_SCRIPT_LIB -DQT_SQL_LIB -DBUILD_CORE")
178   target_link_libraries(quasselcore mod_core mod_common 
179                                     ${QUASSEL_QT_LIBRARIES} ${QUASSEL_SSL_LIBRARIES})
180 endif(WANT_CORE)
181
182 if(WANT_QTCLIENT)
183   setup_qt4_variables(${LINK_DBUS} GUI NETWORK)
184   add_executable(quasselclient WIN32 ${CMAKE_SOURCE_DIR}/src/common/main.cpp
185                                      ${RC_ICONS} ${RC_QUASSEL_ICONS} ${RC_I18N} ${WIN32_RC})
186   set_target_properties(quasselclient PROPERTIES
187                                       COMPILE_FLAGS "-DQT_GUI_LIB -DQT_NETWORK_LIB -DBUILD_QTUI")
188   target_link_libraries(quasselclient mod_qtui mod_uisupport mod_client mod_common
189                                       ${QUASSEL_QT_LIBRARIES} ${QUASSEL_SSL_LIBRARIES})
190 endif(WANT_QTCLIENT)
191
192 if(WANT_MONO)
193   setup_qt4_variables(${LINK_DBUS} GUI NETWORK SCRIPT SQL)
194   add_executable(quassel WIN32 ${CMAKE_SOURCE_DIR}/src/common/main.cpp
195                                ${RC_ICONS} ${RC_QUASSEL_ICONS} ${RC_SQL} ${RC_I18N} ${WIN32_RC})
196   set_target_properties(quassel PROPERTIES 
197                                 COMPILE_FLAGS "-DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_SCRIPT_LIB -DQT_SQL_LIB -DBUILD_MONO")
198   target_link_libraries(quassel mod_qtui mod_uisupport mod_client mod_core mod_common 
199                                 ${QUASSEL_QT_LIBRARIES} ${QUASSEL_SSL_LIBRARIES})
200 endif(WANT_MONO)
201
202 # Build bundles for MacOSX
203 if(APPLE)
204   add_custom_command(TARGET quasselclient POST_BUILD
205                      COMMAND ${CMAKE_SOURCE_DIR}/scripts/build/macosx_makebundle.py
206                              ${CMAKE_SOURCE_DIR} "Quassel Client" quasselclient)
207   add_custom_command(TARGET quassel POST_BUILD
208                      COMMAND ${CMAKE_SOURCE_DIR}/scripts/build/macosx_makebundle.py
209                              ${CMAKE_SOURCE_DIR} "Quassel" quassel)
210   if(DEPLOY)
211     add_custom_command(TARGET quasselclient POST_BUILD
212                        COMMAND ${CMAKE_SOURCE_DIR}/scripts/build/macosx_makePackage.sh Client)
213     add_custom_command(TARGET quasselcore POST_BUILD
214                        COMMAND ${CMAKE_SOURCE_DIR}/scripts/build/macosx_makePackage.sh Core)
215   endif(DEPLOY)
216 endif(APPLE)
217
218 # Install rules
219 if(WANT_CORE)
220   install(TARGETS quasselcore
221           RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
222 endif(WANT_CORE)
223
224 if(WANT_QTCLIENT)
225   install(TARGETS quasselclient
226           RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
227
228   install(FILES quasselclient.desktop
229           DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications)
230 endif(WANT_QTCLIENT)
231
232 if(WANT_MONO)
233   install(TARGETS quassel
234           RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
235
236   install(FILES quassel.desktop
237           DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications)
238 endif(WANT_MONO)