- VS Code, C++, CMake, Catch2, Juce
- By Anthony Leotta
- 1/15/2022
This project was created to serve as a reference on how to setup C++ project using CMake for builds, Catch2 for Unit Tests, VS Code as an IDE. Since most C++ projects will require an external library, I will provide example integrations of popular C++ lirabries such as Juce.
I'll list my motivations for creating and maintaining this repo:
- I want to use VS Code not Microsoft Visual Studio 2022 Community Edition as my IDE.
- I use VS Code on Linux for my day job.
- I like the search feature for VS Code.
- I like how VS Code displays error statements.
- I like how VS Code interactive step debugging works.
- I do want to build outside a IDE using the command line.
- I like that CMake not only supports the command line, it firmnly embraces it.
- There are many reasons to want to do your builds on the command line. I am using docker and kubernetes alot for my day job. I do docker builds many (>20) times a day on some days. My company also has Jenkins setup that does builds and runs unit tests as parf of Pull Request validation. My eyes are open to the fact that most operations really can't rely on a IDE and must be done on the command line.
I watched two Audio Programmer VLogs on CMake and Juce by Eyal Amir, Joshua Hodge, Rahcel Locke and Timur Doumler. Here are the links:
- CMake and JUCE 6 - What is CMake and Why Should I Use It?
- Audio Programmer Virtual Meetup - Jan 11 @ 18:30 GMT
I looked at CMake and became convinced that the features it offers solve many problems facing C++ developers. I was blown away by the fact that CMake downloads libraries from git or other locations on the net and then configures them based your platform and settings.
This is currently a Windows centric project. My plan is to eventually get this project working on Windows, Mac, Linux and Raspberry PI.
- Add examples of using other C++ libraries
- Add examples of using 3rd Party Juce Modules
- Tracktion Engine
- Organic UI
- Organic UI/Timeline
- so many others...
- I installed Microsoft Visual Studio 2022 Community Edition
- Supports 64 bit
- Feature packed
- Free
- Download and install CMake
- Test by running cmake on the command line
cmake --version
- Download and Install VS Code
- Install VS Code Plugins
- With CMake Tools installed, CMake is automated and will even configure when VS Code starts up.
- Cmake can be configured by launching a CMake Tools Extension command.
- F1
- CMake: Configure
- On Windows using Microsoft Visual Studio 2022, choose Microsoft Visual Studio 2022 Release - amd64
- Build by hitting the F7 key
- This is a basic C++ project.
- On Windows: build\01_Hello\Debug\hello.exe
- This is a basic C++ project with unit tests
- Downloads and configurs Catch2
- Adds Catch2 include to path
- Unit tests Catch2 header inclusion
#include <catch2/catch_test_macros.hpp>
- On Windows: build\01_Hello\Debug\hello2.exe
- On Windows: build\01_Hello\Debug\tests.exe
- Create a .vscode\launch.json file
- Add a section for 01_Hello
{ "name": "01 hello", "type": "cppvsdbg", "request": "launch", "program": "${workspaceFolder}/build/01_Hello/Debug/hello.exe", "args": [], "stopAtEntry": false, "cwd": "${fileDirname}", "environment": [], "console": "externalTerminal" }
- Add a sections for 02_Testing hello2 and tests
{ "name": "02 hello", "type": "cppvsdbg", "request": "launch", "program": "${workspaceFolder}/build/02_Testing/Debug/hello2.exe", "args": [], "stopAtEntry": false, "cwd": "${fileDirname}", "environment": [], "console": "externalTerminal" }, { "name": "02 tests", "type": "cppvsdbg", "request": "launch", "program": "${workspaceFolder}/build/02_Testing/Debug/tests.exe", "args": [], "stopAtEntry": false, "cwd": "${fileDirname}", "environment": [], "console": "externalTerminal" },
- Breakpoints can be set on executables and tests. In the below screen capture, the debugger is launched for a Catch2 unit test example.
- This is a basic Juce Hello example project.
- I started with the Projucer
- I needed to add juce_generate_juce_header(JuceHello)
- Juce is downloaded and configured
- Juce CMake extensions take over and do the heavy lifting
- Juce Framework is now installed for other applications in this series to use.
- I started with the Projucer
- On Windows: \build\03_JuceHello\JuceHello_artefacts\Debug\JuceHello.exe
- This is a basic Juce Audio Plugin supporting AU, VST3 and Standalone
- I started with the Projucer
- Projucer Plugin Characteristics
- Plugin is a Synth
- Plugin MIDI Input
- Plugin MIDI Output
- MIDI Effect Plugin
- No support for VST 2.4.
- This is a basic Juce UI Aplication
- The Projucer was not used.
- On Windows: \build\05_JuceUINoJucer\JuceUINoJucer_artefacts\Debug\JuceUINoJucer.exe