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