cmake_minimum_required(VERSION 3.10)

project(Punchie)

if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
	add_compile_definitions("DEBUG_ENGINE=1")
else()
	add_compile_definitions("DEBUG_ENGINE=0")
endif()

# VARIABLES
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(BUILD_SHARED_LIBS ON)

if(CMAKE_HOST_WIN32)
	# Export both *.lib and *.dll on Windows
	set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()

set(CMAKE_INSTALL_RPATH "$ORIGIN;$ORIGIN/../lib")

# TARGETS
add_library(${PROJECT_NAME} SHARED
	src/GameEngine.c
	src/Window.c
	src/Renderer.c
	src/ObjectStore.c
	src/AssetManager.c
	src/BitmapFont.c
	src/reusable_ids.c
	src/math_utils.c
)

target_include_directories(${PROJECT_NAME} PUBLIC
	${CMAKE_CURRENT_BINARY_DIR}
	include
	intern/pakrd
	extern/SDL2/SDL/include
	extern/SDL2/SDL_mixer/include
	extern/SDL2/SDL_image
	extern/SDL2/SDL_ttf
)

target_link_directories(${PROJECT_NAME} PUBLIC intern/pakrd)

target_link_libraries(${PROJECT_NAME} PUBLIC
	pakrd
	SDL2
	SDL2_image
	SDL2_mixer
	SDL2_ttf
)

add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
	COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/intern/pakrd/libpakrd.so ${OUTPUT_BASE_DIR}/${CMAKE_BUILD_TYPE}/lib
)

install(FILES
	include/aliases.h
	include/constants.h
	include/GameEngine.h
	include/Window.h
	include/Renderer.h
	include/ObjectStore.h
	include/AssetManager.h
	include/BitmapFont.h
	include/reusable_ids.h
	include/math_utils.h
	intern/pakrd/pak.h
	CONFIGURATIONS Release
	DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(FILES
	${CMAKE_CURRENT_SOURCE_DIR}/intern/pakrd/libpakrd.a
	CONFIGURATIONS Release
	DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(TARGETS ${PROJECT_NAME}
	CONFIGURATIONS Release
	RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
	ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
	LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

# SUB-DIRECTORIES
add_subdirectory(extern)
