Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ test/
base_test.cpp circular_buffer: #define CB_CONTAINER circular_buffer + common.ipp + extras
space_optimized_test.cpp circular_buffer_space_optimized: same pattern
soft_iterator_invalidation.cpp, constant_erase_test.cpp, bounded_buffer_comparison.cpp
Jamfile.v2 source of truth for which tests run; CMake reuses it via boost_test_jamfile
cmake_install_test/, cmake_subdir_test/ CMake integration tests (CI only)
Jamfile.v2 tests run by b2 (and CI)
CMakeLists.txt tests run by CMake, listed separately. Keep it in sync with Jamfile.v2
cmake_test/ CMake install and add_subdirectory integration test (CI only)
example/ examples; snippets are imported into the docs
doc/circular_buffer.qbk Quickbook documentation
CMakeLists.txt generated by `boostdep --cmake circular_buffer`. Do not hand-edit the dependency list
CMakeLists.txt library target, dependency list (BOOST_CIRCULAR_BUFFER_DEPS) and standalone build.
Started from `boostdep --cmake` output, now maintained by hand. Don't regenerate it
build.jam b2 project and dependency list
```

Expand Down Expand Up @@ -93,8 +95,11 @@ build.jam b2 project and dependency list
compiler workarounds.
- **Dependencies**: keep them minimal. Current direct dependencies are
assert, concept_check, config, core, move, throw_exception and type_traits.
If you add one, update `CMakeLists.txt`, `build.jam` and
`test/cmake_subdir_test/CMakeLists.txt` together.
If you add one, update `CMakeLists.txt` (the `BOOST_CIRCULAR_BUFFER_DEPS`
list), `build.jam` and `test/cmake_test/CMakeLists.txt` together.
The standalone CMake build reads the same list. When an installed Boost
doesn't provide one of these targets, it uses `Boost::headers` instead.
So the standalone build needs no separate update.
- **Self-contained headers**: each header must `#include` what it uses, both
Boost and standard headers.
- **Formatting**: 4-space indent, 120 columns, K&R braces (opening brace on
Expand Down Expand Up @@ -141,6 +146,24 @@ runs them:
./b2 libs/circular_buffer/test toolset=gcc cxxstd=03,11,17 variant=debug,release
```

A standalone CMake build uses an installed Boost (1.85 or newer, found with
`find_package(Boost CONFIG)`) and requires CMake 3.10 or newer:

```sh
cmake -S . -B build -G Ninja -DBUILD_TESTING=ON
ninja -C build check # build and run the tests
ninja -C build check-valgrind # the same under valgrind (ctest -T memcheck)
```

- Pass `-DBUILD_TESTING=ON` explicitly. The `check` targets are defined only
when this is the top-level project and `BUILD_TESTING` is on.
- The tests are `EXCLUDE_FROM_ALL`, so a plain `ninja` doesn't build them.
Use `ninja tests` or the `check` targets.
- `check-valgrind` exists only if valgrind is found. A memory error or a
definite leak fails the test (`--error-exitcode=1`). Logs go to
`build/Testing/Temporary/MemoryChecker.<n>.log`.
- Don't use `check-valgrind` on a sanitizer build.

For a quick standalone run against a separate Boost checkout at `$BOOST`
(this repo's `include/` must come first, so that it shadows the superproject's
copy):
Expand Down
74 changes: 62 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Generated by `boostdep --cmake circular_buffer`
# Copyright 2020, 2021 Peter Dimov
# Copyright 2026 Nigel Stewart
# Distributed under the Boost Software License, Version 1.0.
# https://www.boost.org/LICENSE_1_0.txt

cmake_minimum_required(VERSION 3.8...3.31)
cmake_minimum_required(VERSION 3.10...3.31)

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

Expand All @@ -12,19 +12,69 @@ add_library(Boost::circular_buffer ALIAS boost_circular_buffer)

target_include_directories(boost_circular_buffer INTERFACE include)

target_link_libraries(boost_circular_buffer
INTERFACE
Boost::assert
Boost::concept_check
Boost::config
Boost::core
Boost::move
Boost::throw_exception
Boost::type_traits
set(BOOST_CIRCULAR_BUFFER_DEPS
Boost::assert
Boost::concept_check
Boost::config
Boost::core
Boost::move
Boost::throw_exception
Boost::type_traits
)

target_link_libraries(boost_circular_buffer INTERFACE ${BOOST_CIRCULAR_BUFFER_DEPS})

# Self-contained cmake build

if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)

message(STATUS "Using CMake version ${CMAKE_VERSION}")

set(Boost_DEBUG ON)
find_package(Boost 1.85 CONFIG REQUIRED)

# A b2-installed Boost (e.g. distro packages) provides only Boost::headers,
# not per-library targets. Stand in for any missing dependency with it.
foreach(_dep IN LISTS BOOST_CIRCULAR_BUFFER_DEPS)
if(_dep MATCHES "^Boost::(.+)$" AND NOT TARGET ${_dep})
add_library(boost_circular_buffer_dep_${CMAKE_MATCH_1} INTERFACE)
target_link_libraries(boost_circular_buffer_dep_${CMAKE_MATCH_1} INTERFACE Boost::headers)
add_library(${_dep} ALIAS boost_circular_buffer_dep_${CMAKE_MATCH_1})
endif()
endforeach()

if(BUILD_TESTING)

# --error-exitcode makes a test fail on any valgrind error, including definite leaks.
# (must be set before CTest include)
set(MEMORYCHECK_COMMAND_OPTIONS "--error-exitcode=1 --leak-check=full --errors-for-leak-kinds=definite --track-origins=yes")

include(CTest)

# check - run the unit tests

add_custom_target(check
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure "$<$<BOOL:$<CONFIG>>:-C;$<CONFIG>>"
COMMAND_EXPAND_LISTS)
add_dependencies(check tests)

# check-valgrind - run the unit tests with valgrind

if(MEMORYCHECK_COMMAND)
add_custom_target(check-valgrind
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -T memcheck "$<$<BOOL:$<CONFIG>>:-C;$<CONFIG>>"
COMMAND_EXPAND_LISTS)
add_dependencies(check-valgrind tests)
endif()

endif()

endif()

if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")

add_subdirectory(test)
# Follow the Boost convention: don't build test targets by default,
# and only when explicitly requested by building target tests
add_subdirectory(test EXCLUDE_FROM_ALL)

endif()
36 changes: 32 additions & 4 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
# Copyright 2018, 2019 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

include(BoostTestJamfile OPTIONAL RESULT_VARIABLE HAVE_BOOST_TEST)
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# warning level 4
add_compile_options(/W4)
endif()

if(HAVE_BOOST_TEST)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

boost_test_jamfile(FILE Jamfile.v2 LINK_LIBRARIES Boost::circular_buffer Boost::core)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

if(NOT TARGET tests)
add_custom_target(tests)
endif()

set(PREFIX "boost_circular_buffer_")
set(LINK_LIBRARIES Boost::circular_buffer)
set(COMPILE_FEATURES cxx_std_11)

function(boost_circular_buffer_add_test name source)
set(pname "${PREFIX}${name}")
add_executable(${pname} ${source})
target_link_libraries(${pname} PRIVATE ${LINK_LIBRARIES})
target_compile_features(${pname} PRIVATE ${COMPILE_FEATURES})
add_test(NAME ${pname} COMMAND ${pname})
add_dependencies(tests ${pname})
endfunction()

#

boost_circular_buffer_add_test(base_test base_test.cpp)
boost_circular_buffer_add_test(constant_erase_test constant_erase_test.cpp)
boost_circular_buffer_add_test(soft_iterator_invalidation soft_iterator_invalidation.cpp)
boost_circular_buffer_add_test(space_optimized_test space_optimized_test.cpp)
Loading