cmake_minimum_required(VERSION 3.16)
project(Prog3B)

# === Basis-Konfiguration ===
set(EXECUTABLE_NAME Prog3B)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Default-Build-Type (falls nicht angegeben)
if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
endif()

# === Quell- und Header-Dateien ===
set(SRC_FILES
    ${CMAKE_CURRENT_LIST_DIR}/main.cpp
    ${CMAKE_CURRENT_LIST_DIR}/gamecube.cpp
)

set(INCLUDE_DIRS
    ${CMAKE_CURRENT_LIST_DIR}
)

# === Betriebssystem automatisch erkennen ===
if(WIN32)
    set(OS_DIR "windows")
elseif(APPLE)
    # Prüfen, ob ARM oder x86
    execute_process(
        COMMAND uname -m
        OUTPUT_VARIABLE ARCH
        OUTPUT_STRIP_TRAILING_WHITESPACE
    )
    if(ARCH STREQUAL "arm64")
        set(OS_DIR "mac_arm")
    else()
        set(OS_DIR "mac_x86")
    endif()
elseif(UNIX)
    set(OS_DIR "linux")
else()
    message(FATAL_ERROR "Unbekanntes Betriebssystem!")
endif()


# === Executable erstellen ===
add_executable(${EXECUTABLE_NAME} ${SRC_FILES})
target_include_directories(${EXECUTABLE_NAME} PRIVATE ${INCLUDE_DIRS})

# === Bibliotheken verlinken ===
target_link_libraries(${EXECUTABLE_NAME} PRIVATE
    ${CMAKE_CURRENT_LIST_DIR}/${OS_DIR}/libgamematrix.a
    ${CMAKE_CURRENT_LIST_DIR}/${OS_DIR}/libraylib.a
)

# Windows: zusätzliche Systemlib
if(WIN32)
    target_link_libraries(${EXECUTABLE_NAME} PRIVATE winmm)
endif()

# macOS: Frameworks
if(APPLE)
    target_link_libraries(${EXECUTABLE_NAME}
        "-framework IOKit"
        "-framework Cocoa"
        "-framework OpenGL"
    )
endif()

