#
# project: sokol-samples
#
cmake_minimum_required(VERSION 3.0)
project(CogDemoImgui)
set(CMAKE_C_STANDARD 99)
if (CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
    set(CMAKE_CXX_STANDARD 17)
else()
    set(CMAKE_CXX_STANDARD 14)
endif()

if (SOKOL_USE_WGPU_DAWN)
    set(USE_DAWN_SDK ON)
endif()

# include the fips main cmake file
get_filename_component(FIPS_ROOT_DIR "../fips" ABSOLUTE)
include("${FIPS_ROOT_DIR}/cmake/fips.cmake")

fips_setup()
fips_ide_group("Imports")
if (NOT USE_SOKOL_APP AND NOT SOKOL_USE_WGPU_DAWN AND NOT SOKOL_USE_D3D11 AND NOT SOKOL_USE_METAL)
    fips_import_fips_glfw_glfw3()
endif()
fips_import_fips_imgui_imgui()
#fips_import_fips_cimgui_cimgui()
if (NOT FIPS_UWP)
#    fips_import_fips_libmodplug_libmodplug()
endif()
fips_ide_group("")

# just suppress this pesky "missing field initializer warning" for now
if (FIPS_CLANG OR FIPS_GCC)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-missing-field-initializers -Wsign-conversion")
endif()
if (FIPS_GCC)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-missing-braces")
endif()

# macro to select the sokol-backend and shader dialects
macro(sokol_config)
    add_definitions(-DSOKOL_NO_DEPRECATED)
    if (FIPS_EMSCRIPTEN)
        if (FIPS_EMSCRIPTEN_USE_WEBGPU)
            add_definitions(-DSOKOL_WGPU)
            set(slang "wgpu")
        else()
            add_definitions(-DSOKOL_GLES3)
            set(slang "glsl300es:glsl100")
        endif()
    elseif (FIPS_ANDROID)
        add_definitions(-DSOKOL_GLES3)
        set(slang "glsl300es:glsl100")
    elseif (SOKOL_USE_D3D11)
        add_definitions(-DSOKOL_D3D11)
        set(slang "hlsl4")
    elseif (SOKOL_USE_METAL)
        add_definitions(-DSOKOL_METAL)
        if (FIPS_IOS)
            set(slang "metal_ios:metal_sim")
        else()
            set(slang "metal_macos")
        endif()
    else()
        if (FIPS_IOS)
            add_definitions(-DSOKOL_GLES3)
            set(slang "glsl300es:glsl100")
        else()
            add_definitions(-DSOKOL_GLCORE33)
            set(slang "glsl330")
        endif()
    endif()
endmacro()

if (USE_SOKOL_APP)
# NOTES: trim down to only "SAPP" configurations then below is always performed
    include_directories(libs)
    fips_ide_group("Libs")
    add_subdirectory(libs)
    fips_ide_group("Samples")
    add_subdirectory(sapp)
#    fips_ide_group("Tests")
#    add_subdirectory(tests)
else()
# NOTES: trim down to only "SAPP" configurations then below is dead-code
    if (FIPS_EMSCRIPTEN)
        if (FIPS_EMSCRIPTEN_USE_WEBGPU)
            add_subdirectory(wgpu)
        else()
            add_subdirectory(html5)
        endif()
    elseif (SOKOL_USE_D3D11)
        add_subdirectory(d3d11)
    elseif (SOKOL_USE_METAL)
        add_subdirectory(metal)
    elseif (SOKOL_USE_WGPU_DAWN)
        add_subdirectory(libs/dawnutil)
        add_subdirectory(wgpu)
    else()
        add_subdirectory(glfw)
    endif()
endif()

fips_finish()
