# CMake questions

**URL:** <https://forum.juce.com/t/cmake-questions/52921>\
**Category:** General JUCE discussion\
**Created:** [September 8, 2022, 8:49am UTC](https://forum.juce.com/t/cmake-questions/52921 "2022-09-08T08:49:58Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![leehu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/leehu/32/3280_2.png) [@leehu](https://forum.juce.com/u/leehu)\
**Post date:** [September 8, 2022, 8:49am UTC](https://forum.juce.com/t/cmake-questions/52921/1 "2022-09-08T08:49:59Z")

</div>

Hi, so I’m looking at moving over to CMake and have some questions for those in the know.

1. Is it possible to specify different paths for different systems, e.g. juce\_set\_vst2\_sdk\_path which will be different on Mac and Windows
2. Is it possible to have differences between Debug and Release builds, e.g. different defines sometimes set for release build for example
3. Is it possible to manage different schemes, for example in some of my projects I have V1 and V2 builds which contain different build defines
4. Do I need to do anything special for my modules that I have or do I just include them in CMakeLists like I would a juce module?

thx

---

<div class="post-metadata">

**Author:** ![vallant](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@vallant](https://forum.juce.com/u/vallant)\
**Post date:** [September 8, 2022, 10:09am UTC](https://forum.juce.com/t/cmake-questions/52921/2 "2022-09-08T10:09:15Z")

</div>

1. Sure, you can use something like:

```auto
if (WIN32)
  juce_set_vst2_sdk_path (<win_path>)
elseif (APPLE)
    juce_set_vst2_sdk_path (<mac_path>)
endif()

```

1. This depends on the build system you want to use, especially if you use a multi-config exporter (xcodebuild/msbuild) or a single-config exporter (ninja, nmake, make).  
The difference is that with single-config exporter the build-type is known when you invoke cmake, in that case you can simply query the `CMAKE_BUILD_TYPE` variable:

```auto
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
  target_compile_definitions (<target> PRIVATE "YOUR_DEBUG_FLAG")
elseif (CMAKE_BUILD_TYPE STREQUAL "Release")
    target_compile_definitions (<target> PRIVATE "YOUR_RELEASE_FLAG")
endif()

```

In case you’re using a multi-config exporter (default on windows), you need to use [generator expressions](https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html), as the build type is not known when you invoke cmake. Then you’d probably use something like:

```auto
target_compile_definitions (<target> PRIVATE $<$<CONFIG:Debug>:"YOUR_DEBUG_FLAG">)
target_compile_definitions (<target> PRIVATE $<$<CONFIG:Release>:"YOUR_RELEASE_FLAG">)

```

1. As you can use different compiler definitions depending on your build type, you can also define your own cmake-variables. E.g. you could configure a [cmake option](https://cmake.org/cmake/help/latest/command/option.html) for you project version and change the flags like this:

```auto
...
option(YOUR_PROJECT_VERSION "Determins the version of the project" 1)
...
if (YOUR_PROJECT_VERSION STREQUAL "1")
    target_compile_definitions (<target> PRIVATE "BUILD_VERSION_1")
elseif (YOUR_PROJECT_VERSION STREQUAL "2")
    target_compile_definitions (<target> PRIVATE "BUILD_VERSION_2")
endif()

```

and change the option when invoking cmake:  
`cmake .. -D YOUR_PROJECT_VERSION=2`

1. No, just make sure that you incude juce first.

---

<div class="post-metadata">

**Author:** ![leehu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/leehu/32/3280_2.png) [@leehu](https://forum.juce.com/u/leehu)\
**Post date:** [September 8, 2022, 10:28am UTC](https://forum.juce.com/t/cmake-questions/52921/3 "2022-09-08T10:28:39Z")

</div>

thanks for that - really helpful 🙂

regarding 4, not quite sure what you mean.

I’m adding a module and then looking at the generated JuceHeader.h which is different to the one generated by producer, which contains includes for the module header file, whereas the cmake one doesn’t. is that to be expected? thx

---

<div class="post-metadata">

**Author:** ![gyohng1](https://avatars.discourse-cdn.com/v4/letter/g/e274bd/32.png) [@gyohng1](https://forum.juce.com/u/gyohng1)\
**Post date:** [September 8, 2022, 10:49am UTC](https://forum.juce.com/t/cmake-questions/52921/4 "2022-09-08T10:49:20Z")

</div>

Check this out, this is a full CMake-based template for a plugin with support for all formats (AAX, AU, AUv3, VST2, VST3), Mac and Windows, and it doesn’t even require a full installed version of XCode on Mac:

> **[GitHub - gyohng/NewJucePluginTemplate: New JUCE Plugin template for CLion /...](https://github.com/gyohng/NewJucePluginTemplate)**
>
> New JUCE Plugin template for CLion / CMake with some JUCE patches - GitHub - gyohng/NewJucePluginTemplate: New JUCE Plugin template for CLion / CMake with some JUCE patches

I discovered that recent JUCE bundles VST3 SDK, and only a few extra files are necessary to support VST2, so the vst2 SDK path is short-circuited to the same location where JUCE stores VST3.

Where possible, JUCE is configured and patched to generate binaries that should be still compatible with Mac OSX 10.9

---

<div class="post-metadata">

**Author:** ![leehu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/leehu/32/3280_2.png) [@leehu](https://forum.juce.com/u/leehu)\
**Post date:** [September 8, 2022, 11:27am UTC](https://forum.juce.com/t/cmake-questions/52921/5 "2022-09-08T11:27:12Z")

</div>

thx, looks interesting, will definitely explore.

No custom modules it seems though so not sure it’ll fix the problem I’m having… thx

---

<div class="post-metadata">

**Author:** ![vallant](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@vallant](https://forum.juce.com/u/vallant)\
**Post date:** [September 8, 2022, 11:47am UTC](https://forum.juce.com/t/cmake-questions/52921/6 "2022-09-08T11:47:09Z")

</div>

I think that all you need is to call `juce_add_module (<path>)`, and then link against the module as you are doing with the JUCE-modules. If you’re including the `JuceHeader.h`, then you can probably simply use your modules without any problems.  
It is to be expected that the header-file looks different, since Projucer and CMake use different mechanisms to manage the includes!

---

<div class="post-metadata">

**Author:** ![PluginPenguin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/pluginpenguin/32/10203_2.png) [@PluginPenguin](https://forum.juce.com/u/PluginPenguin)\
**Post date:** [September 8, 2022, 12:00pm UTC](https://forum.juce.com/t/cmake-questions/52921/7 "2022-09-08T12:00:02Z")

</div>

Note that in case you want to use the old `JuceHeader.h` approach, you have to explicitly enable it in CMake via

```auto
juce_generate_juce_header (<target>)

```

This is the case as it’s not recommended best practice anymore to use it if I got it right, but it should work just fine with that comment in case your project relies on it.

The repo from @gyohng1 looks quite detailed. From my experience a lot less lines of cmake are needed to create a usual plugin, that should just work with macOS 10.9 by just setting the `CMAKE_OSX_DEPLOYMENT_TARGET` cache variable right. You might want to start simple with the JUCE example as a template [JUCE/CMakeLists.txt at master · juce-framework/JUCE · GitHub](https://github.com/juce-framework/JUCE/blob/master/examples/CMake/AudioPlugin/CMakeLists.txt). In case it’s helpful here is the CMakeLists.txt of an open source plugin by me, although there are also a few special solutions that are probably not relevant to your project, so I don’t recommend this as a template, just as some kind of inspiration [Schrammel\_OJD/CMakeLists.txt at master · JanosGit/Schrammel\_OJD · GitHub](https://github.com/JanosGit/Schrammel_OJD/blob/master/CMakeLists.txt)

---

<div class="post-metadata">

**Author:** ![yfede](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/yfede/32/506_2.png) [@yfede](https://forum.juce.com/u/yfede)\
**Post date:** [September 9, 2022, 8:20am UTC](https://forum.juce.com/t/cmake-questions/52921/10 "2022-09-09T08:20:17Z")

</div>

Very interesting topic, thanks!

Let me add one such question myself about CMake: is it possible to specify pre- and post- build scripts?

In my projects, I have cross-platform python scripts that take care of several operations that must happen before and after each build, and it would be absolutely a pain to re-implement them in “native” CMake. Transition would be much easier if I could simply tell CMake to execute them for me.

---

<div class="post-metadata">

**Author:** ![vallant](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@vallant](https://forum.juce.com/u/vallant)\
**Post date:** [September 9, 2022, 8:31am UTC](https://forum.juce.com/t/cmake-questions/52921/11 "2022-09-09T08:31:44Z")

</div>

For post-build scripts you can use [custom commands](https://cmake.org/cmake/help/latest/command/add_custom_command.html):

```
add_custom_command (TARGET <target> POST_BUILD COMMAND <command>)

```

Pre-built scripts are slightly more annoying. While you can use `add_custom_command` with a `PRE_BUILD` argument, with all build systems except for `msbuild` this will actually be post-compile pre-link, so probably not what you want.  
Therefore the usual way is to add a [custom target](https://cmake.org/cmake/help/latest/command/add_custom_target.html) and add it as dependency to your actual target:

```
add_custom_target (<target>_PrebuiltScript COMMAND <command>)
add_dependency (<target> <target>_PrebuiltScript)

```

---

<div class="post-metadata">

**Author:** ![leehu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/leehu/32/3280_2.png) [@leehu](https://forum.juce.com/u/leehu)\
**Post date:** [September 9, 2022, 9:21am UTC](https://forum.juce.com/t/cmake-questions/52921/12 "2022-09-09T09:21:36Z")

</div>

Thanks for all the input from everyone - will be giving this a good go tomorrow

---

<div class="post-metadata">

**Author:** ![leehu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/leehu/32/3280_2.png) [@leehu](https://forum.juce.com/u/leehu)\
**Post date:** [September 10, 2022, 12:47pm UTC](https://forum.juce.com/t/cmake-questions/52921/13 "2022-09-10T12:47:32Z")

</div>

Hi, things going pretty well but for some reason get this unresolved:

Undefined symbols for architecture arm64:  
“juce::OnlineUnlockStatus::MachineIDUtilities::getUniqueMachineID()”, referenced from:

I’ve included the juce::juce\_cryptography target in target\_link\_libraries. Obvs finding the headers ok, but not linking. Any suggestions? thx

---

<div class="post-metadata">

**Author:** ![benvining](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/benvining/32/9922_2.png) [@benvining](https://forum.juce.com/u/benvining)\
**Post date:** [September 10, 2022, 3:30pm UTC](https://forum.juce.com/t/cmake-questions/52921/14 "2022-09-10T15:30:02Z")

</div>

I think that class is in the juce\_product\_unlocking module?

---

<div class="post-metadata">

**Author:** ![leehu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/leehu/32/3280_2.png) [@leehu](https://forum.juce.com/u/leehu)\
**Post date:** [September 10, 2022, 9:11pm UTC](https://forum.juce.com/t/cmake-questions/52921/15 "2022-09-10T21:11:56Z")

</div>

ah, yes, thx - thought it was part of cryptography

---

<div class="post-metadata">

**Author:** ![leehu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/leehu/32/3280_2.png) [@leehu](https://forum.juce.com/u/leehu)\
**Post date:** [September 10, 2022, 9:19pm UTC](https://forum.juce.com/t/cmake-questions/52921/16 "2022-09-10T21:19:40Z")

</div>

thx - I’m after a post-build step to copy the generated application folder into /Applications. Can this be done?

---

<div class="post-metadata">

**Author:** ![vallant](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@vallant](https://forum.juce.com/u/vallant)\
**Post date:** [September 12, 2022, 7:38am UTC](https://forum.juce.com/t/cmake-questions/52921/17 "2022-09-12T07:38:02Z")

</div>

Sure, for example you could use the CMake [command-line tool mode](https://cmake.org/cmake/help/latest/manual/cmake.1.html#run-a-command-line-tool):

```
get_target_property (OUTPUT_DIR <target> RUNTIME_OUTPUT_DIRECTORY)
add_custom_command (TARGET <target> POST_BUILD COMMAND ${CMAKE_COMMAND} -R copy_directory ${OUTPUT_DIR} /Applications)

```

Note that it might be necessary to adapt the command since macOS is using bundles instead of plain executables like windows.

---

<div class="post-metadata">

**Author:** ![leehu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/leehu/32/3280_2.png) [@leehu](https://forum.juce.com/u/leehu)\
**Post date:** [September 13, 2022, 7:14am UTC](https://forum.juce.com/t/cmake-questions/52921/18 "2022-09-13T07:14:27Z")

</div>

thanks for everyone’s help and tips - now have cmake build up and running for Mac.

I’m working on getting this working for Windows also and having issues. Please note this is a Windows 11 arm VM running under Parallels, and this is when trying to install JUCE. Normal builds run under Vis Studio 2022. Any tips? thx

C:\Users\lee\dev\JUCE\modules\juce\_core\native/juce\_win32\_SystemStats.cpp(27,10):  
warning C4163: ‘\_\_cpuid’: not available as an intrinsic function (compiling  
source file C:\Users\lee\dev\JUCE\modules\juce\_core\juce\_core.cpp)  
[C:\Users\lee\dev\JUCE\cmake-build-install\tools\extras\Build\juceaide\juceaide.vcxproj]

---

<div class="post-metadata">

**Author:** ![yfede](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/yfede/32/506_2.png) [@yfede](https://forum.juce.com/u/yfede)\
**Post date:** [September 13, 2022, 7:45am UTC](https://forum.juce.com/t/cmake-questions/52921/19 "2022-09-13T07:45:02Z")

</div>

I believe the error regarding \_\_cpuid has something to do with building for ARM, see here (there are proposed solutions at the end of the topic, don’t know if they work):

> [@Windows arm64 support](https://forum.juce.com/t/windows-arm64-support/47572):
>
> Are there any plans to add ARM64 support for windows10 and the upcoming windows11? I tried building Projucer for ARM64 with msvc, but it got stuck on \_\_cpuid and some other stuff that seems to exist only for x86/x64. I know I can run the x64 version of Projucer just fine, but ARM64 is only going to get bigger on windows and compared to rosetta2 on macOS the performance penalty is quite severe on windows. Of course it’s too early for plugins, but being able to compile Windows/ARM64 apps would be…

---

<div class="post-metadata">

**Author:** ![leehu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/leehu/32/3280_2.png) [@leehu](https://forum.juce.com/u/leehu)\
**Post date:** [September 13, 2022, 8:01am UTC](https://forum.juce.com/t/cmake-questions/52921/20 "2022-09-13T08:01:53Z")

</div>

thx - will check it out!

---

<div class="post-metadata">

**Author:** ![leehu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/leehu/32/3280_2.png) [@leehu](https://forum.juce.com/u/leehu)\
**Post date:** [September 13, 2022, 8:56am UTC](https://forum.juce.com/t/cmake-questions/52921/21 "2022-09-13T08:56:44Z")

</div>

Is there any reason why building a VST3 with Projuder just installs a .vst3 file to the destination directory, whereas with cmake it copies a whole folder across?

also CMAKE\_BUILD\_TYPE isn’t being used on Windows - seems ok on Mac

---

<div class="post-metadata">

**Author:** ![PluginPenguin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/pluginpenguin/32/10203_2.png) [@PluginPenguin](https://forum.juce.com/u/PluginPenguin)\
**Post date:** [September 13, 2022, 9:27am UTC](https://forum.juce.com/t/cmake-questions/52921/22 "2022-09-13T09:27:48Z")

</div>

I also had that question when we switched to CMake back then.

The folder is a vst3 bundle, which is the newer version of how vst3 should be distributed – similar to AU and AAX and is recommended by Steinberg for new plugins. The non-bundle format is still allowed for legacy compatibility reasons though.

I think as the CMake system was implemented later, they wanted to take the recommended route there while the Projucer solution with a plain file was created earlier and is left like that for backwards compatibility?

[Next page](https://forum.juce.com/t/cmake-questions/52921.md?page=2)
