_____ __ __ __ _______ ___ __
/ ___/__ ___ ___ _/ /__ / /____ ___ / /_ / ___/ |/ /__ _/ /_____
/ (_ / _ \/ _ \/ _ `/ / -_) __/ -_|_-</ __/ / /__/ /|_/ / _ `/ '_/ -_)
\___/\___/\___/\_, /_/\__/\__/\__/___/\__/ \___/_/ /_/\_,_/_/\_\\__/
/___/
______ __
/ __/ /____ _____/ /____ ____
_\ \/ __/ _ `/ __/ __/ -_) __/
/___/\__/\_,_/_/ \__/\__/_/
- Clang >= 3.3 or GCC >= 4.8.1
- CMake >= 3.13
- Linux users should already have these tools.
- MacOS users with Xcode Developer Tools should already have these.
- Windows users may need to setup Cygwin to install these tools.
Clone/download the repo, then open CMakeLists.txt
in an IDE that supports CMake projects like CLion
┌─────────────┐ ┌─────────────┐
│ │ │ │
│ test1.cpp │ │ testN.cpp │
│ │ │ │
└─────────────┘ └─────────────┘
│ │
└───────┬─────────┘
▼
┌────────────┐ ┌─────────────┐ ┌──────────────┐
│ │ │ │ │ │
│ Test Lib │──∞────▶│ Test Bundle │◀──∞───│ App Bundle │
│ │ │ │ │ │
└────────────┘ └─────────────┘ └──────────────┘
▲ ▲
┌─∞───────┴────∞───┐ ┌─────────┴────────┐
│ │ │ │
┌──────────────┐ ┌──────────────┐ ┌─────────────┐ ┌─────────────┐
│ │ │ │ │ │ │ │
│ GoogleMock │ │ GoogleTest │ │ file1.cpp │ │ fileN.cpp │
│ │ │ │ │ │ │ │
└──────────────┘ └──────────────┘ └─────────────┘ └─────────────┘
- GoogleTest and GoogleMock are distributed as static libraries.
- We create a container static library (Test Lib) that statically links GoogleTest and GoogleMock
- All application sources get compiled into an App Bundle static library.
- All test sources get complied into a Test Bundle executable.
- We statically link Test Lib to Test Bundle because the latter depends on the gtest and gmock functionalities in the former.
- We also statically link App Bundle to Test Bundle, because the former is the payload under test.
- Finally, building the Test Bundle will build its dependencies (TestLib and App Bundle). Then you simply run the resulting executable.
Sets the flag CMAKE_TESTING_ENABLED, which activates additional processing required to register unit tests with ctest, for this and all subdirectories.
You can then add tests by calling add_test() in the CMakeLists.txt file in this or any subdir.
Adds a subdirectory to the build. On encountering this command, CMake halts and evaluates the CMakeLists.txt file in that subdirectory before continuing.
Adds an executable target called to be build from the listed source files.
Stores the list of all the files matching the expr in the variable.
Add a test to the project to be run by ctest.
You can specify the executable bundling all the tests as the test name.
Link a target to the listed libraries. The must have been created in the current directory using either add_executable() or add_library()
Specify include directories to use when compiling a given target. The named must have been created by a command such as add_executable() or add_library()
Make depend on all the targets listed as dependencies. The deps will be built before .
- An IMPORTED library target references a library file located outside the project. No rules are generated to build it.
The target name has scope in the directory in which it is created and below, but the GLOBAL option extends visibility. It may be referenced like any target built within the project.
This project was inspired by