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/VSCodeCppIDE_Template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Dec 14, 2024
68d67c2 · Dec 14, 2024
Dec 3, 2024
Nov 2, 2024
Dec 14, 2024
Oct 30, 2024
Dec 14, 2024
Aug 13, 2024
Aug 12, 2024
Aug 13, 2024
Jul 19, 2024
Nov 19, 2024
Dec 4, 2024
Dec 4, 2024
Nov 20, 2024
Nov 20, 2024
Nov 20, 2024
Nov 20, 2024
Dec 14, 2024
Nov 30, 2024
Dec 2, 2024

Repository files navigation

VSCodeCppIDE_Template

Template of C++ project with config to make a VSCode be IDE-like with set of useful features for simplier development life.

Features

  • configured to run as on host, as inside Docker
  • uses CMake to manage the project
  • configured to work with package managers (automatically downloads and sets packages during project configuration)
    • by default uses vcpkg and vcpkg.json (should be defined environment variable VCPKG_ROOT)
    • can use Conan and conanfile.txt (should NOT be defined environment variable VCPKG_ROOT)
  • easy to make and show Valgrind reports
    • Memcheck
    • Cachegrind
    • Callgrind
  • LiveProcMon feature shows resources consumption of the launched application on the charts
  • CppRunCurrentFile feature to run & debug currently opened C++ snippet
  • easy access to cppreference (via hotkey Ctrl+Shift+A) to get description of specified data type, method, etc
  • enabled auto linting (with clang-tidy) and 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 and Qt6 libraries (installed via package manager)
  • 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

CppEditor

LiveProcMon

Callgrind

Main tasks

  • C++ Project: Clean - runs cmake.clean command + remove all Valgrind reports
  • C++ Project: Configure and Build - configure and run cmake.build command
  • C++ Project: Configure and Rebuild - configure and run cmake.cleanRebuild command
  • C++ Project: Configure and Install Packages - install conanfile.txt and run cmake.configure command
  • CppRunCurrentFile: Run/Debug - 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
  • Fold level 4
  • Fold level 3
  • Fold level 2
  • Fold level 1
  • Unfold all

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 and Open

Variant #1: Inside Docker
Variant #2: On your host machine
  • 1.2.1. install gcc (e.g. apt install gcc gdb)
  • 1.2.2. install clang (e.g. apt install clang clang-tidy clang-format lldb)
  • 1.2.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.2.4. install cmake (e.g. pip install cmake)
  • 1.2.5. install conan (e.g. pip install conan and do conan profile detect)
  • 1.2.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 vcpkg.json or in conanfile.txt, the package manager will handle it automatically during the 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

3. Use

  • 3.1. run task Terminal>Run Task>Project: Configure with Conan Install
  • 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).
  • 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}.
  • 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


If you like that repo, you can support me, I really appreciate it ❤️ ko-fi