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.
9 # NOTE: You need to remove CMakeCache.txt if you plan to change any of these values!
13 # Target scopes don't work in older versions
14 cmake_minimum_required(VERSION 2.4.7 FATAL_ERROR)
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
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)
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)
29 option(STATIC "Enable static building (might not be portable)" OFF)
30 option(SPUTDEV "Do not use!" OFF)
32 set(QT "" CACHE STRING "Path to a Qt installation to use instead of the system Qt")
35 set(CMAKE_BUILD_TYPE Release)
38 # Enable various flags on gcc
39 if(CMAKE_COMPILER_IS_GNUCXX)
40 include(CheckCXXCompilerFlag)
41 check_cxx_compiler_flag(-Wall HAVE_WALL)
43 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
45 check_cxx_compiler_flag(-Wextra HAVE_WEXTRA)
47 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
49 check_cxx_compiler_flag(-ansi HAVE_ANSI)
51 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ansi")
53 endif(CMAKE_COMPILER_IS_GNUCXX)
55 set(QT_MIN_VERSION "4.3.0")
57 # Enable mostly b0rked stuff (new ChatView), do not enable this unless you know what you do...
59 add_definitions(-DSPUTDEV)
65 # Select a Qt installation here, if you don't want to use system Qt
67 # FindQt4 will look for the qmake binary in $PATH, so we just prepend the Qt dir
68 set(ENV{PATH} ${QT}/bin:$ENV{PATH})
71 # Now that we have the correct $PATH, lets find Qt!
72 find_package(Qt4 REQUIRED)
74 set(QT_DONT_USE_QTGUI 1)
75 include(${QT_USE_FILE})
76 include_directories(${QT_INCLUDES})
78 # We need to create a version.gen
79 # For this, we create our genversion binary and make sure it is run every time.
80 add_executable(genversion ${CMAKE_SOURCE_DIR}/src/common/genversion.cpp)
81 target_link_libraries(genversion ${QT_LIBRARIES} ${QT_CORE_LIB_DEPENDENCIES})
83 add_custom_target(genversion_run ALL ${CMAKE_BINARY_DIR}/genversion
84 ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/src/common/version.gen)
85 add_dependencies(genversion_run genversion)
88 add_subdirectory(src/common)
89 include_directories(src/common)
90 if(WANT_CORE OR WANT_MONO)
91 add_subdirectory(src/core)
92 include_directories(src/core)
93 endif(WANT_CORE OR WANT_MONO)
94 if(WANT_QTCLIENT OR WANT_MONO)
95 add_subdirectory(src/client)
96 add_subdirectory(src/uisupport)
97 add_subdirectory(src/qtui)
98 include_directories(src/client)
99 include_directories(src/uisupport)
100 include_directories(src/qtui)
101 endif(WANT_QTCLIENT OR WANT_MONO)
103 # Make sure version.gen exists before building mod_common
104 add_dependencies(mod_common genversion_run)
107 qt4_add_resources(RC_I18N i18n/i18n.qrc)
108 qt4_add_resources(RC_ICONS src/icons/icons.qrc)
109 qt4_add_resources(RC_QUASSEL_ICONS src/icons/quassel-icons.qrc)
110 qt4_add_resources(RC_SQL src/core/sql.qrc)
112 # Set global buildflags
113 # This is very much non-portable, so don't use -DSTATICGCC until you know what
115 if(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
116 set(CMAKE_CXX_FLAGS "-static-libgcc ${CMAKE_CXX_FLAGS}")
117 link_directories(${CMAKE_BINARY_DIR}/staticlibs) # override dynamic libs
119 set(QUASSEL_SSL_LIBRARIES ssl crypto) # these miss in static builds
121 endif(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
124 link_libraries(imm32 winmm) # missing by default :/
126 link_libraries(${OPENSSL_LIBRARIES} libeay32MD)
128 endif(STATIC AND WIN32)
131 set(WIN32_RC src/icons/win32.rc) # for app icons on windows
134 # Here comes the dirty part. Our targets need different Qt4 modules, i.e. different libs
135 # and defines. We can't simply include UseQt4 several times, since definitions add up.
136 # We workaround this by using our own macro to figure out what to add.
138 # This macro sets variables for additional Qt modules.
139 macro(setup_qt4_variables)
140 set(QUASSEL_QT_LIBRARIES )
144 foreach(qtmod CORE ${ARGV} ${MAIN})
145 set(QUASSEL_QT_LIBRARIES ${QUASSEL_QT_LIBRARIES} ${QT_QT${qtmod}_LIBRARY} ${QT_${qtmod}_LIB_DEPENDENCIES})
146 endforeach(qtmod ${ARGV})
147 set(QUASSEL_QT_LIBRARIES ${QUASSEL_QT_LIBRARIES} ${QT_LIBRARIES})
148 endmacro(setup_qt4_variables)
150 # Now we have everything, so just glue the right pieces together :)
152 setup_qt4_variables(NETWORK SCRIPT SQL)
153 add_executable(quasselcore ${CMAKE_SOURCE_DIR}/src/common/main.cpp
154 ${RC_SQL} ${RC_I18N} ${WIN32_RC})
155 set_target_properties(quasselcore PROPERTIES
156 COMPILE_FLAGS "-DQT_NETWORK_LIB -DQT_SCRIPT_LIB -DQT_SQL_LIB -DBUILD_CORE")
157 target_link_libraries(quasselcore mod_core mod_common
158 ${QUASSEL_QT_LIBRARIES} ${QUASSEL_SSL_LIBRARIES})
162 setup_qt4_variables(GUI NETWORK)
163 add_executable(quasselclient WIN32 ${CMAKE_SOURCE_DIR}/src/common/main.cpp
164 ${RC_ICONS} ${RC_QUASSEL_ICONS} ${RC_I18N} ${WIN32_RC})
165 set_target_properties(quasselclient PROPERTIES
166 COMPILE_FLAGS "-DQT_GUI_LIB -DQT_NETWORK_LIB -DBUILD_QTUI")
167 target_link_libraries(quasselclient mod_qtui mod_uisupport mod_client mod_common
168 ${QUASSEL_QT_LIBRARIES} ${QUASSEL_SSL_LIBRARIES})
172 setup_qt4_variables(GUI NETWORK SCRIPT SQL)
173 add_executable(quassel WIN32 ${CMAKE_SOURCE_DIR}/src/common/main.cpp
174 ${RC_ICONS} ${RC_QUASSEL_ICONS} ${RC_SQL} ${RC_I18N} ${WIN32_RC})
175 set_target_properties(quassel PROPERTIES
176 COMPILE_FLAGS "-DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_SCRIPT_LIB -DQT_SQL_LIB -DBUILD_MONO")
177 target_link_libraries(quassel mod_qtui mod_uisupport mod_client mod_core mod_common
178 ${QUASSEL_QT_LIBRARIES} ${QUASSEL_SSL_LIBRARIES})
181 # Build bundles for MacOSX
183 add_custom_command(TARGET quasselclient POST_BUILD
184 COMMAND ${CMAKE_SOURCE_DIR}/scripts/build/macosx_makebundle.py
185 ${CMAKE_SOURCE_DIR} "Quassel Client" quasselclient)
186 add_custom_command(TARGET quassel POST_BUILD
187 COMMAND ${CMAKE_SOURCE_DIR}/scripts/build/macosx_makebundle.py
188 ${CMAKE_SOURCE_DIR} "Quassel" quassel)
193 install(TARGETS quasselcore
194 RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
198 install(TARGETS quasselclient
199 RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
201 install(FILES quasselclient.desktop
202 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications)
206 install(TARGETS quassel
207 RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
209 install(FILES quassel.desktop
210 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications)