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