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