cmake_minimum_required(VERSION 3.16)
project(jtjai_media)
set(CMAKE_CXX_STANDARD 17)

# Find required packages
find_package(fmt CONFIG REQUIRED)
find_package(Boost REQUIRED COMPONENTS json system)
# 查找FFmpeg库
find_path(AVCODEC_INCLUDE_DIR libavcodec/avcodec.h)
find_library(AVCODEC_LIBRARY avcodec)
find_path(AVFORMAT_INCLUDE_DIR libavformat/avformat.h)
find_library(AVFORMAT_LIBRARY avformat)
find_path(AVUTIL_INCLUDE_DIR libavutil/avutil.h)
find_library(AVUTIL_LIBRARY avutil)
find_path(SWSCALE_INCLUDE_DIR libswscale/swscale.h)
find_library(SWSCALE_LIBRARY swscale)

if(NOT AVCODEC_LIBRARY OR NOT AVFORMAT_LIBRARY OR NOT AVUTIL_LIBRARY OR NOT SWSCALE_LIBRARY)
    message(FATAL_ERROR "FFmpeg libraries not found")
endif()

# 设置包含目录
include_directories(${CMAKE_SOURCE_DIR}/include)
include_directories(${AVCODEC_INCLUDE_DIR})
include_directories(${AVFORMAT_INCLUDE_DIR})
include_directories(${AVUTIL_INCLUDE_DIR})
include_directories(${SWSCALE_INCLUDE_DIR})

# Source files for main application
file(GLOB MAIN_SOURCES 
    "src/config.cpp"
    "src/rtsp_client.cpp"
    "src/scheduler.cpp"
    "src/reporter.cpp"
    "src/concurrent_calculator.cpp"
    "src/http_server.cpp"
    "main.cpp"
)

# Source files for HTTP server
file(GLOB HTTP_SERVER_SOURCES
    "src/http_server.cpp"
    "http_server_main.cpp"
)

# Main RTSP client application
add_executable(jtjai_media ${MAIN_SOURCES})

# HTTP server application
add_executable(jtjai_http_server ${HTTP_SERVER_SOURCES})

# 链接库 - RTSP client
target_link_libraries(jtjai_media PRIVATE 
    fmt::fmt
    Boost::json 
    Boost::system 
    ${AVFORMAT_LIBRARY}
    ${AVCODEC_LIBRARY}
    ${AVUTIL_LIBRARY}
    ${SWSCALE_LIBRARY}
    pthread
)

# 链接库 - HTTP server
target_link_libraries(jtjai_http_server PRIVATE 
    fmt::fmt
    Boost::json 
    Boost::system 
    pthread
)
