Giter VIP home page Giter VIP logo

meson-sample-project's Introduction

Meson Sample Project

This sample project uses meson to manage builds and already has auto-formatting, testing, linting, benchmarking, code coverage, static analysis and documentation generation.

Once the project structure follows the same general directory structure there should be minimum changes required to start a new cpp project capable of using these tools out of the box.

  • src : Contains the project source files.
  • include : Contains the project header files.
  • tests : Contains unit tests for project functions + classes.
  • benchmarks : Contains micro benchmarks for project functions + classes.
  • docs : Contains the doxygen config file used to generate the documentation.
  • third_party : Contains the third_party sources and libs. These are ignored for formatting + linting + documentation purposes.

Dependencies (all contained with the Docker container)

  • benchmark
  • build-essential
  • clang-6.0
  • clang-format-6.0
  • clang-tidy-6.0
  • curl
  • dot
  • doxygen
  • gcovr
  • gdb
  • git
  • graphviz
  • gtest
  • libgtest-dev
  • meson-0.46
  • ninja
  • pip3
  • python3.6
  • software-properties-common
  • valgrind
  • wget

[OPTIONAL] Launch The Build Container

In order to avoid costly build environment setup times you can run the builds in a docker container. To launch the build_env it run the following commands.

docker build . -t build_env --build-arg user=$USER --build-arg userid=$UID
docker run -it -v $(pwd):/code  -e USER=$USER -e USERID=$UID build_env bash

You can now run builds from this container. The source code from your local directory will be in the container in the /code/ directory.

Building The Sample Application

The project build directory is created using the following command.

meson build

Builds can be triggered using ninja once inside this build directory.

ninja

Running Tests

Benchmarks require an installed googletest Tests are created using googletest and can be run using ninja once inside the build directory.

ninja test

To run tests with address sanitization, build meson with this command.

meson build -Db_sanitize=address
cd build
ninja
ninja test

Wrapping Tests With Valgrind

Meson has the ability to wrap the tests in valgrind. This is useful for spotting easily avoidable memory leaks. From within the build directory run

meson test --wrap='valgrind --tool=helgrind'

Wrapping Tests With GDB

Meson has the ability to wrap the tests in gdb. This is useful for debugging. From within the build directory run

meson test --gdb

Running Benchmarks

Benchmarks require an installed benchmark Benchmarks are created using google's benchmark library and can be run using ninja once inside the build directory.

ninja benchmark

Formatting

To format you simply run the following command in the build directory.

ninja format

Tidying

There is a linter integrated into this project which enforces various style choices. This will automatically fix your code to align with these standards. It will also display issues that can't be autofixed.

ninja tidy

Creating Documentation

Documentation generation requires doxygen Documentation is created using doxygen. These can be generated using ninja once inside the build directory.

ninja doc

Creating Coverage Reports

Coverage reports require gcov. The build directory can be configured to generate coverage as follows.

 meson build_coverage -Db_coverage=true

Coverage can then be generated as follows.

ninja
ninja test
ninja coverage-html

Running Static Analysis

Static analysis requires clang. Running static analysis is as simple as running the following command from the build directory.

ninja scan-build

Running The Application

The application can be run as follows.

./sample_cpp_application_bin

meson-sample-project's People

Contributors

tiernemi avatar da2ce7 avatar colmartofus avatar coelle avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.