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