cmake_minimum_required(VERSION 3.28)
project(lumi-obs-bridge VERSION 0.1.0 LANGUAGES CXX)
set(LUMI_BRIDGE_VERSION "0.1.0-development" CACHE STRING "Lumi Companion bridge release version")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(FetchContent)
FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.12.0/json.tar.xz
    URL_HASH SHA256=42f6e95cad6ec532fd372391373363b62a14af6d771056dbfc86160e6dfff7aa)
FetchContent_MakeAvailable(json)

if(OBS_SOURCE_DIR AND OBS_IMPORT_DIR)
    set(OBS_DATA_PATH "data")
    set(OBS_PLUGIN_PATH "obs-plugins")
    set(OBS_PLUGIN_DESTINATION "obs-plugins/64bit")
    set(OBS_RELEASE_CANDIDATE 0)
    set(OBS_BETA 0)
    configure_file("${OBS_SOURCE_DIR}/libobs/obsconfig.h.in" "${CMAKE_CURRENT_BINARY_DIR}/config/obsconfig.h" @ONLY)
    add_library(obs-lib SHARED IMPORTED)
    set_target_properties(obs-lib PROPERTIES IMPORTED_IMPLIB "${OBS_IMPORT_DIR}/obs.lib")
    target_include_directories(obs-lib INTERFACE "${OBS_SOURCE_DIR}/libobs" "${CMAKE_CURRENT_BINARY_DIR}/config")
    add_library(obs-frontend SHARED IMPORTED)
    set_target_properties(obs-frontend PROPERTIES IMPORTED_IMPLIB "${OBS_IMPORT_DIR}/obs-frontend-api.lib")
    target_include_directories(obs-frontend INTERFACE "${OBS_SOURCE_DIR}/frontend/api")
else()
    find_package(libobs REQUIRED)
    find_package(obs-frontend-api REQUIRED)
    add_library(obs-lib ALIAS OBS::libobs)
    add_library(obs-frontend ALIAS OBS::obs-frontend-api)
endif()

add_library(lumi-obs-bridge MODULE src/plugin.cpp)
target_include_directories(lumi-obs-bridge PRIVATE include)
target_compile_definitions(lumi-obs-bridge PRIVATE NOMINMAX WIN32_LEAN_AND_MEAN LUMI_BRIDGE_VERSION="${LUMI_BRIDGE_VERSION}")
target_link_libraries(lumi-obs-bridge PRIVATE obs-lib obs-frontend nlohmann_json::nlohmann_json bcrypt)
set_target_properties(lumi-obs-bridge PROPERTIES PREFIX "" OUTPUT_NAME "lumi-obs-bridge")
