# Avoid C11 since it is not supported by the i386-mingw32 toolchain.
set(cflags ${cflags} -Wall -g3 -ffunction-sections -fdata-sections)

set(components
    building
    camera
    container
    font
    game
    gfx
    gui
    header
    input
    instance
    keyboard
    main
    menu
    mouse
    net
    packet
    pad
    peripheral
    player
    settings
    sfx
    system
    terrain
    transport
    unit
    util
)

set(interfaces
)

target_compile_options(${PROJECT_NAME} PUBLIC ${cflags})
# Dependencies for main.c
target_link_libraries(${PROJECT_NAME} PRIVATE main)

foreach(c ${components})
    add_subdirectory("${c}")
    target_compile_options(${c} PUBLIC ${cflags})

    if(${c} STREQUAL "net" AND NOT ESP32_BUILD)
        # ESP32 builds pull non-portable header files (e.g.: xt_utils.h).
        set_target_properties(${c} PROPERTIES C_STANDARD 99 C_EXTENSIONS OFF)
        target_compile_options(${c} PUBLIC -pedantic)
        target_compile_features(${c} PUBLIC c_std_99)
    endif()
endforeach()

foreach(i ${interfaces})
    add_subdirectory("${i}")
    target_compile_options(${i} INTERFACE ${cflags})
    target_link_libraries(${PROJECT_NAME} PRIVATE ${c})
endforeach()

target_link_options(${PROJECT_NAME} PRIVATE -Wl,--gc-sections)
