/ProjectTemplateShellApp

Template for a shell application built using CMake, and using cpputest for unit test execution

Primary LanguageCMakeThe UnlicenseUnlicense

CMake Shell Application Project Template

Build status codecov

About

This repository is just a template for a shell (command line) application built using CMake, and using cpputest for unit test execution.

Usage

  1. Download all the files from this repository as a ZIP file and unzip them to your project base directory.

The main branch is populated with some example files. You may download a version without any examples from the unpopulated branch.

  1. Edit the top level CMakeLists.txt and replace ProjectTemplate in the project command with your own project name (leave the .Top suffix).

  2. Put the headers for your private functions and classes and the implementation files in app/sources/.

  3. Edit app/CMakeLists.txt and replace ProjectTemplate in the project command with your own project name (this time without any suffix). This will be the base name for the executable file. You may also update your project version in the project command.

  4. Edit app/CMakeLists.txt and set the list of source and header files, and modify any other parameters that you like.

  5. Add your common mocks and expectation functions to test/Mocks.

  6. To create unit tests, copy the test/TestTemplate/ directory to another directory under test/ renaming it with the test name, then:

    • Rename the test implementation file TestModule_test.cpp according to your test module name (It's recommended to leave the _ test suffix).
    • Edit the test's CMakeLists.txt:
      • Replace ProjectTemplate and TestModule in the project command with your own project name and test module name (e.g. "YourProjectName.Test.YourTestModuleName").
      • Set the list of production source files to be tested, and the list of test source files (test, mocks, other test helper functions, etc.).
    • Edit the test implementation file to add your tests.
  7. Edit test/CMakeLists.txt and add all the subdirectories for your tests.

  8. Delete all example files and directories from the test/ and app/ directories.

  9. Replace LICENSE.txt with your project's license file.

  10. Create a build directory under the top directory (e.g. build/), and inside it execute cmake .. G "<GeneratorOfYourChoice>" (add any other configuration options that you like).

  11. Modify appveyor.yml (or delete it) according to your continouous integration needs.

CMake Project Options

OPTION Description
-DCMAKE_BUILD_TYPE Selects build type
(only for single-config generators)
Debug
Release(default)
RelWithDebInfo (Release with debug info)
MinSizeRel(Release with size optimization)
Coverage(Debug with code coverage enabled)
-DBUILD_TESTING Enables compilation and execution of tests
ON(default)
OFF
-DCPPUTEST_HOME Path to your CppUTest installation directory
<filesystem path>
-DLCOV_HOME Path to your LCOV installation directory
<filesystem path>
-DENABLE_INSTALLER Enables generation of installer packages
ON(default)
OFF
-DCOVERAGE Enables code coverage in tests
(only for multi-config generators)
ON(default)
OFF
-DCOVERAGE_VERBOSE Enables verbose code coverage
ON
OFF(default)
-DCI_MODE Enables Continous Integration mode
ON
OFF(default)

Requirements

  • cmake (≥ v3.3, tested with v3.22.2)
  • CppUTest [Optional, not needed if tests are disabled] (≥ v4.0, tested with v4.0-gdr0)
  • On Windows:
  • On Linux:
    • GCC (tested with v7.5.0, v8.4.0 and v9.3.0)
    • LCOV [Optional, needed if tests and coverage are enabled using GCC] (tested with v1.14)