Skip to content

lukka/CppCMakeVcpkgTemplate

Repository files navigation

hosted-ninja-vcpkg_submod-autocache hosted-pure-workflow

A C++ project template based on CMake and vcpkg

Content

This repository contains a C++ based project template that leverages vcpkg and CMake's CMakePresets.json to build and test C++ source code.

Supports Linux/macOS/Windows on x64 and arm64 platforms.

vcpkg is driven to use its binary caching feature storing the content in the GitHub Action cache, hence speeding up workflows by reusing previously built packages.

Key features:

  • CMakePresets.json allows to run the same build either locally on your IDE and on GitHub runners.
  • vcpkg greatly helps in pulling and building the needed dependencies (e.g. libraries) which are cached for reuse on GitHub Action cache.

GitHub Action workflows

The repository provides also two GitHub workflows to build the project on GitHub runners. Both builds and tests the project using vcpkg and CMake, the only key difference is their implementation:

  • hosted-pure-workflow.yml: it is a pure workflow which does not use unneeded GitHub Actions that cannot run locally on your development machine. On the other hand it is directly using the CMake, Ninja, vcpkg and the C++ build tools.
  • hosted-ninja-vcpkg_submod.yml: it is a concise workflow based on the custom GitHub Actions get-cmake, run-vcpkg and run-cmake which simplify and shorten the workflow verbosity while adding some goodies like vcpkg binary caching stored on GH's cache and inline error annotations.

Rationale

The main idea of this C++ project template is to show how to obtain a perfectly reproducible software development process that can be run anywhere without any difference and no surprises, either locally using your preferred tools/IDE, either remotely on build agents typically used for continuous integration.

Integrated Development Environment (IDE) Support

The major C++ IDEs should already support CMakePresets.json and require no particular configuration.

For example Visual Studio Code with the CMake Tools extension let you to open the root folder of this repository, and select in the status bar the CMake preset (e.g. ninja-multi-vcpkg), as show in the following image:

CMake's preset selection in the status bar of Visual Studio Code


License

All the content in this repository is licensed under the MIT License.

Copyright © 2021-2022-2023 Luca Cappa

About

A template project to build a C++/CMake/vcpkg based projects with IDE and GitHub Actions. Build is sped up with caching of artifacts.

Topics

Resources

License

Stars

Watchers

Forks