This is a cross-platform C++ sample project which presents a base project structure which is ideal to develop many projects in parallel. The dependencies are organized into one common place by Conan in order to avoid its unnecessary downloading and building. It contains templates to create libraries and applications (executable programs) as well. It uses CMake, Git, GitHub, Conan, Google Test, Google Mock, Markdown, Bash script, Valgrind, LCOV Code Coverage, Clang-Tidy, ClangFormat, Doxygen, Graphviz, Lizard.
.
└── CppSampleProject
├── build
│ ├── Debug
│ └── Release
├── cmake
├── src
│ ├── CMakeLists.txt
│ ├── app
│ │ ├── CMakeLists.txt
│ │ ├── app.cpp
│ │ ├── include
│ │ │ └── app.hpp
│ │ └── main.cpp
│ └── lib
│ ├── CMakeLists.txt
│ ├── include
│ │ └── lib
│ │ ├── iLib.hpp
│ │ └── lib.hpp
│ └── lib.cpp
├── test
│ ├── CMakeLists.txt
│ ├── app
│ │ └── appTest.cpp
│ └── lib
│ ├── libTest.cpp
│ └── mock
│ └── lib
│ └── libMock.hpp
├── tools
└── CMakeLists.txt
-
CppSampleProject
This is the root folder of this Git repository.
It can be renamed without code modification. -
build
*
It is a folder to store the generated files (builds, reports, documents...). -
cmake
It is a folder to store the CMake script files. -
src
It is a folder to store the source files of the application and the library. -
test
It is a folder to store the test related source files. -
tools
It is a folder to store the tools and scripts.
*
Please note that the folders - marked with *
- are not part of this Git repository!
The build will be created implicitly in part Steps to resolve the dependencies and set up the project:.
The project has been tested on:
- Linux (Gcc)
- Windows (MinGW)
The following programs have to be installed and directly available (added into PATH) on the machine:
- a C++ compiler
- CMake
- Git
- Conan
- Python
Run the following commands:
git clone https://github.com/slali87/CppSampleProject.git
cd CppSampleProject
cmake -P cmake/setup.cmake
cmake -P cmake/build.cmake
cmake -P cmake/run.cmake
cmake -P cmake/test.cmake
The first command runs the application, the second runs the tests.
The ctest command also works:
ctest --test-dir ./build/Release/test # For Release
ctest --test-dir ./build/Debug/test # For Debug
cmake -P cmake/clean.cmake
cmake -P cmake/all.cmake
cmake -P cmake/setRelease.cmake
cmake -P cmake/setDebug.cmake
The default mode is Release.
cmake -P cmake/valgrind.cmake
The Valgrind program has to be available on the machine.
The debug version of the executable has to be built.
cmake -P cmake/testCov.cmake
The LCOV Code Coverage program has to be available on the machine.
The report will be saved into the build directory; the main file is "./build/TestCov/CodeCoverage/index.html".
Online the code coverage of the latest version can be found here: Code coverage.
Please note:
- It detects that each Google test`s TEST macro runs multiple times, instead of 1.
- The test files are also checked by design to detect if all tests are run and there is no dead code in the test part; but the branch coverage is not applicable for the tests.
cmake -P cmake/analyseCode.cmake
The Clang-Tidy program has to be available on the machine.
The './run.sh config' command has to be ran before running this.
cmake -P cmake/formatCode.cmake
The ClangFormat program has to be available on the machine.
cmake -P cmake/doxygen.cmake
The Doxygen and the Graphviz programs have to be available on the machine.
The doc will be saved into the build directory; the main file is "./build/Doc/html/index.html".
Online the documentation about the latest version can be found here: Documentation.
cmake -P cmake/complex.cmake
The Lizard program has to be available on the machine.
A codecloud picture will be saved into the build directory; the file is "./build/codecloud.html".
Online the pic about the latest version can be found here: Codecloud.
cmake -P cmake/createPatch.cmake
cmake -P cmake/applyPatch.cmake