cmake_minimum_required(VERSION 3.23)
if(CMAKE_HOST_APPLE AND NOT DEFINED CMAKE_OSX_DEPLOYMENT_TARGET)
  set(CMAKE_OSX_DEPLOYMENT_TARGET 15.2 CACHE STRING "Minimum supported macOS")
endif()
project(feather-session VERSION 0.1.0 LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(NOT SESSION_SOURCE_DIR)
  message(FATAL_ERROR "SESSION_SOURCE_DIR must point to the SHA-256 verified official source release")
endif()
set(SUBMODULE_CHECK OFF CACHE BOOL "" FORCE)
set(BUILD_STATIC_DEPS ON CACHE BOOL "" FORCE)
set(STATIC_BUNDLE OFF CACHE BOOL "" FORCE)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
set(ENABLE_NETWORKING ON CACHE BOOL "" FORCE)
set(ENABLE_NETWORKING_SROUTER OFF CACHE BOOL "" FORCE)
set(WITH_TESTS OFF CACHE BOOL "" FORCE)
set(USE_LTO OFF CACHE BOOL "" FORCE)
set(WITH_LTO OFF CACHE BOOL "" FORCE)
set(LIBSESSION_INSTALL OFF CACHE BOOL "" FORCE)
set(LIBQUIC_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(LIBQUIC_BUILD_SPEEDTEST OFF CACHE BOOL "" FORCE)
set(LIBQUIC_BUILD_BTREQTEST OFF CACHE BOOL "" FORCE)
set(FEATHER_LIBEVENT_PATCH "${CMAKE_CURRENT_SOURCE_DIR}/patch-libevent.cmake")
add_subdirectory("${SESSION_SOURCE_DIR}" libsession EXCLUDE_FROM_ALL)
if(WIN32)
  # Static libevent's imported target omits its Windows system dependencies upstream.
  # Attach them to the archive so the linker receives them after libevent, not before it.
  target_link_libraries(libevent::core INTERFACE ws2_32 iphlpapi)
endif()
add_executable(feather-session main.cpp disabled_router.cpp)
target_link_libraries(feather-session PRIVATE network nlohmann_json::nlohmann_json)
if(MINGW)
  target_link_options(feather-session PRIVATE -municode)
endif()
add_executable(feather-session-fixture EXCLUDE_FROM_ALL fixture.cpp disabled_router.cpp)
target_link_libraries(feather-session-fixture PRIVATE network nlohmann_json::nlohmann_json)
if(APPLE)
  target_link_libraries(feather-session PRIVATE "-framework CoreFoundation" "-framework Security")
  target_link_libraries(feather-session-fixture PRIVATE "-framework CoreFoundation" "-framework Security")
endif()

add_executable(feather-request-category-test EXCLUDE_FROM_ALL request-category-test.cpp)
target_link_libraries(feather-request-category-test PRIVATE nlohmann_json::nlohmann_json)
