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