cmake_minimum_required(VERSION 3.8)

project(librtmp C)

find_package(ZLIB REQUIRED)
find_package(OpenSSL REQUIRED)

include_directories(${ZLIB_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})

set(CMAKE_DEBUG_POSTFIX "d")

if(MSVC)
    add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
    add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
    add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS)
endif()

add_definitions(-DLIBRTMP_ONLY)

# List the header files
set(HEADERS librtmp/amf.h
            librtmp/bytes.h
            librtmp/dh.h
            librtmp/dhgroups.h
            librtmp/handshake.h
            librtmp/http.h
            librtmp/log.h
            librtmp/rtmp.h
            librtmp/rtmp_sys.h
)

# List the source files
set(SRCS librtmp/amf.c
         librtmp/hashswf.c
         librtmp/log.c
         librtmp/parseurl.c
         librtmp/rtmp.c
)

if(MSVC)
    set(SRCS_MSVC "librtmp/librtmp.def")
endif()

add_library(librtmp ${SRCS} ${HEADERS} ${SRCS_MSVC})

target_include_directories(librtmp PRIVATE ./librtmp)
target_link_libraries(librtmp PRIVATE ${ZLIB_LIBRARIES} ${OPENSSL_LIBRARIES})
target_link_libraries(librtmp PRIVATE Ws2_32.lib Winmm.lib)

install(TARGETS librtmp
        RUNTIME DESTINATION bin
        LIBRARY DESTINATION lib
        ARCHIVE DESTINATION lib)

install(DIRECTORY ${PROJECT_SOURCE_DIR}/librtmp DESTINATION include FILES_MATCHING PATTERN "*.h")