+# Set up execinfo
+
+# The problem with this library is that it is built-in in the Linux glib,
+# while on systems like FreeBSD, it is installed separately and thus needs to be linked to.
+# Therefore, we search for the header to see if the it's available in the first place.
+# If it is available, we try to locate the library to figure out whether it is built-in or not.
+
+find_path(EXECINFO_H_DIR "execinfo.h")
+
+if(NOT EXECINFO_H_DIR STREQUAL "EXECINFO_H_DIR-NOTFOUND")
+ # We found the header file's include dir.
+ # Let's add it so the compiler finds it as well.
+ include_directories(${EXECINFO_H_DIR})
+
+ # Now determine if it's built-in or not, by searching the library file.
+ find_library(EXECINFO_LIB_PATH "execinfo")
+
+ if(EXECINFO_LIB_PATH STREQUAL "EXECINFO_LIB_PATH-NOTFOUND")
+ # Built-in, no further action is needed
+ message(STATUS "Found execinfo")
+ else(EXECINFO_LIB_PATH STREQUAL "EXECINFO_LIB_PATH-NOTFOUND")
+ # It's an external library, link it.
+ link_libraries(${EXECINFO_LIB_PATH})
+ message(STATUS "Found execinfo: ${EXECINFO_LIB_PATH}")
+ endif(EXECINFO_LIB_PATH STREQUAL "EXECINFO_LIB_PATH-NOTFOUND")
+
+ set(HAVE_EXECINFO true)
+
+endif(NOT EXECINFO_H_DIR STREQUAL "EXECINFO_H_DIR-NOTFOUND")
+
+if(HAVE_EXECINFO)
+ add_definitions(-DHAVE_EXECINFO)
+endif(HAVE_EXECINFO)
+
+# Select a Qt installation here, if you don't want to use system Qt
+if(QT)
+ # FindQt4 will look for the qmake binary in $PATH, so we just prepend the Qt dir
+ set(ENV{PATH} ${QT}/bin:$ENV{PATH})
+endif(QT)
+
+# Now that we have the correct $PATH, lets find Qt!
+find_package(Qt4 REQUIRED)
+
+set(QT_DONT_USE_QTGUI 1)
+include(${QT_USE_FILE})
+include_directories(${QT_INCLUDES})
+
+# Setup OpenSSL
+if(WITH_OPENSSL)
+ find_package(OpenSSL)
+else(WITH_OPENSSL)
+ message(STATUS "Disabling OpenSSL support")
+endif(WITH_OPENSSL)
+
+if(OPENSSL_FOUND)
+ if(NOT QT_DEFINITIONS MATCHES "QT_NO_OPENSSL")
+ message(STATUS "Found OpenSSL support in Qt")
+ add_definitions(-DHAVE_SSL)
+ set(HAVE_SSL true)
+ set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_SSL)
+ else(NOT QT_DEFINITIONS MATCHES "QT_NO_OPENSSL")
+ message(STATUS "No OpenSSL support found in Qt, disabling")
+ endif(NOT QT_DEFINITIONS MATCHES "QT_NO_OPENSSL")
+else(OPENSSL_FOUND)
+ add_definitions(-DQT_NO_OPENSSL)
+endif(OPENSSL_FOUND)
+
+# Setup D-Bus support
+if(WITH_DBUS)
+ if(QT_QTDBUS_FOUND)
+ message(STATUS "Found QtDBus, enabling D-Bus support")
+ add_definitions(-DHAVE_DBUS)
+ set(LINK_DBUS DBUS)
+ set(HAVE_DBUS true)
+ set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_DBUS)
+ else(QT_QTDBUS_FOUND)
+ message(STATUS "QtDBus not found, disabling D-Bus support")
+ endif(QT_QTDBUS_FOUND)
+else(WITH_DBUS)
+ message(STATUS "Disabling D-Bus support")
+endif(WITH_DBUS)
+
+# We need to create a version.gen
+# For this, we create our genversion binary and make sure it is run every time.
+add_executable(genversion ${CMAKE_SOURCE_DIR}/src/common/genversion.cpp)
+target_link_libraries(genversion ${QT_LIBRARIES} ${QT_CORE_LIB_DEPENDENCIES})
+
+add_custom_target(genversion_run ALL ${CMAKE_BINARY_DIR}/genversion
+ ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/src/common/version.gen)
+add_dependencies(genversion_run genversion)
+