cmake_minimum_required(VERSION 2.8.11)
cmake_policy(SET CMP0003 NEW)
cmake_policy(SET CMP0048 NEW)
project(picoquic VERSION 0.0.1 LANGUAGES C CXX)
find_package (Threads REQUIRED)

set(PICOQUIC_CORE_HEADERS
    picoquic.h
    picosocks.h
    picoquic_utils.h
    picoquic_packet_loop.h
    picoquic_unified_log.h
    picoquic_logger.h
    picoquic_binlog.h
)

find_package(OpenSSL)

include_directories(picoquic "picotls/include" ${OPENSSL_INCLUDE_DIR})

if(WIN32)
    MESSAGE(WARNING "Please build picoquic and picotls with Visual Studio")
    MESSAGE(WARNING "Then put picoquic.lib, picotls-core.lib picotls-openssl.lib and picotls-fusion.lib in build/libs")
else()
    add_subdirectory("picotls")

    set(CMAKE_C_STANDARD 11)

    set(CMAKE_C_FLAGS "-std=c99 -O2 -g ${CC_WARNING_FLAGS} ${CMAKE_C_FLAGS}")

    if(DISABLE_DEBUG_PRINTF)
        set(CMAKE_C_FLAGS "-DDISABLE_DEBUG_PRINTF ${CMAKE_C_FLAGS}")
    endif()

    set(PICOQUIC_LIBRARY_FILES
        bbr.c
        bytestream.c
        cc_common.c
        cubic.c
        fastcc.c
        frames.c
        intformat.c
        logger.c
        logwriter.c
        newreno.c
        packet.c
        picohash.c
        picosocks.c
        picosplay.c
        quicctx.c
        sacks.c
        sender.c
        sim_link.c
        sockloop.c
        spinbit.c
        ticket_store.c
        token_store.c
        tls_api.c
        transport.c
        unified_log.c
        util.c
    )

    add_library(picoquic-core ${PICOQUIC_CORE_HEADERS} ${PICOQUIC_LIBRARY_FILES})
    target_link_libraries(picoquic-core picotls-core picotls-openssl picotls-fusion ${OPENSSL_LIBRARIES})
endif()
