diff --git a/.bumpversion.cfg b/.bumpversion.cfg index b0c0e5a..ef7b528 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 3.20.0 +current_version = 3.20.5 [bumpversion:file:.gitlab-ci.yml] search = cmake-{current_version}-linux diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fa86bb0..3ef5a3a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,7 +5,7 @@ test_code: - apt-get update && apt-get install -y make cmake libboost-dev git # We will install latest CMake, even though Ubuntu has a recent one - mkdir -p $HOME/.local - - curl -s "https://cmake.org/files/v3.20/cmake-3.20.0-linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C $HOME/.local + - curl -s "https://cmake.org/files/v3.20/cmake-3.20.5-linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C $HOME/.local - export PATH=$HOME/.local/bin:$PATH script: - cmake -S examples -B build diff --git a/chapters/intro/installing.md b/chapters/intro/installing.md index 912e172..7bee4ed 100644 --- a/chapters/intro/installing.md +++ b/chapters/intro/installing.md @@ -34,13 +34,13 @@ You can [download CMake from KitWare][download]. This is how you will probably g On Linux, there are several options. Kitware provides a [Debian/Ubunutu apt repository][apt], as well as [snap packages][snap]. There are universal Linux binaries provided, but you'll need to pick an install location. If you already use `~/.local` for user-space packages, the following single line command[^1] will get CMake for you [^2]: {% term %} -~ $ wget -qO- "https://cmake.org/files/v3.20/cmake-3.20.0-linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C ~/.local +~ $ wget -qO- "https://cmake.org/files/v3.20/cmake-3.20.5-linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C ~/.local {% endterm %} The names changed in 3.20; older releases had names like `cmake-3.19.7-Linux-x86_64.tar.gz`. If you just want a local folder with CMake only: {% term %} -~ $ mkdir -p cmake-3.20 && wget -qO- "https://cmake.org/files/v3.20/cmake-3.20.0-linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C cmake-3.20 +~ $ mkdir -p cmake-3.20 && wget -qO- "https://cmake.org/files/v3.20/cmake-3.20.5-linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C cmake-3.20 ~ $ export PATH=`pwd`/cmake-3.20/bin:$PATH {% endterm %} @@ -49,7 +49,7 @@ You'll obviously want to append to the PATH every time you start a new terminal, And, if you want a system install, install to `/usr/local`; this is an excellent choice in a Docker container, for example on GitLab CI. Do not try it on a non-containerized system. {% term %} -docker $ wget -qO- "https://cmake.org/files/v3.20/cmake-3.20.0-linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C /usr/local +docker $ wget -qO- "https://cmake.org/files/v3.20/cmake-3.20.5-linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C /usr/local {% endterm %} diff --git a/chapters/projects/fetch.md b/chapters/projects/fetch.md index e23bbc3..77e6628 100644 --- a/chapters/projects/fetch.md +++ b/chapters/projects/fetch.md @@ -14,7 +14,7 @@ For example, to download Catch2: FetchContent_Declare( catch GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v2.13.0 + GIT_TAG v2.13.6 ) # CMake 3.14+ diff --git a/chapters/testing/catch.md b/chapters/testing/catch.md index 9a04188..b9902c0 100644 --- a/chapters/testing/catch.md +++ b/chapters/testing/catch.md @@ -1,13 +1,42 @@ # Catch -Catch and [Catch2] (C++11 only version) are powerful, idomatic testing solutions similar in philosophy to PyTest for Python. To use Catch in a CMake project, there are several options. +[Catch2] (C++11 only version) is a powerful, idomatic testing solutions similar in philosophy to PyTest for Python. It supports a wider range of compilers than GTest, and is quick to support new things, like M1 builds on macOS. It also has a smaller but faster twin, [doctest](https://github.com/onqtam/doctest), which is quick to compile but misses features like matchers. To use Catch in a CMake project, there are several options. + +## Configure methods + +Catch has nice CMake support, though to use it, you need the full repo. This could be with submodules or FetchContent. Both the [`extended-project`](https://gitlab.com/CLIUtils/modern-cmake/-/tree/master/examples/extended-project) and [`fetch`](https://gitlab.com/CLIUtils/modern-cmake/-/tree/master/examples/fetch) examples use FetchContent. See [the docs](https://github.com/catchorg/Catch2/blob/v2.x/docs/cmake-integration.md#top). + +## Quick download + +This is likely the simplest method and supports older versions of CMake. You can download the all-in-one header file in one step: + +```cmake +add_library(catch_main main.cpp) +target_include_directories(catch_main PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") +set(url https://github.com/philsquared/Catch/releases/download/v2.13.6/catch.hpp) +file( + DOWNLOAD ${url} "${CMAKE_CURRENT_BINARY_DIR}/catch.hpp" + STATUS status + EXPECTED_HASH SHA256=681e7505a50887c9085539e5135794fc8f66d8e5de28eadf13a30978627b0f47) +list(GET status 0 error) +if(error) + message(FATAL_ERROR "Could not download ${url}") +endif() +target_include_directories(catch_main PUBLIC "${CMAKE_CURRENT_BINARY_DIR}") +``` + +This will two downloads when Catch 3 is released, as that now requires two files (but you no longer have to write a main.cpp). The `main.cpp` looks like this: + +```cpp +#define CATCH_CONFIG_MAIN +#include "catch.hpp" +``` ## Vendoring If you simply drop in the single include release of Catch into your project, this is what you would need to add Catch: - ```cmake # Prepare "Catch" library for other executables set(CATCH_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/extern/catch) diff --git a/chapters/testing/googletest.md b/chapters/testing/googletest.md index ff75680..730366e 100644 --- a/chapters/testing/googletest.md +++ b/chapters/testing/googletest.md @@ -1,5 +1,7 @@ # GoogleTest +GoogleTest and GoogleMock are classic options; personally, I personally would recommend Catch2 instead, as GoogleTest heavily follows the Google development philosophy; it drops old compilers very quickly, it assumes users want to live at HEAD, etc. Adding GoogleMock is also often painful - and you need GoogleMock to get matchers, which are a default feature in Catch2 (but not doctest). + ## Submodule method (preferred) To use this method, just checkout GoogleTest as a submodule:[^1] diff --git a/examples/extended-project/tests/CMakeLists.txt b/examples/extended-project/tests/CMakeLists.txt index 96c9129..917e23d 100644 --- a/examples/extended-project/tests/CMakeLists.txt +++ b/examples/extended-project/tests/CMakeLists.txt @@ -2,7 +2,7 @@ FetchContent_Declare( catch GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v2.9.1) + GIT_TAG v2.13.6) FetchContent_MakeAvailable(catch) # Adds Catch2::Catch2 diff --git a/examples/fetch/CMakeLists.txt b/examples/fetch/CMakeLists.txt index 0046d01..3f2310f 100644 --- a/examples/fetch/CMakeLists.txt +++ b/examples/fetch/CMakeLists.txt @@ -8,7 +8,7 @@ include(CTest) FetchContent_Declare( catch GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v2.13.0) + GIT_TAG v2.13.6) # CMake 3.14+ FetchContent_MakeAvailable(catch)