Improving build times with Clion Cmake

Hi,
I am seeking for some advice on best practices for builds.

I am using Clion and Cmake. One problem that i noticed lately (i believe it was not happening in the past) is when i switch between building Release and Debug, it takes a few of minutes, without having changed any code.
I build the Release, then switch and build the Debug, then switch to build the Release again and it is building it from the beginning. Switch to Debug the same happens.
The messages are:
[2/20] Building CXX object CMakeFiles
Up to…
[19/20] Linking CXX static library
[20/20] Linking CXX CFBundle shared module
Is there a way to improve this? Why is it building again? No code was changed, and each Cmake build type has its own directory.

The second question is how to improve the build times with Juce. I saw some posts on creating Juce as a static library but not recommended and this would mean that the header files can not be used.
Is there another way to avoid building all the used Juce modules again on every build?

Thank you!

This is expected. Debug and release builds are totally separate builds that hold no shared caches between them.

Having that said you can improve your build times (in both debug and release) dramatically by switching to unity builds and write your code in a JUCE-modules-style format.

I just reread your original post and I think you have another issue: in CLion make sure both debug and release are configured at the same time (so you see both debug/release as options in the build menu).

In that case it should use the build caches after one build and not rebuild anything.

If you will re-configure the project with another build type instead, all your caches will be lost when building.

Thank you @eyalamir for the advice!
I have them as separate Cmake profiles in Clion

Are there any examples on how to use Unity build and Juce? Will it prevent from recompiling all the Juce modules every time I build or switch from Release to Debug?

Btw, I tried ccache set(CMAKE_CXX_COMPILER_LAUNCHER ccache) but it did not make any difference (Installed with brew on the Mac)

Upon more testing ccache makes a difference when building Debug and RelWithDebInfo. It also helps when switching between Debug and RelWithDebInfo.

When I build a clean Debug, it takes 1 min and 10 seconds to finish. I click again to build Debug, prints Build Finished immediately.
If i click to build again, this time it takes 5 seconds.
The same happens with RelWithDebInfo.
Switching between Debug and RelWithDebInfo also builds fast, which is good, because I can use RelWithDebInfo instead of Release which takes a lot of time.

Without ccache, the second time i build, it starts building all [1/20] Building CXX object CMakeFiles
and it takes 32 seconds to build.

In Release though using ccache, the original build takes 51 seconds. The second time i click build, it prints Build Finished immediately. Then when building again it takes 51 seconds, so ccache seems to make no difference.

Switching to Debug and build, takes 5 seconds.
Then switching to Release and build, took 47 seconds.
Then switching to RelWithDebInfo and build, took 5 seconds.
Going back to Debug and build, takes 5 seconds.

So, it seems ccache makes a difference and switching between Debug and RelWithDebInfo is much better than switching between Debug and Release.

Perhaps with unity_build this can be improved.
If I want to build all plugins (VST3/AU/AAX) it totals up to 12 plugins, so build times make a lot of difference :slight_smile:
The timings above are for building only one plugin.

You absolutely shouldn’t be using ccache for this. The default caching for the build system should ‘just work’.

For me, going between debug/release in CLion with no code changes I get a ‘ninja: no work to do’ message with 0 seconds of build time. The only times I get a full rebuild is if I changed something since the last build on that target.

When you say switching between debug and release though, are you just clicking the dropdown and switching (what you should be doing)? Or a you doing some more heavyweight thing during the switch?

Otherwise I would check if you did something in your prebuild scripts that forces a rebuild. I would compare it with a JUCE template for example.

OMG you are right. I had a simple pre-build script added a few days ago.
:face_with_spiral_eyes: