The second Pure Virtual C++ event took place on the 3rd of May 2021. It had guest speakers such as Daniela Engert, Gabriel Dos Reis, Kyle Edwards, Erika Sweet, Sunny Chatterjee, Jim Radigan, and Augustin Popa.
The main topics for this event were:
- Modules in C++ 20
- CMakePresets.json
- Improving C++ code safety using Static Analysis
- Manage Code Dependencies with vcpkg features
We discuss some of these topics below, starting with modules.
Editor’s Note: You can watch the coverage and learn about all of the C++ 20 updates at the Pure Virtual C++ 2021 Youtube Channel.
C++ Modules
Modules are one of the major additions to C++20. Modules help divide large amounts of code into logical parts. Before C++ modules, only precompiled headers were available. Unfortunately, precompiled headers are not standard, so results may vary depending on the platform and compiler. One or more header files are usually parsed and compiled to an internal representation that can be reused; then, a flag is used to bring this precompiled context into the global state before parsing the compilation unit.
This is where C++20 Modules come in; Modules work as a precompiled header but use a special compilation unit type instead of plain headers. This unit can export a list of types and symbols through a public interface. This interface can then be exported to a file and imported by other compilation units.
CMakePresets.json
CMakePresets.json is a file to specify common configure, build, and test options and share them with others. You can invoke a Configure Preset, Build Preset, or Test Preset from the CLI in the following ways:
- cmake –<configure preset>
cmake –build –<build-preset> ctest –preset<test-preset>
You can use CMakePresets.json for the following:
- Project-wide settings can always be checked in.
- Reproduce builds in a Continuous Integration pipeline and from the CLI on Windows, Linux, and macOS.
- Streamline build instructions for open-source CMake projects.
Improving C++ code safety using Static Analysis
Static Analysis reads C/C++ code, applies some techniques to look for defects, and reports defects at compile time. It drives quality upstream, has Minimal overhead (no instrumentation & no test cases), and has a proven track record in finding a range of correctness, performance, reliability, and safety issues at compile time.
A few checks include:
Vcpkg (Package manager)
This is the simplest solution for C/C++ dependency, management and includes the following advantages:
- Over 1600 public libraries available for installation for Windows, macOS, and Linux.
- Open-source CMake and Git-based workflow.
- Works for local development and in CI What it can do for you.
- Build libraries from the source – avoid ABI incompatibilities.
- Automatically includes dependencies of dependencies.
- Resolves version conflicts.
- Tight integration with MSBuild and CMake projects.
Easy to use.