All Projects → Barthelemy → Cppprojecttemplate

Barthelemy / Cppprojecttemplate

Licence: mit
Basic, but working, C++ project using CMake, boost and Doxygen

Labels

Projects that are alternatives of or similar to Cppprojecttemplate

Cfs
The Core Flight System (cFS)
Stars: ✭ 238 (-8.11%)
Mutual labels:  cmake
cmake-maven-project
Project to enable using CMake from a Maven build.
Stars: ✭ 57 (-77.99%)
Mutual labels:  cmake
cmake-modules
CMake module collection
Stars: ✭ 30 (-88.42%)
Mutual labels:  cmake
Fortran2018 Examples
Fortran 2018 standard examples with broad applications
Stars: ✭ 251 (-3.09%)
Mutual labels:  cmake
cmake-cheatsheet
CMake Cheat Sheet
Stars: ✭ 37 (-85.71%)
Mutual labels:  cmake
c-template
Boilerplate to set up a c project, include CuTest unit testing, cmake build setup
Stars: ✭ 69 (-73.36%)
Mutual labels:  cmake
Sanitizers Cmake
CMake modules to help use sanitizers
Stars: ✭ 232 (-10.42%)
Mutual labels:  cmake
Vanilla Rtb
Real Time Bidding (RTB) - Demand Side Platform framework
Stars: ✭ 257 (-0.77%)
Mutual labels:  cmake
computer-vision-dojo
This is a repository to learn and get more computer vision skills, make robotics projects integrating the computer vision as a perception tool and create a lot of awesome advanced controllers for the robots of the future.
Stars: ✭ 15 (-94.21%)
Mutual labels:  cmake
cuda-cmake-gtest-gbench-starter
A cross-platform CUDA/C++14 starter project with google test and google benchmark support.
Stars: ✭ 24 (-90.73%)
Mutual labels:  cmake
cpp-utilities
Common C++ classes and routines used by my applications such as argument parser, IO and conversion utilities
Stars: ✭ 35 (-86.49%)
Mutual labels:  cmake
esm
Lightweight communicating state machine framework for embedded systems
Stars: ✭ 21 (-91.89%)
Mutual labels:  cmake
CmakeSettings
Example CmakeSettings.json for different configurations for using CMake inside of Visual Studio
Stars: ✭ 27 (-89.58%)
Mutual labels:  cmake
Flingengine
A Vulkan game engine with a focus on data oriented design
Stars: ✭ 239 (-7.72%)
Mutual labels:  cmake
BunnyLOD
Cross platform GLFW based port of Stan Melax's BunnyLOD Easy Mesh Simplification
Stars: ✭ 60 (-76.83%)
Mutual labels:  cmake
Scikit Build
Improved build system generator for CPython C, C++, Cython and Fortran extensions
Stars: ✭ 234 (-9.65%)
Mutual labels:  cmake
FindICU.cmake
[CMake] [BSD-2] CMake module to find ICU
Stars: ✭ 28 (-89.19%)
Mutual labels:  cmake
Google Test Examples
Short example how to use Google Test with CMake project
Stars: ✭ 258 (-0.39%)
Mutual labels:  cmake
catch cmake coverage
Integration of Catch, CMake and CMake CodeCoverage module and basic examples in C++.
Stars: ✭ 30 (-88.42%)
Mutual labels:  cmake
CLUSEK-RT
Vulkan based C++ ray-tracing game engine.
Stars: ✭ 24 (-90.73%)
Mutual labels:  cmake

Build Status

This C++ project demonstrates the usage of CMake, boost's test, boost's option parsing and Doxygen. It is not the simplest example ever because we want to show how to use them in a proper non-minimalistic way. It also shows a way to structure the code and the other type of files.

Project description and aim

Our project is made of two subprojects : ProjA and ProjB. ProjB depends of ProjA. The project produces 2 libraries (libProjA.so and libProjB.so) and 2 binaries linked against their respective library (projArunner and projBrunner). Packages for multiple platform should be produced : 1 single for ProjB and 3 different for ProjA (libs, devel, doc). We have tests for each project that should be runnable.

We want to be able to compile independently one or the other project or both at the same time. When compiling ProjB independently we must have installed ProjA before, either from source or from a package.

Project structure and organisation

The general structure is
├── cmake
│   └── <all cmake macro files requested by more than one subproject>
├── CMakeLists.txt               # main CMakeLists.txt
├── ProjA
│   ├── cmake
│   │   ├── CPackConfig.cmake    # for Cpack
│   │   └── ProjAConfig.cmake    # for subprojects interdependencies
│   ├── CMakeLists.txt           # main CmakeLists.txt for ProjA
│   ├── doc
│   │   └── <Doxygen files and CMakeLists.txt>
│   ├── include
│   │   ├── CMakeLists.txt
│   │   └── ProjA                # project subfolder to appear in includes (e.g. include <ProjA/World.h>)
│   │       ├── CMakeLists.txt
│   │       ├── Version.h.in     # template for the Version class
│   │       └── World.h
│   ├── src
│   │   ├── CMakeLists.txt       # this is where we define the key targets for this subproject
│   │   ├── main.cxx
│   │   ├── Version.cxx
│   │   └── World.cxx
│   └── test
│       ├── CMakeLists.txt
│       └── testProjA.cxx
├── ProjB
│   └── <same as ProjA>
└── README

The headers and source files are split in each subproject. The headers are under a directory with the name of the project. We want that users of our libraries write "include <ProjA/xxx.h>" and not just "include <xxx.h>" to avoid conflicts.

Requirements

CMake

CMake (www.cmake.org) is the make tool we use in this project. Its config file is a plain text file called CMakeLists.txt. You will find a sample one right next to this README. It is commented heavily for reference.

The cmake way

The commands to build the project would be:

    mkdir build_dir
    cd build_dir
    cmake .. 
    make 
    make install

Installation goes to /usr/local/ by default.

More advanced way

To use it run ccmake .. in the top directory of the project. Then turn on the options that you want by going up and down with arrows, hitting "enter" to edit values and hitting it again to exit edition. For example, you might want to enable building documentation for the sample project. Then press "c" followed by "g" to generate a makefile. It will bring you back to the terminal. Then type "make"

One can also pass parameters to cmake when configuring it using "-DMY_VARIABLE VALUE". For example to build a debug version or a release version with debug symbols could look like :

    cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
    cmake -DCMAKE_BUILD_TYPE=Debug ..

List of targets

From the ./build or ./ProjX/build, one can call :

  • make [-j<number_of_parallel_jobs>]
  • make test
  • make install
  • make doc
  • make package

Important note : to be able to compile ProjB alone, one must first make and install ProjA. Moreover, one must add to PATH and LD_LIBRARY_PATH the installation directory of ProjA.

Docs (Doxygen)

There is a default doc target in the CMakeLists.txt, which is built when you type "make doc". You must have doxygen installed on your system for this to work. See source code for hints on how to write doxygen comments. You can customize the output by editing config files in the doc directory.

Documentation is placed in: BUILD_DIR/doc BUILD_DIR is the build in which you say "make". After installation, it will go by default to /usr/local/share.

Tests

There are 2 dummy tests defined in the CMakeLists.txt. The unit test source is in the test directory. To run the dummy test, do "make test".

Boost

We include boost in the CMakeLists.txt using find_package(Boost ...) and passing a list of components we intend to use, namely unit_test_framework and program_options.

The former is to ease the development of unit tests and the latter is to help getting options for your binaries. See apps/hellorunner/main.cxx for an example.

SVN and Git

The project shows how to use Git or SVN revision number. In the main CMakeLists.txt we include one or the other by commenting and uncommenting the corresponding lines. It will define a CMake variable that will be used when generating libs/hello/Version.h.

GetGitRevisionDescription module has been added to the CMake folder in the "CMake" directory in order to retrieve branch and revision information from Git repository. Starting with Git 1.9 the module will be part of official cMake distribution, until then it has to be part of the application.

Packaging

CPack permits building packages based on CMake. One should add CPackConfig as it is done in the last line of the CMakeLists.txt. CPackConfig.cmake is in cmake folder and contains the required variables. If you do "make package" it will create a tarball, a .deb and an rpm.

Code formatting and beautifier

The file .clang-formatter contains a set of rules that one can use to adapt the source code to coding conventions. Clang has a number of predefined formatting rules but here we use a custom one. To use it one must first install clang. To run it on a single file and see the modified file content :

clang-format -style=file <source file> # from the top directory

To run it on all subdirectories and replace the content of the .cxx and .h files with the modified content :

find . -name *.cxx -o -name *.h | xargs clang-format -style=file -i

Remarks

CMake is cross-platforms. Thus there are commands that might be there only to be compatible with one or the other platforms. In this project we focus on Linux and removed most of these specificities for sake of simplicity.

For any question, please contact: Barthélémy von Haller ([email protected])

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].