cmake_minimum_required(VERSION 3.13.0)
project(Editor)

find_package(OGRE REQUIRED COMPONENTS Bites Paging Terrain CONFIG)
find_package(ZLIB)
find_package(SDL2)
find_package(assimp REQUIRED CONFIG)
find_package(OgreProcedural REQUIRED CONFIG)
find_package(pugixml REQUIRED CONFIG)
find_package(flecs REQUIRED CONFIG)

set(COPY_DIRECTORIES characters resources skybox water resources/buildings/parts)
set(INSTALL_DEPS ${CMAKE_CURRENT_BINARY_DIR}/resources.cfg)
foreach(DIR_NAME ${COPY_DIRECTORIES})
	add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${DIR_NAME}
		COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_BINARY_DIR}/../../${DIR_NAME} ${CMAKE_CURRENT_BINARY_DIR}/${DIR_NAME}
		DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/../../${DIR_NAME}
	)
	list(APPEND INSTALL_DEPS ${CMAKE_CURRENT_BINARY_DIR}/${DIR_NAME})
endforeach()

add_custom_target(install_resources DEPENDS import_buildings import_building_parts ${INSTALL_DEPS})
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/resources.cfg
	COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/../../resources.cfg ${CMAKE_CURRENT_BINARY_DIR}/resources.cfg
	DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/../../resources.cfg
)

add_library(editor STATIC EditorGizmoModule.cpp EditorInputModule.cpp)
target_link_libraries(editor PRIVATE
	OgreMain
	GameData
        physics
)
target_include_directories(editor PUBLIC .)

add_executable(Editor main.cpp)
target_link_libraries(Editor PRIVATE
	OgreMain
	OgreBites
	OgrePaging
	OgreTerrain
	OgreOverlay
	OgreMeshLodGenerator
	GameData
	sound
	sceneloader
	editor
	world-build
	physics
	lua
	flecs::flecs_static
        Tracy::TracyClient
)
if(OGRE_STATIC)
	target_link_options(Editor PRIVATE -static-libstdc++ -static-libgcc)
endif()
target_compile_definitions(Editor PRIVATE FLECS_CPP_NO_AUTO_REGISTRATION)
add_dependencies(Editor install_resources)

