cmake_minimum_required(VERSION 3.22)
project(14c C CXX)
set(CMAKE_C_STANDARD 11)

add_subdirectory(dep)

#Source files
set(sources_core
	src/core/fontrender.c       src/core/fontrender.h
	src/core/idxmap.c           src/core/idxmap.h
	src/core/imgload.c          src/core/imgload.h
	src/core/localisation.c     src/core/localisation.h
	src/core/localsettings.c    src/core/localsettings.h
	                            src/core/main.h
	src/core/ogl.c              src/core/ogl.h
	src/core/platform_win64.c   src/core/platform.h
	src/core/quadexport.c       src/core/quadexport.h
	src/core/scenefile.c        src/core/scenefile.h
	src/core/shaders.c
	src/core/srswq.c            src/core/srswq.h
	src/core/stack32.c          src/core/stack32.h
	src/core/stringmap.c        src/core/stringmap.h
	src/core/sys_desktop.c      src/core/sys_desktop.h
	src/core/sys_interaction.c  src/core/sys_interaction.h
	src/core/sys_log.c          src/core/sys_log.h
	src/core/sys_platform.c
	src/core/sys_quadstore.c    src/core/sys_quadstore.h
	src/core/sys_render.c       src/core/sys_render.h
	src/core/sys_steam.cpp
	src/core/sys_tilestore.c    src/core/sys_tilestore.h
	src/core/sys_undo.c         src/core/sys_undo.h
	src/core/sys_vr.cpp         src/core/sys_vr.h
	                            src/core/sys_vr_passthru.h
	src/core/system.c           src/core/system.h
	src/core/tool_background.c
	src/core/tool_color.c
	src/core/tool_copy.c
	src/core/tool_create.c
	src/core/tool_delete.c
	src/core/tool_move.c
	src/core/tool_pen.c
	src/core/tool_resize.c
	src/core/tool_teleport.c
	src/core/tool_undo.c
	                            src/core/ui.h
	                            src/core/ui_internal.h
	src/core/ui_elem.c
	src/core/ui_main.c
	src/core/ui_parse.c
	src/core/ui_screen.c
	                            src/core/vecmath.h
)

option(VIA_STEAMWORKS "Enable Steamworks integration" OFF)

#Main executable
add_executable(14c WIN32)
target_link_libraries(14c PRIVATE opengl openvr stb)
target_link_libraries(14c PRIVATE imm32 winmm opengl32)
target_compile_definitions(14c PUBLIC _UNICODE UNICODE _CRT_SECURE_NO_WARNINGS)
if(VIA_STEAMWORKS)
	target_compile_definitions(14c PRIVATE _ENABLE_STEAMWORKS)
	target_link_libraries(14c PRIVATE steamworks)
endif()
target_include_directories(14c PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/core)
target_compile_options(14c PRIVATE /W3 /WX /external:W0)
target_sources(14c PRIVATE
	${sources_core}
	src/14c/main.c
	src/14c/resource.h
	src/14c/14c.rc
)

#Tools
add_executable(obj2ymd)
target_sources(obj2ymd PRIVATE
	src/obj2ymd/main.c
)

add_executable(via_import)
target_link_libraries(via_import PRIVATE opengl)
target_link_libraries(via_import PRIVATE imm32 winmm opengl32)
target_include_directories(via_import PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/core)
target_compile_definitions(14c PUBLIC _UNICODE UNICODE _CRT_SECURE_NO_WARNINGS)
target_sources(via_import PRIVATE
	src/core/imgload.c          src/core/imgload.h
	                            src/core/main.h
	src/core/platform_win64.c   src/core/platform.h
	src/core/quadexport.c       src/core/quadexport.h
	src/core/sys_quadstore.c    src/core/sys_quadstore.h
	src/core/scenefile.c        src/core/scenefile.h
	                            src/core/system.h
	                            src/core/vecmath.h
	src/via_import/via_import.c
)

add_executable(yrcrashhandler WIN32)
target_sources(yrcrashhandler PRIVATE
	src/yrcrashhandler/yrcrashhandler.c
)
