PROJECT( kmess )


#### System checks ####

# To add checks, see in one or more of these paths
# /usr/share/cmake/Modules
# /usr/share/kde4/apps/cmake/modules
# /usr/share/apps/cmake

# Check for cmake, same as minimum for KDE 4.0.0
CMAKE_MINIMUM_REQUIRED( VERSION 2.4.5 )

# Check for KDE 4
FIND_PACKAGE( KDE4 REQUIRED )

# Check for libxml2
FIND_PACKAGE( LibXml2 )
MACRO_LOG_FEATURE( LIBXML2_FOUND "LibXML2" "Libraries used to develop XML-aware applications" "http://www.xmlsoft.org/" TRUE ""
"  Required for the chat styles system.
  * You will need this package and the matching development package: for example, 'kmess' and 'kmess-dev' or 'kmess-devel'.
  * Usually the package names for this library are:
        on Ubuntu:   'libxml2' and 'libxml2-dev'
        on openSUSE: 'libxml2' and 'libxml2-devel'
  * Please refer to the KMess board for more info, and specially to this guide: http://trac.kmess.org/wiki/Compiling%20KMess" )

# Check for libxslt
FIND_PACKAGE( LibXslt )
MACRO_LOG_FEATURE( LIBXSLT_FOUND "LibXSLT" "A library to transform XML into other formats" "http://www.xmlsoft.org/XSLT" TRUE ""
"  Required for the chat styles system.
  * You will need this package and the matching development package: for example, 'kmess' and 'kmess-dev' or 'kmess-devel'.
  * Usually the package names for this library are:
        on Ubuntu:   'libxslt' and 'libxslt-dev'
        on openSUSE: 'libxslt' and 'libxslt-devel'
  * Please refer to the KMess board for more info, and specially to this guide: http://trac.kmess.org/wiki/Compiling%20KMess" )

# Check for qca2
FIND_PACKAGE( QCA2 )
MACRO_LOG_FEATURE( QCA2_FOUND "QCA 2" "A cryptographic library written in Qt to access various encryption methods" "http://delta.affinix.com/qca/" TRUE ""
"  Required for the Windows Live Messenger login process.
  * You will need this package and the matching development package: for example, 'kmess' and 'kmess-dev' or 'kmess-devel'.
  * Usually the package names for this library are:
      on Ubuntu:   'libqca2', 'libqca2-dev' and 'libqca2-plugin-ossl'
      on openSUSE: 'libqca2' and 'libqca2-devel'
      on Fedora:   'qca2' and 'qca2-devel'
  * Please refer to the KMess board for more info, and specially to this guide: http://trac.kmess.org/wiki/Compiling%20KMess" )

# As far as I know, it is impossible to find out if the required QCA plugin for OpenSSL is installed:
# so we need to ask QCA itself it it's got such a plugin. Pretty darned unportable stuff.
IF( QCA2_FOUND )
  IF( UNIX )
    EXECUTE_PROCESS( COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/cmake/check-qca2-ossl.sh OUTPUT_VARIABLE HAS_QCA2_OSSL_PLUGIN )
    IF( HAS_QCA2_OSSL_PLUGIN EQUAL 1 )
      SET( QCA2_OSSL_PLUGIN_FOUND TRUE )
    ELSE( HAS_QCA2_OSSL_PLUGIN EQUAL 1 )
      SET( QCA2_OSSL_PLUGIN_FOUND FALSE )
    ENDIF( HAS_QCA2_OSSL_PLUGIN EQUAL 1 )
    MACRO_LOG_FEATURE( QCA2_OSSL_PLUGIN_FOUND "QCA 2 - OpenSSL Plugin" "OpenSSL interaction library for QCA2" "http://delta.affinix.com/qca/" TRUE ""
"  Required for the Windows Live Messenger login process.
  * This package should have been installed along QCA2: if you have QCA2 installed
  but still see this message, your distribution probably packages it separately.
  Ubuntu does this, the package name is 'libqca2-plugin-ossl'.
  * Please refer to the KMess forum for more info, and specially to this guide: http://trac.kmess.org/wiki/Compiling%20KMess" )
  ELSE( UNIX )
    # TODO: Find another *portable* way to detect the OSSL plugin.
    MESSAGE( STATUS "NOTE: The qca2 OpenSSL can't be detected on this platform yet. Make sure you have it installed." )
  ENDIF( UNIX )
ENDIF( QCA2_FOUND )

# Check for XScreenSaver extension
OPTION( WANT_XSCREENSAVER "Build with X11 screensaver auto-away support" ON )
IF( WANT_XSCREENSAVER )
  MACRO_BOOL_TO_01( X11_Xscreensaver_FOUND HAVE_XSCREENSAVER )
  MACRO_OPTIONAL_FIND_PACKAGE(X11)
  IF( X11_FOUND )
    MACRO_LOG_FEATURE( X11_Xscreensaver_FOUND "XScreenSaver" "X11 extension used to check idle state" "" FALSE ""
  "  Required for the auto-away feature.
  * Usually the package names for this library are:
      on Ubuntu:   'libxss-dev'
      on openSUSE: 'xorg-x11-libs'
  * Please refer to the KMess board for more info, and specially to this guide: http://trac.kmess.org/wiki/Compiling%20KMess" )
  ELSE( X11_FOUND )
    MESSAGE( STATUS "NOTE: The auto-away feature is not supported on this platform yet." )
  ENDIF( X11_FOUND )
ENDIF( WANT_XSCREENSAVER )

# Check for libkonq
# QUIET is to fix compiling on systems like Debian Lenny, which don't have FindLibKonq.cmake
#   (for an optional feature, we don't want that to be fatal)
MACRO_OPTIONAL_FIND_PACKAGE( LibKonq QUIET )
MACRO_LOG_FEATURE( LIBKONQ_FOUND "LibKonq" "Integration with Konqueror context menu" "http://www.kde.org/" FALSE ""
"  Optional context menu integration with Konqueror.
  * You will need this package and the matching development package: for example, 'kmess' and 'kmess-dev' or 'kmess-devel'.
  * Usually the package names for this library are:
      on Ubuntu:   'libkonq5' and 'libkonq5-dev'
      on openSUSE: 'libkonq5' and 'libkonq-devel'
  * Please refer to the KMess board for more info, and specially to this guide: http://trac.kmess.org/wiki/Compiling%20KMess" )


# Check for libisf-qt
MACRO_OPTIONAL_FIND_PACKAGE( IsfQt QUIET )
MACRO_LOG_FEATURE( ISFQT_FOUND "LibISF-Qt" "Library to manage Microsoft's Mobile Ink" "http://www.kmess.org/" FALSE ""
  " Support to send handwriting messages in a format compatible with Windows Live Messenger.
    In absence of an installed isf-qt version, the bundled version will be compiled.")
MACRO_BOOL_TO_01( ISFQT_FOUND HAVE_LIBISFQT ) # For config-kmess.h.in

# Display the dependency collection results
MACRO_DISPLAY_FEATURE_LOG()



#### Configure build ####

INCLUDE( MacroLibrary )
INCLUDE( KDE4Defaults )

IF( NOT ISFQT_FOUND )
# isf-qt is not installed on the system.
# use the bundled version.
  SET( ISFQT_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/contrib/isf-qt/include )
  SET( ISFQT_LIBRARIES isf-qt )

  SET( USE_BUNDLED_LIBRARIES ${USE_BUNDLED_LIBRARIES} ISFQT )
  SET( HAVE_LIBISFQT 1 )
  SET( ISFQT_FOUND TRUE )
ENDIF( NOT ISFQT_FOUND )

ADD_DEFINITIONS( ${QT_DEFINITIONS} ${KDE4_DEFINITIONS} )

INCLUDE_DIRECTORIES( ${KDE4_INCLUDES} ${KDE4_INCLUDE_DIR} ${QT_INCLUDES} ${LIBXML2_INCLUDE_DIR} )


#### Define the app version number ####

# Switch between the following two commands to force using a predefined version number
#EXECUTE_PROCESS( COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/cmake/get-svn-version.sh OUTPUT_VARIABLE KMESS_VERSION )
SET( KMESS_VERSION "2.0.2" )


#### Define compiler flags ####

# Tune the debug build with even more flags
# also see FindKDE4Internal.cmake for more defaults
IF( CMAKE_COMPILER_IS_GNUCXX )
  # skipped: -ansi -pendantic -Wfatal-errors -Wold-style-cast -Wconversion
  SET( CMAKE_CXX_FLAGS_DEBUG     "-O0 -g -Wall" )
  SET( CMAKE_CXX_FLAGS_DEBUGFULL "-O0 -g3 -fno-inline -Wall -Woverloaded-virtual -Wsign-compare -Wundef" )
  # the -fvisibility option makes symbols also visible to the KDE backtrace dumper, but
  # the MinGW gcc doesn't seem to understand it well, so only add it if we're not on win32
  IF( NOT WIN32 )
    SET( CMAKE_CXX_FLAGS_DEBUGFULL "${CMAKE_CXX_FLAGS_DEBUGFULL} -fvisibility=default" )
  ENDIF( NOT WIN32 )
ENDIF( CMAKE_COMPILER_IS_GNUCXX )


# Define the default build type
# Possible values:
# - none
# - release
# - debug
# - debugfull       (even fewer optimisations)
# - relwithdebinfo  (release with debug info)
# - minsizerel      (minsize release)
# Uncomment the next line to always force building in full debug mode
#SET( CMAKE_BUILD_TYPE debugfull )

# Enable the KMess debug output when compiling a debug build
IF( CMAKE_BUILD_TYPE STREQUAL debugfull OR KMESS_DEBUG_OUTPUT EQUAL 1 )
  SET( KMESS_ENABLE_DEBUG_OUTPUT "1" )
ELSE( CMAKE_BUILD_TYPE STREQUAL debugfull OR KMESS_DEBUG_OUTPUT EQUAL 1 )
  SET( KMESS_ENABLE_DEBUG_OUTPUT "0" )
ENDIF( CMAKE_BUILD_TYPE STREQUAL debugfull OR KMESS_DEBUG_OUTPUT EQUAL 1 )


# Change symbol visibility, to obtain clearer KDE backtraces
SET( __KDE_HAVE_GCC_VISIBILITY 0 )

# Disable LikeBack if not needed
IF( KMESS_DISABLE_LIKEBACK EQUAL 1 )
  SET( KMESS_DISABLE_LIKEBACK "1" )
ELSE( KMESS_DISABLE_LIKEBACK EQUAL 1 )
  SET( KMESS_DISABLE_LIKEBACK "0" )
ENDIF( KMESS_DISABLE_LIKEBACK EQUAL 1 )

# Set a default installation path
IF( NOT CMAKE_INSTALL_PREFIX )
  SET( CMAKE_INSTALL_PREFIX "/usr" )
ENDIF( NOT CMAKE_INSTALL_PREFIX )

IF( CMAKE_USE_CPACK EQUAL 1 )
  MESSAGE( STATUS "Enabling the CPack package target..." )
  # source: http://www.vtk.org/Wiki/CMake:Packaging_With_CPack
  INCLUDE( InstallRequiredSystemLibraries )
  # the installer will be named ${PACKAGENAME}-{VERSIONMAJOR}.{VERSIONMINOR}.{VERSIONPATCH}-win32.exe.
  # the installer will say "Welcome to the ${INSTALL_DIRECTORY} Setup Wizard and install to ${INSTALL_DIRECTORY} too, and
  # put the program in start menu under the ${INSTALL_DIRECTORY} name.
  # it will ask if ${PACKAGENAME} should be put in PATH.
  SET( CPACK_PACKAGE_NAME "KMess" )
  SET( CPACK_PACKAGE_DESCRIPTION_SUMMARY "KMess (package description)" )
  SET( CPACK_PACKAGE_VENDOR "The KMess team" )
  SET( CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README" )
  SET( CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING" )
  SET( CPACK_PACKAGE_VERSION_MAJOR "1" )
  SET( CPACK_PACKAGE_VERSION_MINOR "0" )
  SET( CPACK_PACKAGE_VERSION_PATCH "0" )
  SET( CPACK_PACKAGE_INSTALL_DIRECTORY "KMess" )
  IF( WIN32 AND NOT UNIX )
    # There is a bug in NSI that does not handle full unix paths properly. Make
    # sure there is at least one set of four (4) backslashes.
    SET( CPACK_GENERATOR "NSIS" )
    SET( CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/data/icons\\\\hi32-app-kmess.png" )
    SET( CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\kmess.exe" )
    SET( CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY} KMess (display name)" )
    SET( CPACK_NSIS_HELP_LINK "http:\\\\\\\\kmess.org" )
    SET( CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\kmess.org" )
    SET( CPACK_NSIS_CONTACT "project@kmess.org" )
    SET( CPACK_NSIS_MODIFY_PATH ON )
  ELSE( WIN32 AND NOT UNIX )
    SET( CPACK_STRIP_FILES "bin/kmess" )
    SET( CPACK_SOURCE_STRIP_FILES "" )
  ENDIF( WIN32 AND NOT UNIX )

  SET( CPACK_PACKAGE_EXECUTABLES "kmess" "KMess" )
  INCLUDE( CPack )
ENDIF( CMAKE_USE_CPACK EQUAL 1 )

#### Other settings ####

# Generate config-kmess.h
CONFIGURE_FILE( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/config-kmess.h.in ${CMAKE_CURRENT_BINARY_DIR}/config-kmess.h )
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} )

# continue in directories
ADD_SUBDIRECTORY( po )
ADD_SUBDIRECTORY( data )
ADD_SUBDIRECTORY( doc )
ADD_SUBDIRECTORY( src )

IF( LIBKONQ_FOUND )
  ADD_SUBDIRECTORY( src/utils/kmess-send )
ENDIF( LIBKONQ_FOUND )

IF( USE_BUNDLED_LIBRARIES MATCHES "ISFQT" )
  ADD_SUBDIRECTORY( contrib/isf-qt )
ENDIF( )


# Also add the tests if compiling in development mode
IF( CMAKE_BUILD_TYPE STREQUAL debugfull AND KMESS_DEBUG_OUTPUT EQUAL 1 )
  ADD_SUBDIRECTORY( tests )
ENDIF( CMAKE_BUILD_TYPE STREQUAL debugfull AND KMESS_DEBUG_OUTPUT EQUAL 1 )
