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