How to use build types with CMake?

I am having some trouble getting my plugin to build in release mode, because I cannot correctly get CMake to set the BUILD_TYPE to “Release”. I am using a custom bash script to do it that uses an environment variable, BUILD_TYPE, to use the command cmake -B build -DCMAKE_BUILD_TYPE="$BUILD_TYPE".

I guess my question is do I use a flag and value in the build command or is this something I declare with CMake? If the latter, can I supply it an environment variable from my bash script?

Thanks for the help!

Which generator are you using? Only the single-configuration generators like GNU Makefiles and Ninja support CMAKE_BUILD_TYPE. For multi-config generators like Xcode and Visual Studio, the configuration can be chosen at build time, e.g.

cmake --build build-dir --configuration Release --target my_plugin_All
1 Like

Not entirely sure, but am nearly certain that I am using a multi-config one, most likely for VS2019.

But your answer solved my problem - I was just setting the configuration with a wrong flag. Thanks!

Edit - Except, now the command when using --config Release only builds a Plugin_SharedCode.lib file and no VST3 file. Do you know why this might be happening? Normally the execution continues after generating the base libraries from juce, but it’s now stopping before it starts generating the various platform code.

Here is some sample output:

Building (Garm)...

Microsoft (R) Build Engine version 16.5.0+d4cbfca49 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

  Checking File Globs
  Checking Build System
  Generating Garm_artefacts/JuceLibraryCode/JuceHeader.h
  Building Custom Rule C:/dev/repos/audio/garm/Garm/CMakeLists.txt
  Generating Code...
  Garm.vcxproj -> C:\dev\repos\audio\garm\build\Garm\Garm_artefacts\Debug\Garm_SharedCode.lib

Nevermind… it worked when I removed the --target Plugin flag from the commend, because my debug config had stopped working as well, but it’s fixed now. Doesn’t this mean I don’t have my target properly setup?

  • --target Garm only builds the shared library (Garm_SharedCode.lib).
  • --target Garm_VST3 builds only that plugin format (i.e. Garm_SharedCode.lib and Garm.vst3).
  • --target Garm_All builds all plugin formats (including Garm_SharedCode.lib).

I hope this helps.

1 Like