cmake_minimum_required(VERSION 3.10)
if(POLICY CMP0091)
  cmake_policy(SET CMP0091 NEW)
endif()
project(Piu C)
set(CMAKE_C_STANDARD 99)
if(MSVC AND VCPKG_TARGET_TRIPLET MATCHES "static")
  set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()

# Nucleo sem dependencias (formatos, tempo, julgamento)
add_library(piu_core src/piu_data.c src/piu_play.c)
target_include_directories(piu_core PUBLIC src)
if(NOT WIN32)
  target_link_libraries(piu_core m)
endif()
add_executable(piu_test src/main_test.c)
target_link_libraries(piu_test piu_core)

# Jogo: SDL2 + OpenGL 1.x + zlib (PNG) + dr_mp3
find_package(SDL2 CONFIG REQUIRED)
find_package(ZLIB REQUIRED)
find_package(OpenGL REQUIRED)
if(WIN32)
  enable_language(RC)
  add_executable(piu src/game.c src/piu.rc)
else()
  add_executable(piu src/game.c)
endif()
target_link_libraries(piu piu_core ZLIB::ZLIB OpenGL::GL)
if(TARGET SDL2::SDL2-static)
  target_link_libraries(piu SDL2::SDL2-static)
else()
  target_link_libraries(piu SDL2::SDL2)
endif()
# Build PC (pumpy.exe): mesmo codigo com PIU_BUILD_PC; os ajustes especificos entram sob #ifdef PIU_BUILD_PC
if(WIN32)
  add_executable(piu_pc src/game.c src/piu.rc)
else()
  add_executable(piu_pc src/game.c)
endif()
target_compile_definitions(piu_pc PRIVATE PIU_BUILD_PC)
target_link_libraries(piu_pc piu_core ZLIB::ZLIB OpenGL::GL)
if(TARGET SDL2::SDL2-static)
  target_link_libraries(piu_pc SDL2::SDL2-static)
else()
  target_link_libraries(piu_pc SDL2::SDL2)
endif()
if(MSVC)
  target_compile_definitions(piu_pc PRIVATE _CRT_SECURE_NO_WARNINGS)
  target_compile_definitions(piu PRIVATE _CRT_SECURE_NO_WARNINGS)
  target_compile_definitions(piu_core PRIVATE _CRT_SECURE_NO_WARNINGS)
  target_compile_definitions(piu_test PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()
