# Ground AI simulator module `wto_sim` for the open-source daScript build. native/wto-ai-sim/build.ps1
# links this folder into the daScript checkout as modules/wtoSim, so its build includes it like its
# own modules and daslang loads the shared module at start (.das_module).
IF ((NOT DAS_WTOSIM_INCLUDED) AND ((NOT ${DAS_WTOSIM_DISABLED}) OR (NOT DEFINED DAS_WTOSIM_DISABLED)))
    SET(DAS_WTOSIM_INCLUDED TRUE)
    MESSAGE(STATUS "wtoSim module included.")

    # The project's native folder: given by build.ps1, else found through the link.
    IF(DEFINED WTO_SIM_NATIVE_ROOT)
        SET(WTO_SIM_NATIVE ${WTO_SIM_NATIVE_ROOT})
    ELSE()
        FILE(REAL_PATH "${CMAKE_CURRENT_LIST_DIR}" _wto_sim_here)
        GET_FILENAME_COMPONENT(WTO_SIM_NATIVE "${_wto_sim_here}/../.." ABSOLUTE)
    ENDIF()
    SET(WTO_SIM_DIR ${CMAKE_CURRENT_LIST_DIR})
    SET(WTO_SIM_NAV_DIR ${WTO_SIM_NATIVE}/wto-nav)
    SET(WTO_SIM_DETOUR_DIR ${WTO_SIM_NATIVE}/third_party/recastnavigation/Detour)

    # The game's navigation engine and request protocol with upstream Detour, at their own warning level.
    FILE(GLOB WTO_SIM_DETOUR_SRC ${WTO_SIM_DETOUR_DIR}/Source/*.cpp)
    ADD_LIBRARY(wtoSimNav STATIC
        ${WTO_SIM_DETOUR_SRC}
        ${WTO_SIM_NAV_DIR}/wto_nav_runtime.cpp
        ${WTO_SIM_NAV_DIR}/wto_nav_paths.cpp
        ${WTO_SIM_NAV_DIR}/wto_nav_queries.cpp
        ${WTO_SIM_NAV_DIR}/wto_nav_protocol.c
    )
    TARGET_INCLUDE_DIRECTORIES(wtoSimNav PUBLIC
        $<BUILD_INTERFACE:${WTO_SIM_NAV_DIR}> $<BUILD_INTERFACE:${WTO_SIM_DETOUR_DIR}/Include>)
    # Every translation unit that sees dtQueryFilter must agree on its layout (wto_nav_runtime.cpp).
    TARGET_COMPILE_DEFINITIONS(wtoSimNav PUBLIC DT_VIRTUAL_QUERYFILTER PRIVATE _CRT_SECURE_NO_WARNINGS WIN32_LEAN_AND_MEAN)
    SET_TARGET_PROPERTIES(wtoSimNav PROPERTIES POSITION_INDEPENDENT_CODE ON)
    # The module's static library is in daScript's export set, so what it links must be too.
    INSTALL(TARGETS wtoSimNav EXPORT DASTargets ARCHIVE DESTINATION ${DAS_INSTALL_LIBDIR})

    SET(WTO_SIM_MODULE_SRC
        ${WTO_SIM_DIR}/src/wto_sim_module.cpp
        ${WTO_SIM_DIR}/src/sim_geo.cpp
        ${WTO_SIM_DIR}/src/sim_geo.h
        ${WTO_SIM_DIR}/src/sim_nav.cpp
        ${WTO_SIM_DIR}/src/sim_nav.h
    )
    ADD_MODULE_CPP(WtoSim)
    ADD_MODULE_LIB(libDasModuleWtoSim dasModuleWtoSim ${WTO_SIM_MODULE_SRC})
    TARGET_LINK_LIBRARIES(libDasModuleWtoSim PUBLIC wtoSimNav)
    TARGET_LINK_LIBRARIES(dasModuleWtoSim PUBLIC wtoSimNav)
    SETUP_CPP11(libDasModuleWtoSim)
    SETUP_CPP11(dasModuleWtoSim)
ENDIF()
