ApprovalTests.cpp.CMakeSamples

September 9, 2021 ยท View on GitHub

Contents

Build Status

CMake code for various scenarios, for including in the ApprovalTests.cpp cmake docs, and for copying as templates for new projects.

Using ApprovalTests.cpp with CMake

add_subdirectory_approvaltests_catch2

TopicDetail
Directoryadd_subdirectory_approvaltests_catch2
PurposeDemo how to build your tests against clones or forks of ApprovalTests.cpp and Catch2.
Those source code of those dependencies will be included in your IDE, alongside your own source code.
This allows you to make edits to the dependent projects.
DependenciesApprovalTests.cpp - cloned on your machine
Catch2 - cloned on your machine
MechanismUses CMake's add_subdirectory()
More DetailSee Use own ApprovalTests.cpp and Catch2 clones

fetch_content_approvaltests

TopicDetail
Directoryfetch_content_approvaltests
PurposeDemo how to build your tests using CMake's FetchContent_Declare and FetchContent_MakeAvailable to clone ApprovalTests.cpp, and use its copy of Catch2.
The source code of this dependency will be cloned inside your CMake build space, and will not be shown inside your IDE.
This requires at least CMake 3.14.
DependenciesApprovalTests.cpp - cloned automatically by CMake
Catch2 - the version in the ApprovalTests.cpp repo will be used
MechanismUses CMake's FetchContent module.
More DetailSee Make CMake clone ApprovalTests.cpp

fetch_content_approvaltests_catch2

TopicDetail
Directoryfetch_content_approvaltests_catch2
PurposeDemo how to build your tests using CMake's FetchContent_Declare and FetchContent_MakeAvailable to clone ApprovalTests.cpp and Catch2.
The source code of those dependencies will be cloned inside your CMake build space, and will not be shown inside your IDE.
This requires at least CMake 3.14.
DependenciesApprovalTests.cpp - cloned automatically by CMake
Catch2 - cloned automatically by CMake
MechanismUses CMake's FetchContent module.
More DetailSee Make CMake clone ApprovalTests.cpp and Catch2

Using ApprovalTests.cpp with CMake and Conan

conan_cmake_find_package

TopicDetail
Directoryconan_cmake_find_package
PurposeDemo how to build your tests using Conan's cmake_find_package and optionally cmake_paths generators to download single headers for specific releases of ApprovalTests.cpp and Catch2.
The released headers of those dependencies will be downloaded inside your CMake build space, and will not be shown inside your IDE.
DependenciesApprovalTests.cpp - downloaded automatically by Conan
Catch2 - downloaded automatically by Conan
MechanismUses Conan's cmake_find_package and (optionally) cmake_paths generators.
More DetailSee Example 1. Using Conan's cmake_find_package and cmake_paths generators

conan_cmake

TopicDetail
Directoryconan_cmake
PurposeDemo how to build your tests using Conan's cmake generator to download single headers for specific releases of ApprovalTests.cpp and Catch2.
The released headers of those dependencies will be downloaded inside your CMake build space, and will not be shown inside your IDE.
DependenciesApprovalTests.cpp - downloaded automatically by Conan
Catch2 - downloaded automatically by Conan
MechanismUses Conan's cmake generator.
More DetailSee Example 2. Using Conan's cmake generator

cmake_invoking_conan

TopicDetail
Directorycmake_invoking_conan
PurposeDemo how to build your tests by getting CMake to invoke Conan, to download single headers for specific releases of ApprovalTests.cpp and Catch2.
The released headers of those dependencies will be downloaded inside your CMake build space, and will not be shown inside your IDE.
DependenciesApprovalTests.cpp - downloaded automatically by CMake invoking Conan
Catch2 - downloaded automatically by CMake invoking Conan
MechanismUses the cmake-conan CMake module to invoke Conan automatically from within CMake.
More DetailSee Example 3. Making CMake invoke Conan

Using ApprovalTests.cpp with CMake and vcpkg

vcpkg_cmake

TopicDetail
Directoryvcpkg_cmake
PurposeDemo how to build your tests using vcpkg to obtain Catch2 and ApprovalTests.cpp.

A specific version of vcpkg is cloned automatically by CMake, via FetchContent() in the top level CMakeLists.txt, and then built inside your CMake build space.

The benefit of this approach for obtaining vcpkg is that the project can specify the exact version of vcpkg to use, and obtain it automatically - on all platforms. This keeps both build instructions and CI configurations simple.

The alternative would be to have to write instructions for developers to say how to manually obtain and build the required vcpkg version - which would be tedious and error-prone.

Note that the first time this is run in any given build space, there is a significant wait for vcpkg to be set up, but subsequent runs are much faster.

If you have multiple build spaces, vcpkg will be cloned and built multiple times, so this mechanism may be best used when you are only building one or two configurations.

DependenciesApprovalTests.cpp - obtained automatically by vcpkg
Catch2 - obtained automatically by vcpkg
MechanismUses CMake's FetchContent() to obtain and build a specific version of vcpkg inside the build space.

Uses vcpkg's manifest mode to specify the dependencies.

More DetailSee ApprovalTests.cpp Vcpkg Integration docs - TODO Update that page to add descriptive info for this example

Developing ApprovalTests.cpp with CMake

dev_approvals

TopicDetail
Directorydev_approvals
PurposeDemo how to build the ApprovalTests.cpp project against your clones or forks of all its dependencies.
Those source code of those dependencies will be included in your IDE, alongside your own source code.
This allows you to make edits to the dependent projects.
DependenciesApprovalTests.cpp - cloned on your machine
All its dependencies also cloned on your machine
MechanismUses CMake's find_package() for finding boost, and add_subdirectory() for everything else.
More DetailSee Developing ApprovalTests.cpp with test framework sources

dev_approvals_fetch_content

TopicDetail
Directorydev_approvals_fetch_content
PurposeDemo how to build the ApprovalTests.cpp project using CMake's FetchContent_Declare and FetchContent_MakeAvailable to clone its dependencies.
The source code of the dependencies will be cloned inside your CMake build space, and will not be shown inside your IDE.
This requires at least CMake 3.14.
DependenciesApprovalTests.cpp - cloned on your machine
All its dependencies also cloned on your machine, inside each build space
MechanismUses CMake's FetchContent module.
More Detail