cmake_minimum_required(VERSION 3.8...4.2)

project(boost_redis VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)

# Library
add_library(boost_redis INTERFACE)
add_library(Boost::redis ALIAS boost_redis)
target_include_directories(boost_redis INTERFACE include)
target_compile_features(boost_redis INTERFACE cxx_std_17)

# Dependencies
# Boost dependencies should be already available.
# If other dependencies are not found, we bail out
find_package(Threads)
if(NOT Threads_FOUND)
  message(STATUS "Boost.Redis has been disabled, because the required package Threads hasn't been found")
  return()
endif()
find_package(OpenSSL)
if(NOT OpenSSL_FOUND)
  message(STATUS "Boost.Redis has been disabled, because the required package OpenSSL hasn't been found")
  return()
endif()

# This is generated by boostdep
target_link_libraries(boost_redis
  INTERFACE
    Boost::asio
    Boost::assert
    Boost::core
    Boost::mp11
    Boost::system
    Boost::throw_exception
    Threads::Threads
    OpenSSL::Crypto
    OpenSSL::SSL
)

# Don't run integration testing unless explicitly requested, since these require a running server
option(BOOST_REDIS_INTEGRATION_TESTS OFF "Whether to build and run integration tests or not")
mark_as_advanced(BOOST_REDIS_INTEGRATION_TESTS)

# Examples and tests
if(BUILD_TESTING)
  # Custom target tests; required by the Boost superproject
  if(NOT TARGET tests)
    add_custom_target(tests)
  endif()

  # Tests and common utilities
  add_subdirectory(test)
  
  if (BOOST_REDIS_INTEGRATION_TESTS)
    # Benchmarks. Build them with tests to prevent code rotting.
    # Guarded to prevent them from building in normal builds
    add_subdirectory(benchmarks)

    # Examples. All of them require a real server running
    add_subdirectory(example)
  endif()
endif()
