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)
60 add_subdirectory(src/common)
61 include_directories(src/common)
62 if(BUILD_CORE OR BUILD_MONO)
63 add_subdirectory(src/core)
64 include_directories(src/core)
65 endif(BUILD_CORE OR BUILD_MONO)
66 if(BUILD_QTCLIENT OR BUILD_MONO)
67 add_subdirectory(src/client)
68 add_subdirectory(src/uisupport)
69 add_subdirectory(src/qtui)
70 include_directories(src/client)
71 include_directories(src/uisupport)
72 include_directories(src/qtui)
73 endif(BUILD_QTCLIENT OR BUILD_MONO)
76 qt4_add_resources(RES_I18N ${CMAKE_SOURCE_DIR}/i18n/i18n.qrc)
77 qt4_add_resources(RES_ICONS ${CMAKE_SOURCE_DIR}/src/icons/icons.qrc)
78 qt4_add_resources(RES_SQL ${CMAKE_SOURCE_DIR}/src/core/sql.qrc)
80 # Set global buildflags
82 set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc ${CMAKE_EXE_LINKER_FLAGS}")
83 link_directories(${CMAKE_BINARY_DIR}/staticlibs)
86 # Now see if we can generate a decent version.gen.
87 # First, check if we have a git repo and git-describe gives reasonable output...
88 # NOTE: This may fail if we have .git but not git binaries installed...
89 if(EXISTS ${CMAKE_SOURCE_DIR}/.git)
90 execute_process(COMMAND git-describe --long
91 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
92 RESULT_VARIABLE GIT_RESULT
93 OUTPUT_VARIABLE GIT_OUTPUT)
94 if(GIT_RESULT OR ${GIT_OUTPUT} MATCHES "fatal")
96 endif(GIT_RESULT OR ${GIT_OUTPUT} MATCHES "fatal")
97 endif(EXISTS ${CMAKE_SOURCE_DIR}/.git)
99 # Now if we got a valid revision, let's use it...
100 # A git-describe string has the form "version-commitcount-gdeadbeef"
102 string(REGEX REPLACE "(.*)-0-g[0-9a-f]+" "\\1" VERSION_STRING ${GIT_OUTPUT})
103 string(REGEX REPLACE "(.*)-([0-9]+)-g([0-9a-f]+)\n" "\\1:git-\\3+\\2" VERSION_STRING ${VERSION_STRING})
106 # If got something valid out of it, write it to the file
108 file(WRITE ${CMAKE_BINARY_DIR}/src/common/version.gen
109 "quasselGeneratedVersion = \"${VERSION_STRING}\";\n")
110 elseif(VERSION_STRING)
111 # Maybe we have a version.dist?
112 if(EXISTS ${CMAKE_SOURCE_DIR}/version.dist)
113 file(READ ${CMAKE_SOURCE_DIR}/version.dist VERSION_DIST)
114 file(WRITE ${CMAKE_BINARY_DIR}/src/common/version.gen ${VERSION_DIST})
115 elseif(EXISTS ${CMAKE_SOURCE_DIR}/version.dist)
116 # Ah well, just touch it then
117 file(WRITE ${CMAKE_BINARY_DIR}/src/common/version.gen "\n")
118 endif(EXISTS ${CMAKE_SOURCE_DIR}/version.dist)
119 endif(VERSION_STRING)
122 # Here comes the dirty part. Our targets need different Qt4 modules, i.e. different libs
123 # and defines. We can't simply include UseQt4 several times, since definitions add up.
124 # We workaround this by only setting up QtCore first, and adding additional stuff later.
125 set(QT_DONT_USE_QTGUI 1)
126 include(${QT_USE_FILE})
127 include_directories(${QT_INCLUDES})
129 # This macro sets variables for additional Qt modules.
130 macro(setup_qt4_variables)
131 set(QUASSEL_QT_DEFINITIONS ${QT_DEFINITIONS})
132 set(QUASSEL_QT_LIBRARIES )
133 foreach(qtmod ${ARGV})
134 # This needs to be a string, not a list, otherwise set_target_properties screws up...
135 set(QUASSEL_QT_DEFINITIONS "${QUASSEL_QT_DEFINITIONS} -DQT_${qtmod}_LIB")
136 set(QUASSEL_QT_LIBRARIES ${QUASSEL_QT_LIBRARIES} ${QT_QT${qtmod}_LIBRARY} ${QT_${qtmod}_LIB_DEPENDENCIES})
137 endforeach(qtmod ${ARGV})
138 set(QUASSEL_QT_LIBRARIES ${QUASSEL_QT_LIBRARIES} ${QT_LIBRARIES})
139 endmacro(setup_qt4_variables)
141 # Now we have everything, so just glue the right pieces together :)
143 setup_qt4_variables(NETWORK SCRIPT SQL)
144 add_executable(quasselcore ${CMAKE_SOURCE_DIR}/src/common/main.cpp ${RES_SQL} ${RES_I18N})
145 set_target_properties(quasselcore PROPERTIES COMPILE_FLAGS "${QUASSEL_QT_DEFINITIONS} -DBUILD_CORE")
146 target_link_libraries(quasselcore mod_core mod_common ${QUASSEL_QT_LIBRARIES})
150 setup_qt4_variables(GUI NETWORK)
151 add_executable(quasselclient ${CMAKE_SOURCE_DIR}/src/common/main.cpp ${RES_ICONS} ${RES_I18N})
152 set_target_properties(quasselclient PROPERTIES COMPILE_FLAGS "${QUASSEL_QT_DEFINITIONS} -DBUILD_QTUI")
153 target_link_libraries(quasselclient mod_qtui mod_uisupport mod_client mod_common ${QUASSEL_QT_LIBRARIES})
154 endif(BUILD_QTCLIENT)
157 setup_qt4_variables(GUI NETWORK SCRIPT SQL)
158 add_executable(quassel ${CMAKE_SOURCE_DIR}/src/common/main.cpp ${RES_ICONS} ${RES_SQL} ${RES_I18N})
159 set_target_properties(quassel PROPERTIES COMPILE_FLAGS "${QUASSEL_QT_DEFINITIONS} -DBUILD_MONO")
160 target_link_libraries(quassel mod_qtui mod_uisupport mod_client mod_core mod_common ${QUASSEL_QT_LIBRARIES})