cmake_minimum_required(VERSION 3.28)

project(t5de-renderer
    VERSION 0.1.0
    DESCRIPTION "A new 3D renderer for the IMVU Classic client"
    LANGUAGES CXX)

# The plugin is loaded into IMVU Classic, a 32-bit program built with Visual C++: it must use the same ABI.
if(NOT MSVC) # cl or clang-cl
    message(FATAL_ERROR "Build with MSVC or clang-cl: the plugin must match IMVU Classic's Visual C++ ABI.")
endif()
if(NOT CMAKE_SIZEOF_VOID_P EQUAL 4)
    message(FATAL_ERROR "Build for 32-bit x86 (IMVU Classic is 32-bit): use a CMakePresets.json preset.")
endif()

# The C runtime is linked statically, so the plugin needs nothing installed beside it.
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

# Warnings and conformance for our own targets.
add_library(t5de_options INTERFACE)
add_library(t5de::options ALIAS t5de_options)
target_compile_features(t5de_options INTERFACE cxx_std_20)
target_compile_options(t5de_options INTERFACE /W4 /permissive- /utf-8 /Zc:__cplusplus)
target_compile_definitions(t5de_options INTERFACE WIN32_LEAN_AND_MEAN NOMINMAX UNICODE _UNICODE)

# Our declarations of IMVU's interfaces.
add_library(t5de_imvu INTERFACE)
add_library(t5de::imvu ALIAS t5de_imvu)
target_include_directories(t5de_imvu INTERFACE
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
target_compile_features(t5de_imvu INTERFACE cxx_std_20)

# The renderer plugin, t5deRenderEngine.dll.
add_library(t5de_render_engine SHARED
    src/log.cpp
    src/passthrough_engine.cpp
    src/plugin.cpp
    src/plugin.def)
set_target_properties(t5de_render_engine PROPERTIES OUTPUT_NAME t5deRenderEngine)
target_link_libraries(t5de_render_engine PRIVATE t5de::imvu t5de::options)

install(TARGETS t5de_render_engine RUNTIME DESTINATION .)

include(CTest)
if(BUILD_TESTING)
    add_subdirectory(tests)
endif()
