cmake_minimum_required(VERSION 3.21)
project(mirai LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
set(CMAKE_BUILD_RPATH_USE_ORIGIN ON)

# -- Slint setup
#find_package(Slint QUIET)
#if (NOT Slint_FOUND)
  #message("Slint could not be located in the CMake module search path. Downloading it from Git and building it locally")
  #include(FetchContent)
  #FetchContent_Declare(
    #Slint
    #GIT_REPOSITORY https://github.com/slint-ui/slint.git
    ## `release/1` will auto-upgrade to the latest Slint >= 1.0.0 and < 2.0.0
    ## `release/1.0` will auto-upgrade to the latest Slint >= 1.0.0 and < 1.1.0
    #GIT_TAG release/1
    #SOURCE_SUBDIR api/cpp
  #)
  #FetchContent_MakeAvailable(Slint)
#endif (NOT Slint_FOUND)
# -- End of Slint setup

add_subdirectory(external/slint)
add_subdirectory(external/selenite/cpp)
add_subdirectory(external/mirai-core)
add_subdirectory(external/evalyte-cpp-common)

add_executable(mirai
	src/main.cpp
	src/windows/AppWindow/AppWindow.cpp
	src/windows/AddSourceWindow/AddSourceWindow.cpp
	src/windows/SettingsWindow/SettingsWindow.cpp
	src/windows/EditSourceWindow/EditSourceWindow.cpp
	src/windows/EditEventWindow/EditEventWindow.cpp
	src/SeleniteSetup.cpp
	src/shared/Utils.cpp
)

target_include_directories(mirai PRIVATE "external/mirai-core/include")
target_include_directories(mirai PRIVATE "external/selenite/cpp/include")
target_include_directories(mirai PRIVATE "external/evalyte-cpp-common/include")

set_property(TARGET mirai PROPERTY SLINT_EMBED_RESOURCES embed-files)

target_link_libraries(mirai PRIVATE Slint::Slint)
target_link_libraries(mirai PRIVATE selenite)
target_link_libraries(mirai PRIVATE evalyte-cpp-common)

target_include_directories(mirai PRIVATE "external")
target_link_libraries(mirai PRIVATE mirai-core)

slint_target_sources(
	mirai src/ui.slint
	NAMESPACE ui
	LIBRARY_PATHS selenite=${CMAKE_CURRENT_SOURCE_DIR}/external/selenite/components/index.slint
)

# On Windows, copy the Slint DLL next to the application binary so that it's found.
if (WIN32)
    add_custom_command(TARGET mirai POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:mirai> $<TARGET_FILE_DIR:mirai> COMMAND_EXPAND_LISTS)
endif()
