GithubHelp home page GithubHelp logo

albertzheng / cmake-gbenchmark-gtest-boilerplate Goto Github PK

View Code? Open in Web Editor NEW
4.0 3.0 0.0 16 KB

A cross-platform C++17 boilerplate project with cmake, Google Benchmark and Google Test frameworks support.

CMake 70.47% C++ 29.53%
cmake google-benchmark google-test cpp11 cpp14 cpp17

cmake-gbenchmark-gtest-boilerplate's Introduction

C++17 boilerplate project with cmake, google benchmark and google test

A cross-platform C++17/14/11 boilerplate project with cmake, Google Benchmark and Google Test frameworks support.

This project boilerplate is using git submodule to include Google Benchmark and Google Test so you need either to do

$ git clone --recursive [email protected]:AlbertZheng/cmake-gbenchmark-gtest-boilerplate.git

or

$ git clone [email protected]:AlbertZheng/cmake-gbenchmark-gtest-boilerplate.git
$ cd cmake-gbenchmark-gtest-boilerplate
$ git submodule init
$ git submodule update

Organization

  • src : has the source files and the CMakeLists.txt to compile the api library and executable of your App.
  • include : has the header files of your App.
  • test : has the tests and related CMakeLists.txt of your App.
  • benchmark : has the benchmarks and related CMakeLists.txt of your App.
  • third-party : put all the third party libraries or frameworks and related CMakeLists.txt in this directory. Currently, Google Benchmark and Google Test are already in there.
  • doc : has the documents of your App in this directory if any.
  • examples : has the examples code of App in this directory if any.
  • tools : has your tools code of App in this directory if any.

Build

On Linux/macOS, to build and make the test:

$ mkdir build && cd $_
$ cmake ..

$ cmake --build .
# or
$ make

On Windows, you can use cmake to generate Visual Studio build files with the same cmake .. command.

If you prefer to C++14 or C++11 rather than C++17, modifing the number of the line set(CMAKE_CXX_STANDARD 17) in the root CMakeLists.txt.

Build Options

Options can be turned on and off by providing cmake with a -DOPTIONNAME=ON (or OFF) argument.

For example, to turn off tests and benchmarks, build a shared library, and use sanitize flags in a DEBUG build:

$ cmake .. -DCMAKE_BUILD_TYPE=DEBUG \
           -DBUILD_TESTS=OFF \
           -DBUILD_BENCHMARKS=OFF \
           -DBUILD_SHARED_LIBS=ON \
           -ENABLE_SANITIZE=ON

By default, the project will be built in RELEASE mode, and the default config of Options are:

option(BUILD_TESTS "Build tests" ON)
option(BUILD_BENCHMARKS "Build benchmarks" ON)
option(ENABLE_SANITIZE "Add sanitize flags" OFF)
option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF)

If you encounter the memory leak or Undefined Behavior issues in your codes, recommending you to use Google Sanitizers toolbox for checking the issues by -DENABLE_SANITIZE=ON option.

By default, the makefiles will build the executable, api library, tests, and benchmarks:

  • An executable program named demo (of course, you should change the name for your App)
  • An api library named libdemo-api.a or libdemo-api.so (of course, you should change the name for your App)
  • An executable program named tests for runing unit test cases
  • An executable program named benchmarks for running benchmark test cases

Executable commands

The commands:

$ ./test/tests
$ ./benchmark/benchmarks

will run the tests and benchmarks. And

$ sudo make install

will install (at least on Linux and macOS) the library and executable to your computer's path.

License

Copyright (C) 2018-2019 Lisong Zheng, 郑立松

The binaries and source code of this project can be used according to the Apache License, Version 2.0.

Contributing

Welcome all contributions. You can submit any ideas as pull requests.

cmake-gbenchmark-gtest-boilerplate's People

Contributors

albertzheng avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.