[](https://github.com/TheLartians/ModernCppStarter/actions) [](https://github.com/TheLartians/ModernCppStarter/actions) [](https://github.com/TheLartians/ModernCppStarter/actions) [](https://github.com/TheLartians/ModernCppStarter/actions) [](https://github.com/TheLartians/ModernCppStarter/actions) [](https://codecov.io/gh/TheLartians/ModernCppStarter) # ModernCppStarter Setting up a new C++ project usually requires a significant amount of preparation and boilerplate code, even more so for modern C++ projects with tests, executables and contiguous integration. This template is the result of learnings from many previous projects and should help reduce the work required to setup up a modern C++ project. ## Features - Modern CMake practices - Suited for single header libraries and projects of any scale - Separation into library and executable code - Integrated test suite - Continuous integration via [GitHub Actions](https://help.github.com/en/actions/) - Code coverage via [codecov](https://codecov.io) - Code formatting enforced by [clang-format](https://clang.llvm.org/docs/ClangFormat.html) via [Format.cmake](https://github.com/TheLartians/Format.cmake) - Reproducible dependency management via [CPM.cmake](https://github.com/TheLartians/CPM.cmake) - Installable target with versioning information via [PackageProject.cmake](https://github.com/TheLartians/PackageProject.cmake) - Support for [sanitizer tools and more](#additional-tools) ## Usage ### Adjust the template to your needs - Use this repo [as a template](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-from-a-template) and replace all occurrences of "Greeter" in the relevant CMakeLists.txt with the name of your project - Replace the source files with your own - For single-header libraries: see the comments in [CMakeLists.txt](CMakeLists.txt) - Add your project's codecov token to your project's github secrets under `CODECOV_TOKEN` - Happy coding! Eventually, you can remove any unused files, such as the standalone directory or irrelevant github workflows for your project. Feel free to replace the License with one suited for your project. ### Build and run the standalone target Use the following command to build and run the executable target. ```bash cmake -Hstandalone -Bbuild/standalone cmake --build build/standalone ./build/standalone/Greeter --help ``` ### Build and run test suite Use the following commands from the project's root directory to run the test suite. ```bash cmake -Htest -Bbuild/test cmake --build build/test CTEST_OUTPUT_ON_FAILURE=1 cmake --build build/test --target test # or simply call the executable: ./build/test/GreeterTests ``` To collect code coverage information, run CMake with the `-DENABLE_TEST_COVERAGE=1` option. ### Run clang-format Use the following commands from the project's root directory to run clang-format (must be installed on the host system). ```bash cmake -Htest -Bbuild/test # view changes cmake --build build/test --target format # apply changes cmake --build build/test --target fix-format ``` See [Format.cmake](https://github.com/TheLartians/Format.cmake) for more options. ### Additional tools The project includes an [tools.cmake](cmake/tools.cmake) file that can be used to import additional tools on-demand through CMake configuration arguments. The following are currently supported. - `-DUSE_SANITIZER=
` - `-DUSE_CCACHE=