cmake_minimum_required(VERSION 3.25.1)

set(CMAKE_CXX_STANDARD 20)

set(PROJECT_EXECUTABLE_NAME oe_editor)

set(CMAKE_BUILD_RPATH ".")

project(SandBox
    VERSION 0.1.0
)

find_package(imgui REQUIRED CONFIG)
find_package(spdlog REQUIRED CONFIG)
find_package(EnTT REQUIRED)

file(GLOB_RECURSE SRC_FILES "src/*.cpp")
add_executable(${PROJECT_EXECUTABLE_NAME}
    ${SRC_FILES}
)

file(GLOB NETHOST_DIR_CANDIDATES
    "/usr/share/dotnet/packs/Microsoft.NETCore.App.Host.*-x64/*/runtimes/linux-x64/native"
    "/usr/share/dotnet/packs/Microsoft.NETCore.App.Host.*-x64/*/runtimes/arch-x64/native"
)

# Pick the first match
list(GET NETHOST_DIR_CANDIDATES 0 NETHOST_DIR)

if(NOT NETHOST_DIR)
    message(FATAL_ERROR "Could not find NETCore native directory")
else()
    message(STATUS "Found nethost dir: ${NETHOST_DIR}")
endif()

target_include_directories(${PROJECT_EXECUTABLE_NAME} PRIVATE
    "${PROJECT_SOURCE_DIR}/include"
    "${PROJECT_SOURCE_DIR}/editor/include"
    "/usr/include/freetype2/"
    "${NETHOST_DIR}"
)

target_link_libraries(${PROJECT_EXECUTABLE_NAME} PRIVATE
    spdlog::spdlog
    imgui::imgui
    open_engine
    dl
    freetype
    EnTT::EnTT
    nethost
)

target_link_directories(${PROJECT_EXECUTABLE_NAME} PRIVATE
    ${CMAKE_SOURCE_DIR}/lib
    ${NETHOST_DIR}
)
