# Author:
#   Sven Czarnian <devel@svcz.de>
# Copyright:
#   2021 Sven Czarnian
# License:
#   GNU General Public License (GPLv3)
# Brief:
#   Creates the plug-in which is used by Euroscope

# define the Google Protobuf-files
SET(PROTO_FILES
    ${CMAKE_CURRENT_SOURCE_DIR}/com/protobuf/Aircraft.proto
    ${CMAKE_CURRENT_SOURCE_DIR}/com/protobuf/AircraftReport.proto
    ${CMAKE_CURRENT_SOURCE_DIR}/com/protobuf/AircraftSchedule.proto
    ${CMAKE_CURRENT_SOURCE_DIR}/com/protobuf/BaseTypes.proto
)

# generate the Protobuf C++ files
SET(PROTO_SOURCE_FILES "")
ProtobufCompile("${PROTO_FILES}" PROTO_SOURCE_FILES)

SET(SOURCE_FILES
    ArrivalMANagerMain.cpp
    PlugIn.cpp
    PlugIn.h
    RadarScreen.cpp
    RadarScreen.h
    stdafx.cpp
    stdafx.h
)

SET(SOURCE_CONFIG_FILES
    config/CommunicationFileFormat.cpp
    config/FileFormat.cpp
    config/IdentifierFileFormat.cpp
)

SET(SOURCE_FILES_RES
    ${CMAKE_BINARY_DIR}/ArrivalMANager.rc
    ${CMAKE_SOURCE_DIR}/res/resource.h
    ${CMAKE_SOURCE_DIR}/res/targetver.h
)

SET(INCLUDE_CONFIG_FILES
    ${CMAKE_SOURCE_DIR}/include/aman/config/CommunicationFileFormat.h
    ${CMAKE_SOURCE_DIR}/include/aman/config/FileFormat.h
    ${CMAKE_SOURCE_DIR}/include/aman/config/IdentifierFileFormat.h
)

SET(INCLUDE_HELPER_FILES
    ${CMAKE_SOURCE_DIR}/include/aman/helper/String.h
)

SET(INCLUDE_TYPES_FILES
    ${CMAKE_SOURCE_DIR}/include/aman/types/Communication.h
)

# define the plug in
ADD_LIBRARY(
    ArrivalMANager SHARED
        ${SOURCE_FILES_RES}
        ${SOURCE_CONFIG_FILES}
        ${SOURCE_FILES}
        ${PROTO_SOURCE_FILES}
        ${PROTO_FILES}
        ${INCLUDE_CONFIG_FILES}
        ${INCLUDE_HELPER_FILES}
        ${INCLUDE_TYPES_FILES}
)

# define the dependencies
TARGET_INCLUDE_DIRECTORIES(ArrivalMANager INTERFACE EuroScope)
TARGET_LINK_LIBRARIES(ArrivalMANager EuroScope GSL Shlwapi.lib)
TARGET_LINK_LIBRARIES(ArrivalMANager protobuf)

# configure the debugger and update the linker flags
IF(MSVC)
    SET_TARGET_PROPERTIES(ArrivalMANager
        PROPERTIES
            VS_DEBUGGER_COMMAND ${EuroScope_EXECUTABLE}
            VS_DEBUGGER_WORKING_DIRECTORY ${EuroScope_DIR}
    )
    SET_TARGET_PROPERTIES(ArrivalMANager
        PROPERTIES
            LINK_FLAGS /SUBSYSTEM:WINDOWS
    )
ENDIF()

SOURCE_GROUP("Generated Files" FILES ${PROTO_SOURCE_FILES})
SOURCE_GROUP("Protocol Files" FILES ${PROTO_FILES})
SOURCE_GROUP("Source Files" FILES ${SOURCE_FILES})
SOURCE_GROUP("Source Files\\config" FILES ${SOURCE_CONFIG_FILES})
SOURCE_GROUP("Source Files\\res" FILES ${SOURCE_FILES_RES})
SOURCE_GROUP("Header Files\\config" FILES ${INCLUDE_CONFIG_FILES})
SOURCE_GROUP("Header Files\\helper" FILES ${INCLUDE_HELPER_FILES})
SOURCE_GROUP("Header Files\\types" FILES ${INCLUDE_TYPES_FILES})
