This is a basic Cmake project snippet for x86 linux based applications. It tries to cover most of the most important topics in project development in the minimal but functional form. This minimal approach helps with understanding the topic. The project intentionally contains some bugs in code to show that the verification works.
The project contains of three folders: doc, objLibEx and libEx.
This folder contains the example of Doxygen documentation.
This folder contains an example of the Object library. It contains the main function but doesn't create an application. It is created by the top level CMakeLists.txt file instead.
This folder contains an example of the library, GoogleTests and library installation.
The project can be compile using the Docker-based development environment.
Important
- Export
UIDto expose the user id as an environment variable by callingexport UID=${UID}1.
Run the following command to compile and run the complete suite
docker compose build && docker compose up -dCode formatting is based on
clang-format
utility. It uses the ./.clang-format file containing the style configuration.
The code formatting operation will not be triggered by build but can
be manually/automatically triggered by the IDE.
Hit Ctrl+Shift+P and search for Open User Settings.
Search for format and select Editor: Format On Save.
Static analysis is done using cppcheck
tool. Custom target scheck is handling the static analysis process. This
target is a part of the ALL group which means that it'll be run automatically
by make when make or make all command is executed.
- Run
make scheckin the./buildfolder to start static analysis manually.
SonarQube is a very usefull on-the-fly static analysis tool for your Visual Studio Code.
Unit tests are using GoogleTest framework. This project uses an installed version of the GoogleTest framework.
- Run
ctest -VVin the./buildfolder to start tests.
Memory leaks detection is made using Valgrind utility.
- Run
ctest -T memcheckin the./buildfolder to start memory check.
Code coverage analysis is done using the gcov as the coverage testing utility and the gcovr for presentation.
- Navigate to the build folder.
- Run
cmake -DCMAKE_BUILD_TYPE=Coverage ..to configure coverage build. - Run
maketo build the application. - Run
ctest -VVto test the application. - Run
make coverageto get the coverage results.
Installation is done via the built-in CMake installation mechanism.
- Navigate to the build folder.
- Run
cmake -DCMAKE_BUILD_TYPE=Release ..to configure release build. - Run
maketo build the release. - Run
sudo make installto install application. - Use
-DCMAKE_INSTALL_PREFIX=/new/prefixif you want to change the default/usr/local/installation directory prefix. - Use
-DINSTALL_GTEST=OFFto prevent google tests installation with the application.
The example full build and installation:
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=/tmp/test-install \
-DCMAKE_BUILD_TYPE=Release -DINSTALL_GTEST=OFF ..
make all
make installThe AppImage creation process description can be found on the AppImage documentation pages. The best starting point for the CMake based projects is the build-with-cmake.sh script explained there.
The adapted version of this script has been added to this project as
make-appimage.sh.
- Run
./make-appimage.shto generate Appimage of this application.
Footnotes
-
This should be done even if there's an automatic Bash
UIDread only variable present since it is ignored by the docker. ↩