IF out apple stuffz on non-Apple systems
[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 # -DSTATICWIN=1    : Enable static building for Windows.
8 # -DSPUTDEV        : Do not use.
9 #
10 # NOTE: You need to remove CMakeCache.txt if you plan to change any of these values!
11
12 project(QuasselIRC)
13
14 cmake_minimum_required(VERSION 2.4.5)
15
16 # This would suppress annoying warnings on cmake-2.6, but we can't use it 
17 # with 2.4, so... DUH!
18 # cmake_policy(SET CMP0003 OLD)  # suppress linker warnings
19
20 if(STATICWIN)
21   set(CMAKE_BUILD_TYPE Release)
22 endif(STATICWIN)
23
24 set(QT_MIN_VERSION "4.4.0")
25
26 # By default, we build all binaries
27 if(NOT DEFINED BUILD)
28   set(BUILD all)
29 endif(NOT DEFINED BUILD)
30
31 # User might define which binaries to build by invoking cmake -DBUILD=<string>,
32 # where <string> might contain any combination of "core", "client", "mono" or "all"
33 if(BUILD MATCHES all)
34   set(BUILD_CORE true)
35   set(BUILD_QTCLIENT true)
36   set(BUILD_MONO true)
37   message(STATUS "Building Quassel Client, Quassel Core and monolithic Quassel.")
38 else(BUILD MATCHES all)
39   if(BUILD MATCHES core)
40     set(BUILD_CORE true)
41     message(STATUS "Building Quassel Core")
42   endif(BUILD MATCHES core)
43   if(BUILD MATCHES client)
44     set(BUILD_QTCLIENT true)
45     message(STATUS "Building Quassel Client")
46   endif(BUILD MATCHES client)
47   if(BUILD MATCHES mono)
48     set(BUILD_MONO true)
49     message(STATUS "Building monolithic Quassel")
50   endif(BUILD MATCHES mono)
51 endif(BUILD MATCHES all)
52
53 # Enable mostly b0rked stuff (new ChatView), do not enable this unless you know what you do...
54 if(SPUTDEV)
55   add_definitions(-DSPUTDEV)
56 endif(SPUTDEV)
57
58 # Set up OpenSSL
59 find_package(OpenSSL)
60
61 # Select a Qt installation here, if you don't want to use system Qt
62 if(DEFINED QT)
63   # FindQt4 will look for the qmake binary in $PATH, so we just prepend the Qt dir
64   set(ENV{PATH} ${QT}/bin:$ENV{PATH})
65   #SET(QT_QMAKE_EXECUTABLE ${QT}/bin/qmake CACHE FILEPATH "" FORCE)
66 endif(DEFINED QT)
67
68 # Now that we have the correct $PATH, lets find Qt!
69 find_package(Qt4 REQUIRED)
70
71 set(QT_DONT_USE_QTGUI 1)
72 include(${QT_USE_FILE})
73 include_directories(${QT_INCLUDES})
74
75 # We need to create a version.gen
76 # For this, we create our genversion binary and make sure it is run every time.
77 add_executable(genversion ${CMAKE_SOURCE_DIR}/src/common/genversion.cpp)
78 target_link_libraries(genversion ${QT_LIBRARIES})
79
80 add_custom_target(genversion_run ALL ${CMAKE_BINARY_DIR}/genversion
81                   ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/src/common/version.gen)
82 add_dependencies(genversion_run genversion)
83
84 # Add needed subdirs
85 add_subdirectory(src/common)
86 include_directories(src/common)
87 if(BUILD_CORE OR BUILD_MONO)
88   add_subdirectory(src/core)
89   include_directories(src/core)
90 endif(BUILD_CORE OR BUILD_MONO)
91 if(BUILD_QTCLIENT OR BUILD_MONO)
92   add_subdirectory(src/client)
93   add_subdirectory(src/uisupport)
94   add_subdirectory(src/qtui)
95   include_directories(src/client)
96   include_directories(src/uisupport)
97   include_directories(src/qtui)
98 endif(BUILD_QTCLIENT OR BUILD_MONO)
99
100 # Make sure version.gen exists before building mod_common
101 add_dependencies(mod_common genversion_run)
102
103 # Add resources
104 qt4_add_resources(RC_I18N i18n/i18n.qrc)
105 qt4_add_resources(RC_ICONS src/icons/icons.qrc)
106 qt4_add_resources(RC_QUASSEL_ICONS src/icons/quassel-icons.qrc)
107 qt4_add_resources(RC_SQL src/core/sql.qrc)
108
109 # Set global buildflags
110 if(DEFINED STATIC)
111   set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc ${CMAKE_EXE_LINKER_FLAGS}")
112   link_directories(${CMAKE_BINARY_DIR}/staticlibs)
113 endif(DEFINED STATIC)
114
115 if(STATICWIN AND WIN32)
116   link_libraries(imm32 winmm)  # missing by default :/
117    if(OPENSSL_FOUND)
118      link_libraries(${OPENSSL_LIBRARIES} libeay32MD)
119    endif(OPENSSL_FOUND)
120 endif(STATICWIN AND WIN32)
121
122 if(WIN32)
123   set(WIN32_RC src/icons/win32.rc)  # for app icons on windows
124 endif(WIN32)
125
126 # Here comes the dirty part. Our targets need different Qt4 modules, i.e. different libs
127 # and defines. We can't simply include UseQt4 several times, since definitions add up.
128 # We workaround this by using our own macro to figure out what to add.
129
130 # This macro sets variables for additional Qt modules.
131 macro(setup_qt4_variables)
132   set(QUASSEL_QT_LIBRARIES )
133   foreach(qtmod CORE ${ARGV})
134     set(QUASSEL_QT_LIBRARIES ${QUASSEL_QT_LIBRARIES} ${QT_QT${qtmod}_LIBRARY} ${QT_${qtmod}_LIB_DEPENDENCIES})
135   endforeach(qtmod ${ARGV})
136   set(QUASSEL_QT_LIBRARIES ${QUASSEL_QT_LIBRARIES} ${QT_LIBRARIES})
137 endmacro(setup_qt4_variables)
138
139 # Now we have everything, so just glue the right pieces together :)
140 if(BUILD_CORE)
141   setup_qt4_variables(NETWORK SCRIPT SQL)
142   add_executable(quasselcore ${CMAKE_SOURCE_DIR}/src/common/main.cpp
143                              ${RC_SQL} ${RC_I18N} ${WIN32_RC})
144   set_target_properties(quasselcore PROPERTIES 
145                                     COMPILE_FLAGS "-DQT_NETWORK_LIB -DQT_SCRIPT_LIB -DQT_SQL_LIB -DBUILD_CORE")
146   target_link_libraries(quasselcore mod_core mod_common ${QUASSEL_QT_LIBRARIES})
147 endif(BUILD_CORE)
148
149 if(BUILD_QTCLIENT)
150   setup_qt4_variables(GUI NETWORK)
151   add_executable(quasselclient ${CMAKE_SOURCE_DIR}/src/common/main.cpp
152                                ${RC_ICONS} ${RC_QUASSEL_ICONS} ${RC_I18N} ${WIN32_RC})
153   set_target_properties(quasselclient PROPERTIES
154                                       COMPILE_FLAGS "-DQT_GUI_LIB -DQT_NETWORK_LIB -DBUILD_QTUI")
155   target_link_libraries(quasselclient mod_qtui mod_uisupport mod_client mod_common ${QUASSEL_QT_LIBRARIES})
156 endif(BUILD_QTCLIENT)
157
158 if(BUILD_MONO)
159   setup_qt4_variables(GUI NETWORK SCRIPT SQL)
160   add_executable(quassel ${CMAKE_SOURCE_DIR}/src/common/main.cpp
161                          ${RC_ICONS} ${RC_QUASSEL_ICONS} ${RC_SQL} ${RC_I18N} ${WIN32_RC})
162   set_target_properties(quassel PROPERTIES 
163                                 COMPILE_FLAGS "-DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_SCRIPT_LIB -DQT_SQL_LIB -DBUILD_MONO")
164   target_link_libraries(quassel mod_qtui mod_uisupport mod_client mod_core mod_common ${QUASSEL_QT_LIBRARIES})
165 endif(BUILD_MONO)
166
167 # Build bundles for MacOSX
168 if(APPLE)
169   add_custom_command(TARGET quasselclient POST_BUILD
170                      COMMAND ${CMAKE_SOURCE_DIR}/scripts/build/macosx_makebundle.py
171                              ${CMAKE_SOURCE_DIR} "Quassel Client" quasselclient)
172   add_custom_command(TARGET quassel POST_BUILD
173                      COMMAND ${CMAKE_SOURCE_DIR}/scripts/build/macosx_makebundle.py
174                              ${CMAKE_SOURCE_DIR} "Quassel" quassel)
175 endif(APPLE)