Starting with a Really Simple C++ Project¶
- Create a folder
<project>
with the name of your project and initializegit
git init <project>
- Start with
.gitignore
-whitelisting* !*.cc !*.h !CMakeLists.txt !README.md !.gitignore
- Create a file
README.md
and write down most important informations about your project. - For directly testing the source code create the file
doctest_main.cc
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN #include <doctest/doctest.h>
- Create a C++ source file with the name
<code>.cc
to write the actual code#include <doctest/doctest.h> // STL includes #include <iostream> // custom includes // namespace directives and declarations using namespace std; // actual code // test cases to test the actual code TEST_CASE(""){ // your checks and requirements }
- Create the file
CMakeLists.txt
for building the codecmake_minimum_required(3.10) project(<project> VERSION 0.1.0 LANGUAGES CXX) enable_testing() find_package(doctest REQUIRED) add_executable(main_test doctest_main.cc <code>.cc ) target_link_libraries(main_test PRIVATE doctest::doctest ) add_test(main_test main_test)
- Create a GitHub repository for your project, make the initial commit and push it to the master branch
git add . git commit -m "Initial commit" git remote add origin git@github.com:<user>/<project>.git git push origin master
- Initialize the build process
mkdir build cd build cmake ..
-
Use test-driven development cycle to write, test and commit new code
- Write test
- Make sure building or testing fails
- Write least simple code for a successful building and testing
- Make sure building and testing is successful.
- Commit the changes.
- Refactor the code for better design.
- Make sure building and testing is successful.
- Commit the changes.
Building and Testing:
cmake --build . ctest --verbose
Last update: July 11, 2020