cmake_minimum_required(VERSION 3.20)
project(RealFlightVoice LANGUAGES CXX)
if(NOT WIN32)
  message(WARNING "TS3 3.5.6 is a Windows client; build this project on Windows.")
endif()
# 静态链接 MSVC 运行库: 分发给别人时不需要额外安装 VC++ Redistributable
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
# 版本号唯一来源: 同时写入 DLL 资源(资源管理器"详细信息"可见)与 ts3plugin_version()
set(RFV_VERSION 1.3.0)
string(REPLACE "." "," RFV_VERSION_COMMA "${RFV_VERSION}")
# LOGO 位图也复制到构建目录, 让 .rc 里的 BITMAP 用相对路径(整个工程可任意搬运)
configure_file(native/logo.bmp "${CMAKE_BINARY_DIR}/logo.bmp" COPYONLY)
foreach(PAIR IN ITEMS "GENERAL_BASE" "Boeing_BASE" "AIRBUS_BASE")
  configure_file("新版更新要求及素材/${PAIR}.png" "${CMAKE_BINARY_DIR}/${PAIR}.png" COPYONLY)
endforeach()
configure_file(native/version.rc.in "${CMAKE_BINARY_DIR}/version.rc" @ONLY)
add_library(real_flight_voice SHARED native/freqbridge_plugin.cpp "${CMAKE_BINARY_DIR}/version.rc")
target_include_directories(real_flight_voice PRIVATE native/include native)
target_compile_features(real_flight_voice PRIVATE cxx_std_17)
target_compile_definitions(real_flight_voice PRIVATE NOMINMAX UNICODE _UNICODE "RFV_VERSION_STR=\"${RFV_VERSION}\"")
if(MSVC)
  target_compile_options(real_flight_voice PRIVATE /utf-8 /EHsc)
endif()
set_target_properties(real_flight_voice PROPERTIES OUTPUT_NAME "real_flight_voice_win64" PREFIX "")

# DSP 回归测试: 验证"无线电失真"在任何麦克风电平下都不会把自己的语音清零。
# 构建: cmake -S . -B build -A x64 -DRFV_BUILD_TESTS=ON && cmake --build build --config Release
# 运行: build\Release\rfv_dsp_test.exe  (返回码非 0 表示有回归)
option(RFV_BUILD_TESTS "Build the DSP regression test" OFF)
if(RFV_BUILD_TESTS)
  enable_testing()
  add_executable(rfv_dsp_test tests/dsp_test.cpp "${CMAKE_BINARY_DIR}/version.rc")
  add_test(NAME dsp COMMAND rfv_dsp_test)
  target_include_directories(rfv_dsp_test PRIVATE native/include native)
  target_compile_features(rfv_dsp_test PRIVATE cxx_std_17)
  target_compile_definitions(rfv_dsp_test PRIVATE NOMINMAX UNICODE _UNICODE)
  if(MSVC)
    target_compile_options(rfv_dsp_test PRIVATE /utf-8 /EHsc)
  endif()
endif()

if(RFV_BUILD_TESTS)
  add_executable(rfv_core_test tests/core_test.cpp "${CMAKE_BINARY_DIR}/version.rc")
  target_include_directories(rfv_core_test PRIVATE native/include native)
  target_compile_features(rfv_core_test PRIVATE cxx_std_17)
  target_compile_definitions(rfv_core_test PRIVATE NOMINMAX UNICODE _UNICODE "RFV_VERSION_STR=\"${RFV_VERSION}\"")
  target_compile_options(rfv_core_test PRIVATE /utf-8 /EHsc)
  add_test(NAME radio_core COMMAND rfv_core_test)
  add_executable(rfv_ui_preview WIN32 tests/ui_preview.cpp "${CMAKE_BINARY_DIR}/version.rc")
  target_include_directories(rfv_ui_preview PRIVATE native/include native)
  target_compile_features(rfv_ui_preview PRIVATE cxx_std_17)
  target_compile_definitions(rfv_ui_preview PRIVATE NOMINMAX UNICODE _UNICODE "RFV_VERSION_STR=\"${RFV_VERSION}\"")
  target_compile_options(rfv_ui_preview PRIVATE /utf-8 /EHsc)
endif()
