cmake_minimum_required(VERSION 3.16)
project(ImGuiUI_Test)

set(CMAKE_CXX_STANDARD 17)

# 🚫 CRITICAL: Prohibit 'auto' keyword as type (explicit types required)
# Applied only to project files, not external dependencies

# 🔧 DEVELOPMENT MODE - Enable all debugging tools (can be overridden)
# set(CMAKE_BUILD_TYPE Debug)  # Commented out to allow Release builds
set(CMAKE_CXX_FLAGS_DEBUG "-fsanitize=address -fsanitize=undefined -g -O0 -Wall -Wextra")
set(CMAKE_C_FLAGS_DEBUG "-fsanitize=address -fsanitize=undefined -g -O0 -Wall -Wextra")

# Link AddressSanitizer
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "-fsanitize=address -fsanitize=undefined")

# Find packages
find_package(glfw3 REQUIRED)
find_package(OpenGL REQUIRED)

# Add FetchContent for dependencies
include(FetchContent)

# nlohmann/json
FetchContent_Declare(
  nlohmann_json
  GIT_REPOSITORY https://github.com/nlohmann/json.git
  GIT_TAG v3.11.3
)

# Dear ImGui
FetchContent_Declare(
  imgui
  GIT_REPOSITORY https://github.com/ocornut/imgui.git
  GIT_TAG v1.90.1
)

FetchContent_MakeAvailable(nlohmann_json imgui)

# Create ImGui library with OpenGL/GLFW backends
add_library(imgui_backends
    ${imgui_SOURCE_DIR}/imgui.cpp
    ${imgui_SOURCE_DIR}/imgui_demo.cpp
    ${imgui_SOURCE_DIR}/imgui_draw.cpp
    ${imgui_SOURCE_DIR}/imgui_tables.cpp
    ${imgui_SOURCE_DIR}/imgui_widgets.cpp
    ${imgui_SOURCE_DIR}/backends/imgui_impl_glfw.cpp
    ${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.cpp
)

target_include_directories(imgui_backends PUBLIC
    ${imgui_SOURCE_DIR}
    ${imgui_SOURCE_DIR}/backends
)

target_link_libraries(imgui_backends PUBLIC glfw OpenGL::GL)

# Test executable
add_executable(test_imgui_ui
    test_imgui_ui.cpp
    src/core/src/ImGuiUI.cpp
)

target_include_directories(test_imgui_ui PRIVATE
    src/core/include
    ${imgui_SOURCE_DIR}
    ${imgui_SOURCE_DIR}/backends
)

target_link_libraries(test_imgui_ui
    imgui_backends
    nlohmann_json::nlohmann_json
    glfw
    OpenGL::GL
)

# Note: Auto keyword restriction enforced via code review and linting tools

# Copy to build directory
set_target_properties(test_imgui_ui PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)

# Test constraints executable
add_executable(test_constraints
    test_constraints.cpp
    src/core/src/ImGuiUI.cpp
)

target_include_directories(test_constraints PRIVATE
    src/core/include
    ${imgui_SOURCE_DIR}
    ${imgui_SOURCE_DIR}/backends
)

target_link_libraries(test_constraints
    imgui_backends
    nlohmann_json::nlohmann_json
    glfw
    OpenGL::GL
)

# Note: Auto keyword restriction enforced via code review and linting tools

set_target_properties(test_constraints PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)