When setting out on a new project in C++ there are a few configuration steps which need to be completed prior to actually getting down to writing code. This repository is going to be a C++ project template that already has the following components:
- Directory Structure
- Make Build (CMake)
- Unit Test Framework (Google Test)
- API Documentation (Doxygen)
Feel free to fork this repository and tailor it to suit you.
-
Download Bash script to create new C++ projects
curl -O https://raw.githubusercontent.com/TimothyHelton/cpp_project_template/master/new_cpp_project.sh chmod u+x new_cpp_project.sh
-
Create new C++ project
./new_cpp_project.sh NewProjectName
-
In the project top level CMakeLists.txt: a. Line 4: Set the version of C++ to use. For example, let's set up the NewProject to use C++ 11.
cmake set(CMAKE_CXX_STANDARD 11) -
Update project description in the
Doxyfilelocated in thedocsdirectory.a. Update line
PROJECT_NUMBERThis is the version number of your project. b. Update linePROJECT_BRIEFAny text entered here will also appear on each documentation page. Try not to make this one too long. -
Reload the top CMake file.
I started using an IDE from JET Brains tailored for Python called PyCharm and thought it helped me write better code. I'd been wanting to learn C++ and decided to give JET Brains C/C++ IDE called CLion a try. The code completion, interactive suggestions, debugger, introspection tools, and built-in test execution are very handy. There are a couple extra details to set when using this IDE.
- The IDE allows you to mark directories with their desired purpose.
To mark a directory right click on the directory name in the
Projectwindow and selectMark Directory asfrom the drop-down menu.- Mark the
srcdirectory asProject Sources and Headers - Mark the
tests/lib/googletestdirectory asLibrary Files
- Mark the
- Setup the
Run/Debug Configurationby selectingEdit Configurations...from the pull-down menu from the run button (green triangle) in the upper right corner. A. Update Doxygen Build to execute the unit test suite. 1) Select Doxygen from the Application menu on the left. 2) Choose the executable for Doxygen to beUnit_Tests_run. B. Create aGoogle Testconfiguration 1) In the upper left corner select the plus symbol. 2) ChoseGoogle Testfrom the drop-down menu. 3) Set Name toUnit Tests. 4) Set Target toUnit_Tests_run.
That should be all it takes to start writing code. If you find any issues or bugs with this repository please file an issue on GitHub.
Hope you find this template useful and enjoy learning C++!