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