Skip to content

rapid start the new C++ project, easy to debug and obtain profiling reports

Notifications You must be signed in to change notification settings

R3D9477/CppProjectTemplate_VSCodeCMakeTools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CppProjectTemplate_VSCodeCMakeTools

Universal template of C++ project, was made to rapid start the new C++ project, easy debug and profile it.
Configured over MS C/C++ Extension Pack extension.

LiveProcMon

LiveProcMon


Main tasks

  • CMake: Clean - run cmake.clean command + remove all Valgrind reports
  • CMake: Configure and Build - configure and run cmake.build command
  • CMake: Configure and Rebuild - configure and run cmake.cleanRebuild command
  • CMake: Configure with Conan Install - install conanfile.txt and run cmake.configure command
  • CppRunCurrentFile: Run/Debu - build, run & debug currently opened .cpp source file
  • LiveProcMon: Start Monitoring - start real-time monitoring of the target process (by default taken from cmake.launchTargetPath)
  • LiveProcMon: Stop Monitoring - stop monitoring
  • Valgrind: Show Memcheck Report - show profiler's report (check for memory leaks)
  • Valgrind: Show Cachegrind Report - show profiler's report (check for chache missings)
  • Valgrind: Show Callgrind Report - show profiler's report (check for tree of calls and theirs performing times)

Shortcuts (in status bar)

  • Debug
  • LiveProcMon: Start Monitoring
  • LiveProcMon: Stop Monitoring
  • Valgrind: Show Memcheck Report
  • Valgrind: Show Cachegrind Report
  • Valgrind: Show Callgrind Report
  • CppRunCurrentFile: Run/Debug

Features

  • uses CMake to manage the project, configured to use extension ms-vscode.cmake-tools
  • uses Conan, automatically downloads packages from conanfile.txt before building the project
  • easy to make and show Valgrind reports
  • LiveProcMon feature checks resources consumption of the launched application, easy to configure, strart and stop:
  • easy access to cppreference (via hotkey Ctrl+Shift+A) to get description of specified data type, method, etc
  • enabled auto linting (with clang-tidy)
  • enabled auto formatting (with clang-format)
  • automatically applies name of directory as name of a project/library
  • automatically finds and adds needed sources from certain folders, and includes them into the project's tree (described in Configure and Internal functions and variables description)
  • automatically adds (if possible) Boost, Qt5/Qt6 libraries
  • applies set of compiler's flags for extra safety: GCC, Clang or MSVC
  • automatically finds and adds unit tests (don't use the dot symbol '.' in the name of test's source file!)
  • for MSVC automatically copies MS Visual C++ runtime libs to target building directory

Basic project's stucture

ㅤㅤㅤㅤ[ PROJECT_FOLDER = PROJECT_NAME ]
ㅤㅤㅤㅤㅤㅤㅤㅤ|
ㅤㅤㅤㅤㅤㅤㅤㅤ|- CMakeLists.txt
ㅤㅤㅤㅤㅤㅤㅤㅤ|- src
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ|- main.cpp
ㅤㅤㅤㅤㅤㅤㅤㅤ|- test
ㅤㅤㅤㅤㅤㅤㅤㅤ|- lib
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ|- [ somelib ]
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ|
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ|- CMakeLists.txt
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ|- include
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ|- src
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ|- test
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ|- thirdparty
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ|
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ|- [ thirdlib ]
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ|
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ|- CMakeLists.txt
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ|- include
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ|- src
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ|- test


HOW TO

1. Install

  • 1.1. install gcc (e.g. apt install gcc gdb)
  • 1.2. install clang (e.g. apt install clang clang-tidy clang-format lldb)
  • 1.3. install python (e.g. apt install python3 python3-venv, do python3 -m venv ~/.local --system-site-packages and add ~/.local/bin to global PATH variable)
  • 1.4. install cmake (e.g. pip install cmake)
  • 1.5. install conan (e.g. pip install conan and do conan profile detect)
  • 1.6. install ploting tools (e.g. pip install gprof2dot matplotlib pillow)

2. Configure

  • 2.1. clone that repositoy to your local machine
  • 2.2. current source directory is ./src. if needed, change main sources directory HERE
  • 2.3. add some external libraries in CMakeLists.txt_a_Project_Libs.cmake
  • 2.4. add source of uint tests to folder test or add/change you testing configuration in CMakeLists.txt_b_Project_Tests.cmake
  • 2.5. change required libraries in conanfile.txt, the package manager will handle it automatically during first build
  • 2.6. if needed, you can customize safety flags for your current compiler: GCC, Clang or MSVC
  • 2.7. if neeeded, add HERE specific sources and includes of your current project (example you can see HERE)

3. Use

  • 3.1. for the first time it will be proposed to choose sertain development kit via standard menu of CMake Tools (the same as >CMake: Select a Kit)
  • 3.2. press F5 to build Debug version (variant selected by default in CMake Tools) and run debugging process (by default using LLDB, can be changed in launch.json)
  • 3.3. use additinal tasks for profiling:
    • LiveProcMon: Start Monitoring to check resources consumption at real-time
    • Valgrind: Show Memcheck Report, Valgrind: Show Callgrind Report and Valgrind: Show Cachegrind Report to get profiler's reports
    • CppRunCurrentFile: Run/Debug to compile and run currently snippet (e.g. single .cpp file located in folder test_cpp_snippets)

Internal functions and variables description

  • function get_sources_from_dir( SOURCES_DEST_VAR INCLUDES_DEST_VAR TARGET_FOLDER_PATH ) - scans TARGET_FOLDER_PATH (non-recursive globbing) and adds C++ files by the mask into variables: SOURCES_DEST_VAR (list of source files) and INCLUDES_DEST_VAR (list of include paths). examples of usage you can find HERE and HERE
  • variable OUTPUT_NAME - the name of the current target name (target executable file name). usually it the same as varibale PROJECT_NAME, but for Qt6 application it different: app${PROJECT_NAME}. example of usage you can find in CMakeLists.txt_z_Utils_Qt.cmake
  • variable SAFETY_FLAGS - contains the list of the compiler's flags (GCC, Clang or MSVC)

Used extensions

Tested on

  • Linux (GCC,Clang)
  • Windows (Clang,MinGW,MSVC)

Notes:

  • Valgrind reports feature currently available for Linux only
  • LiveProcMon feature currently available for Linux only

Links