cmake_minimum_required(VERSION 3.20)
project(recomp_presentation_core VERSION 0.1.0 LANGUAGES C CXX)
include(CTest)
option(RECOMP_PRESENTATION_BUILD_SDL2_TESTS "Check the optional borrowed SDL2 renderer backend" OFF)
add_library(retro_presentation STATIC src/geometry.cpp src/image.cpp src/presentation.cpp)
add_library(retro-runtime::presentation ALIAS retro_presentation)
target_compile_features(retro_presentation PUBLIC cxx_std_17)
target_include_directories(retro_presentation PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)
set_target_properties(retro_presentation PROPERTIES EXPORT_NAME presentation)
if(MSVC)
  target_compile_options(retro_presentation PRIVATE /W4 /permissive-)
else()
  target_compile_options(retro_presentation PRIVATE -Wall -Wextra -Wpedantic)
endif()
if(BUILD_TESTING)
  if(RECOMP_PRESENTATION_BUILD_SDL2_TESTS)
    find_package(SDL2 CONFIG REQUIRED)
    add_executable(sdl2_presentation_test tests/sdl2_test.cpp src/sdl2.c)
    target_include_directories(sdl2_presentation_test PRIVATE include)
    target_compile_features(sdl2_presentation_test PRIVATE cxx_std_17)
    target_link_libraries(sdl2_presentation_test PRIVATE SDL2::SDL2)
    add_test(NAME sdl2_presentation COMMAND sdl2_presentation_test)
  endif()
  add_executable(portable_presentation_test tests/portable_test.cpp)
  target_link_libraries(portable_presentation_test PRIVATE retro_presentation)
  add_test(NAME portable_presentation COMMAND portable_presentation_test)
  add_executable(pacing_c_test tests/pacing_c_test.c)
  target_include_directories(pacing_c_test PRIVATE include)
  add_test(NAME pacing_c_abi COMMAND pacing_c_test)
  if(WIN32)
    add_executable(native_gl_test tests/native_gl_test.cpp)
    target_link_libraries(native_gl_test PRIVATE retro_presentation opengl32 user32 gdi32)
    add_test(NAME hidden_native_gl COMMAND native_gl_test)
    set_tests_properties(hidden_native_gl PROPERTIES SKIP_RETURN_CODE 77)
  endif()
endif()
install(TARGETS retro_presentation EXPORT retro-presentation-targets ARCHIVE DESTINATION lib)
install(DIRECTORY include/ DESTINATION include)
install(EXPORT retro-presentation-targets NAMESPACE retro-runtime:: DESTINATION lib/cmake/retro-presentation)
