cmake_minimum_required(VERSION 3.22.1)
project(rosetta_e2ee LANGUAGES C CXX)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

add_library(rosetta_e2ee SHARED
    crypto.c
    rosetta_e2ee.cpp
)

target_include_directories(rosetta_e2ee PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

# Hide all C++ symbols to avoid ODR clashes with WebRTC's .so
set_target_properties(rosetta_e2ee PROPERTIES
    CXX_VISIBILITY_PRESET hidden
    C_VISIBILITY_PRESET hidden
)

# Match WebRTC SDK build flags:
#  -fno-rtti -fno-exceptions — standard WebRTC flags
#  -fexperimental-relative-c++-abi-vtables — WebRTC uses relative vtables
#    (32-bit offsets instead of 64-bit absolute pointers in vtable).
#    Without this, setFrameEncryptor crashes with SIGSEGV because WebRTC
#    reads our 64-bit pointers as 32-bit offsets.
target_compile_options(rosetta_e2ee PRIVATE
    -fno-rtti
    -fno-exceptions
    -fexperimental-relative-c++-abi-vtables
)

find_library(log-lib log)
target_link_libraries(rosetta_e2ee ${log-lib})
