CMake workflow and compiler flags, CPU settings

I started my first tries with CMAKE and JUCE. I’m a CMAKE beginner, but i was able to build the plugin with the command line, i also can open and build the project in CLion and export an XCode project.

I want to be able to build the plugins on all platforms with command line (expect the iOS build, where i want to use the XCode generator). I don’t know how i can configure things for each platform or if it isn’t required at all…

Would be great if someone can give me some answers to following questions:

  1. I have a shell script that executes all the CMAKE build / install steps and triggers the CMakeLists.txt. I imagine that the CMakeLists.txt is the same on all platforms and i start the same CMAKE on windows with a windows batch file. Is that ok this way?

  2. How can i configure for example static linking on windows or compiler optimisation flags for every platform? Is there a clean way to do this. I have tried target_compile_options but i’m not sure if it works (the flag is not set when i generate a XCode project). Any examples would be great.

  3. Will it work out of the box in linux. Do we still use make directly or do we also use cmake on lunix and does it automatically output a *.so file?

I know that this is CMAKE related, but i really hope that i get some answers here and best practices to work with CMAKE and JUCE. In the end i want to have the same configuration like i had with projucer.

Any input is welcome.

This doesn’t answer all of your questions but I recently add cmake support to pluginval and at the same time added GitHub Actions CI so I now have a single script that builds the apps, installers and signs, notarises etc. on each platform: https://github.com/Tracktion/pluginval/blob/develop/install/build

These days I’m preferring to use a single bash script for all platforms as its easier to maintain than a script per platform and there’s so much in common once you’ve set up the various variables for the platforms. I call out so larger platform specific scripts where needed like notarising.

Also of not that this project is an app, not a plugin so there may be some differences. Hopefully it serves as a useful reference though.

2 Likes

No CMake expert here either, but I’m currently trying to learn it myself through a small plugin side project :wink:

You can have a look at its CMakeLists.txt here, maybe it will help you

This can be easily achieved by e.g. if (APPLE) or similar blocks, that allow you to enable parts depending on the deployment platform, compiler or whatever

1 Like

Thanks for the answers. Hope i can also manage a to do all in a single script.

Thanks a lot for this. It helps a lot. Good to see that it can be done this way.

Don’t you set any compiler flags like “-O3” for speed optimization? Do i need this flag or is this already the default?

CMake has some standard build types predefined

I’m using CLion and you can create various profiles there that use these build types and manage it through this. Just found this screenshot of the profiles settings page where you can specify all this – its from a different project, but you see that you can also specify other options, such as a custom toolchain (which can be managed under the Toolchains tab – I used a self built GCC ARM toolchain here) and pass variables. In CLion you can then see the CMake command that is generated, I found this very convenient to getting started with it all.

1 Like

Ad 3. it worked out of the box for me on Linux.
Just be sure to install a CMake version that’s high enough (I think you should install at least 3.14 or 3.15). The apt package manager for instance is now still at 3.10, so I recommend to install a more recent version manually.

If that’s interesting for you, with CMake it’s also easy to compile on ARM devices (for me a RPi 4 using most recent Raspberry OS). You just need to add some flags:
TARGET_ARCH='-march=armv6' LDFLAGS=-latomic cmake .. -G "Unix Makefiles"

1 Like

Thanks for the replies. I got it working now.

I was able to do it with two different start scripts with the plugin name as parameter that install and build the JUCE cmake library (i don’t have JUCE in a subfolder) and the plugin. One for windows (normal batch file) and one for linux and os x. The make file itself is the same for all platforms.

I didn’t build an iOS app for the moment. I don’t think i can do this the same way. But we will see.