# Copyright 2018, 2019, 2026 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt

cmake_minimum_required(VERSION 3.5...3.31)

project(cmake_subdir_test LANGUAGES CXX)

# Those 2 should work the same
# while using find_package for the installed Boost avoids the need to manually specify dependencies
if(BOOST_CI_INSTALL_TEST)
    # B2 does not (yet) create/install CMake targets for them, so users are supposed to use the generic Boost::headers target
    if(BOOST_CI_INSTALLED_BY STREQUAL "B2")
        find_package(Boost REQUIRED)
        add_library(Boost_circular_buffer INTERFACE)
        target_link_libraries(Boost_circular_buffer INTERFACE Boost::headers)
        add_library(Boost::circular_buffer ALIAS Boost_circular_buffer)
    else()
        # Regular usage. Works when installed by CMake
        find_package(Boost COMPONENTS circular_buffer REQUIRED)
    endif()
else()
    add_subdirectory(../.. boostorg/circular_buffer)

    # boostdep --brief circular_buffer

    set(deps
    # Primary dependencies
    assert
    concept_check
    config
    core
    move
    throw_exception
    type_traits

    # Secondary dependencies
    preprocessor
    )

    foreach(dep IN LISTS deps)
        add_subdirectory(../../../${dep} boostorg/${dep})
    endforeach()
endif()

add_executable(main main.cpp)
target_link_libraries(main Boost::circular_buffer)

enable_testing()
add_test(NAME main COMMAND main)

add_custom_target(check VERBATIM COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)
