cmake_minimum_required(VERSION 3.12)
project(libcoro_examples)

add_executable(coro_task coro_task.cpp)
target_link_libraries(coro_task PUBLIC libcoro)

add_executable(coro_generator coro_generator.cpp)
target_link_libraries(coro_generator PUBLIC libcoro)

add_executable(coro_event coro_event.cpp)
target_link_libraries(coro_event PUBLIC libcoro)

if(LIBCORO_FEATURE_PLATFORM)
    add_executable(coro_latch coro_latch.cpp)
    target_link_libraries(coro_latch PUBLIC libcoro)
endif()

add_executable(coro_mutex coro_mutex.cpp)
target_link_libraries(coro_mutex PUBLIC libcoro)

add_executable(coro_thread_pool coro_thread_pool.cpp)
target_link_libraries(coro_thread_pool PUBLIC libcoro)

add_executable(coro_semaphore coro_semaphore.cpp)
target_link_libraries(coro_semaphore PUBLIC libcoro)

add_executable(coro_ring_buffer coro_ring_buffer.cpp)
target_link_libraries(coro_ring_buffer PUBLIC libcoro)

add_executable(coro_shared_mutex coro_shared_mutex.cpp)
target_link_libraries(coro_shared_mutex PUBLIC libcoro)

if(LIBCORO_FEATURE_NETWORKING)
    add_executable(coro_task_container coro_task_container.cpp)
    target_link_libraries(coro_task_container PUBLIC libcoro)

    add_executable(coro_io_scheduler coro_io_scheduler.cpp)
    target_link_libraries(coro_io_scheduler PUBLIC libcoro)

    add_executable(coro_tcp_echo_server coro_tcp_echo_server.cpp)
    target_link_libraries(coro_tcp_echo_server PUBLIC libcoro)

    add_executable(coro_http_200_ok_server coro_http_200_ok_server.cpp)
    target_link_libraries(coro_http_200_ok_server PUBLIC libcoro)
endif()

if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
    target_compile_options(coro_task               PUBLIC -fcoroutines -Wall -Wextra -pipe)
    target_compile_options(coro_generator          PUBLIC -fcoroutines -Wall -Wextra -pipe)
    target_compile_options(coro_event              PUBLIC -fcoroutines -Wall -Wextra -pipe)
    target_compile_options(coro_latch              PUBLIC -fcoroutines -Wall -Wextra -pipe)
    target_compile_options(coro_mutex              PUBLIC -fcoroutines -Wall -Wextra -pipe)
    target_compile_options(coro_thread_pool        PUBLIC -fcoroutines -Wall -Wextra -pipe)
    target_compile_options(coro_semaphore          PUBLIC -fcoroutines -Wall -Wextra -pipe)
    target_compile_options(coro_ring_buffer        PUBLIC -fcoroutines -Wall -Wextra -pipe)
    target_compile_options(coro_shared_mutex       PUBLIC -fcoroutines -Wall -Wextra -pipe)
    if(LIBCORO_FEATURE_NETWORKING)
    target_compile_options(coro_task_container     PUBLIC -fcoroutines -Wall -Wextra -pipe)
        target_compile_options(coro_io_scheduler       PUBLIC -fcoroutines -Wall -Wextra -pipe)
        target_compile_options(coro_tcp_echo_server    PUBLIC -fcoroutines -Wall -Wextra -pipe)
        target_compile_options(coro_http_200_ok_server PUBLIC -fcoroutines -Wall -Wextra -pipe)
    endif()
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
    target_compile_options(coro_task               PUBLIC -Wall -Wextra -pipe)
    target_compile_options(coro_generator          PUBLIC -Wall -Wextra -pipe)
    target_compile_options(coro_event              PUBLIC -Wall -Wextra -pipe)
    if(LIBCORO_FEATURE_PLATFORM)
      target_compile_options(coro_latch              PUBLIC -Wall -Wextra -pipe)
    endif()
    target_compile_options(coro_mutex              PUBLIC -Wall -Wextra -pipe)
    target_compile_options(coro_thread_pool        PUBLIC -Wall -Wextra -pipe)
    target_compile_options(coro_semaphore          PUBLIC -Wall -Wextra -pipe)
    target_compile_options(coro_ring_buffer        PUBLIC -Wall -Wextra -pipe)
    target_compile_options(coro_shared_mutex       PUBLIC -Wall -Wextra -pipe)
    if(LIBCORO_FEATURE_NETWORKING)
    target_compile_options(coro_task_container     PUBLIC -Wall -Wextra -pipe)
        target_compile_options(coro_io_scheduler       PUBLIC -Wall -Wextra -pipe)
        target_compile_options(coro_tcp_echo_server    PUBLIC -Wall -Wextra -pipe)
        target_compile_options(coro_http_200_ok_server PUBLIC -Wall -Wextra -pipe)
    endif()
elseif(MSVC)
    target_compile_options(coro_task               PUBLIC /W4)
    target_compile_options(coro_generator          PUBLIC /W4)
    target_compile_options(coro_event              PUBLIC /W4)
    target_compile_options(coro_mutex              PUBLIC /W4)
    target_compile_options(coro_thread_pool        PUBLIC /W4)
    target_compile_options(coro_semaphore          PUBLIC /W4)
    target_compile_options(coro_ring_buffer        PUBLIC /W4)
    target_compile_options(coro_shared_mutex       PUBLIC /W4)
else()
    message(FATAL_ERROR "Unsupported compiler.")
endif()
