A template application for C++ with CMake and GoogleTest
A CMake file template and sample C++ application which allows unit test by GoogleTest. This template application is :
- Able to collaborate with Visual Studio CODE editor.
- Build in GoogleTest which is downloaded automatically.
- "src" directory for application source code.
- "test" directory for unit tests.
- std::thread aware.
- Generate Gcov data files during test ( except Windows platform )
- Tested:
- Ubuntu 20.04 with GCC.
- Windows 11 with Visual Studio C++ compiler.
- WSL2 with VS CODE remote server.
- Automatically tested by GitHub Actions.
- linux-latest, Debug (With gcovr report)
- linux-latest, Release
- windows-latest, Debug
- windows-latest, Release
- Ubuntu 20.04
- VS Code
- CMake 3.15 or newer
- Python 3
- g++
- Windows 10 or 11
- VS Code
- CMake 3.15 or newer
- Python 3
- Microsoft Visual C++ compiler
- Windows 10 or 11
- VS Code with Remote Development extension pack
- CMake 3.15 or newer
- Python 3
- g++
- ca-certificates
Run the followings command inside this directory ( Where README.md exists) to start the VS CODE:
code .
Inside VS CODE, Type Ctrl-Shift-P to show the command pallet. And then, execute following command :
CMake: Configure
Now, you can build, run the executable and Ctest from the status bar of the VS CODE.
Run the followings commands inside this directory ( Where README.md exists) :
mkdir build
cd build
cmake ..
cmake --build .
The executables are stored in the subdirectories:
- build/src
- build/test
In the case of MS Visual Studio C, the executables are located under the build configuration subdirectories like :
- build/src/Debug, build/src/Release
- build/test/Debug, build/test/Release
To run the Ctest, type :
ctest
Run followings on the shell.
sudo snap install code --classic
sudo apt-get install build-essential cmake doxygen
- Note 1: After installing VS CODE, install the C++ Extension Pack and the Gcov Viewer extension to the VS CODE.
Run followings on the PowerShell or Command .
winget install Microsoft.VisualStudioCode -e
winget install Kitware.CMake -e
winget install Microsoft.VisualStudio.2022.Community -e
winget install Git.Git -e
winget install Python.Python.3 -e
winget install doxygen -e
winget install graphviz -e
- Note 1: After installing VS CODE, install the C++ Extension Pack and the Gcov Viewer extension to the VS CODE.
- Note 2: The above winget install the CMake installer only. Run the CMake once and complete the installation.
- Note 3: The above wget install the VisualStudio launcher only. Install the C++ workload after winget installation.
After the installation, set the PATH environment variable for CMake, Visual Studio, Git and Graphviz.
Run followings on the PowerShell or Command to install the Visual Studio CODE editor.
winget install Microsoft.VisualStudioCode -e
Then, run followings on the Ubuntu shell.
sudo apt-get install build-essential cmake doxygen ca-certificates
- Note 1: After installing VS CODE, install the C++ Extension Pack and the Gcov Viewer extension to the VS CODE.
To change the project name, edit the CMakeLists.txt and change following line :
project("template_application")
The quoted string is the project name.
This project is shared with the MIT License.