cmake_minimum_required(VERSION 3.20)
project(opengl_tutorial C CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# GLFW：Windowsは公式のビルド済みバイナリ、Linux/FreeBSDはシステムのパッケージ
# GLFW: prebuilt binaries on Windows, the system package on Linux/FreeBSD
if(WIN32)
  set(GLFW_ROOT "C:/glfw-3.4.bin.WIN64" CACHE PATH "GLFW prebuilt binaries")
  add_library(glfw STATIC IMPORTED)
  set_target_properties(glfw PROPERTIES
    IMPORTED_LOCATION "${GLFW_ROOT}/lib-vc2022/glfw3.lib"
    INTERFACE_INCLUDE_DIRECTORIES "${GLFW_ROOT}/include")
else()
  find_package(glfw3 3.3 REQUIRED)
endif()

# GLAD：生成したOpenGLローダー / the generated OpenGL loader
add_library(glad STATIC external/glad/src/glad.c)
target_include_directories(glad PUBLIC external/glad/include)

add_executable(game
  src/main.cc
  src/window.cc
  src/gl_debug.cc)
target_include_directories(game PRIVATE src external/stb external/linalg)
target_link_libraries(game PRIVATE glad glfw)

# 警告を有効にする（自分のコードだけ） / enable warnings (our own code only)
if(MSVC)
  target_compile_options(game PRIVATE /W4 /utf-8)
else()
  target_compile_options(game PRIVATE -Wall -Wextra)
endif()

# シェーダーとアセットは作業ディレクトリからの相対パスで読む。
# Visual Studioではプロジェクトのルートを作業ディレクトリにする。Unixではルートから ./build/game を実行。
# Shaders and assets are loaded relative to the working directory.
# Visual Studio: use the project root as the working directory. Unix: run ./build/game from the root.
set_property(TARGET game PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT game)
