cmake_minimum_required(VERSION 3.19)
set(CMAKE_POLICY_DEFAULT_CMP0110 NEW) # requires CMake 3.19

if(BUILDCORE_TARGET STREQUAL "gba")
	project(nostalgia ASM CXX)
elseif(APPLE)
	project(nostalgia C CXX OBJC OBJCXX)
else()
	project(nostalgia C CXX)
endif()

include(deps/buildcore/base.cmake)

set(OX_ENABLE_TRACEHOOK OFF CACHE BOOL "Generate OxTraceHook shared library for uprobes")

if(BUILDCORE_TARGET STREQUAL "gba")
	include(deps/gbabuildcore/base.cmake)
else()
	set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

set(CMAKE_CXX_STANDARD 23)

if(APPLE)
	set(CMAKE_MACOSX_RPATH OFF)
else()
	if(UNIX AND NOT DEFINED BUILD_SHARED_LIBS)
		set(BUILD_SHARED_LIBS ON)
	endif()
	set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib")
	set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
endif()

add_subdirectory(deps/ox)
include_directories(
	deps/ox/src
)
add_subdirectory(deps/teagba)

if(NOT BUILDCORE_TARGET STREQUAL "gba")
	include_directories(
		SYSTEM
			deps/glfw/include
			deps/imgui
			deps/imgui/backends
			deps/nfde/src/include
			/usr/local/include
	)
	add_subdirectory(deps/glad)
	set(GLFW_BUILD_EXAMPLES OFF)
	set(GLFW_BUILD_TESTS OFF)
	set(GLFW_BUILD_DOCS OFF)
	if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
		set(GLFW_BUILD_WAYLAND OFF)
	endif()
	add_subdirectory(deps/glfw)
	add_subdirectory(deps/glutils)
	add_subdirectory(deps/imgui)
	add_subdirectory(deps/lodepng)
	set(NFD_INSTALL ON)
	add_subdirectory(deps/nfde)
endif()

add_subdirectory(src)
