# Author:
#   Sven Czarnian <devel@svcz.de>
# Copyright:
#   2021 Sven Czarnian
# License:
#   GPLv3
# Brief:
#   Creates the AMAN-EuroScope solution

CMAKE_MINIMUM_REQUIRED(VERSION 3.14)

# define the project information
PROJECT(ArrivalMANager LANGUAGES CXX VERSION "0.1.0")

# define the language parameters
SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)
SET(CMAKE_CXX_STANDARD 20)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(CMAKE_CXX_EXTENSIONS OFF)
SET(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)

# adapt compiler flags based on used compiler
IF (MSVC)
    IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
        STRING(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
    ELSE ()
        SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
    ENDIF ()
    IF (NOT CMAKE_CXX_FLAGS MATCHES "/MP")
        SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
        SET(CMAKE_C_FLAGS   "${CMAKE_C_FLAGS} /MP")
    ENDIF ()

    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /sdl /permissive- /DNOMINMAX")
    SET(CMAKE_C_FLAGS   "${CMAKE_C_FLAGS} /sdl /permissive- /DNOMINMAX")
    SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /MANIFESTUAC:NO")
    ADD_DEFINITIONS(/D_USRDLL /D_CRT_SECURE_NO_WARNINGS)
ENDIF ()

CONFIGURE_FILE(
    ${CMAKE_SOURCE_DIR}/version.h.in
    ${CMAKE_BINARY_DIR}/include/version.h
)
CONFIGURE_FILE(
    ${CMAKE_SOURCE_DIR}/res/ArrivalMANager.rc.in
    ${CMAKE_BINARY_DIR}/ArrivalMANager.rc
)

# define include directories
INCLUDE_DIRECTORIES(
    ${CMAKE_SOURCE_DIR}
    ${CMAKE_SOURCE_DIR}/include
    ${CMAKE_BINARY_DIR}/include
)

INCLUDE(cmake/3rdParty.cmake)
INCLUDE(cmake/Protobuf.cmake)
INCLUDE(cmake/FindEuroScope.cmake)

# register all cmake helper to find required modules and find 3rd-party components
SET(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_SOURCE_DIR}/cmake")
FIND_PACKAGE(EuroScope REQUIRED)
IF(NOT EuroScope_FOUND)
    MESSAGE(FATAL_ERROR "Unablet to build without EuroScope and the EuroScope-SDK")
ENDIF()

ADD_SUBDIRECTORY(src)
