Try to fix icons not being found on some 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 # -DWANT_(CORE|QTCLIENT|MONO)=(ON|OFF)
4 #                     : select binaries to build
5 # -DWITH_OPENSSL=OFF  : Disable OpenSSL support
6 # -DWITH_DBUS=OFF     : Disable D-Bus support
7 # -DOXYGEN_ICONS=(Builtin|External)  : If "Builtin" (the default), compile our Oxygen Icon Theme subset into the binary
8 #                                    : If "External", we assume Oxygen is already installed on the system
9 # -DQUASSEL_ICONS=(Builtin|External) : If "Builtin" (the default), put our own icons into the binary
10 #                                    : If "External", we install our icons into $PREFIX/share/apps/quassel (UNIX only)
11 # -DQT=/path/to/qt    : Choose a Qt4 installation to use instead of the system Qt4
12 # -DSTATIC=ON         : Enable static building of Quassel. Use with care.
13 # -DDEPLOY=ON         : Mac OS X only. Use only for creating Quassel Packages!
14 #
15 # NOTE: You need to remove CMakeCache.txt if you plan to change any of these values!
16
17 project(QuasselIRC)
18
19 cmake_minimum_required(VERSION 2.6.0 FATAL_ERROR)
20
21 if(COMMAND cmake_policy)
22    cmake_policy(SET CMP0003 NEW)
23 endif(COMMAND cmake_policy)
24
25 # Use our own (well, and KDE's) version of some modules
26 # In particular cmake's FindQt4 and FindOpenSSL are quite buggy
27 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
28
29 # Various options and variables that can be set on the command line
30 option(WANT_CORE     "Build the core (server) binary"           ON)
31 option(WANT_QTCLIENT "Build the Qt4 GUI client binary"          ON)
32 option(WANT_MONO     "Build the monolithic (all-in-one) binary" OFF)
33
34 option(WITH_OPENSSL  "Enable OpenSSL support if present on the system"  ON)
35 option(WITH_DBUS     "Enable D-Bus support if present on the system"    ON)
36 option(WITH_WEBKIT   "Enable WebKit support if present on the system"   ON)
37
38 option(STATIC        "Enable static building (might not be portable)" OFF)
39 option(DEPLOY        "Mac OS X only! Adds required libs to bundle resources and create a dmg. Note: requires Qt to be built with 10.4u SDK" OFF)
40 option(SPUTDEV       "Do not use!" OFF)
41
42 set(OXYGEN_ICONS "Builtin" CACHE STRING "Builtin: Compile Oxygen icons into the binary; External: Use system-installed Oxygen")
43 set(QUASSEL_ICONS "Builtin" CACHE STRING "Builtin: Compile Quassel icons into the binary; External: Install them separately")
44
45 set(QT "" CACHE STRING "Path to a Qt installation to use instead of the system Qt")
46 set(LINGUAS "" CACHE STRING "Space-separated List of locales specifying languages that should be compiled")
47
48 if(STATIC)
49   set(CMAKE_BUILD_TYPE Release)
50   set(OXYGEN_ICONS "Builtin")
51   set(QUASSEL_ICONS "Builtin")
52 endif(STATIC)
53
54 # RPATH needs to be set correctly
55 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH 1) 
56 set(CMAKE_BUILD_WITH_INSTALL_RPATH 1)
57
58 # Define install locations. Using variables will allow overriding this by the KDE macros later.
59 set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin)
60 set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/apps)
61 set(ICON_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/icons)
62 set(XDG_APPS_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/applications)
63
64 # Enable various flags on gcc
65 if(CMAKE_COMPILER_IS_GNUCXX)
66   # Let's just hope that all gccs support these options and skip the tests...
67   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ansi -Wall -Wextra -Wnon-virtual-dtor")
68 endif(CMAKE_COMPILER_IS_GNUCXX)
69
70 set(QT_MIN_VERSION "4.4.0")
71
72 if(APPLE AND DEPLOY)
73   set(CMAKE_OSX_ARCHITECTURES "i386;ppc")
74   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.4")
75   set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.4u.sdk/")
76   add_definitions(-DMAC_10_4_SDK)
77 endif(APPLE AND DEPLOY)
78
79 include(QuasselMacros)
80
81 # Execinfo is needed for generating backtraces
82 find_package(ExecInfo)
83 if(EXECINFO_FOUND)
84   add_definitions(-DHAVE_EXECINFO)
85   include_directories(${EXECINFO_INCLUDES})
86   link_libraries(${EXECINFO_LIBRARIES})
87 endif(EXECINFO_FOUND)
88
89 # Select a Qt installation here, if you don't want to use system Qt
90 if(QT)
91   # FindQt4 will look for the qmake binary in $PATH, so we just prepend the Qt dir
92   set(ENV{PATH} ${QT}/bin:$ENV{PATH})
93 endif(QT)
94
95 # Now that we have the correct $PATH, lets find Qt!
96 find_package(Qt4 REQUIRED)
97
98 set(QT_DONT_USE_QTGUI 1)
99 include(${QT_USE_FILE})
100 include_directories(${QT_INCLUDES})
101
102 # Setup OpenSSL
103 if(WITH_OPENSSL)
104   find_package(OpenSSL)
105 else(WITH_OPENSSL)
106   message(STATUS "Disabling OpenSSL support")
107 endif(WITH_OPENSSL)
108
109 if(OPENSSL_FOUND)
110   if(NOT QT_DEFINITIONS MATCHES "QT_NO_OPENSSL")
111     message(STATUS "Found OpenSSL support in Qt")
112     add_definitions(-DHAVE_SSL)
113     set(HAVE_SSL true)
114     set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_SSL)
115   else(NOT QT_DEFINITIONS MATCHES "QT_NO_OPENSSL")
116     message(STATUS "No OpenSSL support found in Qt, disabling")
117   endif(NOT QT_DEFINITIONS MATCHES "QT_NO_OPENSSL")
118 else(OPENSSL_FOUND)
119   add_definitions(-DQT_NO_OPENSSL)
120 endif(OPENSSL_FOUND)
121
122 # Setup D-Bus support
123 if(WITH_DBUS)
124   if(QT_QTDBUS_FOUND)
125     message(STATUS "Found QtDBus, enabling D-Bus support")
126     add_definitions(-DHAVE_DBUS)
127     set(LINK_DBUS DBUS)
128     set(HAVE_DBUS true)
129     set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_DBUS)
130   else(QT_QTDBUS_FOUND)
131     message(STATUS "QtDBus not found, disabling D-Bus support")
132   endif(QT_QTDBUS_FOUND)
133 else(WITH_DBUS)
134   message(STATUS "Disabling D-Bus support")
135 endif(WITH_DBUS)
136
137 # Setup QtWebKit support
138 if(WITH_WEBKIT)
139   if(QT_QTWEBKIT_FOUND)
140     message(STATUS "Found QtWebKit, enabling WebKit support")
141     add_definitions(-DHAVE_WEBKIT)
142     set(LINK_WEBKIT WEBKIT)
143     set(HAVE_WEBKIT true)
144     set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_WEBKIT)
145   else(QT_QTWEBKIT_FOUND)
146     message(STATUS "QtWebKit not found, disabling D-Bus support")
147   endif(QT_QTWEBKIT_FOUND)
148 else(WITH_WEBKIT)
149   message(STATUS "Disabling WebKit support")
150 endif(WITH_WEBKIT)
151
152
153 # Set global buildflags
154 # This is very much non-portable, so don't use -DSTATIC until you know what
155 # you do.
156 if(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
157   set(CMAKE_CXX_FLAGS "-static-libgcc ${CMAKE_CXX_FLAGS}")
158   link_directories(${CMAKE_BINARY_DIR}/staticlibs) # override dynamic libs
159   if(HAVE_SSL)
160     set(QUASSEL_SSL_LIBRARIES ssl crypto)  # these miss in static builds
161   endif(HAVE_SSL)
162 endif(STATIC AND CMAKE_COMPILER_IS_GNUCXX)
163
164 if(STATIC AND WIN32)
165   link_libraries(imm32 winmm)  # missing by default :/
166    if(HAVE_SSL)
167      link_libraries(${OPENSSL_LIBRARIES} libeay32MD)
168    endif(HAVE_SSL)
169 endif(STATIC AND WIN32)
170
171 if(WIN32)
172   set(RC_WIN32 ../pics/win32.rc)  # for app icons on windows
173 endif(WIN32)
174
175 # This is dirty, but I haven't found a cleaner way to ensure that the generated .qrc files
176 # (which will be removed with make clean) are regenerated :/
177 set_directory_properties(PROPERTIES
178                          ADDITIONAL_MAKE_CLEAN_FILES CMakeCache.txt)
179
180 # We need to create a version.gen
181 # For this, we create our genversion binary and make sure it is run every time.
182 add_executable(genversion ${CMAKE_SOURCE_DIR}/src/common/genversion.cpp)
183 target_link_libraries(genversion ${QT_LIBRARIES} ${QT_CORE_LIB_DEPENDENCIES})
184
185 get_target_property(GENVERSION_EXECUTABLE genversion LOCATION)
186 add_custom_target(genversion_run ALL ${GENVERSION_EXECUTABLE}
187                   ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/src/common/version.gen)
188 add_dependencies(genversion_run genversion)
189
190 # Decide what to do with icons
191 if(WANT_QTCLIENT OR WANT_MONO)
192   if(QUASSEL_ICONS MATCHES "External")
193     message(STATUS "Install Quassel icons to ${CMAKE_INSTALL_PREFIX}/share/apps/quassel")
194   else(QUASSEL_ICONS MATCHES "External")
195     set(QUASSEL_ICONS "Builtin")
196     message(STATUS "Compile Quassel icons into the binary")
197   endif(QUASSEL_ICONS MATCHES "External")
198
199   if(OXYGEN_ICONS MATCHES "External")
200     message(STATUS "Use system-installed Oxygen icon theme")
201   else(OXYGEN_ICONS MATCHES "External")
202     set(OXYGEN_ICONS "Builtin")
203     message(STATUS "Compile Oxygen icon theme subset into the binary")
204   endif(OXYGEN_ICONS MATCHES "External")
205 endif(WANT_QTCLIENT OR WANT_MONO)
206
207 # These variables will be added to the main targets (CORE, QTCLIENT, MONO)
208
209 set(COMMON_DEPS ${RC_WIN32})
210 set(CORE_DEPS )
211 set(CLIENT_DEPS )
212 set(KDE_DEPS )
213
214 # Add needed subdirs - the order is important, since src needs some vars set by other dirs
215 add_subdirectory(data)
216 add_subdirectory(icons)
217 #add_subdirectory(pics)
218 add_subdirectory(i18n)
219 add_subdirectory(src)
220
221 # Make sure version.gen exists before building mod_common
222 # TODO: make only main.cpp depend on that! Recompiles suck...
223 add_dependencies(mod_common genversion_run)