Skip to content

CMake: standalone build with check and check-valgrind targets - #63

Merged
nigels-com merged 4 commits into
boostorg:developfrom
nigels-com:cmake-stand-alone
Nov 30, 2026
Merged

nigels-com merged 4 commits into
boostorg:developfrom
nigels-com:cmake-stand-alone

Conversation

@nigels-com

Copy link
Copy Markdown
Collaborator

Let the library be configured and tested on its own, against an installed Boost, without a Boost superproject checkout. Add check and check-valgrind targets.

Usage

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

Requires CMake 3.10 or newer and Boost 1.85 or newer, found with find_package(Boost CONFIG).

Changes

Standalone build (only when circular_buffer is the top-level project)

  • find_package(Boost 1.85 CONFIG REQUIRED).
  • check runs ctest --output-on-failure. -C is passed only when a configuration is set. A bare $ expands to nothing with a single-config generator and no CMAKE_BUILD_TYPE, and ctest then fails with CMake Error: Invalid value used with -C.
  • check-valgrind runs ctest -T memcheck, and is only added if valgrind is found. Valgrind runs with --error-exitcode=1 --leak-check=full --errors-for-leak-kinds=definite --track-origins=yes, so a memory error or a definite leak fails the test. Without --error-exitcode, memcheck only lists defects in its summary and still exits 0.

Dependencies

  • The Boost dependencies are now in a BOOST_CIRCULAR_BUFFER_DEPS list, passed to target_link_libraries.
  • A b2-installed Boost, such as the distro packages, provides only Boost::headers and none of the per-library targets. In the standalone build, each missing dependency target becomes an alias of an interface library that links Boost::headers. Targets that already exist, from the superproject or a CMake-installed Boost, are left alone.
  • Nothing changes for the superproject or test/cmake_test: the stand-ins are only created in standalone mode.
  • The file is now maintained by hand rather than generated by boostdep --cmake, because regenerating it would drop the list variable.

Tests

  • test/CMakeLists.txt lists the tests directly: base_test, constant_erase_test, soft_iterator_invalidation and space_optimized_test. It no longer reads them from Jamfile.v2 via boost_test_jamfile, so the two lists must be kept in sync.
  • The tests are built with C++11 and -Wall -Wextra -Wpedantic (/W4 on MSVC).
  • The tests are added with EXCLUDE_FROM_ALL, following the Boost convention. They're built by the tests target, which check and check-valgrind depend on.

Other

  • cmake_minimum_required is raised from 3.8 to 3.10. CMake 3.31 and later warn that compatibility with versions older than 3.10 is deprecated.
  • CLAUDE.md covers the standalone build, the hand-maintained dependency list, the separate CMake test list and test/cmake_test.

Testing

With the system Boost 1.90 (b2-installed, Boost::headers only), CMake 4.2 and Ninja:

  • A fresh configure with no CMAKE_BUILD_TYPE: check and check-valgrind pass all 4 tests.
  • CMAKE_BUILD_TYPE=Release: check passes, and runs ctest with -C Release.
  • check-valgrind fails as it should on a test program with a deliberate leak (Defects: 1, non-zero exit).
  • The repo's include/ is the only -I in the generated build, so the tests compile against the working tree rather than the installed headers.

Allow the library to be configured on its own, outside the Boost
superproject, using an installed Boost (find_package(Boost 1.85
CONFIG)).

- When this is the top-level project and BUILD_TESTING is on,
  include CTest and add two targets:
    check           run the unit tests (ctest --output-on-failure)
    check-valgrind  run them under valgrind (ctest -T memcheck),
                    only when valgrind is found
- Pass -C <config> to ctest only when a configuration is set, so the
  targets work with single-config generators and an empty
  CMAKE_BUILD_TYPE (a bare "-C" made ctest fail).
- Run valgrind with --error-exitcode=1, --leak-check=full and
  --errors-for-leak-kinds=definite, so memory errors and definite
  leaks fail the test instead of only being listed in the memcheck
  summary.
- test/CMakeLists.txt: list the tests directly (base_test,
  constant_erase_test, soft_iterator_invalidation,
  space_optimized_test) instead of reading them from Jamfile.v2. The
  tests are built with C++11 and -Wall -Wextra -Wpedantic (/W4 on
  MSVC), and a "tests" target builds them all.

The library target no longer lists its Boost dependencies.
- Raise the cmake_minimum_required lower bound from 3.8 to 3.10.
  CMake 3.31 and later warn that compatibility with versions older
  than 3.10 is deprecated.
- Add the test subdirectory with EXCLUDE_FROM_ALL. A plain build no
  longer compiles the tests, following the Boost convention. They
  are built through the "tests" target, which check and
  check-valgrind depend on.
The library target's Boost dependencies had been removed because the
standalone build failed with them. A b2-installed Boost (for example
the distro packages) provides only Boost::headers and none of the
per-library targets, so the link interface named targets that did
not exist ("The link interface of target boost_circular_buffer
contains: Boost::assert but the target was not found").

Without the list, Boost::circular_buffer did not pass on its
dependencies' include paths in the superproject or in
test/cmake_test.

- Put the dependencies back, in a BOOST_CIRCULAR_BUFFER_DEPS list
  that is passed to target_link_libraries.
- In the standalone build, after find_package(Boost), make each
  dependency target that does not exist an alias of an interface
  library that links Boost::headers. Targets that already exist,
  from the superproject or a CMake-installed Boost, are left alone.
- The file is now maintained by hand rather than generated by
  boostdep, so drop the "Generated by" line.

CLAUDE.md:
- Describe the hand-maintained dependency list and the
  Boost::headers fallback, and stop telling people to regenerate
  CMakeLists.txt with boostdep.
- test/CMakeLists.txt lists its tests separately from Jamfile.v2
  and must be kept in sync with it. cmake_install_test and
  cmake_subdir_test are replaced by cmake_test.
- Add instructions for the standalone CMake build (CMake 3.10 or
  newer, Boost 1.85 or newer, -DBUILD_TESTING=ON, check and
  check-valgrind).
@nigels-com
nigels-com requested a review from pdimov November 30, 2026 10:25
The header was lost when the file was rewritten to list the tests
directly. Restore the Boost Software License notice.
@codecov

codecov Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (develop@c3faa18). Learn more about missing BASE report.

Additional details and impacted files
@@            Coverage Diff             @@
##             develop      #63   +/-   ##
==========================================
  Coverage           ?   99.43%           
==========================================
  Files              ?       10           
  Lines              ?     4578           
  Branches           ?     3358           
==========================================
  Hits               ?     4552           
  Misses             ?       23           
  Partials           ?        3           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@pdimov

pdimov commented Nov 30, 2026

Copy link
Copy Markdown
Member

Looks OK.

The change from 3.8 to 3.10 is unnecessary (for the stated reason) but harmless.

It's possible to avoid the target_link_libraries change by getting the property in the standalone case, instead of introducing a variable earlier.

Starting from 1.92, the b2-installed Boost actually provides compatibility targets for the header-only libraries (boostorg/boost_install@cd84189) but that's not going to be an issue because the code checks if(TARGET.

But everything is fine as it is, these are minor comments.

The standalone case probably needs to be added to CI, though.

@nigels-com nigels-com added this to the boost 1.94.0 milestone Nov 30, 2026
@nigels-com

Copy link
Copy Markdown
Collaborator Author

@pdimov All good, just didn't want to (inadvertently) cause you more headaches.

@nigels-com
nigels-com merged commit 7a33b2b into boostorg:develop Nov 30, 2026
75 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants