Skip to content

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

License

Notifications You must be signed in to change notification settings

jgonzalezdr/ProjectTemplateLib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CMake Library Project Template

Build status codecov

About

This repository is just a template for a library 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 ProjectTemplateLib in the project command with your own project name (leave the .Top suffix).

  2. Put the headers for your public functions and classes in lib/include/.

  3. Put the headers for your private functions and classes and the implementation files in lib/sources/.

  4. Edit lib/CMakeLists.txt and replace ProjectTemplate in the project command with your own project name (this time without the ".Top" suffix, and also don't use any "lib" prefix or suffix in the project name). This will be the base name for the library file. You may also update your project version in the project command.

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

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

  7. 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.
  8. Edit test/CMakeLists.txt and add all the subdirectories for your tests.

  9. To create example applications that use the library, copy the examples/ExampleTemplate/ directory to another directory under examples/ renaming it with the example name, then:

  • Rename the example implementation file ExampleTemplate.cpp according to your example's name.
  • Edit the examples's CMakeLists.txt:
    • Replace ProjectTemplate and ExampleTemplate in the project command with your own project name and example name (e.g. "YourProjectName.Test.YourExampleName").
    • Set the list of source files for the example.
  • Edit the example implementation file to add your tests.
  1. Edit examples/CMakeLists.txt and add all the subdirectories for your examples.

  2. Delete all example files and directories from the examples/, test/ and lib/ directories.

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

  4. 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).

  5. 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_SHARED_LIB Enables generation of shared library
ON(default)
OFF
-DBUILD_STATIC_LIB Enables generation of static library
ON(default)
OFF
-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
-DBUILD_EXAMPLES Enables building examples
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)

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published