cmake_minimum_required(VERSION 3.28)

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

# Two programs, for two architectures (a preset for each, see CMakePresets.json):
# - 32-bit: the adapter, t5deRenderEngine.dll, a renderer plugin loaded into IMVU Classic (a 32-bit Visual C++
#   program, so it must match its ABI).
# - 64-bit: the renderer process, t5de-renderer.exe, which draws.
if(NOT MSVC) # cl or clang-cl
    message(FATAL_ERROR "Build with MSVC or clang-cl: the adapter must match IMVU Classic's Visual C++ ABI.")
endif()

# No C++ modules: skip scanning for them.
set(CMAKE_CXX_SCAN_FOR_MODULES OFF)

# The C runtime is linked statically, so the programs need nothing installed beside them.
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)

# What the adapter and the renderer process share.
add_library(t5de_protocol INTERFACE)
add_library(t5de::protocol ALIAS t5de_protocol)
target_include_directories(t5de_protocol INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
target_compile_features(t5de_protocol INTERFACE cxx_std_20)

include(CTest)

if(CMAKE_SIZEOF_VOID_P EQUAL 4)
    # Our declarations of IMVU's interfaces (32-bit layouts).
    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)

    add_subdirectory(adapter)
    if(BUILD_TESTING)
        add_subdirectory(tests)
    endif()
else()
    add_subdirectory(renderer)
endif()
