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