ba3948cb49c56c7902bfc3d15ab38e9a85c9a2bb
[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 # -DSPUTDEV        : Do not use.
7
8 project(QuasselIRC)
9
10 cmake_minimum_required(VERSION 2.4.5)
11
12 set(QT_MIN_VERSION "4.4.0")
13 find_package(Qt4 REQUIRED)
14
15 # By default, we build all binaries
16 if(NOT DEFINED BUILD)
17   set(BUILD all)
18 endif(NOT DEFINED BUILD)
19
20 # User might define which binaries to build by invoking cmake -DBUILD=<string>,
21 # where <string> might contain any combination of "core", "client", "mono" or "all"
22 if(BUILD MATCHES all)
23   set(BUILD_CORE true)
24   set(BUILD_QTCLIENT true)
25   set(BUILD_MONO true)
26   message(STATUS "Building Quassel Client, Quassel Core and monolithic Quassel.")
27 else(BUILD MATCHES all)
28   if(BUILD MATCHES core)
29     set(BUILD_CORE true)
30     message(STATUS "Building Quassel Core")
31   endif(BUILD MATCHES core)
32   if(BUILD MATCHES client)
33     set(BUILD_QTCLIENT true)
34     message(STATUS "Building Quassel Client")
35   endif(BUILD MATCHES client)
36   if(BUILD MATCHES mono)
37     set(BUILD_MONO true)
38     message(STATUS "Building monolithic Quassel")
39   endif(BUILD MATCHES mono)
40 endif(BUILD MATCHES all)
41
42 # Select a Qt installation here, if you don't want to use system Qt
43 if(DEFINED QT)
44   # FindQt4 will look for the qmake binary in $PATH, so we just prepend the Qt dir
45   set(ENV{PATH} ${QT}/bin:$ENV{PATH})
46 endif(DEFINED QT)
47
48 # Enable mostly b0rked stuff (new ChatView), do not enable this unless you know what you do...
49 if(SPUTDEV)
50   add_definitions(-DSPUTDEV)
51 endif(SPUTDEV)
52
53 # Add needed subdirs
54 add_subdirectory(src/common)
55 include_directories(src/common)
56 if(BUILD_CORE OR BUILD_MONO)
57   add_subdirectory(src/core)
58   include_directories(src/core)
59 endif(BUILD_CORE OR BUILD_MONO)
60 if(BUILD_QTCLIENT OR BUILD_MONO)
61   add_subdirectory(src/client)
62   add_subdirectory(src/uisupport)
63   add_subdirectory(src/qtui)
64   include_directories(src/client)
65   include_directories(src/uisupport)
66   include_directories(src/qtui)
67 endif(BUILD_QTCLIENT OR BUILD_MONO)
68
69 # Add resources
70 qt4_add_resources(RES_I18N ${CMAKE_SOURCE_DIR}/i18n/i18n.qrc)
71 qt4_add_resources(RES_ICONS ${CMAKE_SOURCE_DIR}/src/icons/icons.qrc)
72 qt4_add_resources(RES_SQL ${CMAKE_SOURCE_DIR}/src/core/sql.qrc)
73
74 # Here comes the dirty part. Our targets need different Qt4 modules, i.e. different libs
75 # and defines. We can't simply include UseQt4 several times, since definitions add up.
76 # We workaround this by only setting up QtCore first, and adding additional stuff later.
77 set(QT_DONT_USE_QTGUI 1)
78 include(${QT_USE_FILE})
79 include_directories(${QT_INCLUDES})
80
81 # This macro sets variables for additional Qt modules.
82 macro(setup_qt4_variables)
83   set(QUASSEL_QT_DEFINITIONS )
84   set(QUASSEL_QT_LIBRARIES )
85   foreach(qtmod ${ARGV})
86     # This needs to be a string, not a list, otherwise set_target_properties screws up...
87     set(QUASSEL_QT_DEFINITIONS "${QUASSEL_QT_DEFINITIONS} -DQT_${qtmod}_LIB")
88     set(QUASSEL_QT_LIBRARIES ${QUASSEL_QT_LIBRARIES} ${QT_QT${qtmod}_LIBRARY} ${QT_${qtmod}_LIB_DEPENDENCIES})
89   endforeach(qtmod ${ARGV})
90 endmacro(setup_qt4_variables)
91
92 # Now we have everything, so just glue the right pieces together :)
93 if(BUILD_CORE)
94   setup_qt4_variables(NETWORK SCRIPT SQL)
95   add_executable(quasselcore ${CMAKE_SOURCE_DIR}/src/common/main.cpp ${RES_SQL} ${RES_I18N})
96   set_target_properties(quasselcore PROPERTIES COMPILE_FLAGS "${QUASSEL_QT_DEFINITIONS} -DBUILD_CORE")
97   target_link_libraries(quasselcore mod_core mod_common ${QUASSEL_QT_LIBRARIES})
98 endif(BUILD_CORE)
99
100 if(BUILD_QTCLIENT)
101   setup_qt4_variables(GUI NETWORK)
102   add_executable(quasselclient ${CMAKE_SOURCE_DIR}/src/common/main.cpp ${RES_ICONS} ${RES_I18N})
103   set_target_properties(quasselclient PROPERTIES COMPILE_FLAGS "${QUASSEL_QT_DEFINITIONS} -DBUILD_QTUI")
104   target_link_libraries(quasselclient mod_qtui mod_uisupport mod_client mod_common ${QUASSEL_QT_LIBRARIES})
105 endif(BUILD_QTCLIENT)
106
107 if(BUILD_MONO)
108   setup_qt4_variables(GUI NETWORK SCRIPT SQL)
109   add_executable(quassel ${CMAKE_SOURCE_DIR}/src/common/main.cpp ${RES_ICONS} ${RES_SQL} ${RES_I18N})
110   set_target_properties(quassel PROPERTIES COMPILE_FLAGS "${QUASSEL_QT_DEFINITIONS} -DBUILD_MONO")
111   target_link_libraries(quassel mod_qtui mod_uisupport mod_client mod_core mod_common ${QUASSEL_QT_LIBRARIES})
112 endif(BUILD_MONO)