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 # -DSPUTDEV : Do not use.
9 # NOTE: You need to remove CMakeCache.txt if you plan to change any of these values!
13 cmake_minimum_required(VERSION 2.4.5)
15 set(QT_MIN_VERSION "4.4.0")
17 # By default, we build all binaries
20 endif(NOT DEFINED BUILD)
22 # User might define which binaries to build by invoking cmake -DBUILD=<string>,
23 # where <string> might contain any combination of "core", "client", "mono" or "all"
26 set(BUILD_QTCLIENT true)
28 message(STATUS "Building Quassel Client, Quassel Core and monolithic Quassel.")
29 else(BUILD MATCHES all)
30 if(BUILD MATCHES core)
32 message(STATUS "Building Quassel Core")
33 endif(BUILD MATCHES core)
34 if(BUILD MATCHES client)
35 set(BUILD_QTCLIENT true)
36 message(STATUS "Building Quassel Client")
37 endif(BUILD MATCHES client)
38 if(BUILD MATCHES mono)
40 message(STATUS "Building monolithic Quassel")
41 endif(BUILD MATCHES mono)
42 endif(BUILD MATCHES all)
44 # Select a Qt installation here, if you don't want to use system Qt
46 # FindQt4 will look for the qmake binary in $PATH, so we just prepend the Qt dir
47 set(ENV{PATH} ${QT}/bin:$ENV{PATH})
48 #SET(QT_QMAKE_EXECUTABLE ${QT}/bin/qmake CACHE FILEPATH "" FORCE)
51 # Enable mostly b0rked stuff (new ChatView), do not enable this unless you know what you do...
53 add_definitions(-DSPUTDEV)
56 # Now that we have the correct $PATH, lets find Qt!
57 find_package(Qt4 REQUIRED)
59 set(QT_DONT_USE_QTGUI 1)
60 include(${QT_USE_FILE})
61 include_directories(${QT_INCLUDES})
63 # We need to create a version.gen
64 # For this, we create our genversion binary and make sure it is run every time.
65 add_executable(genversion ${CMAKE_SOURCE_DIR}/src/common/genversion.cpp)
66 target_link_libraries(genversion ${QT_LIBRARIES})
68 add_custom_target(genversion_run ALL ${CMAKE_BINARY_DIR}/genversion
69 ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/src/common/version.gen)
70 add_dependencies(genversion_run genversion)
73 add_subdirectory(src/common)
74 include_directories(src/common)
75 if(BUILD_CORE OR BUILD_MONO)
76 add_subdirectory(src/core)
77 include_directories(src/core)
78 endif(BUILD_CORE OR BUILD_MONO)
79 if(BUILD_QTCLIENT OR BUILD_MONO)
80 add_subdirectory(src/client)
81 add_subdirectory(src/uisupport)
82 add_subdirectory(src/qtui)
83 include_directories(src/client)
84 include_directories(src/uisupport)
85 include_directories(src/qtui)
86 endif(BUILD_QTCLIENT OR BUILD_MONO)
88 # Make sure version.gen exists before building mod_common
89 add_dependencies(mod_common genversion_run)
92 qt4_add_resources(RES_I18N ${CMAKE_SOURCE_DIR}/i18n/i18n.qrc)
93 qt4_add_resources(RES_ICONS ${CMAKE_SOURCE_DIR}/src/icons/icons.qrc)
94 qt4_add_resources(RES_SQL ${CMAKE_SOURCE_DIR}/src/core/sql.qrc)
96 # Set global buildflags
98 set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc ${CMAKE_EXE_LINKER_FLAGS}")
99 link_directories(${CMAKE_BINARY_DIR}/staticlibs)
100 endif(DEFINED STATIC)
102 # Here comes the dirty part. Our targets need different Qt4 modules, i.e. different libs
103 # and defines. We can't simply include UseQt4 several times, since definitions add up.
104 # We workaround this by using our own macro to figure out what to add.
106 # This macro sets variables for additional Qt modules.
107 macro(setup_qt4_variables)
108 set(QUASSEL_QT_DEFINITIONS ${QT_DEFINITIONS})
109 set(QUASSEL_QT_LIBRARIES )
110 foreach(qtmod ${ARGV})
111 # This needs to be a string, not a list, otherwise set_target_properties screws up...
112 set(QUASSEL_QT_DEFINITIONS "${QUASSEL_QT_DEFINITIONS} -DQT_${qtmod}_LIB")
113 set(QUASSEL_QT_LIBRARIES ${QUASSEL_QT_LIBRARIES} ${QT_QT${qtmod}_LIBRARY} ${QT_${qtmod}_LIB_DEPENDENCIES})
114 endforeach(qtmod ${ARGV})
115 set(QUASSEL_QT_LIBRARIES ${QUASSEL_QT_LIBRARIES} ${QT_LIBRARIES})
116 endmacro(setup_qt4_variables)
118 # Now we have everything, so just glue the right pieces together :)
120 setup_qt4_variables(NETWORK SCRIPT SQL)
121 add_executable(quasselcore ${CMAKE_SOURCE_DIR}/src/common/main.cpp ${RES_SQL} ${RES_I18N})
122 set_target_properties(quasselcore PROPERTIES COMPILE_FLAGS "${QUASSEL_QT_DEFINITIONS} -DBUILD_CORE")
123 target_link_libraries(quasselcore mod_core mod_common ${QUASSEL_QT_LIBRARIES})
127 setup_qt4_variables(GUI NETWORK)
128 add_executable(quasselclient ${CMAKE_SOURCE_DIR}/src/common/main.cpp ${RES_ICONS} ${RES_I18N})
129 set_target_properties(quasselclient PROPERTIES COMPILE_FLAGS "${QUASSEL_QT_DEFINITIONS} -DBUILD_QTUI")
130 target_link_libraries(quasselclient mod_qtui mod_uisupport mod_client mod_common ${QUASSEL_QT_LIBRARIES})
131 endif(BUILD_QTCLIENT)
134 setup_qt4_variables(GUI NETWORK SCRIPT SQL)
135 add_executable(quassel ${CMAKE_SOURCE_DIR}/src/common/main.cpp ${RES_ICONS} ${RES_SQL} ${RES_I18N})
136 set_target_properties(quassel PROPERTIES COMPILE_FLAGS "${QUASSEL_QT_DEFINITIONS} -DBUILD_MONO")
137 target_link_libraries(quassel mod_qtui mod_uisupport mod_client mod_core mod_common ${QUASSEL_QT_LIBRARIES})