Use cmake FetchContent to manage boost-test dependency
- No need to configure vcpkg or download the full Boost library.
- Simplifies CMake dependency management for C++ unit testing.
- Provides a header-only approach for Boost.Test in your project.
The easiest way to use this repository is to copy FindBoostTestHeaders.cmake into your project, add it to your CMake module path, call find_package(BoostTestHeaders), and link with boost-test-headers when building your tests.
-
Copy Module File:
Download or copy theFindBoostTestHeaders.cmakefile from this repository into your project's CMake modules directory (e.g.,cmake). -
Set CMake Module Path:
In your project's mainCMakeLists.txt, ensure your module path is set to include the directory containingFindBoostTestHeaders.cmake:list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
-
Find Package:
Add the following line to your test build logic to locate Boost.Test headers:find_package(BoostTestHeaders REQUIRED) -
Link Your Test Target:
When declaring your test executable, link it with theboost_test_headerstarget to make the Boost.Test headers available:add_executable(my_test main.cpp) target_link_libraries(my_test PRIVATE boost_test_headers)