cmake_minimum_required(VERSION 3.10)

# 工程名称（随便改）
project(rtsp_server)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_compile_definitions(GLIB_DISABLE_DEPRECATION_WARNINGS)

# 设置可执行文件输出目录
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../bin)

# 找 GStreamer
find_package(PkgConfig REQUIRED)
pkg_check_modules(GSTREAMER REQUIRED gstreamer-1.0)
pkg_check_modules(GSTREAMER_RTSP REQUIRED gstreamer-rtsp-server-1.0)

# 添加头文件目录
include_directories(
    ${CMAKE_SOURCE_DIR}/include
    ${CMAKE_SOURCE_DIR}/third_party/include
    ${CMAKE_SOURCE_DIR}/third_party/include/paho_mqtt
    ${GSTREAMER_INCLUDE_DIRS}
    ${GSTREAMER_RTSP_INCLUDE_DIRS}
)

# 源码目录
file(GLOB SRC_FILES src/*.cpp)

# 生成可执行文件（名字和 project 不一定要一样）
add_executable(camera_to_rtsp ${SRC_FILES})

# 链接库目录
link_directories(
    ${GSTREAMER_LIBRARY_DIRS}
    ${GSTREAMER_RTSP_LIBRARY_DIRS}
    ${CMAKE_SOURCE_DIR}/third_party/lib
)

# 链接库
target_link_libraries(camera_to_rtsp
    ${GSTREAMER_LIBRARIES}
    ${GSTREAMER_RTSP_LIBRARIES}
    pthread
    ${CMAKE_SOURCE_DIR}/third_party/lib/libpaho-mqttpp3.a
    ${CMAKE_SOURCE_DIR}/third_party/lib/libpaho-mqtt3a.a
    ${CMAKE_SOURCE_DIR}/third_party/lib/libpaho-mqtt3c.a
)

# 运行时把 config.json 复制到 bin/ 目录
add_custom_command(TARGET camera_to_rtsp POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_if_different
    ${CMAKE_SOURCE_DIR}/config.json
    $<TARGET_FILE_DIR:camera_to_rtsp>/config.json
)
