Skip to content

Modern C++ Development Notes

Warning

This is a draft.

Build Generation (CMake)

cmake CMakeLists.txt
cmake_minimum_required(VERSION 3.23)
project(PROJECT_NAME)

add_subdirectory(src)

option(OPTION_NAME "Option Explanation" ON)

if (OPTION_NAME)
    message(STATUS "Building with option")
    add_subdirectory(tests)
endif()

VSCode Build & Debug C/C++

launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C/C++: g++ build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": true,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb",
            "preLaunchTask": "C/C++: g++ build active file"
        }
    ]
}
tasks.json
{
    "tasks": [
        {   
            "type": "cppbuild",
            "label": "C/C++: g++ build active file",
            "command": "/usr/bin/g++",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "*.cpp",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}