Giter VIP home page Giter VIP logo

cpp-starter's Introduction

CMake C++ Project Structure Template

This project, derivative of the CMake Tutorial, is aimed at showing a preferred "common" CMake/C++ project structure.

If your project is mulit-language, and you absolutely have to keep them together, make the root one level above, and create folders such as "cpp" and "ruby", or "python", etc.

Project Intention and Structure

By "exporting a component" we mean that the component is meant to be consumed by other projects or developers. IE. it's public, not private to the project.

Example Project

For the simplicity sake, we'll build a tool that for every input number prints out if it's divisible by a particular number, that can also be supplied as an argument that would override the default value of 2. We'll call this tool divisible, and that name will now be our project's name too.

Our goal is to have a working binary, such as :

$ bin/divis [ -h/--help ] [ -m/--modulo ] [ -d/--denominator N ] value

# eg:
$ bin/divis -d 17 34
yes, 17 x 2 is 34

$ bin/divis -d 10 -m 45
45 modulo 10 is 5 

And C++ usage:

#include <iostream>
#include <divisible>

std::cout << Divisible.new(int denominator).modulo();

Sources:

  • src/* โ€” C++ code that ultimately compiles into a library
  • We'll also build a library libdivisible.a and install into lib/
  • src/CLI.cpp C++ CLI interface parser that parses arguments and flags passed to a binary
  • a tiny src/main.cpp that calls into the CLI, which then calls the library.

Tests:

  • A test folder with the automated tests and fixtures that mimics the directory structure of src.
  • For every C++ file in src/A/B/<name>.cpp there is a corresponding test file test/A/B/<name>_test.cpp
  • Tests compile into a single binary test/bin/runner that is run on a command line to run the tests.
  • test/lib folder with a git submodule in test/lib/googletest, and possibly other libraries.

Here is the structure proposed here:

divisible/ 
   CMakeLists.txt       -> Top level CMake file
   build/                 -> exported compiled executables
   doc/                 -> and compiled documentation
       usage/           -> documentation folder for how to use the tool
       design/          -> documentation folder for the developers of the tool
   include/             -> externally exported header files
       name/
   lib/                 -> compiled library we are exporting
       extern/          -> external libraries if they must be included
      
   src/                 -> sources of the project
       CLI.cpp          -> the CLI argument parser/wrapper
       main.cpp         -> small main.cpp that calls into the CLI module
       divisible/       -> cmake project that produces divisible library
          CMakeLists.txt
          Divisible.cpp
          Divisible.h
   test/                -> sources for all the tests
       bin/             -> where the binary `test-runner` is installed
       lib/             -> where any external libraries live
           googletest/ -> most importantly, our googletest library as a submodule
       src/
   util/                -> any bash tools, build wrappers, etc.

Development

TBD.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/kigster/cmake-project-template

License

CMake Project Template is ยฉ 2017 Konstantin Gredeskoul, available as open source under the terms of the MIT License.

https://github.com/catchorg/Catch2 https://github.com/kigster/cmake-project-template https://github.com/derekmolloy/exploringBB/blob/master/extras/cmake/

TODO

  • Catch2 integration
  • Build script
  • Documentation

cpp-starter's People

Contributors

evanxg852000 avatar

Watchers

 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.