file(GLOB PSEMEK_LIB_DIRS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/*")
list(REMOVE_ITEM PSEMEK_LIB_DIRS "CMakeLists.txt")

if(PSEMEK_LEGACY_UI)
	list(REMOVE_ITEM PSEMEK_LIB_DIRS "ui")
else()
	list(REMOVE_ITEM PSEMEK_LIB_DIRS "ui_legacy")
endif()

if(NOT (PSEMEK_GRAPHICS_API STREQUAL WEBGPU))
	list(REMOVE_ITEM PSEMEK_LIB_DIRS "wgpu")
endif()

list(REMOVE_ITEM PSEMEK_LIB_DIRS sdl2 android)
set(PSEMEK_BACKEND_LIB_DIR)
if(PSEMEK_BACKEND STREQUAL "SDL2")
	set(PSEMEK_BACKEND_LIB_DIR "sdl2")
elseif(PSEMEK_BACKEND STREQUAL "ANDROID")
	set(PSEMEK_BACKEND_LIB_DIR "android")
endif()

set(PSEMEK_LIBRARIES)
set(PSEMEK_BACKEND_LIBRARY)

foreach(lib ${PSEMEK_LIB_DIRS} ${PSEMEK_BACKEND_LIB_DIR})
	add_subdirectory(${lib})
	target_compile_definitions(psemek-${lib} PUBLIC ${PSEMEK_DEFINITIONS})
	target_compile_options(psemek-${lib} PUBLIC ${PSEMEK_CXX_FLAGS})
	set_target_properties(psemek-${lib} PROPERTIES EXCLUDE_FROM_ALL TRUE)
	if(lib STREQUAL PSEMEK_BACKEND_LIB_DIR)
		set(PSEMEK_BACKEND_LIBRARY psemek-${lib})
	else()
		list(APPEND PSEMEK_LIBRARIES psemek-${lib})
	endif()
endforeach()

set(PSEMEK_LIBRARIES ${PSEMEK_LIBRARIES} PARENT_SCOPE)
set(PSEMEK_BACKEND_LIBRARY ${PSEMEK_BACKEND_LIBRARY} CACHE INTERNAL "Application backend library target")
