Merge branch 'cmake' of git@git.quassel-irc.org:quassel into cmake
[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 cmake_policy(SET CMP0003 OLD)  # suppress linker warnings
16
17 if(STATICWIN)
18   set(CMAKE_BUILD_TYPE Release)
19 endif(STATICWIN)
20
21 set(QT_MIN_VERSION "4.4.0")
22
23 # By default, we build all binaries
24 if(NOT DEFINED BUILD)
25   set(BUILD all)
26 endif(NOT DEFINED BUILD)
27
28 # User might define which binaries to build by invoking cmake -DBUILD=<string>,
29 # where <string> might contain any combination of "core", "client", "mono" or "all"
30 if(BUILD MATCHES all)
31   set(BUILD_CORE true)
32   set(BUILD_QTCLIENT true)
33   set(BUILD_MONO true)
34   message(STATUS "Building Quassel Client, Quassel Core and monolithic Quassel.")
35 else(BUILD MATCHES all)
36   if(BUILD MATCHES core)
37     set(BUILD_CORE true)
38     message(STATUS "Building Quassel Core")
39   endif(BUILD MATCHES core)
40   if(BUILD MATCHES client)
41     set(BUILD_QTCLIENT true)
42     message(STATUS "Building Quassel Client")
43   endif(BUILD MATCHES client)
44   if(BUILD MATCHES mono)
45     set(BUILD_MONO true)
46     message(STATUS "Building monolithic Quassel")
47   endif(BUILD MATCHES mono)
48 endif(BUILD MATCHES all)
49
50 # Select a Qt installation here, if you don't want to use system Qt
51 if(DEFINED QT)
52   # FindQt4 will look for the qmake binary in $PATH, so we just prepend the Qt dir
53   set(ENV{PATH} ${QT}/bin:$ENV{PATH})
54   #SET(QT_QMAKE_EXECUTABLE ${QT}/bin/qmake CACHE FILEPATH "" FORCE)
55 endif(DEFINED QT)
56
57 # Enable mostly b0rked stuff (new ChatView), do not enable this unless you know what you do...
58 if(SPUTDEV)
59   add_definitions(-DSPUTDEV)
60 endif(SPUTDEV)
61
62 # Now that we have the correct $PATH, lets find Qt!
63 find_package(Qt4 REQUIRED)
64
65 set(QT_DONT_USE_QTGUI 1)
66 include(${QT_USE_FILE})
67 include_directories(${QT_INCLUDES})
68
69 # We need to create a version.gen
70 # For this, we create our genversion binary and make sure it is run every time.
71 add_executable(genversion ${CMAKE_SOURCE_DIR}/src/common/genversion.cpp)
72 target_link_libraries(genversion ${QT_LIBRARIES})
73
74 add_custom_target(genversion_run ALL ${CMAKE_BINARY_DIR}/genversion
75                   ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/src/common/version.gen)
76 add_dependencies(genversion_run genversion)
77
78 # Add needed subdirs
79 add_subdirectory(src/common)
80 include_directories(src/common)
81 if(BUILD_CORE OR BUILD_MONO)
82   add_subdirectory(src/core)
83   include_directories(src/core)
84 endif(BUILD_CORE OR BUILD_MONO)
85 if(BUILD_QTCLIENT OR BUILD_MONO)
86   add_subdirectory(src/client)
87   add_subdirectory(src/uisupport)
88   add_subdirectory(src/qtui)
89   include_directories(src/client)
90   include_directories(src/uisupport)
91   include_directories(src/qtui)
92 endif(BUILD_QTCLIENT OR BUILD_MONO)
93
94 # Make sure version.gen exists before building mod_common
95 add_dependencies(mod_common genversion_run)
96
97 # Add resources
98 qt4_add_resources(RES_I18N ${CMAKE_SOURCE_DIR}/i18n/i18n.qrc)
99 qt4_add_resources(RES_ICONS ${CMAKE_SOURCE_DIR}/src/icons/icons.qrc)
100 qt4_add_resources(RES_SQL ${CMAKE_SOURCE_DIR}/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 endif(STATICWIN AND WIN32)
111
112 # FIXME: Add icons for windows as soon as we have merged with trunk (which has reorganized
113 #        the icon files):
114 #        Simply add the .rc file to the targets
115
116 # Here comes the dirty part. Our targets need different Qt4 modules, i.e. different libs
117 # and defines. We can't simply include UseQt4 several times, since definitions add up.
118 # We workaround this by using our own macro to figure out what to add.
119
120 # This macro sets variables for additional Qt modules.
121 macro(setup_qt4_variables)
122   set(QUASSEL_QT_DEFINITIONS ${QT_DEFINITIONS})
123   set(QUASSEL_QT_LIBRARIES )
124   foreach(qtmod ${ARGV})
125     # This needs to be a string, not a list, otherwise set_target_properties screws up...
126     set(QUASSEL_QT_DEFINITIONS "${QUASSEL_QT_DEFINITIONS} -DQT_${qtmod}_LIB")
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(BUILD_CORE)
134   setup_qt4_variables(NETWORK SCRIPT SQL)
135   add_executable(quasselcore ${CMAKE_SOURCE_DIR}/src/common/main.cpp ${RES_SQL} ${RES_I18N})
136   set_target_properties(quasselcore PROPERTIES COMPILE_FLAGS "${QUASSEL_QT_DEFINITIONS} -DBUILD_CORE")
137   target_link_libraries(quasselcore mod_core mod_common ${QUASSEL_QT_LIBRARIES})
138 endif(BUILD_CORE)
139
140 if(BUILD_QTCLIENT)
141   setup_qt4_variables(GUI NETWORK)
142   add_executable(quasselclient ${CMAKE_SOURCE_DIR}/src/common/main.cpp ${RES_ICONS} ${RES_I18N})
143   set_target_properties(quasselclient PROPERTIES COMPILE_FLAGS "${QUASSEL_QT_DEFINITIONS} -DBUILD_QTUI")
144   target_link_libraries(quasselclient mod_qtui mod_uisupport mod_client mod_common ${QUASSEL_QT_LIBRARIES})
145 endif(BUILD_QTCLIENT)
146
147 if(BUILD_MONO)
148   setup_qt4_variables(GUI NETWORK SCRIPT SQL)
149   add_executable(quassel ${CMAKE_SOURCE_DIR}/src/common/main.cpp ${RES_ICONS} ${RES_SQL} ${RES_I18N})
150   set_target_properties(quassel PROPERTIES COMPILE_FLAGS "${QUASSEL_QT_DEFINITIONS} -DBUILD_MONO")
151   target_link_libraries(quassel mod_qtui mod_uisupport mod_client mod_core mod_common ${QUASSEL_QT_LIBRARIES})
152 endif(BUILD_MONO)