# It also compiles one file straight out of the client tree (mwmp/content/Json.cpp) to parse
# requiredDataFiles.json and player saves with the fork's own tolerant parser - no new JSON
# dependency.
project(SiltStriderLoadTest)

set(LOADTEST_SOURCES
    main.cpp
    Safety.cpp
    Population.cpp
    Seed.cpp
    SyntheticClient.cpp
    # Reused verbatim from the client: the fork's dependency-free JSON parser.
    ${CMAKE_SOURCE_DIR}/apps/openmw/mwmp/content/Json.cpp
)

set(LOADTEST_HEADERS
    Safety.hpp
    Population.hpp
    Seed.hpp
    SyntheticClient.hpp
)

add_executable(SiltStriderLoadTest ${LOADTEST_SOURCES} ${LOADTEST_HEADERS})

# SiltVersions.hpp (SILTSTRIDER_ENGINE_REV) is generated at build time by the silt-version custom target into
# OpenMW_BINARY_DIR. Depend on it so our build stamps the SAME engine rev the server build stamped - which is what
# lets a client from this tree clear the server's build gate.
add_dependencies(SiltStriderLoadTest tes3mp-wire)
if (TARGET silt-version)
    add_dependencies(SiltStriderLoadTest silt-version)
endif ()

# The RakNet headers live under <include>/raknet; tes3mp-wire adds <include>, so add the subdir here for
# <RakPeerInterface.h> and friends. The build root carries SiltVersions.hpp.
target_include_directories(SiltStriderLoadTest SYSTEM PRIVATE
    ${RakNet_INCLUDES}
    ${RakNet_INCLUDES}/raknet
)
target_include_directories(SiltStriderLoadTest PRIVATE ${OpenMW_SOURCE_DIR} ${OpenMW_BINARY_DIR})

set_target_properties(SiltStriderLoadTest PROPERTIES
    CXX_STANDARD 20
    CXX_STANDARD_REQUIRED YES
)

if (MSVC)
    target_compile_options(SiltStriderLoadTest PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/MP>)
    target_compile_definitions(SiltStriderLoadTest PRIVATE _USE_MATH_DEFINES)
endif ()

target_link_libraries(SiltStriderLoadTest
    tes3mp-wire
    ${RakNet_LIBRARY}
    ws2_32
    iphlpapi
)
