cmake_minimum_required(VERSION 3.20)
project(dofs LANGUAGES CXX)

# Global C++ settings
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE BOOL "Export compile_commands.json")

# Dev toggle: convenient but less deterministic than listing files explicitly
option(DOFS_GLOB_SOURCES "Dev: auto-add *.cc files via GLOB (not ideal for CI)" OFF)

# Interface target to export common config (include dirs, features)
add_library(dofs_config INTERFACE)
target_compile_features(dofs_config INTERFACE cxx_std_20)

# Let everyone include headers like: #include "core/error.h"
target_include_directories(dofs_config INTERFACE "${PROJECT_SOURCE_DIR}/src")

# yaml-cpp submodule (static)
if(EXISTS "${PROJECT_SOURCE_DIR}/third_party/yaml-cpp/CMakeLists.txt")
    # Use yaml-cpp's options; force them at configure-time
    set(YAML_BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
    set(YAML_CPP_BUILD_TESTS OFF CACHE BOOL "" FORCE)
    set(YAML_CPP_BUILD_TOOLS OFF CACHE BOOL "" FORCE)
    set(YAML_CPP_BUILD_CONTRIB ON  CACHE BOOL "" FORCE)
    set(YAML_ENABLE_PIC ON          CACHE BOOL "" FORCE)
    set(YAML_CPP_INSTALL OFF        CACHE BOOL "" FORCE)

    add_subdirectory(third_party/yaml-cpp EXCLUDE_FROM_ALL)
else()
    message(WARNING "yaml-cpp submodule missing at third_party/yaml-cpp")
endif()

# add_subdirectory(src)
add_subdirectory(src/core)
add_subdirectory(src/network)
add_subdirectory(src/hosts)
