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 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, Google Test, Google Mock, Markdown, Bash script, Valgrind, LCOV Code Coverage, Clang-Tidy, ClangFormat, Doxygen, Graphviz, Lizard.
ProgrammingRepo
Deps
Projects
CppSampleProject
build
incl
Lib.h
src
main.cpp
App.h
App.cpp
CMakeLists.txt
src_lib
Lib.cpp
CMakeLists.txt
test
main.cpp
AppTestCases.cpp
LibTestCases.cpp
CMakeLists.txt
tools
CMakeLists.txt
-
ProgrammingRepo
*
It is a folder to store the projects and the dependencies. -
Deps
*
It is a folder to store the dependencies like Google Test.
Since this directory is at the same level as the Projects, many CppSampleProjects or other projects can use it and its contents. -
Projects
*
It is an umbrella folder to store the similar projects. -
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...). -
incl
It is a folder to store the library related include files. -
src
It is a folder to store the header and source files of the application. -
src_lib
It is a folder to store the library related source files. -
test
It is a folder to store the test related header and 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 ProgrammingRepo and Projects folders are prerequisites.
The Deps will be created implicitly in part Steps to resolve the dependencies.
The build will be created implicitly in part Steps of build.
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
The ProgrammingRepo and Projects folders have to exist. Other folder names can be used without code modification.
Move into the ProgrammingRepo folder and run:
cd Projects
git clone https://github.com/slali87/CppSampleProject.git
cd CppSampleProject
Open the build.config file and edit it if it is needed.
After that, move into the CppSampleProject folder and run the run.sh script with the following parameters.
On Windows, it should be run from git-bash or something like that.
./run.sh deps
It creates the Deps folder and fetches, builds the Google Test if any of them is missing.
./run.sh setup
./run.sh config
./run.sh build
./run.sh run
./run.sh test
cd ./build && ctest && cd -
The first command runs the application, the second runs the tests.
The third runs the tests by ctest.
./run.sh clean
./run.sh all
./run.sh setRel
./run.sh setDeb
The default mode is Release.
./run.sh valgrind
The Valgrind program has to be available on the machine.
The debug version of the executable has to be built.
./run.sh testCov
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.
./run.sh analyseCode
The Clang-Tidy program has to be available on the machine.
The './run.sh config' command has to be ran before running this.
./run.sh formatCode
The ClangFormat program has to be available on the machine.
./run.sh doc
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.
./run.sh complex
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.
./run.sh createPatch
./run.sh applyPatch