# Copyright (C) 2020 Tycho Softworks.
#
# This file is free software; as a special exception the author gives
# unlimited permission to copy and/or distribute it, with or without
# modifications, as long as this notice is preserved.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

cmake_minimum_required(VERSION 3.16.0)
project(Coventry VERSION 0.9.3 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17)

file(
    GLOB LINT_SOURCES
    RELATIVE ${PROJECT_SOURCE_DIR}
    src/*.[ch]pp utils/*.cpp)

include(cmake/custom.cmake OPTIONAL)
include(cmake/project.cmake)
include(cmake/features.cmake)
include(cmake/coverage.cmake)
include(cmake/linting.cmake)
include(cmake/tune.cmake)
include(cmake/paths.cmake)
include(cmake/deploy.cmake OPTIONAL)

file(GLOB testing test/*.conf test/*.scr)
file(GLOB optional .git[a-z]* *.json *.in *.yml .clang* cmake/*)
file(GLOB markdown *.md)

# Setup headers and definitions
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)

add_compile_definitions(PROJECT_VERSION="${PROJECT_VERSION}")
add_compile_definitions(PROJECT_SOURCE_DIR="${PROJECT_SOURCE_DIR}")
add_compile_definitions(SERVER_ID="${SERVER_ID}")
add_compile_definitions(SERVER_CONTROL_IPC="${SERVER_CONTROL_IPC}")
add_compile_definitions(SERVER_IPCPATH="${SERVER_IPCPATH}")
add_compile_definitions(SERVER_CONFIG_FILE="${SERVER_CONFIG_FILE}")
add_compile_definitions(SERVER_LOGGER_PATH="${SERVER_LOGGER_PATH}")
add_compile_definitions(SERVER_PREFIX_PATH="${SERVER_PREFIX_PATH}")

# Tunable config
add_compile_definitions(TUNE_CALL_LIMIT=${SERVER_CALL_LIMIT})

# Build Server and utils
add_subdirectory(src)
add_subdirectory(utils)

# Testing
enable_testing()
add_subdirectory(test)

# Extras...
add_custom_target(support-files SOURCES ${optional} ${markdown})
add_custom_target(testing-files SOURCES ${testing})
