# On web SDL is provided by emsdk itself
if(NOT CMAKE_SYSTEM_NAME STREQUAL Emscripten)
find_package(SDL2 REQUIRED)
endif()

file(GLOB_RECURSE PSEMEK_SDL2_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "include/*.hpp")
file(GLOB_RECURSE PSEMEK_SDL2_SOURCES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "source/*.cpp")

set(PSEMEK_SDL2_PLATFORM_SOURCES)

if(APPLE)
	file(GLOB_RECURSE PSEMEK_SDL2_PLATFORM_SOURCES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "platform/apple/*.m")
endif()

psemek_add_library(psemek-sdl2 ${PSEMEK_SDL2_HEADERS} ${PSEMEK_SDL2_SOURCES} ${PSEMEK_SDL2_PLATFORM_SOURCES})
target_include_directories(psemek-sdl2 PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(psemek-sdl2 PUBLIC psemek-log psemek-util psemek-audio psemek-app SDL2)
if(PSEMEK_GRAPHICS_API STREQUAL OPENGL)
	target_link_libraries(psemek-sdl2 PUBLIC psemek-gfx)
elseif(PSEMEK_GRAPHICS_API STREQUAL WEBGPU)
	# TODO: shouldn't these come from SDL2 dependencies?
	find_library(FOUNDATION_FRAMEWORK Foundation REQUIRED)
	find_library(METAL_FRAMEWORK Metal REQUIRED)
	find_library(QUARTZCORE_FRAMEWORK QuartzCore REQUIRED)

	target_link_libraries(psemek-sdl2
		PUBLIC
			psemek-wgpu
		PRIVATE
			${FOUNDATION_FRAMEWORK}
			${METAL_FRAMEWORK}
			${QUARTZCORE_FRAMEWORK}
	)
endif()
