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