CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
CMAKE_POLICY(VERSION 2.6)

PROJECT(MANAPLUS)

IF (NOT VERSION)
    SET(VERSION 1.0.0)
ENDIF()

STRING(REPLACE "." " " _VERSION ${VERSION})
SEPARATE_ARGUMENTS(_VERSION)
LIST(LENGTH _VERSION _LEN)
IF(NOT _LEN EQUAL 4 AND NOT _LEN EQUAL 3)
    MESSAGE(FATAL_ERROR "Version needs to be in the form MAJOR.MINOR.RELEASE[.BUILD]")
ENDIF()

LIST(GET _VERSION 0 VER_MAJOR)
LIST(GET _VERSION 1 VER_MINOR)
LIST(GET _VERSION 2 VER_RELEASE)
IF(_LEN EQUAL 4)
    LIST(GET _VERSION 3 VER_BUILD)
ELSE()
    SET(VER_BUILD 0)
ENDIF()

# where to look for cmake modules
SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake/Modules)

FIND_PACKAGE(Gettext)

OPTION(WITH_OPENGL "Enable OpenGL support" ON)
OPTION(ENABLE_NLS "Enable building of tranlations" ON)
OPTION(ENABLE_TMWA "Enable tmwA support" ON)

IF (WIN32)
    SET(PKG_DATADIR ".")
    SET(PKG_BINDIR ".")
    SET(LOCALEDIR ".")
    CONFIGURE_FILE(src/winver.h.in src/winver.h)
ELSE (WIN32)
    IF (NOT OSX AND NOT BEOS)
        OPTION(USE_X11 "Use X11 Clipboard functionality" ON)
    ENDIF ()
    SET(PKG_DATADIR ${CMAKE_INSTALL_PREFIX}/share/manaplus)
    SET(LOCALEDIR ${CMAKE_INSTALL_PREFIX}/share/locale)
    SET(PKG_BINDIR ${CMAKE_INSTALL_PREFIX}/bin)
ENDIF (WIN32)

ADD_SUBDIRECTORY(data)
ADD_SUBDIRECTORY(src)

IF (GETTEXT_FOUND AND ENABLE_NLS)
    ADD_SUBDIRECTORY(po)
ENDIF()

If(UNIX)
    INSTALL(FILES manaplus.desktop DESTINATION share/applications)
    INSTALL(FILES manaplustest.desktop DESTINATION share/applications)

    INSTALL(FILES manaplus.appdata.xml DESTINATION share/appdata)
ENDIF()

SET(CPACK_PACKAGE_NAME "manaplus")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "ManaPlus")
SET(CPACK_PACKAGE_VENDOR "ManaPlus Development Team")
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README")
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING")
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "ManaPlus")
SET(CPACK_PACKAGE_VERSION_MAJOR ${VER_MAJOR})
SET(CPACK_PACKAGE_VERSION_MINOR ${VER_MINOR})
SET(CPACK_PACKAGE_VERSION_PATCH ${VER_RELEASE})
IF(WIN32)
    SET(CPACK_NSIS_DISPLAY_NAME "ManaPlus")
    SET(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}/data/icons/manaplus.ico")
    SET(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/packaging/windows/setup_welcome.bmp")
    SET(CPACK_NSIS_URL_INFO_ABOUT "http://manaplus.org")
ENDIF()
INCLUDE(CPack)
