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