Autogenerate version.gen - no more outdated versions!
[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 # -DSTATIC=1       : Enable static building of Quassel, most useful with a static Qt.
7 # -DSPUTDEV        : Do not use.
8 #
9 # NOTE: You need to remove CMakeCache.txt if you plan to change any of these values!
10
11 project(QuasselIRC)
12
13 cmake_minimum_required(VERSION 2.4.5)
14
15 set(QT_MIN_VERSION "4.4.0")
16
17 # By default, we build all binaries
18 if(NOT DEFINED BUILD)
19   set(BUILD all)
20 endif(NOT DEFINED BUILD)
21
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"
24 if(BUILD MATCHES all)
25   set(BUILD_CORE true)
26   set(BUILD_QTCLIENT true)
27   set(BUILD_MONO true)
28   message(STATUS "Building Quassel Client, Quassel Core and monolithic Quassel.")
29 else(BUILD MATCHES all)
30   if(BUILD MATCHES core)
31     set(BUILD_CORE true)
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)
39     set(BUILD_MONO true)
40     message(STATUS "Building monolithic Quassel")
41   endif(BUILD MATCHES mono)
42 endif(BUILD MATCHES all)
43
44 # Select a Qt installation here, if you don't want to use system Qt
45 if(DEFINED 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)
49 endif(DEFINED QT)
50
51 # Enable mostly b0rked stuff (new ChatView), do not enable this unless you know what you do...
52 if(SPUTDEV)
53   add_definitions(-DSPUTDEV)
54 endif(SPUTDEV)
55
56 # Now that we have the correct $PATH, lets find Qt!
57 find_package(Qt4 REQUIRED)
58
59 # Add needed subdirs
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)
74
75 # Add resources
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)
79
80 # Set global buildflags
81 if(DEFINED STATIC)
82   set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc ${CMAKE_EXE_LINKER_FLAGS}")
83   link_directories(${CMAKE_BINARY_DIR}/staticlibs)
84 endif(DEFINED STATIC)
85
86 # Here comes the dirty part. Our targets need different Qt4 modules, i.e. different libs
87 # and defines. We can't simply include UseQt4 several times, since definitions add up.
88 # We workaround this by only setting up QtCore first, and adding additional stuff later.
89 set(QT_DONT_USE_QTGUI 1)
90 include(${QT_USE_FILE})
91 include_directories(${QT_INCLUDES})
92
93 # We need to create a version.gen
94 # For this, we create our genversion binary and make sure it is run every time.
95 add_executable(genversion ${CMAKE_SOURCE_DIR}/src/common/genversion.cpp)
96 target_link_libraries(genversion ${QT_LIBRARIES})
97
98 add_custom_target(genversion_run ALL ${CMAKE_BINARY_DIR}/genversion
99                   ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/src/common/version.gen)
100 add_dependencies(genversion_run genversion)
101 set_source_files_properties(src/common/global.cpp PROPERTIES OBJECT_DEPENDS genversion_run)
102
103 # This macro sets variables for additional Qt modules.
104 macro(setup_qt4_variables)
105   set(QUASSEL_QT_DEFINITIONS ${QT_DEFINITIONS})
106   set(QUASSEL_QT_LIBRARIES )
107   foreach(qtmod ${ARGV})
108     # This needs to be a string, not a list, otherwise set_target_properties screws up...
109     set(QUASSEL_QT_DEFINITIONS "${QUASSEL_QT_DEFINITIONS} -DQT_${qtmod}_LIB")
110     set(QUASSEL_QT_LIBRARIES ${QUASSEL_QT_LIBRARIES} ${QT_QT${qtmod}_LIBRARY} ${QT_${qtmod}_LIB_DEPENDENCIES})
111   endforeach(qtmod ${ARGV})
112   set(QUASSEL_QT_LIBRARIES ${QUASSEL_QT_LIBRARIES} ${QT_LIBRARIES})
113 endmacro(setup_qt4_variables)
114
115 # Now we have everything, so just glue the right pieces together :)
116 if(BUILD_CORE)
117   setup_qt4_variables(NETWORK SCRIPT SQL)
118   add_executable(quasselcore ${CMAKE_SOURCE_DIR}/src/common/main.cpp ${RES_SQL} ${RES_I18N})
119   set_target_properties(quasselcore PROPERTIES COMPILE_FLAGS "${QUASSEL_QT_DEFINITIONS} -DBUILD_CORE")
120   target_link_libraries(quasselcore mod_core mod_common ${QUASSEL_QT_LIBRARIES})
121 endif(BUILD_CORE)
122
123 if(BUILD_QTCLIENT)
124   setup_qt4_variables(GUI NETWORK)
125   add_executable(quasselclient ${CMAKE_SOURCE_DIR}/src/common/main.cpp ${RES_ICONS} ${RES_I18N})
126   set_target_properties(quasselclient PROPERTIES COMPILE_FLAGS "${QUASSEL_QT_DEFINITIONS} -DBUILD_QTUI")
127   target_link_libraries(quasselclient mod_qtui mod_uisupport mod_client mod_common ${QUASSEL_QT_LIBRARIES})
128 endif(BUILD_QTCLIENT)
129
130 if(BUILD_MONO)
131   setup_qt4_variables(GUI NETWORK SCRIPT SQL)
132   add_executable(quassel ${CMAKE_SOURCE_DIR}/src/common/main.cpp ${RES_ICONS} ${RES_SQL} ${RES_I18N})
133   set_target_properties(quassel PROPERTIES COMPILE_FLAGS "${QUASSEL_QT_DEFINITIONS} -DBUILD_MONO")
134   target_link_libraries(quassel mod_qtui mod_uisupport mod_client mod_core mod_common ${QUASSEL_QT_LIBRARIES})
135 endif(BUILD_MONO)