Basic C and C++ devcontainer with cmake, compiler warnings, clang-tidy and clang-format.
- ccache
- clang
- clang-tidy
- clang-format
- cmake
- cppcheck
- lldb
- vcpkg
- vscode
- clion
- Configure/build the project using the buttons in the vscode status bar
- Select the target to run in vscode
View > Command Palette... > CMake: Set Launch/Debug Target
- Run/Debug the selected target executable using the buttons in the vscode status bar
- Settings > Build, Execution, Deployment > Toolchains
- CMake: Change from Bundled to Custom CMake executable with value /usr/local/bin/cmake
- Debugger: Change from Bundled GDB to Custom LLDB executable with value /usr/bin/lldb
- Settings > Build, Execution, Deployment > CMake
- Delete Debug preset
- Enable clang-debug and clang-release presets
- Settings > Build, Execution, Deployment > Dynamic Analysis Tools > Sanitizers
- LeakSanitizer: Set LSAN_OPTIONS field to detect_leaks=0 (disables leak detection, required for running with the debugger)
- Create a new directory for each module in the
srcdirectory - Add
CMakeLists.txtin the new directory
cpprog_add_library(
TARGET exercise_1_lib # library will be called exercise_1_lib
CXX_MODULES # module source files here
"my_module_1.cpp"
"my_module_2.cpp"
DEPENDENCIES # libraries on which the library depends
datetime
)cpprog_add_executable(
TARGET exercise_1 # executable will be called exercise_1
CXX_MODULES # module source files here
"my_module_1.cpp"
"my_module_2.cpp"
CXX_SOURCES # old-style source files here
"main.cpp"
DEPENDENCIES # libraries on which the exercise depends
exercise_1_lib
)- Add the new directory to the
src/CMakeLists.txtfile after the lineadd_subdirectory(cpprog)
add_subdirectory(my_new_directory)- Configure/build the project using the buttons in the vscode status bar
- Select the target to run in vscode
View > Command Palette... > CMake: Set Launch/Debug Target
- Run/Debug the selected target executable using the buttons in the vscode status bar
- Add unittest source files to the
testdirectory - Add unittests to the
test/CMakeListst.txtfile
cpprog_add_test(
TARGET test_exercise_1 # test will be called test_exercise_1
CXX_SOURCES # unittest source files
"my_module_1.test.cpp"
DEPENDENCIES # libraries on which the test depends
exercise_1_lib
)- Run test from the
Testingactivity in the vscode action bar - View test results in the
Test Resultstab in the vscode bottom panel