cmake_minimum_required(VERSION 3.12)

# Build mode debug/release?
set(CMAKE_BUILD_TYPE Debug)

# Set C++ standard to C++11
set(CMAKE_CXX_STANDARD 11)

project("Metin2 Server")

set(BINARY_OUTPUT_DIR ${CMAKE_BINARY_DIR}/bin)

# Set build directory
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

# Set the CMake module directory
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")

# Set environment variables
set(METIN2_OS_NAME ${CMAKE_SYSTEM})
set(METIN2_COMPILER "${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
set(METIN2_CPU_TARGET ${CMAKE_SYSTEM_PROCESSOR})

# Git revision
include(FindGit)
find_package(Git)

if(GIT_FOUND)
    GIT_WC_INFO(${PROJECT_SOURCE_DIR} Metin2)
    set(METIN2_REVISION ${Metin2_WC_REVISION_NAME})
    set(METIN2_LAST_CHANGED_DATE ${Metin2_WC_LAST_CHANGED_DATE})

    if (${Metin2_WC_LATEST_TAG} NOT STREQUAL "")
        set(METIN2_LATEST_TAG ${Metin2_WC_LATEST_TAG})
    else()
        set(METIN2_LATEST_TAG "unknown")
    endif()
else()
    set(METIN2_REVISION "unknown")
    set(METIN2_LAST_CHANGED_DATE "\"unknown\"")
    set(METIN2_LATEST_TAG "unknown")
endif()

message(STATUS "Current revision is ${METIN2_REVISION}")

# Generate the version header
configure_file (
        "${PROJECT_SOURCE_DIR}/common/version.h.in"
        "${PROJECT_BINARY_DIR}/common/version.h"
)
include_directories(${PROJECT_BINARY_DIR}/common/)

# Set the global include directories
include_directories(${CMAKE_CURRENT_SOURCE_DIR})

add_subdirectory(libgame)
add_subdirectory(liblua)
add_subdirectory(libpoly)
add_subdirectory(libsql)
add_subdirectory(libthecore)
add_subdirectory(game)
add_subdirectory(db)
add_subdirectory(quest)