I created a template in C++ for the integration of Catch2 in a generic project integrated in VScode environment. I provided the following files: src/Main.cpp, include/Header.hpp, test/Tests.cpp, CmakeLists.txt and .vscode/tasks.json and .vscode/launch. During the build, a new folder called build is created to collect the intermediate artifacts, while the final artifacts (the executable) is inside a created folder bin/Debug. Inside tasks.json I created three different tasks: Cmake configure, Cmake build and Cmake test. They can be retrieved using: Cntrl + Shift + P (VScode palette), then Tasks: Run Tasks and then selecting the proper task. Inside launch.json there is a generic call for the debugger.
Please provide a README for this project, noting the relevant information that I provided in this query. Moreover consider that this project will be used as template, so my expectation is that the user will git clone it, remove locally the git, create a new git and then synchronize it to a remote Gitlab.
Assistant
User
Please add some notes about how to run the code from the left bar menu Run and Debug (Ctrl + Shift + D) or debug (same command, name of the pre-configured launch: Windows GDB Debugger).
Assistant
Project Template for C++ Development with Catch2 and Visual Studio Code
This project template is designed to bootstrap C++ development with Catch2 integration in a Visual Studio Code (VSCode) environment.
Use the Command Palette to run the CMake configuration.
code
Ctrl + Shift + P
Then select:
code
Tasks: Run Task
And choose:
code
Cmake configure
2. Build the Project
To build the project, use the Command Palette.
code
Ctrl + Shift + P
Then select:
code
Tasks: Run Task
And choose:
code
Cmake build
The output executable will be placed in bin/Debug/.
3. Run Unit Tests
To execute Catch2 unit tests, follow these steps:
code
Ctrl + Shift + P
Then select:
code
Tasks: Run Task
And choose:
code
Cmake test
Debugging
The launch.json provided is a generic configuration to help you start debugging your C++ applications. Adjust it as necessary according to your environment and project needs.
Customization
Source Code: Modify src/Main.cpp, include/Header.hpp, and test/Tests.cpp to fit your specific project needs.
CMakeLists.txt: Make changes to this file to include additional source files, libraries, and set other configuration options.
VSCode Tasks and Launch Configurations: The .vscode/tasks.json and .vscode/launch.json are pre-configured for basic tasks and debugging. Customize them if needed.
CMakeLists.txt
Below is a template for the CMakeLists.txt provided within the project. Ensure you modify it as per your project structure and dependencies.
cmake
cmake_minimum_required(VERSION 3.10)
# Set the project name and version
project(MyProject VERSION 1.0)
# Specify the C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# Add executable
add_executable(MyProject src/Main.cpp)
# Include directories
target_include_directories(MyProject PUBLIC "${PROJECT_BINARY_DIR}")
target_include_directories(MyProject PUBLIC "include")
# Add Catch2 for testing
include(FetchContent)
FetchContent_Declare(
catch
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v2.13.4
)
FetchContent_MakeAvailable(catch)
add_executable(tests test/Tests.cpp)
target_link_libraries(tests Catch2::Catch2)
Contributing
When contributing to this repository, please submit an issue or make a pull request if you encounter any bugs or have improvements.
License
This project is licensed under the MIT License - see the LICENSE file for details.
This project template aims to streamline the setup process and promote a consistent development environment for C++ projects utilizing Catch2 in Visual Studio Code. Happy coding!
Project Template for C++ Development with Catch2 and Visual Studio Code
This project template is designed to bootstrap C++ development with Catch2 integration in a Visual Studio Code (VSCode) environment.
Use the Command Palette to run the CMake configuration.
code
Ctrl + Shift + P
Then select:
code
Tasks: Run Task
And choose:
code
Cmake configure
2. Build the Project
To build the project, use the Command Palette.
code
Ctrl + Shift + P
Then select:
code
Tasks: Run Task
And choose:
code
Cmake build
The output executable will be placed in bin/Debug/.
3. Run Unit Tests
To execute Catch2 unit tests, follow these steps:
code
Ctrl + Shift + P
Then select:
code
Tasks: Run Task
And choose:
code
Cmake test
Running and Debugging the Code in VSCode
Running the Code
You can run the code directly from the left sidebar menu in VSCode by following these steps:
Open the Run and Debug view by pressing Ctrl + Shift + D or by clicking on the Run icon in the left sidebar.
In the Run and Debug view, you will see a green play button at the top. Click this button to run your code using the pre-configured launch settings.
Debugging the Code
You can start a debugging session by following these steps:
Open the Run and Debug view (Ctrl + Shift + D or by clicking on the Run icon).
At the top of the Run and Debug view, open the configuration dropdown and select Windows GDB Debugger (or the relevant launcher if you’ve customized it).
Click the green play button or press F5 to start debugging.
This configuration will enable you to set breakpoints, watch variables, and step through your code to troubleshoot and understand its behavior.
Customization
Source Code: Modify src/Main.cpp, include/Header.hpp, and test/Tests.cpp to fit your specific project needs.
CMakeLists.txt: Make changes to this file to include additional source files, libraries, and set other configuration options.
VSCode Tasks and Launch Configurations: The .vscode/tasks.json and .vscode/launch.json are pre-configured for basic tasks and debugging. Customize them if needed.
CMakeLists.txt
Below is a template for the CMakeLists.txt provided within the project. Ensure you modify it as per your project structure and dependencies.
cmake
cmake_minimum_required(VERSION 3.10)
# Set the project name and version
project(MyProject VERSION 1.0)
# Specify the C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# Add executable
add_executable(MyProject src/Main.cpp)
# Include directories
target_include_directories(MyProject PUBLIC "${PROJECT_BINARY_DIR}")
target_include_directories(MyProject PUBLIC "include")
# Add Catch2 for testing
include(FetchContent)
FetchContent_Declare(
catch
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v2.13.4
)
FetchContent_MakeAvailable(catch)
add_executable(tests test/Tests.cpp)
target_link_libraries(tests Catch2::Catch2)
Contributing
When contributing to this repository, please submit an issue or make a pull request if you encounter any bugs or have improvements.
License
This project is licensed under the MIT License - see the LICENSE file for details.
This project template aims to streamline the setup process and promote a consistent development environment for C++ projects utilizing Catch2 in Visual Studio Code. Happy coding!