-cmake_minimum_required(VERSION 2.4.5)
-
-# This would suppress annoying warnings on cmake-2.6, but we can't use it
-# with 2.4, so... DUH!
-# cmake_policy(SET CMP0003 OLD) # suppress linker warnings
-
-if(STATICWIN)
- set(CMAKE_BUILD_TYPE Release)
-endif(STATICWIN)
-
-set(QT_MIN_VERSION "4.4.0")
-
-# By default, we build all binaries
-if(NOT DEFINED BUILD)
- set(BUILD all)
-endif(NOT DEFINED BUILD)
-
-# User might define which binaries to build by invoking cmake -DBUILD=<string>,
-# where <string> might contain any combination of "core", "client", "mono" or "all"
-if(BUILD MATCHES all)
- set(BUILD_CORE true)
- set(BUILD_QTCLIENT true)
- set(BUILD_MONO true)
- message(STATUS "Building Quassel Client, Quassel Core and monolithic Quassel.")
-else(BUILD MATCHES all)
- if(BUILD MATCHES core)
- set(BUILD_CORE true)
- message(STATUS "Building Quassel Core")
- endif(BUILD MATCHES core)
- if(BUILD MATCHES client)
- set(BUILD_QTCLIENT true)
- message(STATUS "Building Quassel Client")
- endif(BUILD MATCHES client)
- if(BUILD MATCHES mono)
- set(BUILD_MONO true)
- message(STATUS "Building monolithic Quassel")
- endif(BUILD MATCHES mono)
-endif(BUILD MATCHES all)
-
-# Enable mostly b0rked stuff (new ChatView), do not enable this unless you know what you do...
-if(SPUTDEV)
- add_definitions(-DSPUTDEV)
-endif(SPUTDEV)
-
-# Set up OpenSSL
-find_package(OpenSSL)
+cmake_minimum_required(VERSION 2.6.0 FATAL_ERROR)
+
+if(COMMAND cmake_policy)
+ cmake_policy(SET CMP0003 NEW)
+endif(COMMAND cmake_policy)
+
+# Use our own (well, and KDE's) version of some modules
+# In particular cmake's own FindQt4 and FindOpenSSL are quite buggy
+set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
+include(QuasselMacros)
+
+# Various options and variables that can be set on the command line
+option(WANT_CORE "Build the core (server) binary" ON)
+option(WANT_QTCLIENT "Build the Qt4 GUI client binary" ON)
+option(WANT_MONO "Build the monolithic (all-in-one) binary" ON)
+
+option(WITH_OPENSSL "Enable OpenSSL support if present on the system" ON)
+option(WITH_DBUS "Enable D-Bus support if present on the system" ON)
+option(WITH_WEBKIT "Enable WebKit support (for link previews)" ON)
+option(WITH_PHONON "Enable Phonon support (for audio notifications)" ON)
+option(WITH_KDE "Enable KDE4 integration" OFF)
+
+# We use icon paths from KDE 4.3.x, which are partially invalid on older and possibly
+# even on newer KDE versions. Do not disable this unless you are sure that your Quassel will
+# run on a matching KDE version only.
+set(WITH_OXYGEN AUTO CACHE STRING "Install Oxygen icons (default is \"AUTO\" to install when KDE 4.3 or later is present")
+
+option(STATIC "Enable static building (might not be portable)" OFF)
+
+if(APPLE)
+ 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)
+endif(APPLE)
+
+# Default to embedding data in the static case
+if(STATIC OR WIN32)
+ set(EMBED_DEFAULT ON)
+else(STATIC OR WIN32)
+ set(EMBED_DEFAULT ON) # should be OFF as soon as everything works
+endif(STATIC OR WIN32)
+
+option(EMBED_DATA "Embed all data files in the binary (rather than installing them separately)" ${EMBED_DEFAULT})
+
+set(QT "" CACHE STRING "Path to a Qt installation to use instead of the system Qt (e.g. for static builds)")
+set(LINGUAS "" CACHE STRING "Comma-separated list of locales specifying languages that should be compiled")
+
+# Some settings imply others
+if(STATIC)
+ add_definitions(-DSTATIC)
+ set(WITH_KDE OFF CACHE BOOL "Static building with KDE is not supported")
+endif(STATIC)
+
+if(WIN32)
+ # We don't support separately installed resources yet on Win32
+ set(EMBED_DATA ON)
+endif(WIN32)
+
+# For static builds, arbitrary extra libs might need to be linked
+# Define a comma-separated list here
+# e.g. for pgsql, we need -DLINK_EXTRA=pq;crypt
+set(LINK_EXTRA "" CACHE STRING "Semicolon-separated list of libraries to be linked")
+if(LINK_EXTRA)
+ string(REPLACE "," ";" LINK_EXTRA ${LINK_EXTRA})
+ link_libraries(${LINK_EXTRA})
+endif(LINK_EXTRA)
+
+# Build Type
+# We need to make sure it's not empty
+# Supported: Release, RelWithDebugInfo, Debug, Debugfull
+
+# On WIN32, only Release seems to work correctly (?)
+if(WIN32)
+ set(DEFAULT_BUILD_TYPE "Release")
+else(WIN32)
+ set(DEFAULT_BUILD_TYPE "RelWithDebugInfo")
+endif(WIN32)
+
+set(CMAKE_BUILD_TYPE ${DEFAULT_BUILD_TYPE} CACHE STRING "CMake Build Type")
+if(NOT CMAKE_BUILD_TYPE)
+ set(CMAKE_BUILD_TYPE ${DEFAULT_BUILD_TYPE} CACHE STRING "CMake Build Type" FORCE)
+endif(NOT CMAKE_BUILD_TYPE)
+
+# Enable various flags on gcc
+if(CMAKE_COMPILER_IS_GNUCXX)
+ # Let's just hope that all gccs support these options and skip the tests...
+ # -fno-strict-aliasing is needed apparently for Qt < 4.6
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ansi -Wall -Wextra -Wnon-virtual-dtor -fno-strict-aliasing")
+ set(CMAKE_CXX_FLAGS_RELWITHDEBUGINFO "-O2")
+ set(CMAKE_CXX_FLAGS_DEBUG "-g -fno-reorder-blocks -fno-schedule-insns -fno-inline")
+ set(CMAKE_CXX_FLAGS_DEBUGFULL "-g3")
+endif(CMAKE_COMPILER_IS_GNUCXX)
+
+if(WANT_MONO OR WANT_QTCLIENT)
+ set(QT_MIN_VERSION "4.4.1") # Client crashes often with 4.4.0
+else(WANT_MONO OR WANT_QTCLIENT)
+ set(QT_MIN_VERSION "4.4.0")
+endif(WANT_MONO OR WANT_QTCLIENT)
+
+if(APPLE AND DEPLOY)
+ set(CMAKE_OSX_ARCHITECTURES "i386;ppc")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.4")
+ set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.4u.sdk/")
+ add_definitions(-DMAC_10_4_SDK)
+endif(APPLE AND DEPLOY)
+
+# Execinfo is needed for generating backtraces
+find_package(ExecInfo)
+if(EXECINFO_FOUND)
+ add_definitions(-DHAVE_EXECINFO)
+ include_directories(${EXECINFO_INCLUDES})
+ link_libraries(${EXECINFO_LIBRARIES})
+endif(EXECINFO_FOUND)