6523028c8ccc4b242f14b329108a6eae4a459e5e
[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 # We can't use this on 2.4, so we'll have to live with warnings from 2.6 in
17 # the meantime...
18 #cmake_policy(SET CMP0003 OLD)  # suppress linker warnings
19
20 if(STATICWIN)
21   set(CMAKE_BUILD_TYPE Release)
22 endif(STATICWIN)
23
24 set(QT_MIN_VERSION "4.4.0")
25
26 # By default, we build all binaries
27 if(NOT DEFINED BUILD)
28   set(BUILD all)
29 endif(NOT DEFINED BUILD)
30
31 # User might define which binaries to build by invoking cmake -DBUILD=<string>,
32 # where <string> might contain any combination of "core", "client", "mono" or "all"
33 if(BUILD MATCHES all)
34   set(BUILD_CORE true)
35   set(BUILD_QTCLIENT true)
36   set(BUILD_MONO true)
37   message(STATUS "Building Quassel Client, Quassel Core and monolithic Quassel.")
38 else(BUILD MATCHES all)
39   if(BUILD MATCHES core)
40     set(BUILD_CORE true)
41     message(STATUS "Building Quassel Core")
42   endif(BUILD MATCHES core)
43   if(BUILD MATCHES client)
44     set(BUILD_QTCLIENT true)
45     message(STATUS "Building Quassel Client")
46   endif(BUILD MATCHES client)
47   if(BUILD MATCHES mono)
48     set(BUILD_MONO true)
49     message(STATUS "Building monolithic Quassel")
50   endif(BUILD MATCHES mono)
51 endif(BUILD MATCHES all)
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 # Enable mostly b0rked stuff (new ChatView), do not enable this unless you know what you do...
61 if(SPUTDEV)
62   add_definitions(-DSPUTDEV)
63 endif(SPUTDEV)
64
65 # Now that we have the correct $PATH, lets find Qt!
66 find_package(Qt4 REQUIRED)
67
68 set(QT_DONT_USE_QTGUI 1)
69 include(${QT_USE_FILE})
70 include_directories(${QT_INCLUDES})
71
72 # We need to create a version.gen
73 # For this, we create our genversion binary and make sure it is run every time.
74 add_executable(genversion ${CMAKE_SOURCE_DIR}/src/common/genversion.cpp)
75 target_link_libraries(genversion ${QT_LIBRARIES})
76
77 add_custom_target(genversion_run ALL ${CMAKE_BINARY_DIR}/genversion
78                   ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/src/common/version.gen)
79 add_dependencies(genversion_run genversion)
80
81 # Add needed subdirs
82 add_subdirectory(src/common)
83 include_directories(src/common)
84 if(BUILD_CORE OR BUILD_MONO)
85   add_subdirectory(src/core)
86   include_directories(src/core)
87 endif(BUILD_CORE OR BUILD_MONO)
88 if(BUILD_QTCLIENT OR BUILD_MONO)
89   add_subdirectory(src/client)
90   add_subdirectory(src/uisupport)
91   add_subdirectory(src/qtui)
92   include_directories(src/client)
93   include_directories(src/uisupport)
94   include_directories(src/qtui)
95 endif(BUILD_QTCLIENT OR BUILD_MONO)
96
97 # Make sure version.gen exists before building mod_common
98 add_dependencies(mod_common genversion_run)
99
100 # Add resources
101 qt4_add_resources(RES_I18N i18n/i18n.qrc)
102 qt4_add_resources(RES_ICONS src/icons/icons.qrc)
103 qt4_add_resources(RES_QUASSEL_ICONS src/icons/quassel-icons.qrc)
104 qt4_add_resources(RES_SQL src/core/sql.qrc)
105
106 # Set global buildflags
107 if(DEFINED STATIC)
108   set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc ${CMAKE_EXE_LINKER_FLAGS}")
109   link_directories(${CMAKE_BINARY_DIR}/staticlibs)
110 endif(DEFINED STATIC)
111
112 if(STATICWIN AND WIN32)
113   link_libraries(imm32 winmm)  # missing by default :/
114 endif(STATICWIN AND WIN32)
115
116 # FIXME: Add icons for windows as soon as we have merged with trunk (which has reorganized
117 #        the icon files):
118 #        Simply add the .rc file to the targets
119
120 # Here comes the dirty part. Our targets need different Qt4 modules, i.e. different libs
121 # and defines. We can't simply include UseQt4 several times, since definitions add up.
122 # We workaround this by using our own macro to figure out what to add.
123
124 # This macro sets variables for additional Qt modules.
125 macro(setup_qt4_variables)
126   set(QUASSEL_QT_DEFINITIONS ${QT_DEFINITIONS})
127   set(QUASSEL_QT_LIBRARIES )
128   foreach(qtmod ${ARGV})
129     # This needs to be a string, not a list, otherwise set_target_properties screws up...
130     set(QUASSEL_QT_DEFINITIONS "${QUASSEL_QT_DEFINITIONS} -DQT_${qtmod}_LIB")
131     set(QUASSEL_QT_LIBRARIES ${QUASSEL_QT_LIBRARIES} ${QT_QT${qtmod}_LIBRARY} ${QT_${qtmod}_LIB_DEPENDENCIES})
132   endforeach(qtmod ${ARGV})
133   set(QUASSEL_QT_LIBRARIES ${QUASSEL_QT_LIBRARIES} ${QT_LIBRARIES})
134 endmacro(setup_qt4_variables)
135
136 # Now we have everything, so just glue the right pieces together :)
137 if(BUILD_CORE)
138   setup_qt4_variables(NETWORK SCRIPT SQL)
139   add_executable(quasselcore ${CMAKE_SOURCE_DIR}/src/common/main.cpp ${RES_SQL} ${RES_I18N})
140   set_target_properties(quasselcore PROPERTIES COMPILE_FLAGS "${QUASSEL_QT_DEFINITIONS} -DBUILD_CORE")
141   target_link_libraries(quasselcore mod_core mod_common ${QUASSEL_QT_LIBRARIES})
142 endif(BUILD_CORE)
143
144 if(BUILD_QTCLIENT)
145   setup_qt4_variables(GUI NETWORK)
146   add_executable(quasselclient ${CMAKE_SOURCE_DIR}/src/common/main.cpp ${RES_ICONS} ${RES_QUASSEL_ICONS} ${RES_I18N})
147   set_target_properties(quasselclient PROPERTIES COMPILE_FLAGS "${QUASSEL_QT_DEFINITIONS} -DBUILD_QTUI")
148   target_link_libraries(quasselclient mod_qtui mod_uisupport mod_client mod_common ${QUASSEL_QT_LIBRARIES})
149 endif(BUILD_QTCLIENT)
150
151 if(BUILD_MONO)
152   setup_qt4_variables(GUI NETWORK SCRIPT SQL)
153   add_executable(quassel ${CMAKE_SOURCE_DIR}/src/common/main.cpp ${RES_ICONS} ${RES_QUASSEL_ICONS} ${RES_SQL} ${RES_I18N})
154   set_target_properties(quassel PROPERTIES COMPILE_FLAGS "${QUASSEL_QT_DEFINITIONS} -DBUILD_MONO")
155   target_link_libraries(quassel mod_qtui mod_uisupport mod_client mod_core mod_common ${QUASSEL_QT_LIBRARIES})
156 endif(BUILD_MONO)