A project that illustrates how you can use CMakeUnit to test CMake code.
This is (or at least should be) a self-explanatory example.
-
generic
Examples illustrating key concepts behind CMakeUnit -
assertions
Examples illustrating usage of CMakeUnit assertions -
mocks
Examples illustrating usage of CMakeUnit mocks -
set
Example of how to test custom macro
In CMakeLists.txt do the following
- include CTest
- add the location of CMakeUnit to the CMAKE_MODULE_PATH (see the next section)
- optionally add the location of the source code to test to the CMAKE_MODULE_PATH
There are at least three ways to add CMakeUnit to your project:
-
Add CMakeUnit using
FetchContentand add CMakeUnit source folder to CMAKE_MODULE_PATH (see CMakeLists.txt). -
Add CMakeUnit as a git submodule and add path to CMakeUnit root folder to CMAKE_MODULE_PATH
list(PREPEND CMAKE_MODULE_PATH "path/to/CMakeUnit")
-
Add a copy of CMakeUnit.cmake to the folder of your choice and add this folder to CMAKE_MODULE_PATH
list(PREPEND CMAKE_MODULE_PATH "path/to/folder")
You may organize the code in the way the most suits your needs. CMakeUnit does not force anything in this matter. Readability should be the rule of thumb.